|
3 | 3 | using EntityDb.Abstractions.Leases;
|
4 | 4 | using EntityDb.Abstractions.Loggers;
|
5 | 5 | using EntityDb.Abstractions.Queries;
|
| 6 | +using EntityDb.Abstractions.Queries.FilterBuilders; |
| 7 | +using EntityDb.Abstractions.Queries.SortBuilders; |
6 | 8 | using EntityDb.Abstractions.Transactions;
|
7 | 9 | using EntityDb.Common.Exceptions;
|
8 | 10 | using EntityDb.Common.Extensions;
|
@@ -736,6 +738,81 @@ public async Task GivenEntityInsertedWithLeases_WhenRemovingAllLeases_ThenFinalE
|
736 | 738 | actualFinalLeases.ShouldBeEmpty();
|
737 | 739 | }
|
738 | 740 |
|
| 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 | + |
739 | 816 | [Theory]
|
740 | 817 | [InlineData(60, 20, 30)]
|
741 | 818 | public async Task GivenTransactionAlreadyInserted_WhenQueryingByTransactionTimeStamp_ThenReturnExpectedObjects(int timeSpanInMinutes, int gteInMinutes, int lteInMinutes)
|
|
0 commit comments