Skip to content

Commit dbf791b

Browse files
test: ensure that repository inserts next command with version number equal to ExpectedPreviousVersionNumber + 1
1 parent 398b7f5 commit dbf791b

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

EntityDb.Abstractions/Transactions/ITransactionCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public interface ITransactionCommand<TEntity>
2121
/// <remarks>
2222
/// The repository must use a VersionNumber equal to <see cref="ExpectedPreviousVersionNumber"/> + 1.
2323
/// </remarks>
24-
//TODO: Make sure that the generic test suite verifies that this requirement is satisified.
2524
ulong ExpectedPreviousVersionNumber { get; }
2625

2726
/// <summary>

EntityDb.Common.Tests/Transactions/TransactionTestsBase.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using EntityDb.Abstractions.Leases;
44
using EntityDb.Abstractions.Loggers;
55
using EntityDb.Abstractions.Queries;
6+
using EntityDb.Abstractions.Queries.FilterBuilders;
7+
using EntityDb.Abstractions.Queries.SortBuilders;
68
using EntityDb.Abstractions.Transactions;
79
using EntityDb.Common.Exceptions;
810
using EntityDb.Common.Extensions;
@@ -736,6 +738,81 @@ public async Task GivenEntityInsertedWithLeases_WhenRemovingAllLeases_ThenFinalE
736738
actualFinalLeases.ShouldBeEmpty();
737739
}
738740

741+
[Fact]
742+
public async Task GivenTransactionCreatesEntity_WhenQueryingForVersisonOne_ThenReturnTheExpectedCommand()
743+
{
744+
// ARRANGE
745+
746+
var expectedCommand = new Count(1);
747+
748+
var transaction = _serviceProvider
749+
.GetTransactionBuilder<TransactionEntity>()
750+
.Create(Guid.NewGuid(), expectedCommand)
751+
.Build(Guid.NewGuid(), new NoSource());
752+
753+
var versionOneCommandQuery = new EntityVersionNumberQuery(1, 1);
754+
755+
using var transactionRepository = await CreateRepository();
756+
757+
// ACT
758+
759+
await transactionRepository.PutTransaction(transaction);
760+
761+
var newCommands = await transactionRepository.GetCommands(versionOneCommandQuery);
762+
763+
// ASSERT
764+
765+
transaction.Commands.Length.ShouldBe(1);
766+
767+
transaction.Commands[0].ExpectedPreviousVersionNumber.ShouldBe(default);
768+
769+
newCommands.Length.ShouldBe(1);
770+
771+
newCommands[0].ShouldBeEquivalentTo(expectedCommand);
772+
}
773+
774+
[Fact]
775+
public async Task GivenTransactionAppendsEntityWithOneVersion_WhenQueryingForVersionTwo_ThenReturnExpectedCommand()
776+
{
777+
// ARRANGE
778+
779+
var expectedCommand = new Count(2);
780+
781+
var entityId = Guid.NewGuid();
782+
783+
var transactionBuilder = _serviceProvider.GetTransactionBuilder<TransactionEntity>();
784+
785+
var firstTransaction = transactionBuilder
786+
.Create(entityId, new Count(1))
787+
.Build(Guid.NewGuid(), new NoSource());
788+
789+
var secondTransaction = transactionBuilder
790+
.Append(entityId, expectedCommand)
791+
.Build(Guid.NewGuid(), new NoSource());
792+
793+
var versionTwoCommandQuery = new EntityVersionNumberQuery(2, 2);
794+
795+
using var transactionRepository = await CreateRepository();
796+
797+
await transactionRepository.PutTransaction(firstTransaction);
798+
799+
// ACT
800+
801+
await transactionRepository.PutTransaction(secondTransaction);
802+
803+
var newCommands = await transactionRepository.GetCommands(versionTwoCommandQuery);
804+
805+
// ASSERT
806+
807+
secondTransaction.Commands.Length.ShouldBe(1);
808+
809+
secondTransaction.Commands[0].ExpectedPreviousVersionNumber.ShouldBe(1ul);
810+
811+
newCommands.Length.ShouldBe(1);
812+
813+
newCommands[0].ShouldBeEquivalentTo(expectedCommand);
814+
}
815+
739816
[Theory]
740817
[InlineData(60, 20, 30)]
741818
public async Task GivenTransactionAlreadyInserted_WhenQueryingByTransactionTimeStamp_ThenReturnExpectedObjects(int timeSpanInMinutes, int gteInMinutes, int lteInMinutes)

0 commit comments

Comments
 (0)