diff --git a/CoreUnitTests/Infrastructure/Model/TestDocument.cs b/CoreUnitTests/Infrastructure/Model/TestDocument.cs index 2985c16..9d09bf6 100644 --- a/CoreUnitTests/Infrastructure/Model/TestDocument.cs +++ b/CoreUnitTests/Infrastructure/Model/TestDocument.cs @@ -25,6 +25,8 @@ public class TestDocument : Document public int GroupingKey { get; set; } + public Guid OtherGroupingKey { get; set; } + public Nested Nested { get; set; } public List Children { get; set; } diff --git a/CoreUnitTests/Infrastructure/Model/TestDocumentWithKey.cs b/CoreUnitTests/Infrastructure/Model/TestDocumentWithKey.cs index 2a76873..a189b86 100644 --- a/CoreUnitTests/Infrastructure/Model/TestDocumentWithKey.cs +++ b/CoreUnitTests/Infrastructure/Model/TestDocumentWithKey.cs @@ -22,6 +22,8 @@ public class TestDocumentWithKey : IDocument public int SomeValue { get; set; } + public int SomeDecimalValue { get; set; } + public string SomeContent { get; set; } public string SomeContent2 { get; set; } public string SomeContent3 { get; set; } @@ -31,4 +33,4 @@ public class TestDocumentWithKey : IDocument public Nested Nested { get; set; } public List Children { get; set; } -} \ No newline at end of file +} diff --git a/CoreUnitTests/Infrastructure/TestReadOnlyMongoRepository.cs b/CoreUnitTests/Infrastructure/TestReadOnlyMongoRepository.cs new file mode 100644 index 0000000..2b0c5d3 --- /dev/null +++ b/CoreUnitTests/Infrastructure/TestReadOnlyMongoRepository.cs @@ -0,0 +1,29 @@ +using System; +using MongoDB.Driver; +using MongoDbGenericRepository; +using MongoDbGenericRepository.DataAccess.Read; + +namespace CoreUnitTests.Infrastructure; + +public class TestReadOnlyMongoRepository : ReadOnlyMongoRepository +{ + /// + public TestReadOnlyMongoRepository(string connectionString, string databaseName = null) + : base(connectionString, databaseName) + { + } + + /// + public TestReadOnlyMongoRepository(IMongoDatabase mongoDatabase) + : base(mongoDatabase) + { + } + + /// + public TestReadOnlyMongoRepository(IMongoDbContext mongoDbContext) + : base(mongoDbContext) + { + } + + public void SetReader(IMongoDbReader reader) => MongoDbReader = reader; +} diff --git a/CoreUnitTests/Infrastructure/TestReadOnlyMongoRepositoryContext.cs b/CoreUnitTests/Infrastructure/TestReadOnlyMongoRepositoryContext.cs new file mode 100644 index 0000000..6c34efe --- /dev/null +++ b/CoreUnitTests/Infrastructure/TestReadOnlyMongoRepositoryContext.cs @@ -0,0 +1,49 @@ +using System; +using AutoFixture; +using AutoFixture.AutoMoq; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; + +namespace CoreUnitTests.Infrastructure; + +public class TestReadOnlyMongoRepositoryContext +{ + private readonly Mock mongoDatabase; + + private TestReadOnlyMongoRepository sut; + + protected TestReadOnlyMongoRepositoryContext() + { + mongoDatabase = new Mock(); + Fixture = new Fixture().Customize(new AutoMoqCustomization()); + } + + protected IFixture Fixture { get; set; } + + protected TestReadOnlyMongoRepository Sut + { + get + { + if (sut != null) + { + return sut; + } + + sut = Fixture.Create(); + + if (Reader != null) + { + sut.SetReader(Reader.Object); + } + + return sut; + } + } + + protected Mock Reader { get; set; } + + protected Mock MockOf() + where T : class => + Fixture.Freeze>(); +} diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyAsyncTests.cs index 6ba8dae..a3a06fb 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyAsyncTests.cs @@ -12,9 +12,9 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public async Task WithFilter_GetsResult() @@ -28,7 +28,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.AnyAsync(filter, null, CancellationToken.None), + x => x.AnyAsync, int>(filter, null, CancellationToken.None), Times.Once); } @@ -46,7 +46,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.AnyAsync(filter, null, token), + x => x.AnyAsync, int>(filter, null, token), Times.Once); } @@ -64,7 +64,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.AnyAsync(filter, partitionKey, CancellationToken.None), + x => x.AnyAsync, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -83,7 +83,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.AnyAsync(filter, partitionKey, token), + x => x.AnyAsync, int>(filter, partitionKey, token), Times.Once); } @@ -92,8 +92,8 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.AnyAsync( - It.IsAny>>(), + x => x.AnyAsync, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(true); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyTests.cs index af13658..2918a54 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/AnyTests.cs @@ -11,9 +11,9 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext +public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public void WithFilter_GetsResult() @@ -27,7 +27,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.Any(filter, null, CancellationToken.None), + x => x.Any, int>(filter, null, CancellationToken.None), Times.Once); } @@ -45,7 +45,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.Any(filter, null, token), + x => x.Any, int>(filter, null, token), Times.Once); } @@ -63,7 +63,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.Any(filter, partitionKey, CancellationToken.None), + x => x.Any, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -82,7 +82,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().BeTrue(); Reader.Verify( - x => x.Any(filter, partitionKey, token), + x => x.Any, int>(filter, partitionKey, token), Times.Once); } @@ -91,8 +91,8 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.Any( - It.IsAny>>(), + x => x.Any, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .Returns(true); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountAsyncTests.cs index 96723f7..902c905 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountAsyncTests.cs @@ -14,9 +14,9 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public async Task WithFilter_GetsOne() @@ -32,7 +32,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.CountAsync(filter, null, CancellationToken.None), + x => x.CountAsync, int>(filter, null, CancellationToken.None), Times.Once); } @@ -51,7 +51,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.CountAsync(filter, null, token), + x => x.CountAsync, int>(filter, null, token), Times.Once); } @@ -70,7 +70,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.CountAsync(filter, partitionKey, CancellationToken.None), + x => x.CountAsync, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -90,7 +90,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.CountAsync(filter, partitionKey, token), + x => x.CountAsync, int>(filter, partitionKey, token), Times.Once); } @@ -99,8 +99,8 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.CountAsync( - It.IsAny>>(), + x => x.CountAsync, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(count); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountTests.cs index a84fe1c..c1f0626 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/CountTests.cs @@ -11,9 +11,9 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class CountTests : TestKeyedReadOnlyMongoRepositoryContext +public class CountTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public void WithFilter_GetsOne() @@ -29,7 +29,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.Count(filter, null, CancellationToken.None), + x => x.Count, int>(filter, null, CancellationToken.None), Times.Once); } @@ -48,7 +48,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.Count(filter, null, token), + x => x.Count, int>(filter, null, token), Times.Once); } @@ -67,7 +67,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.Count(filter, partitionKey, CancellationToken.None), + x => x.Count, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -87,7 +87,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(count); Reader.Verify( - x => x.Count(filter, partitionKey, token), + x => x.Count, int>(filter, partitionKey, token), Times.Once); } @@ -96,8 +96,8 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.Count( - It.IsAny>>(), + x => x.Count, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .Returns(count); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs index a871c08..049f5db 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs @@ -14,15 +14,15 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public async Task WithFilter_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); SetupReader(document); @@ -33,7 +33,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAllAsync(filter, null, CancellationToken.None), + x => x.GetAllAsync, int>(filter, null, CancellationToken.None), Times.Once); } @@ -41,7 +41,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); var token = new CancellationToken(true); SetupReader(document); @@ -53,7 +53,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAllAsync(filter, null, token), + x => x.GetAllAsync, int>(filter, null, token), Times.Once); } @@ -61,7 +61,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -73,7 +73,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAllAsync(filter, partitionKey, CancellationToken.None), + x => x.GetAllAsync, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -81,7 +81,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -94,17 +94,17 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAllAsync(filter, partitionKey, token), + x => x.GetAllAsync, int>(filter, partitionKey, token), Times.Once); } - private void SetupReader(List documents) + private void SetupReader(List> documents) { Reader = new Mock(); Reader .Setup( - x => x.GetAllAsync( - It.IsAny>>(), + x => x.GetAllAsync, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(documents); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllTests.cs index 3ff29bb..82aac09 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetAllTests.cs @@ -13,15 +13,15 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public void WithFilter_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); SetupReader(document); @@ -32,7 +32,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAll(filter, null, CancellationToken.None), + x => x.GetAll, int>(filter, null, CancellationToken.None), Times.Once); } @@ -40,7 +40,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); var token = new CancellationToken(true); SetupReader(document); @@ -52,7 +52,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAll(filter, null, token), + x => x.GetAll, int>(filter, null, token), Times.Once); } @@ -60,7 +60,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -72,7 +72,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAll(filter, partitionKey, CancellationToken.None), + x => x.GetAll, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -80,7 +80,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.CreateMany().ToList(); + var document = Fixture.CreateMany>().ToList(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -93,17 +93,17 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetAll(filter, partitionKey, token), + x => x.GetAll, int>(filter, partitionKey, token), Times.Once); } - private void SetupReader(List documents) + private void SetupReader(List> documents) { Reader = new Mock(); Reader .Setup( - x => x.GetAll( - It.IsAny>>(), + x => x.GetAll, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .Returns(documents); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs index d51f1be..6d9e8c2 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; -using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using AutoFixture; @@ -13,24 +10,24 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { [Fact] public async Task WithId_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); // Act - var result = await Sut.GetByIdAsync(document.Id); + var result = await Sut.GetByIdAsync>(document.Id); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByIdAsync(document.Id, null, CancellationToken.None), + x => x.GetByIdAsync, int>(document.Id, null, CancellationToken.None), Times.Once); } @@ -38,19 +35,19 @@ public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithIdAndCancellationToken_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); // Act - var result = await Sut.GetByIdAsync(document.Id, token); + var result = await Sut.GetByIdAsync>(document.Id, token); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByIdAsync(document.Id, null, token), + x => x.GetByIdAsync, int>(document.Id, null, token), Times.Once); } @@ -58,19 +55,19 @@ public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithIdAndPartitionKey_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); // Act - var result = await Sut.GetByIdAsync(document.Id, partitionKey); + var result = await Sut.GetByIdAsync>(document.Id, partitionKey); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByIdAsync(document.Id, partitionKey, CancellationToken.None), + x => x.GetByIdAsync, int>(document.Id, partitionKey, CancellationToken.None), Times.Once); } @@ -78,30 +75,30 @@ public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithIdAndPartitionKeyAndCancellationToken_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); SetupReader(document); // Act - var result = await Sut.GetByIdAsync(document.Id, partitionKey, token); + var result = await Sut.GetByIdAsync>(document.Id, partitionKey, token); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByIdAsync(document.Id, partitionKey, token), + x => x.GetByIdAsync, int>(document.Id, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetByIdAsync( - It.IsAny(), + x => x.GetByIdAsync, int>( + It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdTests.cs index c7e39a3..f9cef3d 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByIdTests.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Linq.Expressions; using System.Threading; -using System.Threading.Tasks; using AutoFixture; using CoreUnitTests.Infrastructure; using CoreUnitTests.Infrastructure.Model; @@ -13,24 +9,24 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext { [Fact] public void WithId_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); // Act - var result = Sut.GetById(document.Id); + var result = Sut.GetById>(document.Id); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetById(document.Id, null, CancellationToken.None), + x => x.GetById, int>(document.Id, null, CancellationToken.None), Times.Once); } @@ -38,19 +34,19 @@ public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext public void WithIdAndCancellationToken_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); // Act - var result = Sut.GetById(document.Id, token); + var result = Sut.GetById>(document.Id, token); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetById(document.Id, null, token), + x => x.GetById, int>(document.Id, null, token), Times.Once); } @@ -58,19 +54,19 @@ public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext public void WithIdAndPartitionKey_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); // Act - var result = Sut.GetById(document.Id, partitionKey); + var result = Sut.GetById>(document.Id, partitionKey); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetById(document.Id, partitionKey, CancellationToken.None), + x => x.GetById, int>(document.Id, partitionKey, CancellationToken.None), Times.Once); } @@ -78,30 +74,30 @@ public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext public void WithIdAndPartitionKeyAndCancellationToken_Gets() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); SetupReader(document); // Act - var result = Sut.GetById(document.Id, partitionKey, token); + var result = Sut.GetById>(document.Id, partitionKey, token); // Assert result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetById(document.Id, partitionKey, token), + x => x.GetById, int>(document.Id, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetById( - It.IsAny(), + x => x.GetById, int>( + It.IsAny(), It.IsAny(), It.IsAny())) .Returns(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs index 508e637..00f8fba 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs @@ -12,16 +12,16 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> selector = document => document.SomeValue; [Fact] public async Task WithFilterAndSelector_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); @@ -32,7 +32,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMaxAsync(filter, selector, null, CancellationToken.None), + x => x.GetByMaxAsync, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -40,7 +40,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndSelectorAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); @@ -52,7 +52,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMaxAsync(filter, selector, null, token), + x => x.GetByMaxAsync, int>(filter, selector, null, token), Times.Once); } @@ -60,7 +60,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndSelectorAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -72,7 +72,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMaxAsync(filter, selector, partitionKey, CancellationToken.None), + x => x.GetByMaxAsync, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -80,7 +80,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -93,18 +93,18 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMaxAsync(filter, selector, partitionKey, token), + x => x.GetByMaxAsync, int>(filter, selector, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetByMaxAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetByMaxAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxTests.cs index 987bca6..b694cdb 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMaxTests.cs @@ -11,16 +11,16 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> selector = document => document.SomeValue; [Fact] public void WithFilterAndSelector_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); @@ -31,7 +31,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMax(filter, selector, null, CancellationToken.None), + x => x.GetByMax, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -39,7 +39,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndSelectorAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); @@ -51,7 +51,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMax(filter, selector, null, token), + x => x.GetByMax, int>(filter, selector, null, token), Times.Once); } @@ -59,7 +59,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndSelectorAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -71,7 +71,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMax(filter, selector, partitionKey, CancellationToken.None), + x => x.GetByMax, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -79,7 +79,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -92,18 +92,18 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMax(filter, selector, partitionKey, token), + x => x.GetByMax, int>(filter, selector, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetByMax( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetByMax, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), It.IsAny(), It.IsAny())) .Returns(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs index fc2e3c7..02032b1 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs @@ -12,16 +12,16 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> selector = document => document.SomeValue; [Fact] public async Task WithFilterAndSelector_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); @@ -32,7 +32,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMinAsync(filter, selector, null, CancellationToken.None), + x => x.GetByMinAsync, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -40,7 +40,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndSelectorAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); @@ -52,7 +52,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMinAsync(filter, selector, null, token), + x => x.GetByMinAsync, int>(filter, selector, null, token), Times.Once); } @@ -60,7 +60,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndSelectorAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -72,7 +72,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMinAsync(filter, selector, partitionKey, CancellationToken.None), + x => x.GetByMinAsync, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -80,7 +80,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -93,18 +93,18 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMinAsync(filter, selector, partitionKey, token), + x => x.GetByMinAsync, int>(filter, selector, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetByMinAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetByMinAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinTests.cs index e3eacee..9efd7f2 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetByMinTests.cs @@ -11,16 +11,16 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> selector = document => document.SomeValue; [Fact] public void WithFilterAndSelector_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); @@ -31,7 +31,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMin(filter, selector, null, CancellationToken.None), + x => x.GetByMin, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -39,7 +39,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndSelectorAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); @@ -51,7 +51,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMin(filter, selector, null, token), + x => x.GetByMin, int>(filter, selector, null, token), Times.Once); } @@ -59,7 +59,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndSelectorAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -71,7 +71,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMin(filter, selector, partitionKey, CancellationToken.None), + x => x.GetByMin, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -79,7 +79,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -92,18 +92,18 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetByMin(filter, selector, partitionKey, token), + x => x.GetByMin, int>(filter, selector, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetByMin( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetByMin, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), It.IsAny(), It.IsAny())) .Returns(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs index f9fe0c8..5b16f95 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs @@ -12,10 +12,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> selector = document => document.SomeValue; [Fact] public async Task WithFilterAndSelector_GetsMaxValue() @@ -31,7 +31,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMaxValueAsync(filter, selector, null, CancellationToken.None), + x => x.GetMaxValueAsync, int, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -50,7 +50,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMaxValueAsync(filter, selector, null, token), + x => x.GetMaxValueAsync, int, int>(filter, selector, null, token), Times.Once); } @@ -69,7 +69,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMaxValueAsync(filter, selector, partitionKey, CancellationToken.None), + x => x.GetMaxValueAsync, int, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -89,7 +89,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMaxValueAsync(filter, selector, partitionKey, token), + x => x.GetMaxValueAsync, int, int>(filter, selector, partitionKey, token), Times.Once); } @@ -98,9 +98,9 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext(); Reader .Setup( - x => x.GetMaxValueAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetMaxValueAsync, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(value); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueTests.cs index 06af072..ada314c 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMaxValueTests.cs @@ -11,10 +11,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> selector = document => document.SomeValue; [Fact] public void WithFilterAndSelector_GetsMaxValue() @@ -30,7 +30,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMaxValue(filter, selector, null, CancellationToken.None), + x => x.GetMaxValue, int, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -49,7 +49,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMaxValue(filter, selector, null, token), + x => x.GetMaxValue, int, int>(filter, selector, null, token), Times.Once); } @@ -68,7 +68,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMaxValue(filter, selector, partitionKey, CancellationToken.None), + x => x.GetMaxValue, int, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -88,7 +88,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMaxValue(filter, selector, partitionKey, token), + x => x.GetMaxValue, int, int>(filter, selector, partitionKey, token), Times.Once); } @@ -97,9 +97,9 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.GetMaxValue( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetMaxValue, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), It.IsAny(), It.IsAny())) .Returns(value); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs index 4e0cc5d..375d672 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs @@ -12,10 +12,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> selector = document => document.SomeValue; [Fact] public async Task WithFilterAndSelector_GetsMaxValue() @@ -31,7 +31,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMinValueAsync(filter, selector, null, CancellationToken.None), + x => x.GetMinValueAsync, int, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -50,7 +50,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMinValueAsync(filter, selector, null, token), + x => x.GetMinValueAsync, int, int>(filter, selector, null, token), Times.Once); } @@ -69,7 +69,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMinValueAsync(filter, selector, partitionKey, CancellationToken.None), + x => x.GetMinValueAsync, int, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -89,7 +89,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.GetMinValueAsync(filter, selector, partitionKey, token), + x => x.GetMinValueAsync, int, int>(filter, selector, partitionKey, token), Times.Once); } @@ -98,9 +98,9 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext(); Reader .Setup( - x => x.GetMinValueAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetMinValueAsync, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(value); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueTests.cs index 5b861a6..05a6c18 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetMinValueTests.cs @@ -11,10 +11,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> selector = document => document.SomeValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> selector = document => document.SomeValue; [Fact] public void WithFilterAndSelector_GetsMinValue() @@ -30,7 +30,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMinValue(filter, selector, null, CancellationToken.None), + x => x.GetMinValue, int, int>(filter, selector, null, CancellationToken.None), Times.Once); } @@ -49,7 +49,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMinValue(filter, selector, null, token), + x => x.GetMinValue, int, int>(filter, selector, null, token), Times.Once); } @@ -68,7 +68,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMinValue(filter, selector, partitionKey, CancellationToken.None), + x => x.GetMinValue, int, int>(filter, selector, partitionKey, CancellationToken.None), Times.Once); } @@ -88,7 +88,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(value); Reader.Verify( - x => x.GetMinValue(filter, selector, partitionKey, token), + x => x.GetMinValue, int, int>(filter, selector, partitionKey, token), Times.Once); } @@ -97,9 +97,9 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.GetMinValue( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetMinValue, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), It.IsAny(), It.IsAny())) .Returns(value); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs index 9ae88f4..01efd4c 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs @@ -12,15 +12,15 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] public async Task WithFilter_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); @@ -31,7 +31,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOneAsync(filter, null, CancellationToken.None), + x => x.GetOneAsync, int>(filter, null, CancellationToken.None), Times.Once); } @@ -39,7 +39,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); @@ -51,7 +51,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOneAsync(filter, null, token), + x => x.GetOneAsync, int>(filter, null, token), Times.Once); } @@ -59,7 +59,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -71,7 +71,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOneAsync(filter, partitionKey, CancellationToken.None), + x => x.GetOneAsync, int>(filter, partitionKey, CancellationToken.None), Times.Once); } @@ -79,7 +79,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -92,17 +92,17 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOneAsync(filter, partitionKey, token), + x => x.GetOneAsync, int>(filter, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetOneAsync( - It.IsAny>>(), + x => x.GetOneAsync, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneTests.cs index 289f1d0..803e999 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetOneTests.cs @@ -1,7 +1,6 @@ using System; using System.Linq.Expressions; using System.Threading; -using System.Threading.Tasks; using AutoFixture; using CoreUnitTests.Infrastructure; using CoreUnitTests.Infrastructure.Model; @@ -12,15 +11,15 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; [Fact] - public void WithId_GetsOne() + public void WithFilter_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); SetupReader(document); @@ -31,15 +30,15 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOne(filter, null, CancellationToken.None), + x => x.GetOne, int>(filter, null, CancellationToken.None), Times.Once); } [Fact] - public void WithIdAndCancellationToken_GetsOne() + public void WithFilterAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var token = new CancellationToken(true); SetupReader(document); @@ -51,15 +50,15 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOne(filter, null, token), + x => x.GetOne, int>(filter, null, token), Times.Once); } [Fact] - public void WithIdAndPartitionKey_GetsOne() + public void WithFilterAndPartitionKey_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); SetupReader(document); @@ -71,15 +70,15 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOne(filter, partitionKey, CancellationToken.None), + x => x.GetOne, int>(filter, partitionKey, CancellationToken.None), Times.Once); } [Fact] - public void WithIdAndPartitionKeyAndCancellationToken_GetsOne() + public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne() { // Arrange - var document = Fixture.Create(); + var document = Fixture.Create>(); var partitionKey = Fixture.Create(); var token = new CancellationToken(true); @@ -92,17 +91,17 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(document); Reader.Verify( - x => x.GetOne(filter, partitionKey, token), + x => x.GetOne, int>(filter, partitionKey, token), Times.Once); } - private void SetupReader(TestDocument document) + private void SetupReader(TestDocumentWithKey document) { Reader = new Mock(); Reader .Setup( - x => x.GetOne( - It.IsAny>>(), + x => x.GetOne, int>( + It.IsAny, bool>>>(), It.IsAny(), It.IsAny())) .Returns(document); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs index 1b199c8..189b5b1 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs @@ -15,11 +15,11 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.GroupingKey == 1; - private readonly Expression> selector = document => document.GroupingKey; - private readonly SortDefinition sortDefinition = Builders.Sort.Ascending(document => document.GroupingKey); + private readonly Expression, bool>> filter = document => document.GroupingKey == 1; + private readonly Expression, object>> selector = document => document.GroupingKey; + private readonly SortDefinition> sortDefinition = Builders>.Sort.Ascending(document => document.GroupingKey); private const bool DefaultAscending = true; private const int DefaultSkipNumber = 0; @@ -178,15 +178,15 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, token); } - private List SetupReaderWithSortSelector() + private List> SetupReaderWithSortSelector() { - var documents = Fixture.CreateMany().ToList(); + var documents = Fixture.CreateMany>().ToList(); Reader = new Mock(); Reader.Setup( - x => x.GetSortedPaginatedAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.GetSortedPaginatedAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), It.IsAny(), It.IsAny(), It.IsAny(), @@ -196,12 +196,12 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont return documents; } - private void VerifySelector(List result, List documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) + private void VerifySelector(List> result, List> documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) { result.Should().NotBeNull(); result.Should().BeEquivalentTo(documents); Reader.Verify( - x => x.GetSortedPaginatedAsync( + x => x.GetSortedPaginatedAsync, int>( filter, selector, ascending, @@ -212,15 +212,15 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont Times.Once); } - private List SetupReaderWithSortDefinition() + private List> SetupReaderWithSortDefinition() { - var documents = Fixture.CreateMany().ToList(); + var documents = Fixture.CreateMany>().ToList(); Reader = new Mock(); Reader.Setup( - x => x.GetSortedPaginatedAsync( - It.IsAny>>(), - It.IsAny>(), + x => x.GetSortedPaginatedAsync, int>( + It.IsAny, bool>>>(), + It.IsAny>>(), It.IsAny(), It.IsAny(), It.IsAny(), @@ -229,12 +229,12 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont return documents; } - private void VerifyDefinition(List result, List documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) + private void VerifyDefinition(List> result, List> documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) { result.Should().NotBeNull(); result.Should().BeEquivalentTo(documents); Reader.Verify( - x => x.GetSortedPaginatedAsync( + x => x.GetSortedPaginatedAsync, int>( filter, sortDefinition, skipNumber, diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GroupByTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GroupByTests.cs index 018c4bc..4c39155 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GroupByTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/GroupByTests.cs @@ -12,11 +12,11 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext +public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> grouping = document => document.GroupingKey; - private readonly Expression, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()}; - private readonly Expression> filter = document => document.GroupingKey == 1; + private readonly Expression, int>> grouping = document => document.GroupingKey; + private readonly Expression>, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()}; + private readonly Expression, bool>> filter = document => document.GroupingKey == 1; [Fact] public void WithGroupingCriteriaAndProjection_Groups() @@ -26,9 +26,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader.Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -40,7 +40,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(grouping, projection, null, CancellationToken.None), + x => x.GroupBy, int, TestProjection, int>(grouping, projection, null, CancellationToken.None), Times.Once); } @@ -54,9 +54,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader .Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -68,7 +68,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(grouping, projection, null, token), + x => x.GroupBy, int, TestProjection, int>(grouping, projection, null, token), Times.Once); } @@ -82,9 +82,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader .Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -96,7 +96,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(grouping, projection, partitionKey, CancellationToken.None), + x => x.GroupBy, int, TestProjection, int>(grouping, projection, partitionKey, CancellationToken.None), Times.Once); } @@ -111,9 +111,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader .Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -125,7 +125,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(grouping, projection, partitionKey, token), + x => x.GroupBy, int, TestProjection, int>(grouping, projection, partitionKey, token), Times.Once); } @@ -137,10 +137,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader.Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -152,7 +152,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(filter, grouping, projection, null, CancellationToken.None), + x => x.GroupBy, int, TestProjection, int>(filter, grouping, projection, null, CancellationToken.None), Times.Once); } @@ -165,10 +165,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader.Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -180,7 +180,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(filter, grouping, projection, null, token), + x => x.GroupBy, int, TestProjection, int>(filter, grouping, projection, null, token), Times.Once); } @@ -193,10 +193,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader.Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -208,7 +208,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(filter, grouping, projection, partitionKey, CancellationToken.None), + x => x.GroupBy, int, TestProjection, int>(filter, grouping, projection, partitionKey, CancellationToken.None), Times.Once); } @@ -222,10 +222,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader.Setup( - x => x.GroupBy( - It.IsAny>>(), - It.IsAny>>(), - It.IsAny, TestProjection>>>(), + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); @@ -237,7 +237,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext result.Should().NotBeNull(); result.Should().BeEquivalentTo(projections); Reader.Verify( - x => x.GroupBy(filter, grouping, projection, partitionKey, token), + x => x.GroupBy, int, TestProjection, int>(filter, grouping, projection, partitionKey, token), Times.Once); } } diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs index 53535b4..1b2eca6 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs @@ -14,10 +14,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; [Fact] public async Task WithFilterAndProjection_Projects() @@ -33,7 +33,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext projections.Contains(x)); Reader.Verify( - x => x.ProjectManyAsync( + x => x.ProjectManyAsync, TestProjection, int>( filter, projection, null, @@ -56,7 +56,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext projections.Contains(x)); Reader.Verify( - x => x.ProjectManyAsync(filter, projection, null, token), + x => x.ProjectManyAsync, TestProjection, int>(filter, projection, null, token), Times.Once); } @@ -75,7 +75,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext projections.Contains(x)); Reader.Verify( - x => x.ProjectManyAsync(filter, projection, partitionKey, CancellationToken.None), + x => x.ProjectManyAsync, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None), Times.Once); } @@ -95,7 +95,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext projections.Contains(x)); Reader.Verify( - x => x.ProjectManyAsync(filter, projection, partitionKey, token), + x => x.ProjectManyAsync, TestProjection, int>(filter, projection, partitionKey, token), Times.Once); } @@ -104,9 +104,9 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext(); Reader .Setup( - x => x.ProjectManyAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.ProjectManyAsync, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(projections); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyTests.cs index 47b9a09..324090e 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectManyTests.cs @@ -13,10 +13,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext +public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; [Fact] public void WithFilterAndProjection_Projects() @@ -32,7 +32,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().OnlyContain(x => projections.Contains(x)); Reader.Verify( - x => x.ProjectMany( + x => x.ProjectMany, TestProjection, int>( filter, projection, null, @@ -55,7 +55,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().OnlyContain(x => projections.Contains(x)); Reader.Verify( - x => x.ProjectMany(filter, projection, null, token), + x => x.ProjectMany, TestProjection, int>(filter, projection, null, token), Times.Once); } @@ -74,7 +74,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().OnlyContain(x => projections.Contains(x)); Reader.Verify( - x => x.ProjectMany(filter, projection, partitionKey, CancellationToken.None), + x => x.ProjectMany, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None), Times.Once); } @@ -94,7 +94,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().OnlyContain(x => projections.Contains(x)); Reader.Verify( - x => x.ProjectMany(filter, projection, partitionKey, token), + x => x.ProjectMany, TestProjection, int>(filter, projection, partitionKey, token), Times.Once); } @@ -103,9 +103,9 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.ProjectMany( - It.IsAny>>(), - It.IsAny>>(), + x => x.ProjectMany, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(projections); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs index e027aa3..4d160f9 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs @@ -12,10 +12,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; [Fact] public async Task WithFilterAndProjection_Projects() @@ -31,7 +31,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.ProjectOneAsync( + x => x.ProjectOneAsync, TestProjection, int>( filter, projection, null, @@ -54,7 +54,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.ProjectOneAsync(filter, projection, null, token), + x => x.ProjectOneAsync, TestProjection, int>(filter, projection, null, token), Times.Once); } @@ -73,7 +73,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.ProjectOneAsync(filter, projection, partitionKey, CancellationToken.None), + x => x.ProjectOneAsync, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None), Times.Once); } @@ -93,7 +93,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext x.ProjectOneAsync(filter, projection, partitionKey, token), + x => x.ProjectOneAsync, TestProjection, int>(filter, projection, partitionKey, token), Times.Once); } @@ -102,9 +102,9 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext(); Reader .Setup( - x => x.ProjectOneAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.ProjectOneAsync, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(result); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneTests.cs index 280fcd0..d7b5eb3 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/ProjectOneTests.cs @@ -11,10 +11,10 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext +public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; [Fact] public void WithFilterAndProjection_Projects() @@ -30,7 +30,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.ProjectOne( + x => x.ProjectOne, TestProjection, int>( filter, projection, null, @@ -53,7 +53,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.ProjectOne(filter, projection, null, token), + x => x.ProjectOne, TestProjection, int>(filter, projection, null, token), Times.Once); } @@ -72,7 +72,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.ProjectOne(filter, projection, partitionKey, CancellationToken.None), + x => x.ProjectOne, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None), Times.Once); } @@ -92,7 +92,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.ProjectOne(filter, projection, partitionKey, token), + x => x.ProjectOne, TestProjection, int>(filter, projection, partitionKey, token), Times.Once); } @@ -101,9 +101,9 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.ProjectOne( - It.IsAny>>(), - It.IsAny>>(), + x => x.ProjectOne, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), It.IsAny(), It.IsAny())) .Returns(result); diff --git a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/SumByAsyncTests.cs b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/SumByAsyncTests.cs index 9652042..43f613f 100644 --- a/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/SumByAsyncTests.cs +++ b/CoreUnitTests/KeyedReadOnlyMongoRepositoryTests/SumByAsyncTests.cs @@ -12,11 +12,11 @@ using Xunit; namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests; -public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext { - private readonly Expression> filter = document => document.SomeContent == "SomeContent"; - private readonly Expression> intSelector = document => document.SomeValue; - private readonly Expression> decimalSelector = document => document.SomeDecimalValue; + private readonly Expression, bool>> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> intSelector = document => document.SomeValue; + private readonly Expression, decimal>> decimalSelector = document => document.SomeDecimalValue; [Fact] public async Task Int_WithFilterAndSelector_Sums() @@ -32,7 +32,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, intSelector, null, CancellationToken.None), + x => x.SumByAsync, int>(filter, intSelector, null, CancellationToken.None), Times.Once); } @@ -51,7 +51,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, intSelector, null, token), + x => x.SumByAsync, int>(filter, intSelector, null, token), Times.Once); } @@ -70,7 +70,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, intSelector, partitionKey, CancellationToken.None), + x => x.SumByAsync, int>(filter, intSelector, partitionKey, CancellationToken.None), Times.Once); } @@ -90,7 +90,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, intSelector, partitionKey, token), + x => x.SumByAsync, int>(filter, intSelector, partitionKey, token), Times.Once); } @@ -108,7 +108,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, decimalSelector, null, CancellationToken.None), + x => x.SumByAsync, int>(filter, decimalSelector, null, CancellationToken.None), Times.Once); } @@ -127,7 +127,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, decimalSelector, null, token), + x => x.SumByAsync, int>(filter, decimalSelector, null, token), Times.Once); } @@ -146,7 +146,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, decimalSelector, partitionKey, CancellationToken.None), + x => x.SumByAsync, int>(filter, decimalSelector, partitionKey, CancellationToken.None), Times.Once); } @@ -166,7 +166,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext // Assert result.Should().Be(expected); Reader.Verify( - x => x.SumByAsync(filter, decimalSelector, partitionKey, token), + x => x.SumByAsync, int>(filter, decimalSelector, partitionKey, token), Times.Once); } @@ -175,9 +175,9 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.SumByAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.SumByAsync, int>( + It.IsAny, bool>>>(), + It.IsAny,int>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(expected); @@ -188,9 +188,9 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext Reader = new Mock(); Reader .Setup( - x => x.SumByAsync( - It.IsAny>>(), - It.IsAny>>(), + x => x.SumByAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, decimal>>>(), It.IsAny(), It.IsAny())) .ReturnsAsync(expected); diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/AnyAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/AnyAsyncTests.cs new file mode 100644 index 0000000..8957937 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/AnyAsyncTests.cs @@ -0,0 +1,349 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class AnyAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(x => x.Id, 1); + + [Fact] + public async Task WithExpression_GetsResult() + { + // Arrange + SetupReader(); + + // Act + var result = await Sut.AnyAsync(expression); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + + SetupReader(); + + // Act + var result = await Sut.AnyAsync(expression, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync(expression, null, token), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + + SetupReader(); + + // Act + var result = await Sut.AnyAsync(expression, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(); + + // Act + var result = await Sut.AnyAsync(expression, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync(expression, partitionKey, token), + Times.Once); + } + + #region keyed + + [Fact] + public async Task Keyed_WithExpression_GetsResult() + { + // Arrange + SetupKeyedReaderWithExpression(); + + // Act + var result = await Sut.AnyAsync, int>(keyedExpression); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + + SetupKeyedReaderWithExpression(); + + // Act + var result = await Sut.AnyAsync, int>(keyedExpression, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithExpression(); + + // Act + var result = await Sut.AnyAsync, int>(keyedExpression, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithExpression(); + + // Act + var result = await Sut.AnyAsync, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilter_GetsResult() + { + // Arrange + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndOptions_GetsResult() + { + // Arrange + var options = new CountOptions(); + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, options); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, options, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndOptionsAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + var options = new CountOptions(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, options, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, options, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCountOptionsAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var options = new CountOptions(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, options, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, options, partitionKey, CancellationToken.None), + Times.Once); + } + [Fact] + public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCountOptionsAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var options = new CountOptions(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = await Sut.AnyAsync, int>(keyedFilter, options, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.AnyAsync, int>(keyedFilter, options, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderWithExpression() + { + Reader = new Mock(); + Reader + .Setup( + x => x.AnyAsync, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(true); + } + + private void SetupKeyedReaderWithFilter() + { + Reader = new Mock(); + Reader + .Setup( + x => x.AnyAsync, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(true); + } + + #endregion + + private void SetupReader() + { + Reader = new Mock(); + Reader + .Setup( + x => x.AnyAsync( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(true); + } +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/AnyTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/AnyTests.cs new file mode 100644 index 0000000..420aaae --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/AnyTests.cs @@ -0,0 +1,349 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class AnyTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public void WithExpression_GetsResult() + { + // Arrange + SetupReader(); + + // Act + var result = Sut.Any(expression); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + + SetupReader(); + + // Act + var result = Sut.Any(expression, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any(expression, null, token), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + + SetupReader(); + + // Act + var result = Sut.Any(expression, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(); + + // Act + var result = Sut.Any(expression, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader() + { + Reader = new Mock(); + Reader + .Setup( + x => x.Any( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(true); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(document => document.SomeContent, "SomeContent"); + + [Fact] + public void Keyed_WithExpression_GetsResult() + { + // Arrange + SetupKeyedReaderWithExpression(); + + // Act + var result = Sut.Any, int>(keyedExpression); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + + SetupKeyedReaderWithExpression(); + + // Act + var result = Sut.Any, int>(keyedExpression, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithExpression(); + + // Act + var result = Sut.Any, int>(keyedExpression, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithExpression(); + + // Act + var result = Sut.Any, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilter_GetsResult() + { + // Arrange + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndCancellationToken_GetsResult() + { + // Arrange + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndOptions_GetsResult() + { + // Arrange + var options = new CountOptions(); + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, options); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, options, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndOptionsAndCancellationToken_GetsResult() + { + // Arrange + var options = new CountOptions(); + var token = new CancellationToken(true); + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, options, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, options, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndOptionsAndPartitionKey_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var options = new CountOptions(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, options, partitionKey); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, options, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndOptionsAndPartitionKeyAndCancellationToken_GetsResult() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var options = new CountOptions(); + + SetupKeyedReaderWithFilter(); + + // Act + var result = Sut.Any, int>(keyedFilter, options, partitionKey, token); + + // Assert + result.Should().BeTrue(); + Reader.Verify( + x => x.Any, int>(keyedFilter, options, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderWithExpression() + { + Reader = new Mock(); + Reader + .Setup( + x => x.Any, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .Returns(true); + } + + private void SetupKeyedReaderWithFilter() + { + Reader = new Mock(); + Reader + .Setup( + x => x.Any, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(true); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/CountAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/CountAsyncTests.cs new file mode 100644 index 0000000..5a89a57 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/CountAsyncTests.cs @@ -0,0 +1,371 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class CountAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public async Task WithExpression_Counts() + { + // Arrange + var count = Fixture.Create(); + + SetupReader(count); + + // Act + var result = await Sut.CountAsync(expression); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(count); + + // Act + var result = await Sut.CountAsync(expression, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync(expression, null, token), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(count); + + // Act + var result = await Sut.CountAsync(expression, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(count); + + // Act + var result = await Sut.CountAsync(expression, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader(long count) + { + Reader = new Mock(); + Reader + .Setup( + x => x.CountAsync( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(count); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(document => document.Id, 1); + + [Fact] + public async Task Keyed_WithExpression_Counts() + { + // Arrange + var count = Fixture.Create(); + + SetupKeyedReaderWithExpression(count); + + // Act + var result = await Sut.CountAsync, int>(keyedExpression); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithExpression(count); + + // Act + var result = await Sut.CountAsync, int>(keyedExpression, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithExpression(count); + + // Act + var result = await Sut.CountAsync, int>(keyedExpression, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithExpression(count); + + // Act + var result = await Sut.CountAsync, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilter_Counts() + { + // Arrange + var count = Fixture.Create(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCountOptions_Counts() + { + // Arrange + var count = Fixture.Create(); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, countOptions); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, countOptions, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCountOptionsAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, countOptions, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, countOptions, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCountOptionsAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, countOptions, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, countOptions, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCountOptionsPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = await Sut.CountAsync, int>(keyedFilter, countOptions, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.CountAsync, int>(keyedFilter, countOptions, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderWithExpression(long count) + { + Reader = new Mock(); + Reader + .Setup( + x => x.CountAsync, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(count); + } + + private void SetupKeyedReaderWithFilter(long count) + { + Reader = new Mock(); + Reader + .Setup( + x => x.CountAsync, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(count); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/CountTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/CountTests.cs new file mode 100644 index 0000000..4e0044d --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/CountTests.cs @@ -0,0 +1,373 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class CountTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public void WithExpression_Counts() + { + // Arrange + var count = Fixture.Create(); + + SetupReader(count); + + // Act + var result = Sut.Count(expression); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(count); + + // Act + var result = Sut.Count(expression, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count(expression, null, token), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(count); + + // Act + var result = Sut.Count(expression, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(count); + + // Act + var result = Sut.Count(expression, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader(long count) + { + Reader = new Mock(); + Reader + .Setup( + x => x.Count( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(count); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq( + document => document.SomeContent, + "SomeContent"); + + [Fact] + public void Keyed_WithExpression_Counts() + { + // Arrange + var count = Fixture.Create(); + + SetupKeyedReader(count); + + // Act + var result = Sut.Count, int>(keyedExpression); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(count); + + // Act + var result = Sut.Count, int>(keyedExpression, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(count); + + // Act + var result = Sut.Count, int>(keyedExpression, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(count); + + // Act + var result = Sut.Count, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(long count) + { + Reader = new Mock(); + Reader + .Setup( + x => x.Count, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .Returns(count); + } + + [Fact] + public void Keyed_WithFilter_Counts() + { + // Arrange + var count = Fixture.Create(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter); + + // Assert + Reader.Verify( + x => x.Count, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + result.Should().Be(count); + } + + [Fact] + public void Keyed_WithFilterAndCountOptions_Counts() + { + // Arrange + var count = Fixture.Create(); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, countOptions); + + // Assert + Reader.Verify( + x => x.Count, int>(keyedFilter, countOptions, null, CancellationToken.None), + Times.Once); + result.Should().Be(count); + } + + [Fact] + public void Keyed_WithFilterAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndCountOptionsAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var token = new CancellationToken(true); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, countOptions, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedFilter, countOptions, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndCountOptionsAndPartitionKey_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, countOptions, partitionKey); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedFilter, countOptions, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndCountOptionsAndPartitionKeyAndCancellationToken_Counts() + { + // Arrange + var count = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var countOptions = new CountOptions(); + + SetupKeyedReaderWithFilter(count); + + // Act + var result = Sut.Count, int>(keyedFilter, countOptions, partitionKey, token); + + // Assert + result.Should().Be(count); + Reader.Verify( + x => x.Count, int>(keyedFilter, countOptions, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderWithFilter(long count) + { + Reader = new Mock(); + Reader + .Setup( + x => x.Count, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(count); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs new file mode 100644 index 0000000..38c8af7 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetAllAsyncTests.cs @@ -0,0 +1,389 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetAllAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public async Task WithExpression_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync(expression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync(expression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync(expression, null, token), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync(expression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync(expression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader(List documents) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetAllAsync( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(document => document.SomeContent, "SomeContent"); + + [Fact] + public async Task Keyed_WithExpression_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedExpression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedExpression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedExpression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilter_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndOptions_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var options = new FindOptions(); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, options); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, options, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var token = new CancellationToken(true); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, options, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, options, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var options = new FindOptions(); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, options, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, options, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupReaderWithFilter(document); + + // Act + var result = await Sut.GetAllAsync, int>(keyedFilter, options, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAllAsync, int>(keyedFilter, options, partitionKey, token), + Times.Once); + } + + private void SetupReaderWithFilter(List> documents) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetAllAsync, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + } + + private void SetupReader(List> documents) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetAllAsync, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetAllTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetAllTests.cs new file mode 100644 index 0000000..a25f5f8 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetAllTests.cs @@ -0,0 +1,388 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetAllTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public void WithExpression_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + + SetupReader(document); + + // Act + var result = Sut.GetAll(expression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetAll(expression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll(expression, null, token), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetAll(expression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetAll(expression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader(List documents) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetAll( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(documents); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(document => document.SomeContent, "SomeContent"); + + [Fact] + public void Keyed_WithExpression_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetAll, int>(keyedExpression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetAll, int>(keyedExpression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetAll, int>(keyedExpression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetAll, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilter_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptions_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, options); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, options, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, options, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, options, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, options, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, options, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsAll() + { + // Arrange + var document = Fixture.CreateMany>().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetAll, int>(keyedFilter, options, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetAll, int>(keyedFilter, options, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderWithFilter(List> documents) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetAll, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(documents); + } + + private void SetupKeyedReader(List> documents) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetAll, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .Returns(documents); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs new file mode 100644 index 0000000..21487fd --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByIdAsyncTests.cs @@ -0,0 +1,203 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetByIdAsyncTests : TestReadOnlyMongoRepositoryContext +{ + [Fact] + public async Task WithId_Gets() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByIdAsync(document.Id); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync(document.Id, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithIdAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByIdAsync(document.Id, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync(document.Id, null, token), + Times.Once); + } + + [Fact] + public async Task WithIdAndPartitionKey_Gets() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByIdAsync(document.Id, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync(document.Id, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithIdAndPartitionKeyAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByIdAsync(document.Id, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync(document.Id, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByIdAsync( + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #region Keyed + + [Fact] + public async Task Keyed_WithId_Gets() + { + // Arrange + var document = Fixture.Create>(); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByIdAsync, int>(document.Id); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync, int>(document.Id, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithIdAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByIdAsync, int>(document.Id, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync, int>(document.Id, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithIdAndPartitionKey_Gets() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByIdAsync, int>(document.Id, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync, int>(document.Id, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithIdAndPartitionKeyAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByIdAsync, int>(document.Id, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByIdAsync, int>(document.Id, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByIdAsync, int>( + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByIdTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByIdTests.cs new file mode 100644 index 0000000..9e3a9b3 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByIdTests.cs @@ -0,0 +1,202 @@ +using System; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetByIdTests : TestReadOnlyMongoRepositoryContext +{ + [Fact] + public void WithId_Gets() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetById(document.Id); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById(document.Id, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithIdAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetById(document.Id, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById(document.Id, null, token), + Times.Once); + } + + [Fact] + public void WithIdAndPartitionKey_Gets() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetById(document.Id, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById(document.Id, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithIdAndPartitionKeyAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetById(document.Id, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById(document.Id, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetById( + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #region Keyed + + [Fact] + public void Keyed_WithId_Gets() + { + // Arrange + var document = Fixture.Create>(); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetById, int>(document.Id); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById, int>(document.Id, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithIdAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetById, int>(document.Id, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById, int>(document.Id, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithIdAndPartitionKey_Gets() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetById, int>(document.Id, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById, int>(document.Id, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithIdAndPartitionKeyAndCancellationToken_Gets() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetById, int>(document.Id, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetById, int>(document.Id, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetById, int>( + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs new file mode 100644 index 0000000..8c307ed --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMaxAsyncTests.cs @@ -0,0 +1,212 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetByMaxAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public async Task WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync(filter, selector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync(filter, selector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync(filter, selector, null, token), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync(filter, selector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync(filter, selector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMaxAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> keyedSelector = document => document.SomeValue; + + [Fact] + public async Task Keyed_WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByMaxAsync, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMaxAsync, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMaxAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMaxTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMaxTests.cs new file mode 100644 index 0000000..19f755e --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMaxTests.cs @@ -0,0 +1,211 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetByMaxTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public void WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetByMax(filter, selector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMax(filter, selector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax(filter, selector, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetByMax(filter, selector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMax(filter, selector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMax( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> keyedSelector = document => document.SomeValue; + + [Fact] + public void Keyed_WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupReader(document); + + // Act + var result = Sut.GetByMax, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMax, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetByMax, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMax, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMax, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMax, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs new file mode 100644 index 0000000..0f897ad --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMinAsyncTests.cs @@ -0,0 +1,212 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetByMinAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public async Task WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByMinAsync(filter, selector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByMinAsync(filter, selector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync(filter, selector, null, token), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetByMinAsync(filter, selector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetByMinAsync(filter, selector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMinAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> keyedSelector = document => document.SomeValue; + + [Fact] + public async Task Keyed_WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByMinAsync, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByMinAsync, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByMinAsync, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = await Sut.GetByMinAsync, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMinAsync, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMinAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMinTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMinTests.cs new file mode 100644 index 0000000..29b9f34 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetByMinTests.cs @@ -0,0 +1,211 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetByMinTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public void WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetByMin(filter, selector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMin(filter, selector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin(filter, selector, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetByMin(filter, selector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMin(filter, selector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMin( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, object>> keyedSelector = document => document.SomeValue; + + [Fact] + public void Keyed_WithFilterAndSelector_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupReader(document); + + // Act + var result = Sut.GetByMin, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMin, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetByMin, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetByMin, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetByMin, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetByMin, int>( + It.IsAny, bool>>>(), + It.IsAny, object>>>(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs new file mode 100644 index 0000000..d24d118 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMaxValueAsyncTests.cs @@ -0,0 +1,204 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetMaxValueAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public async Task WithFilterAndSelector_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + + SetupReader(value); + + // Act + var result = await Sut.GetMaxValueAsync(filter, selector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = await Sut.GetMaxValueAsync(filter, selector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync(filter, selector, null, token), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKey_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(value); + + // Act + var result = await Sut.GetMaxValueAsync(filter, selector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = await Sut.GetMaxValueAsync(filter, selector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMaxValueAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(value); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> keyedSelector = document => document.SomeValue; + + [Fact] + public async Task Keyed_WithFilterAndSelector_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMaxValueAsync, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(value); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMaxValueTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMaxValueTests.cs new file mode 100644 index 0000000..34f65c2 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMaxValueTests.cs @@ -0,0 +1,203 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetMaxValueTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public void WithFilterAndSelector_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + + SetupReader(value); + + // Act + var result = Sut.GetMaxValue(filter, selector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = Sut.GetMaxValue(filter, selector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue(filter, selector, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKey_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(value); + + // Act + var result = Sut.GetMaxValue(filter, selector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = Sut.GetMaxValue(filter, selector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMaxValue( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(value); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> keyedSelector = document => document.SomeValue; + + [Fact] + public void Keyed_WithFilterAndSelector_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMaxValue, int, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMaxValue, int, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue, int, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMaxValue, int, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMaxValue, int, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMaxValue, int, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMaxValue, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), + It.IsAny(), + It.IsAny())) + .Returns(value); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs new file mode 100644 index 0000000..8743b90 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMinValueAsyncTests.cs @@ -0,0 +1,204 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetMinValueAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public async Task WithFilterAndSelector_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + + SetupReader(value); + + // Act + var result = await Sut.GetMinValueAsync(filter, selector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = await Sut.GetMinValueAsync(filter, selector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync(filter, selector, null, token), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKey_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(value); + + // Act + var result = await Sut.GetMinValueAsync(filter, selector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = await Sut.GetMinValueAsync(filter, selector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMinValueAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(value); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> keyedSelector = document => document.SomeValue; + + [Fact] + public async Task Keyed_WithFilterAndSelector_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMinValueAsync, int, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = await Sut.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValueAsync, int, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMinValueAsync, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(value); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMinValueTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMinValueTests.cs new file mode 100644 index 0000000..34f9c58 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetMinValueTests.cs @@ -0,0 +1,203 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetMinValueTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> selector = document => document.SomeValue; + + [Fact] + public void WithFilterAndSelector_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + + SetupReader(value); + + // Act + var result = Sut.GetMinValue(filter, selector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue(filter, selector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndCancellationToken_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = Sut.GetMinValue(filter, selector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue(filter, selector, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKey_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(value); + + // Act + var result = Sut.GetMinValue(filter, selector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue(filter, selector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(value); + + // Act + var result = Sut.GetMinValue(filter, selector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue(filter, selector, partitionKey, token), + Times.Once); + } + + private void SetupReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMinValue( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(value); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> keyedSelector = document => document.SomeValue; + + [Fact] + public void Keyed_WithFilterAndSelector_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMinValue, int, int>(keyedFilter, keyedSelector); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMinValue, int, int>(keyedFilter, keyedSelector, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue, int, int>(keyedFilter, keyedSelector, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMinValue, int, int>(keyedFilter, keyedSelector, partitionKey); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMinValue() + { + // Arrange + var value = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(value); + + // Act + var result = Sut.GetMinValue, int, int>(keyedFilter, keyedSelector, partitionKey, token); + + // Assert + result.Should().Be(value); + Reader.Verify( + x => x.GetMinValue, int, int>(keyedFilter, keyedSelector, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(int value) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetMinValue, int, int>( + It.IsAny, bool>>>(), + It.IsAny, int>>>(), + It.IsAny(), + It.IsAny())) + .Returns(value); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs new file mode 100644 index 0000000..561cd2f --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetOneAsyncTests.cs @@ -0,0 +1,387 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetOneAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public async Task WithExpression_GetsOne() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync(expression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync(expression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync(expression, null, token), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync(expression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithExpressionAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync(expression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetOneAsync( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(document => document.SomeContent, "SomeContent"); + + [Fact] + public async Task Keyed_WithExpression_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedExpression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedExpression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedExpression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilter_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptions_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, options); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter, options, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, options, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter, options, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter,null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, options, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter,options, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter,null, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = await Sut.GetOneAsync, int>(keyedFilter, options, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOneAsync, int>(keyedFilter,options, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderWithFilter(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetOneAsync, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + private void SetupReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetOneAsync, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetOneTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetOneTests.cs new file mode 100644 index 0000000..7a4f0d6 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetOneTests.cs @@ -0,0 +1,386 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetOneTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> expression = document => document.SomeContent == "SomeContent"; + + [Fact] + public void WithExpression_GetsOne() + { + // Arrange + var document = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetOne(expression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne(expression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetOne(expression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne(expression, null, token), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(document); + + // Act + var result = Sut.GetOne(expression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne(expression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithExpressionAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(document); + + // Act + var result = Sut.GetOne(expression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne(expression, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestDocument document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetOne( + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #region Keyed + + private readonly Expression, bool>> keyedExpression = document => document.SomeContent == "SomeContent"; + private readonly FilterDefinition> keyedFilter = Builders>.Filter.Eq(document => document.SomeContent, "SomeContent"); + + [Fact] + public void Keyed_WithExpression_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetOne, int>(keyedExpression); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedExpression, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetOne, int>(keyedExpression, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedExpression, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetOne, int>(keyedExpression, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedExpression, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(document); + + // Act + var result = Sut.GetOne, int>(keyedExpression, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedExpression, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilter_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, null, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptions_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, options); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, options, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, null, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, options, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, options, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, null, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, options, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, options, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, null, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsOne() + { + // Arrange + var document = Fixture.Create>(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var options = new FindOptions(); + + SetupKeyedReaderWithFilter(document); + + // Act + var result = Sut.GetOne, int>(keyedFilter, options, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(document); + Reader.Verify( + x => x.GetOne, int>(keyedFilter, options, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetOne, int>( + It.IsAny, bool>>>(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + private void SetupKeyedReaderWithFilter(TestDocumentWithKey document) + { + Reader = new Mock(); + Reader + .Setup( + x => x.GetOne, int>( + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(document); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs new file mode 100644 index 0000000..a525bd2 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs @@ -0,0 +1,246 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetSortedPaginatedAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.GroupingKey == 1; + private readonly Expression> selector = document => document.GroupingKey; + private readonly SortDefinition sortDefinition = Builders.Sort.Ascending(document => document.GroupingKey); + + private const bool DefaultAscending = true; + private const int DefaultSkipNumber = 0; + private const int DefaultTakeNumber = 50; + + [Fact] + public async Task WithFilterAndSortSelector_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector); + + // Assert + VerifySelector(result, documents, DefaultAscending, DefaultSkipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndAscending_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var ascending = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, ascending); + + // Assert + VerifySelector(result, documents, ascending, DefaultSkipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndSkipNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var skipNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, skipNumber: skipNumber); + + // Assert + VerifySelector(result, documents, DefaultAscending, skipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndTakeNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var ascending = Fixture.Create(); + var takeNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, ascending, takeNumber: takeNumber); + + // Assert + VerifySelector(result, documents, ascending, DefaultSkipNumber, takeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndPartitionKey_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var partitionKey = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, partitionKey: partitionKey); + + // Assert + VerifySelector(result, documents, DefaultAscending, DefaultSkipNumber, DefaultTakeNumber, partitionKey, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndCancellationToken_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var cancellationToken = new CancellationToken(true); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, cancellationToken: cancellationToken); + + // Assert + VerifySelector(result, documents, DefaultAscending, DefaultSkipNumber, DefaultTakeNumber, null, cancellationToken); + } + + [Fact] + public async Task WithFilterAndSortDefinition_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndSkipNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var skipNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, skipNumber); + + // Assert + VerifyDefinition(result, documents, skipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndTakeNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var takeNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, takeNumber: takeNumber); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, takeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndPartitionKey_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var partitionKey = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, partitionKey: partitionKey); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, partitionKey, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndCancellationToken_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var token = new CancellationToken(true); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, cancellationToken: token); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, token); + } + + private List SetupReaderWithSortSelector() + { + var documents = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GetSortedPaginatedAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + return documents; + } + + private void VerifySelector(List result, List documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) + { + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(documents); + Reader.Verify( + x => x.GetSortedPaginatedAsync( + filter, + selector, + ascending, + skipNumber, + takeNumber, + partitionKey, + cancellationToken), + Times.Once); + } + + private List SetupReaderWithSortDefinition() + { + var documents = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GetSortedPaginatedAsync( + It.IsAny>>(), + It.IsAny>(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + return documents; + } + + private void VerifyDefinition(List result, List documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) + { + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(documents); + Reader.Verify( + x => x.GetSortedPaginatedAsync( + filter, + sortDefinition, + skipNumber, + takeNumber, + partitionKey, + cancellationToken), + Times.Once); + } +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs new file mode 100644 index 0000000..090b433 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs @@ -0,0 +1,474 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GroupByTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> grouping = document => document.GroupingKey; + private readonly Expression, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()}; + private readonly Expression> filter = document => document.GroupingKey == 1; + + [Fact] + public void WithGroupingCriteriaAndProjection_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithGroupingCriteriaAndProjectionAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, null, token), + Times.Once); + } + + [Fact] + public void WithGroupingCriteriaAndProjectionAndPartitionKey_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, partitionKey, token), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjection_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjectionAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjectionAndPartitionKey_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, partitionKey, token), + Times.Once); + } + + #region Keyed + + private readonly Expression, int>> keyedGrouping = document => document.GroupingKey; + private readonly Expression>, TestProjection>> keyedProjection = documents => new TestProjection {Count = documents.Count()}; + private readonly Expression, bool>> keyedFilter = document => document.GroupingKey == 1; + + [Fact] + public void Keyed_WithGroupingCriteriaAndProjection_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithGroupingCriteriaAndProjectionAndCancellationToken_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithGroupingCriteriaAndProjectionAndPartitionKey_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndGroupingCriteriaAndProjection_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndGroupingCriteriaAndProjectionAndCancellationToken_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndGroupingCriteriaAndProjectionAndPartitionKey_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy, int, TestProjection, int>( + It.IsAny,bool>>>(), + It.IsAny, int>>>(), + It.IsAny>, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + + // Act + var result = Sut.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(keyedProjections); + Reader.Verify( + x => x.GroupBy, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey, token), + Times.Once); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs new file mode 100644 index 0000000..cedbb19 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectManyAsyncTests.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class ProjectManyAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public async Task WithFilterAndProjection_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + + SetupReader(projections); + + // Act + var result = await Sut.ProjectManyAsync(filter, projection); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync( + filter, + projection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + + SetupReader(projections); + + // Act + var result = await Sut.ProjectManyAsync(filter, projection, token); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync(filter, projection, null, token), + Times.Once); + } + + [Fact] + public async Task WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + + SetupReader(projections); + + // Act + var result = await Sut.ProjectManyAsync(filter, projection, partitionKey); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync(filter, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(projections); + + // Act + var result = await Sut.ProjectManyAsync(filter, projection, partitionKey, token); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync(filter, projection, partitionKey, token), + Times.Once); + } + + private void SetupReader(List projections) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectManyAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(projections); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public async Task Keyed_WithFilterAndProjection_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + + SetupKeyedReader(keyedProjections); + + // Act + var result = await Sut.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync, TestProjection, int>( + keyedFilter, + keyedProjection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + + SetupKeyedReader(keyedProjections); + + // Act + var result = await Sut.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection, token); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(keyedProjections); + + // Act + var result = await Sut.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(keyedProjections); + + // Act + var result = await Sut.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectManyAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(List keyedProjections) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectManyAsync, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(keyedProjections); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectManyTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectManyTests.cs new file mode 100644 index 0000000..2e761fb --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectManyTests.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class ProjectManyTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public void WithFilterAndProjection_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + + SetupReader(projections); + + // Act + var result = Sut.ProjectMany(filter, projection); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectMany( + filter, + projection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + + SetupReader(projections); + + // Act + var result = Sut.ProjectMany(filter, projection, token); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectMany(filter, projection, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + + SetupReader(projections); + + // Act + var result = Sut.ProjectMany(filter, projection, partitionKey); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectMany(filter, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(projections); + + // Act + var result = Sut.ProjectMany(filter, projection, partitionKey, token); + + // Assert + result.Should().OnlyContain(x => projections.Contains(x)); + Reader.Verify( + x => x.ProjectMany(filter, projection, partitionKey, token), + Times.Once); + } + + private void SetupReader(List projections) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectMany( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public void Keyed_WithFilterAndProjection_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + + SetupKeyedReader(keyedProjections); + + // Act + var result = Sut.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectMany, TestProjection, int>( + keyedFilter, + keyedProjection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + + SetupKeyedReader(keyedProjections); + + // Act + var result = Sut.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection, token); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(keyedProjections); + + // Act + var result = Sut.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection, partitionKey); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var keyedProjections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(keyedProjections); + + // Act + var result = Sut.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token); + + // Assert + result.Should().OnlyContain(x => keyedProjections.Contains(x)); + Reader.Verify( + x => x.ProjectMany, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(List keyedProjections) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectMany, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(keyedProjections); + } + + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs new file mode 100644 index 0000000..40dc725 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectOneAsyncTests.cs @@ -0,0 +1,212 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class ProjectOneAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public async Task WithFilterAndProjection_Projects() + { + // Arrange + var expected = Fixture.Create(); + + SetupReader(expected); + + // Act + var result = await Sut.ProjectOneAsync(filter, projection); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync( + filter, + projection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(expected); + + // Act + var result = await Sut.ProjectOneAsync(filter, projection, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync(filter, projection, null, token), + Times.Once); + } + + [Fact] + public async Task WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(expected); + + // Act + var result = await Sut.ProjectOneAsync(filter, projection, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync(filter, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(expected); + + // Act + var result = await Sut.ProjectOneAsync(filter, projection, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync(filter, projection, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestProjection result) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectOneAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(result); + } + + #region keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public async Task Keyed_WithFilterAndProjection_Projects() + { + // Arrange + var expected = Fixture.Create(); + + SetupKeyedReader(expected); + + // Act + var result = await Sut.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync, TestProjection, int>( + keyedFilter, + keyedProjection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(expected); + + // Act + var result = await Sut.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(expected); + + // Act + var result = await Sut.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(expected); + + // Act + var result = await Sut.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOneAsync, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(TestProjection result) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectOneAsync, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(result); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectOneTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectOneTests.cs new file mode 100644 index 0000000..7b14d3b --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/ProjectOneTests.cs @@ -0,0 +1,211 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class ProjectOneTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> projection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public void WithFilterAndProjection_Projects() + { + // Arrange + var expected = Fixture.Create(); + + SetupReader(expected); + + // Act + var result = Sut.ProjectOne(filter, projection); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne( + filter, + projection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(expected); + + // Act + var result = Sut.ProjectOne(filter, projection, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne(filter, projection, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReader(expected); + + // Act + var result = Sut.ProjectOne(filter, projection, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne(filter, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReader(expected); + + // Act + var result = Sut.ProjectOne(filter, projection, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne(filter, projection, partitionKey, token), + Times.Once); + } + + private void SetupReader(TestProjection result) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectOne( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .Returns(result); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate}; + + [Fact] + public void Keyed_WithFilterAndProjection_Projects() + { + // Arrange + var expected = Fixture.Create(); + + SetupKeyedReader(expected); + + // Act + var result = Sut.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne, TestProjection, int>( + keyedFilter, + keyedProjection, + null, + CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndProjectionAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(expected); + + // Act + var result = Sut.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection, null, token), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndProjectionAndPartitionKey_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReader(expected); + + // Act + var result = Sut.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReader(expected); + + // Act + var result = Sut.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.ProjectOne, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReader(TestProjection result) + { + Reader = new Mock(); + Reader + .Setup( + x => x.ProjectOne, TestProjection, int>( + It.IsAny, bool>>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(result); + } + + #endregion +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/SumByAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/SumByAsyncTests.cs new file mode 100644 index 0000000..3a18707 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/SumByAsyncTests.cs @@ -0,0 +1,384 @@ +using System; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class SumByAsyncTests : TestReadOnlyMongoRepositoryContext +{ + private readonly Expression> decimalSelector = document => document.SomeDecimalValue; + private readonly Expression> filter = document => document.SomeContent == "SomeContent"; + private readonly Expression> intSelector = document => document.SomeValue; + + [Fact] + public async Task Int_WithFilterAndSelector_Sums() + { + // Arrange + var expected = Fixture.Create(); + + SetupReaderInt(expected); + + // Act + var result = await Sut.SumByAsync(filter, intSelector); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, intSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Int_WithFilterAndSelectorAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReaderInt(expected); + + // Act + var result = await Sut.SumByAsync(filter, intSelector, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, intSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Int_WithFilterAndSelectorAndPartitionKey_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReaderInt(expected); + + // Act + var result = await Sut.SumByAsync(filter, intSelector, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, intSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Int_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReaderInt(expected); + + // Act + var result = await Sut.SumByAsync(filter, intSelector, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, intSelector, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Decimal_WithFilterAndSelector_Sums() + { + // Arrange + var expected = Fixture.Create(); + + SetupReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync(filter, decimalSelector); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, decimalSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Decimal_WithFilterAndSelectorAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync(filter, decimalSelector, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, decimalSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Decimal_WithFilterAndSelectorAndPartitionKey_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync(filter, decimalSelector, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, decimalSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Decimal_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync(filter, decimalSelector, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync(filter, decimalSelector, partitionKey, token), + Times.Once); + } + + private void SetupReaderInt(int expected) + { + Reader = new Mock(); + Reader + .Setup( + x => x.SumByAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(expected); + } + + private void SetupReaderDecimal(decimal expected) + { + Reader = new Mock(); + Reader + .Setup( + x => x.SumByAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(expected); + } + + #region Keyed + + private readonly Expression, bool>> keyedFilter = document => document.SomeContent == "SomeContent"; + private readonly Expression, int>> keyedIntSelector = document => document.SomeValue; + private readonly Expression, decimal>> keyedDecimalSelector = document => document.SomeDecimalValue; + + [Fact] + public async Task Keyed_Int_WithFilterAndSelector_Sums() + { + // Arrange + var expected = Fixture.Create(); + + SetupKeyedReaderInt(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedIntSelector); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedIntSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_Int_WithFilterAndSelectorAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderInt(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedIntSelector, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedIntSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_Int_WithFilterAndSelectorAndPartitionKey_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderInt(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedIntSelector, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedIntSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_Int_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderInt(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedIntSelector, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedIntSelector, partitionKey, token), + Times.Once); + } + + [Fact] + public async Task Keyed_Decimal_WithFilterAndSelector_Sums() + { + // Arrange + var expected = Fixture.Create(); + + SetupKeyedReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedDecimalSelector); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedDecimalSelector, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_Decimal_WithFilterAndSelectorAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedDecimalSelector, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedDecimalSelector, null, token), + Times.Once); + } + + [Fact] + public async Task Keyed_Decimal_WithFilterAndSelectorAndPartitionKey_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + + SetupKeyedReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedDecimalSelector, partitionKey); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedDecimalSelector, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public async Task Keyed_Decimal_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums() + { + // Arrange + var expected = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + + SetupKeyedReaderDecimal(expected); + + // Act + var result = await Sut.SumByAsync, int>(keyedFilter, keyedDecimalSelector, partitionKey, token); + + // Assert + result.Should().Be(expected); + Reader.Verify( + x => x.SumByAsync, int>(keyedFilter, keyedDecimalSelector, partitionKey, token), + Times.Once); + } + + private void SetupKeyedReaderInt(int expected) + { + Reader = new Mock(); + Reader + .Setup( + x => x.SumByAsync, int>( + It.IsAny, bool>>>(), + It.IsAny,int>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(expected); + } + + private void SetupKeyedReaderDecimal(decimal expected) + { + Reader = new Mock(); + Reader + .Setup( + x => x.SumByAsync, int>( + It.IsAny, bool>>>(), + It.IsAny, decimal>>>(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(expected); + } + + #endregion +} diff --git a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs index 185ef77..be4bbee 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs @@ -1,56 +1,194 @@ -using MongoDB.Driver; -using MongoDbGenericRepository.Models; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Threading; using System.Threading.Tasks; +using MongoDB.Driver; +using MongoDbGenericRepository.Models; +using CancellationToken = System.Threading.CancellationToken; namespace MongoDbGenericRepository { /// - /// The IBaseReadOnlyRepository exposes the generic Read Only functionality of the BaseMongoRepository. + /// The IBaseReadOnlyRepository exposes the generic Read Only functionality of the BaseMongoRepository. /// public interface IBaseReadOnlyRepository { /// - /// The connection string. + /// The connection string. /// string ConnectionString { get; } /// - /// The database name. + /// The database name. /// string DatabaseName { get; } #region Read TKey /// - /// Asynchronously returns one document given its id. + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + Task GetByIdAsync(TKey id) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional cancellation Token. + Task GetByIdAsync(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + Task GetByIdAsync(TKey id, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given its id. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. /// An optional cancellation Token. - Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) + Task GetByIdAsync(TKey id, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Returns one document given its id. + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + TDocument GetById(TKey id) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional cancellation token. + TDocument GetById(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given its id. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - TDocument GetById(TKey id, string partitionKey = null) + TDocument GetById(TKey id, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Asynchronously returns one document given filter definition. + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + /// An optional cancellation token. + TDocument GetById(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + Task GetOneAsync(FilterDefinition condition) + where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + Task GetOneAsync(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + Task GetOneAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + Task GetOneAsync(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation Token. + Task GetOneAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional cancellation Token. + Task GetOneAsync(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + /// An optional cancellation Token. + Task GetOneAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -58,46 +196,201 @@ namespace MongoDbGenericRepository /// A mongodb filter option. /// An optional partition key. /// An optional cancellation Token. - Task GetOneAsync(FilterDefinition condition, FindOptions findOption = null, - string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument where TKey : IEquatable; + Task GetOneAsync( + FilterDefinition condition, + FindOptions findOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; /// - /// Returns one document given filter definition. + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + TDocument GetOne(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + TDocument GetOne(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + TDocument GetOne(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given filter definition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A mongodb filter definition. /// A mongodb filter option. /// An optional partition key. - TDocument GetOne(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) - where TDocument : IDocument where TKey : IEquatable; + TDocument GetOne(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; /// - /// Asynchronously returns one document given an expression filter. + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation token. + TDocument GetOne(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + + /// + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional cancellation token. + TDocument GetOne(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + /// An optional cancellation token. + TDocument GetOne(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation token. + TDocument GetOne( + FilterDefinition condition, + FindOptions findOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + Task GetOneAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation Token. + Task GetOneAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task GetOneAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given an expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + Task GetOneAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Returns one document given an expression filter. + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + TDocument GetOne(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation token. + TDocument GetOne(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given an expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - TDocument GetOne(Expression> filter, string partitionKey = null) + TDocument GetOne(Expression> filter, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Returns a collection cursor. + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// An optional cancellation token. + TDocument GetOne(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a collection cursor. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -108,7 +401,86 @@ namespace MongoDbGenericRepository where TKey : IEquatable; /// - /// Returns true if any of the document of the collection matches the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation Token. + Task AnyAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + Task AnyAsync(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + Task AnyAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + Task AnyAsync(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partition key. + Task AnyAsync(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + /// An optional cancellation Token. + Task AnyAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional cancellation Token. + Task AnyAsync(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -116,46 +488,271 @@ namespace MongoDbGenericRepository /// A mongodb counting option. /// An optional partition key. /// An optional cancellation Token. - Task AnyAsync(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument where TKey : IEquatable; + Task AnyAsync(FilterDefinition condition, CountOptions countOption, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; /// - /// Returns true if any of the document of the collection matches the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + bool Any(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + bool Any(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + bool Any(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A mongodb filter definition. /// A mongodb counting option. /// An optional partition key. - bool Any(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null) - where TDocument : IDocument where TKey : IEquatable; + bool Any(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; /// - /// Returns true if any of the document of the collection matches the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation token. + bool Any(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + /// An optional cancellation token. + bool Any(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional cancellation token. + bool Any(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partition key. + /// An optional cancellation token. + bool Any(FilterDefinition condition, CountOptions countOption, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + Task AnyAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation Token. + Task AnyAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task AnyAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + Task AnyAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Returns true if any of the document of the collection matches the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + bool Any(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation Token. + bool Any(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - bool Any(Expression> filter, string partitionKey = null) + bool Any(Expression> filter, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Asynchronously returns a list of the documents matching the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// An optional cancellation Token. + bool Any(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + Task> GetAllAsync(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + Task> GetAllAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + Task> GetAllAsync(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + Task> GetAllAsync(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation Token. + Task> GetAllAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + /// An optional cancellation Token. + Task> GetAllAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional cancellation Token. + Task> GetAllAsync(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -163,46 +760,271 @@ namespace MongoDbGenericRepository /// A mongodb filter option. /// An optional partition key. /// An optional cancellation Token. - Task> GetAllAsync(FilterDefinition condition, - FindOptions findOption = null, string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument where TKey : IEquatable; + Task> GetAllAsync(FilterDefinition condition, FindOptions findOption, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; /// - /// Returns a list of the documents matching the filter condition. + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + List GetAll(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + List GetAll(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + List GetAll(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A mongodb filter definition. /// A mongodb filter option. /// An optional partition key. - List GetAll(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) - where TDocument : IDocument where TKey : IEquatable; - + List GetAll(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + /// - /// Asynchronously returns a list of the documents matching the filter condition. + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation Token. + List GetAll(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partition key. + /// An optional cancellation Token. + List GetAll(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional cancellation Token. + List GetAll(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + List GetAll(FilterDefinition condition, FindOptions findOption, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + Task> GetAllAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation Token. + Task> GetAllAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task> GetAllAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + Task> GetAllAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Returns a list of the documents matching the filter condition. + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + List GetAll(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation token. + List GetAll(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - List GetAll(Expression> filter, string partitionKey = null) + List GetAll(Expression> filter, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Asynchronously counts how many documents match the filter condition. + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// An optional cancellation token. + List GetAll(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + Task CountAsync(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partitionKey + Task CountAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + Task CountAsync(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partitionKey + Task CountAsync(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation Token. + Task CountAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partitionKey + /// An optional cancellation Token. + Task CountAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional cancellation Token. + Task CountAsync(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -210,42 +1032,187 @@ namespace MongoDbGenericRepository /// A mongodb counting option. /// An optional partitionKey /// An optional cancellation Token. - Task CountAsync(FilterDefinition condition, CountOptions countOption = null, - string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument where TKey : IEquatable; + Task CountAsync(FilterDefinition condition, CountOptions countOption, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; /// - /// Counts how many documents match the filter condition. + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + long Count(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partitionKey + long Count(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + long Count(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A mongodb filter definition. /// A mongodb counting option. /// An optional partitionKey - long Count(FilterDefinition condition, CountOptions countOption = null, - string partitionKey = null) - where TDocument : IDocument where TKey : IEquatable; - + long Count(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + /// - /// Asynchronously counts how many documents match the filter condition. + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional cancellation token. + long Count(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// An optional partitionKey + /// An optional cancellation token. + long Count(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional cancellation token. + long Count(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partitionKey + /// An optional cancellation token. + long Count(FilterDefinition condition, CountOptions countOption, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + Task CountAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional cancellation Token. + Task CountAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + Task CountAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partitionKey /// An optional cancellation Token. - Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + Task CountAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Counts how many documents match the filter condition. + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + long Count(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional Cancellation Token. + long Count(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partitionKey - long Count(Expression> filter, string partitionKey = null) + long Count(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + /// An optional Cancellation Token. + long Count(Expression> filter, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; @@ -254,7 +1221,47 @@ namespace MongoDbGenericRepository #region Min / Max /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional cancellation Token. + Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional partitionKey. + Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// The type of the primary key. @@ -262,55 +1269,193 @@ namespace MongoDbGenericRepository /// A property selector to order by descending. /// An optional partitionKey. /// An optional cancellation Token. - Task GetByMaxAsync( - Expression> filter, - Expression> maxValueSelector, - string partitionKey = null, CancellationToken cancellationToken = default) + Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + TDocument GetByMax(Expression> filter, Expression> orderByDescending) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional cancellation token. + TDocument GetByMax(Expression> filter, Expression> orderByDescending, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. - TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey = null) + TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional partitionKey. + /// An optional cancellation token. + TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector for the minimum value you are looking for. + Task GetByMinAsync(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector for the minimum value you are looking for. - /// An optional partitionKey. /// An optional cancellation Token. - Task GetByMinAsync(Expression> filter, - Expression> minValueSelector, - string partitionKey = null, - CancellationToken cancellationToken = default) + Task GetByMinAsync(Expression> filter, Expression> minValueSelector, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector for the minimum value you are looking for. /// An optional partitionKey. - TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) + Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector for the minimum value you are looking for. + /// An optional partitionKey. + /// An optional cancellation token. + Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector for the minimum value you are looking for. + TDocument GetByMin(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector for the minimum value you are looking for. + /// An optional cancellation token. + TDocument GetByMin(Expression> filter, Expression> minValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector for the minimum value you are looking for. + /// An optional partitionKey. + TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector for the minimum value you are looking for. + /// An optional partitionKey. + /// An optional cancellation token. + TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector for the maximum value you are looking for. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector for the maximum value you are looking for. + /// An optional cancellation Token. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. @@ -318,17 +1463,51 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// A property selector for the maximum value you are looking for. /// An optional partitionKey. - /// An optional cancellation Token. - Task GetMaxValueAsync( - Expression> filter, - Expression> maxValueSelector, - string partitionKey = null, - CancellationToken cancellationToken = default) + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector for the maximum value you are looking for. + /// An optional partitionKey. + /// An optional cancellation token. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional cancellation token. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. @@ -336,30 +1515,51 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + /// An optional cancellation token. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. - /// An optional partition key. /// An optional cancellation Token. - Task GetMinValueAsync( - Expression> filter, - Expression> minValueSelector, - string partitionKey = null, - CancellationToken cancellationToken = default) + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. @@ -367,7 +1567,73 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey = null) + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partition key. + /// An optional cancellation token. + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + TValue GetMinValue(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional cancellation token. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partition key. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partition key. + /// An optional cancellation token. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; @@ -376,60 +1642,125 @@ namespace MongoDbGenericRepository #region Sum /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key. + /// A LINQ expression filter. + /// The field you want to sum. + Task SumByAsync(Expression> filter, Expression> selector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key. /// A LINQ expression filter. /// The field you want to sum. - /// The partition key of your document, if any. /// An optional cancellation Token. - Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null, - CancellationToken cancellationToken = default) + Task SumByAsync(Expression> filter, Expression> selector, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. - int SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. - Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null) + /// An optional cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. - decimal SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) + int SumBy(Expression> filter, Expression> selector, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key. + /// A LINQ expression filter. + /// The field you want to sum. + Task SumByAsync(Expression> filter, Expression> selector) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key. + /// A LINQ expression filter. + /// The field you want to sum. + /// An optional cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + /// An optional cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + decimal SumBy( + Expression> filter, + Expression> selector, + string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; @@ -438,7 +1769,34 @@ namespace MongoDbGenericRepository #region Project TKey /// - /// Asynchronously returns a projected document matching the filter condition. + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + Task ProjectOneAsync(Expression> filter, Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional cancellation Token. + Task ProjectOneAsync(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -446,32 +1804,13 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - /// An optional cancellation Token. - Task ProjectOneAsync( - Expression> filter, - Expression> projection, - string partitionKey = null, - CancellationToken cancellationToken = default) + Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey) where TDocument : IDocument where TKey : IEquatable where TProjection : class; /// - /// Returns a projected document matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type representing the model you want to project to. - /// - /// The projection expression. - /// An optional partition key. - TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class; - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. + /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -479,18 +1818,41 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - /// An optional cancellation Token. - Task> ProjectManyAsync( - Expression> filter, - Expression> projection, - string partitionKey = null, - CancellationToken cancellationToken = default) + /// An optional cancellation token. + Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable where TProjection : class; /// - /// Asynchronously returns a list of projected documents matching the filter condition. + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + TProjection ProjectOne(Expression> filter, Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional cancellation token. + TProjection ProjectOne(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -498,7 +1860,134 @@ namespace MongoDbGenericRepository /// /// The projection expression. /// An optional partition key. - List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + /// An optional cancellation token. + TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + Task> ProjectManyAsync(Expression> filter, Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional cancellation Token. + Task> ProjectManyAsync(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + /// An optional cancellation token. + Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + List ProjectMany(Expression> filter, Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional cancellation token. + List ProjectMany(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + List ProjectMany(Expression> filter, Expression> projection, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + /// An optional cancellation token. + List ProjectMany(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable where TProjection : class; @@ -508,8 +1997,39 @@ namespace MongoDbGenericRepository #region Group By /// - /// Groups filtered a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The type of the primary key. + /// The grouping criteria. + /// The projected group result. + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The type of the primary key. + /// The grouping criteria. + /// The projected group result. + /// An optional cancellation token. + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. /// /// The type representing a Document. /// The type of the grouping criteria. @@ -518,17 +2038,64 @@ namespace MongoDbGenericRepository /// The grouping criteria. /// The projected group result. /// The partition key of your document, if any. - List GroupBy( - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey) where TDocument : IDocument where TKey : IEquatable where TProjection : class, new(); /// - /// Groups filtered a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The type of the primary key. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// An optional cancellation token. + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The type of the primary key. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The type of the primary key. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + /// An optional cancellation token. + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. /// /// The type representing a Document. /// The type of the grouping criteria. @@ -538,21 +2105,35 @@ namespace MongoDbGenericRepository /// The grouping criteria. /// The projected group result. /// The partition key of your document, if any. - List GroupBy( - Expression> filter, - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class, new(); + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The type of the primary key. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// An optional cancellation token. + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); #endregion Group By #region Pagination /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// Asynchronously returns a paginated list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -562,18 +2143,20 @@ namespace MongoDbGenericRepository /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation token. Task> GetSortedPaginatedAsync( Expression> filter, Expression> sortSelector, bool ascending = true, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// Asynchronously returns a paginated list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. @@ -595,4 +2178,4 @@ namespace MongoDbGenericRepository #endregion Pagination } -} +} \ No newline at end of file diff --git a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs index 7d8325a..54913fc 100644 --- a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs +++ b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs @@ -1,22 +1,22 @@ -using MongoDB.Driver; -using MongoDbGenericRepository.Models; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using MongoDB.Driver; +using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { /// - /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. - /// Its constructor must be given a connection string and a database name. + /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. + /// Its constructor must be given a connection string and a database name. /// public abstract class ReadOnlyMongoRepository : ReadOnlyMongoRepository, IReadOnlyMongoRepository { /// - /// The constructor taking a connection string and a database name. + /// The constructor taking a connection string and a database name. /// /// The connection string of the MongoDb server. /// The name of the database against which you want to perform operations. @@ -25,717 +25,24 @@ namespace MongoDbGenericRepository } /// - /// The constructor taking a . + /// The constructor taking a . /// - /// A mongodb context implementing + /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } /// - /// The constructor taking a . + /// The constructor taking a . /// - /// A mongodb context implementing + /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase) { } - #region Read TKey /// - /// Asynchronously returns one document given its id. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The Id of the document you want to get. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetByIdAsync(id, partitionKey, cancellationToken); - } - - /// - /// Returns one document given its id. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The Id of the document you want to get. - /// An optional partition key. - public virtual TDocument GetById(TKey id, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetById(id, partitionKey); - } - - /// - /// Asynchronously returns one document given filter definition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb filter option. - /// An optional partition key. - /// An optional cancellation Token. - public Task GetOneAsync(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null, - CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.GetOneAsync(condition, findOption, partitionKey, cancellationToken); - } - - /// - /// Returns one document given filter definition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb filter option. - /// An optional partition key. - public TDocument GetOne(FilterDefinition condition, FindOptions findOption = null, - string partitionKey = null) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.GetOne(condition, findOption, partitionKey); - } - - /// - /// Asynchronously returns one document given an expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetOneAsync(filter, partitionKey, cancellationToken); - } - - /// - /// Returns one document given an expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - public virtual TDocument GetOne(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetOne(filter, partitionKey); - } - - /// - /// Returns a collection cursor. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - public virtual IFindFluent GetCursor(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetCursor(filter, partitionKey); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb counting option. - /// An optional partition key. - /// An optional cancellation Token. - public Task AnyAsync(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null, - CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.AnyAsync(condition, countOption, partitionKey, cancellationToken); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb counting option. - /// An optional partition key. - public bool Any(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.Any(condition, countOption, partitionKey); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.AnyAsync(filter, partitionKey, cancellationToken); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - public virtual bool Any(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.Any(filter, partitionKey); - } - - /// - /// Asynchronously returns a list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb filter option. - /// An optional partition key. - /// An optional cancellation Token. - public Task> GetAllAsync(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null, - CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.GetAllAsync(condition, findOption, partitionKey, cancellationToken); - } - - /// - /// Returns a list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb filter option. - /// An optional partition key. - public List GetAll(FilterDefinition condition, FindOptions findOption = null, - string partitionKey = null) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.GetAll(condition, findOption, partitionKey); - } - - /// - /// Asynchronously returns a list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetAllAsync(filter, partitionKey, cancellationToken); - } - - /// - /// Returns a list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - public virtual List GetAll(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetAll(filter, partitionKey); - } - - /// - /// Asynchronously counts how many documents match the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb counting option. - /// An optional partitionKey - /// An optional cancellation Token. - public Task CountAsync(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null, - CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.CountAsync(condition, countOption, partitionKey, cancellationToken); - } - - /// - /// Counts how many documents match the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A mongodb filter definition. - /// A mongodb counting option. - /// An optional partitionKey - public long Count(FilterDefinition condition, CountOptions countOption = null, - string partitionKey = null) where TDocument : IDocument where TKey : IEquatable - { - return MongoDbReader.Count(condition, countOption, partitionKey); - } - - /// - /// Asynchronously counts how many documents match the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partitionKey - /// An optional cancellation Token. - public virtual async Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.CountAsync(filter, partitionKey, cancellationToken); - } - - /// - /// Counts how many documents match the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partitionKey - public virtual long Count(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.Count(filter, partitionKey); - } - - /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// A LINQ expression filter. - /// A property selector to order by descending. - /// An optional partitionKey. - /// An optional cancellation Token. - public virtual async Task GetByMaxAsync( - Expression> filter, - Expression> maxValueSelector, - string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey, cancellationToken); - } - - /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// A LINQ expression filter. - /// A property selector to order by descending. - /// An optional partitionKey. - public virtual TDocument GetByMax(Expression> filter, Expression> maxValueSelector, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetByMax(filter, maxValueSelector, partitionKey); - } - - /// - /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// A LINQ expression filter. - /// A property selector for the minimum value you are looking for. - /// An optional partitionKey. - /// An optional cancellation Token. - public virtual async Task GetByMinAsync(Expression> filter, - Expression> minValueSelector, - string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetByMinAsync(filter, minValueSelector, partitionKey, cancellationToken); - } - - /// - /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// A LINQ expression filter. - /// A property selector for the minimum value you are looking for. - /// An optional partitionKey. - public virtual TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetByMin(filter, minValueSelector, partitionKey); - } - - /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector for the maximum value you are looking for. - /// An optional partitionKey. - /// An optional cancellation Token. - public virtual async Task GetMaxValueAsync( - Expression> filter, - Expression> maxValueSelector, - string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey, cancellationToken); - } - - /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partitionKey. - public virtual TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetMaxValue(filter, maxValueSelector, partitionKey); - } - - /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task GetMinValueAsync( - Expression> filter, - Expression> minValueSelector, - string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey, cancellationToken); - } - - /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the primary key. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partition key. - public virtual TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.GetMinValue(filter, minValueSelector, partitionKey); - } - - #endregion - - #region Sum TKey - - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// The type of the primary key. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - /// An optional cancellation Token. - public virtual async Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.SumByAsync(filter, selector, partitionKey, cancellationToken); - } - - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// The type of the primary key. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual int SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.SumBy(filter, selector, partitionKey); - } - - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// The type of the primary key. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual async Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return await MongoDbReader.SumByAsync(filter, selector, partitionKey); - } - - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// The type of the primary key. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual decimal SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - return MongoDbReader.SumBy(filter, selector, partitionKey); - } - - #endregion Sum TKey - - #region Project TKey - - /// - /// Asynchronously returns a projected document matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type representing the model you want to project to. - /// A LINQ expression filter. - /// The projection expression. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task ProjectOneAsync( - Expression> filter, - Expression> projection, - string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class - { - return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey, cancellationToken); - } - - /// - /// Returns a projected document matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type representing the model you want to project to. - /// A LINQ expression filter. - /// The projection expression. - /// An optional partition key. - public virtual TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class - { - return MongoDbReader.ProjectOne(filter, projection, partitionKey); - } - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type representing the model you want to project to. - /// A LINQ expression filter. - /// The projection expression. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task> ProjectManyAsync( - Expression> filter, - Expression> projection, - string partitionKey = null, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class - { - return await MongoDbReader.ProjectManyAsync(filter, projection, partitionKey, cancellationToken); - } - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type representing the model you want to project to. - /// The document filter. - /// The projection expression. - /// An optional partition key. - public virtual List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class - { - return MongoDbReader.ProjectMany(filter, projection, partitionKey); - } - - #endregion Project TKey - - #region Group By TKey - - /// - /// Groups filtered a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the grouping criteria. - /// The type of the projected group. - /// The grouping criteria. - /// The projected group result. - /// The partition key of your document, if any. - public virtual List GroupBy( - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class, new() - { - return MongoDbReader.GroupBy(groupingCriteria, groupProjection, partitionKey); - } - - /// - /// Groups filtered a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the grouping criteria. - /// The type of the projected group. - /// A LINQ expression filter. - /// The grouping criteria. - /// The projected group result. - /// The partition key of your document, if any. - public virtual List GroupBy( - Expression> filter, - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class, new() - { - return MongoDbReader.GroupBy(filter, groupingCriteria, groupProjection, partitionKey); - } - - #endregion Group By TKey - - - #region Pagination - - /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// The property selector. - /// Order of the sorting. - /// The number of documents you want to skip. Default value is 0. - /// The number of documents you want to take. Default value is 50. - /// An optional partition key. - public virtual async Task> GetSortedPaginatedAsync( - Expression> filter, - Expression> sortSelector, - bool ascending = true, - int skipNumber = 0, - int takeNumber = 50, - string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - { - var sorting = ascending - ? Builders.Sort.Ascending(sortSelector) - : Builders.Sort.Descending(sortSelector); - - return await HandlePartitioned(partitionKey) - .Find(filter) - .Sort(sorting) - .Skip(skipNumber) - .Limit(takeNumber) - .ToListAsync(); - } - - /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// The sort definition. - /// The number of documents you want to skip. Default value is 0. - /// The number of documents you want to take. Default value is 50. - /// An optional partition key. - /// An optional cancellation Token. - public virtual async Task> GetSortedPaginatedAsync( - Expression> filter, - SortDefinition sortDefinition, - int skipNumber = 0, - int takeNumber = 50, - string partitionKey = null, - CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable - { - return await HandlePartitioned(partitionKey) - .Find(filter) - .Sort(sortDefinition) - .Skip(skipNumber) - .Limit(takeNumber) - .ToListAsync(cancellationToken); - } - - #endregion Pagination - - - - /// - /// Gets a collections for a potentially partitioned document type. + /// Gets a collections for a potentially partitioned document type. /// /// The document type. /// The type of the primary key. @@ -749,7 +56,7 @@ namespace MongoDbGenericRepository } /// - /// Gets a collections for a potentially partitioned document type. + /// Gets a collections for a potentially partitioned document type. /// /// The document type. /// The type of the primary key. @@ -763,11 +70,12 @@ namespace MongoDbGenericRepository { return GetCollection(partitionKey); } + return GetCollection(); } /// - /// Gets a collections for a potentially partitioned document type. + /// Gets a collections for a potentially partitioned document type. /// /// The document type. /// The document. @@ -779,7 +87,7 @@ namespace MongoDbGenericRepository } /// - /// Gets a collections for the type TDocument with a partition key. + /// Gets a collections for the type TDocument with a partition key. /// /// The document type. /// The type of the primary key. @@ -791,5 +99,1693 @@ namespace MongoDbGenericRepository { return MongoDbReader.GetCollection(partitionKey); } + + #region Read TKey + + /// + public virtual async Task GetByIdAsync(TKey id) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByIdAsync(id, null, CancellationToken.None); + } + + /// + public virtual async Task GetByIdAsync(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByIdAsync(id, null, cancellationToken); + } + + /// + public virtual async Task GetByIdAsync(TKey id, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByIdAsync(id, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetByIdAsync(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetByIdAsync(id, partitionKey, cancellationToken); + } + + /// + public virtual TDocument GetById(TKey id) + where TDocument : IDocument + where TKey : IEquatable + { + return GetById(id, null, CancellationToken.None); + } + + /// + public virtual TDocument GetById(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetById(id, null, cancellationToken); + } + + /// + public virtual TDocument GetById(TKey id, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetById(id, partitionKey, CancellationToken.None); + } + + /// + public virtual TDocument GetById(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetById(id, partitionKey, cancellationToken); + } + + /// + public Task GetOneAsync(FilterDefinition condition) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, null, null, CancellationToken.None); + } + + /// + public Task GetOneAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, null, null, cancellationToken); + } + + /// + public Task GetOneAsync(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, findOption, null, CancellationToken.None); + } + + /// + public Task GetOneAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, null, partitionKey, CancellationToken.None); + } + + /// + public Task GetOneAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, null, partitionKey, cancellationToken); + } + + /// + public Task GetOneAsync(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, findOption, null, cancellationToken); + } + + /// + public Task GetOneAsync(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument where TKey : IEquatable + { + return GetOneAsync(condition, findOption, partitionKey, CancellationToken.None); + } + + /// + public Task GetOneAsync( + FilterDefinition condition, + FindOptions findOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetOneAsync(condition, findOption, partitionKey, cancellationToken); + } + + /// + public TDocument GetOne(FilterDefinition condition) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, null, null, CancellationToken.None); + } + + /// + public TDocument GetOne(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, findOption, null, CancellationToken.None); + } + + /// + public TDocument GetOne(FilterDefinition condition, string partitionKey) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, null, partitionKey, CancellationToken.None); + } + + + /// + public TDocument GetOne(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, findOption, partitionKey, CancellationToken.None); + } + + + /// + public TDocument GetOne(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, null, null, cancellationToken); + } + + /// + public TDocument GetOne(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, null, partitionKey, cancellationToken); + } + + /// + public TDocument GetOne(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return GetOne(condition, findOption, null, cancellationToken); + } + + /// + public TDocument GetOne( + FilterDefinition condition, + FindOptions findOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetOne(condition, findOption, partitionKey, cancellationToken); + } + + /// + public virtual async Task GetOneAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetOneAsync(filter, null, CancellationToken.None); + } + + /// + public virtual async Task GetOneAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetOneAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetOneAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetOneAsync(filter, null, cancellationToken); + } + + /// + public virtual async Task GetOneAsync( + Expression> filter, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetOneAsync(filter, partitionKey, cancellationToken); + } + + /// + public virtual TDocument GetOne(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return GetOne(filter, null, CancellationToken.None); + } + + /// + public virtual TDocument GetOne(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetOne(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual TDocument GetOne(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetOne(filter, null, cancellationToken); + } + + /// + public virtual TDocument GetOne(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetOne(filter, partitionKey, cancellationToken); + } + + /// + public virtual IFindFluent GetCursor(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetCursor(filter, partitionKey); + } + + /// + public Task AnyAsync(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, null, null, CancellationToken.None); + } + + /// + public Task AnyAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, null, partitionKey, CancellationToken.None); + } + + /// + public Task AnyAsync(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, countOption, null, CancellationToken.None); + } + + /// + public Task AnyAsync(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, countOption, partitionKey, CancellationToken.None); + } + + /// + public Task AnyAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, null, null, cancellationToken); + } + + /// + public Task AnyAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, null, partitionKey, cancellationToken); + } + + /// + public Task AnyAsync(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return AnyAsync(condition, countOption, null, cancellationToken); + } + + /// + public Task AnyAsync( + FilterDefinition condition, + CountOptions countOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.AnyAsync(condition, countOption, partitionKey, cancellationToken); + } + + /// + public bool Any(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(condition, null, null, CancellationToken.None); + } + + /// + public bool Any(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(condition, null, partitionKey, CancellationToken.None); + } + + /// + public bool Any(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(condition, countOption, null, CancellationToken.None); + } + + /// + public bool Any(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Any(condition, countOption, partitionKey, CancellationToken.None); + } + + /// + public bool Any(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(condition, null, null, cancellationToken); + } + + /// + public bool Any(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(condition, null, partitionKey, cancellationToken); + } + + /// + public bool Any(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(condition, countOption, null, cancellationToken); + } + + /// + public bool Any( + FilterDefinition condition, + CountOptions countOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Any(condition, countOption, partitionKey, cancellationToken); + } + + /// + public virtual async Task AnyAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return await AnyAsync(filter, null, CancellationToken.None); + } + + /// + public virtual async Task AnyAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await AnyAsync(filter, null, cancellationToken); + } + + /// + public virtual async Task AnyAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await AnyAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task AnyAsync( + Expression> filter, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.AnyAsync(filter, partitionKey, cancellationToken); + } + + /// + public virtual bool Any(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Any(filter, null, CancellationToken.None); + } + + /// + public virtual bool Any(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Any(filter, null, cancellationToken); + } + + /// + public virtual bool Any(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return Any(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual bool Any(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Any(filter, partitionKey, cancellationToken); + } + + /// + public Task> GetAllAsync(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, null, null, CancellationToken.None); + } + + /// + public Task> GetAllAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, null, partitionKey, CancellationToken.None); + } + + /// + public Task> GetAllAsync(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, findOption, null, CancellationToken.None); + } + + /// + public Task> GetAllAsync(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, findOption, partitionKey, CancellationToken.None); + } + + /// + public Task> GetAllAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, null, null, cancellationToken); + } + + /// + public Task> GetAllAsync( + FilterDefinition condition, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, null, partitionKey, cancellationToken); + } + + /// + public Task> GetAllAsync( + FilterDefinition condition, + FindOptions findOption, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAllAsync(condition, findOption, null, cancellationToken); + } + + /// + public Task> GetAllAsync( + FilterDefinition condition, + FindOptions findOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetAllAsync(condition, findOption, partitionKey, cancellationToken); + } + + /// + public List GetAll(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, null, null, CancellationToken.None); + } + + /// + public List GetAll(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, null, null, cancellationToken); + } + + /// + public List GetAll(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, null, partitionKey, CancellationToken.None); + } + + /// + public List GetAll(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, null, partitionKey, cancellationToken); + } + + /// + public List GetAll(FilterDefinition condition, FindOptions findOption) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, findOption, null, CancellationToken.None); + } + + /// + public List GetAll(FilterDefinition condition, FindOptions findOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, findOption, null, cancellationToken); + } + + /// + public List GetAll(FilterDefinition condition, FindOptions findOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(condition, findOption, partitionKey, CancellationToken.None); + } + + /// + public List GetAll( + FilterDefinition condition, + FindOptions findOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetAll(condition, findOption, partitionKey, cancellationToken); + } + + /// + public virtual async Task> GetAllAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetAllAsync(filter, null, CancellationToken.None); + } + + /// + public virtual async Task> GetAllAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetAllAsync(filter, null, cancellationToken); + } + + /// + public virtual async Task> GetAllAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetAllAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task> GetAllAsync( + Expression> filter, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetAllAsync(filter, partitionKey, cancellationToken); + } + + /// + public virtual List GetAll(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(filter, null, CancellationToken.None); + } + + /// + public virtual List GetAll(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(filter, null, cancellationToken); + } + + /// + public virtual List GetAll(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetAll(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual List GetAll( + Expression> filter, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetAll(filter, partitionKey, cancellationToken); + } + + /// + public Task CountAsync(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, null, null, CancellationToken.None); + } + + /// + public Task CountAsync(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, null, null, cancellationToken); + } + + /// + public Task CountAsync(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, countOption, null, CancellationToken.None); + } + + /// + public Task CountAsync(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, null, partitionKey, CancellationToken.None); + } + + /// + public Task CountAsync(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, null, partitionKey, cancellationToken); + } + + /// + public Task CountAsync(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, countOption, null, cancellationToken); + } + + /// + public Task CountAsync(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return CountAsync(condition, countOption, partitionKey, CancellationToken.None); + } + + /// + public Task CountAsync( + FilterDefinition condition, + CountOptions countOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.CountAsync(condition, countOption, partitionKey, cancellationToken); + } + + /// + public long Count(FilterDefinition condition) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, null, null, CancellationToken.None); + } + + /// + public long Count(FilterDefinition condition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, null, null, cancellationToken); + } + + /// + public long Count(FilterDefinition condition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, null, partitionKey, CancellationToken.None); + } + + /// + public long Count(FilterDefinition condition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, null, partitionKey, cancellationToken); + } + + /// + public long Count(FilterDefinition condition, CountOptions countOption) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, countOption, null, CancellationToken.None); + } + + /// + public long Count(FilterDefinition condition, CountOptions countOption, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, countOption, null, cancellationToken); + } + + /// + public long Count(FilterDefinition condition, CountOptions countOption, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(condition, countOption, partitionKey, CancellationToken.None); + } + + /// + public long Count( + FilterDefinition condition, + CountOptions countOption, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Count(condition, countOption, partitionKey, cancellationToken); + } + + /// + public virtual async Task CountAsync(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return await CountAsync(filter, null, CancellationToken.None); + } + + /// + public virtual async Task CountAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CountAsync(filter, null, cancellationToken); + } + + /// + public virtual async Task CountAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CountAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CountAsync( + Expression> filter, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.CountAsync(filter, partitionKey, cancellationToken); + } + + /// + public virtual long Count(Expression> filter) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(filter, null, CancellationToken.None); + } + + /// + public virtual long Count(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(filter, null, cancellationToken); + } + + /// + public virtual long Count(Expression> filter, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return Count(filter, partitionKey, CancellationToken.None); + } + + /// + public virtual long Count(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.Count(filter, partitionKey, cancellationToken); + } + + /// + public virtual async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByMaxAsync(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public virtual async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByMaxAsync(filter, maxValueSelector, null, cancellationToken); + } + + /// + public virtual async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByMaxAsync(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual TDocument GetByMax(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return GetByMax(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public virtual TDocument GetByMax( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetByMax(filter, maxValueSelector, null, cancellationToken); + } + + /// + public virtual TDocument GetByMax( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetByMax(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual TDocument GetByMax( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetByMax(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByMinAsync(filter, minValueSelector, null, CancellationToken.None); + } + + /// + public virtual async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByMinAsync(filter, minValueSelector, null, cancellationToken); + } + + /// + public virtual async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetByMinAsync(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetByMinAsync(filter, minValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual TDocument GetByMin(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return GetByMin(filter, minValueSelector, null, CancellationToken.None); + } + + /// + public virtual TDocument GetByMin( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetByMin(filter, minValueSelector, null, cancellationToken); + } + + /// + public virtual TDocument GetByMin( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetByMin(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual TDocument GetByMin( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetByMin(filter, minValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetMaxValueAsync(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public virtual async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetMaxValueAsync(filter, maxValueSelector, null, cancellationToken); + } + + /// + public virtual async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetMaxValueAsync(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMaxValue(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public virtual TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMaxValue(filter, maxValueSelector, null, cancellationToken); + } + + /// + public virtual TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMaxValue(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetMaxValue(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetMinValueAsync(filter, minValueSelector, null, CancellationToken.None); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetMinValueAsync(filter, minValueSelector, null, cancellationToken); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetMinValueAsync(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMinValue(filter, minValueSelector, null, CancellationToken.None); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMinValue(filter, minValueSelector, null, cancellationToken); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMinValue(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.GetMinValue(filter, minValueSelector, partitionKey, cancellationToken); + } + + #endregion + + #region Sum TKey + + /// + public virtual async Task SumByAsync(Expression> filter, Expression> selector) + where TDocument : IDocument + where TKey : IEquatable + { + return await SumByAsync(filter, selector, null, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await SumByAsync(filter, selector, null, cancellationToken); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await SumByAsync(filter, selector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.SumByAsync(filter, selector, partitionKey, cancellationToken); + } + + /// + public virtual int SumBy( + Expression> filter, + Expression> selector, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.SumBy(filter, selector, partitionKey); + } + + /// + public virtual async Task SumByAsync(Expression> filter, Expression> selector) + where TDocument : IDocument + where TKey : IEquatable + { + return await SumByAsync(filter, selector, null, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await SumByAsync(filter, selector, null, cancellationToken); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await SumByAsync(filter, selector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbReader.SumByAsync(filter, selector, partitionKey, cancellationToken); + } + + /// + public virtual decimal SumBy( + Expression> filter, + Expression> selector, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbReader.SumBy(filter, selector, partitionKey); + } + + #endregion Sum TKey + + #region Project TKey + + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await ProjectOneAsync(filter, projection, null, CancellationToken.None); + } + + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await ProjectOneAsync(filter, projection, null, cancellationToken); + } + + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await ProjectOneAsync(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey, cancellationToken); + } + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return ProjectOne(filter, projection, null, CancellationToken.None); + } + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return ProjectOne(filter, projection, null, cancellationToken); + } + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return ProjectOne(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return MongoDbReader.ProjectOne(filter, projection, partitionKey, cancellationToken); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await ProjectManyAsync(filter, projection, null, CancellationToken.None); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await ProjectManyAsync(filter, projection, null, cancellationToken); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await ProjectManyAsync(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await MongoDbReader.ProjectManyAsync(filter, projection, partitionKey, cancellationToken); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return ProjectMany(filter, projection, null, CancellationToken.None); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return ProjectMany(filter, projection, null, cancellationToken); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return ProjectMany(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return MongoDbReader.ProjectMany(filter, projection, partitionKey, cancellationToken); + } + + #endregion Project TKey + + #region Group By TKey + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return GroupBy(groupingCriteria, groupProjection, null, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return GroupBy(groupingCriteria, groupProjection, null, cancellationToken); + } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return GroupBy(groupingCriteria, groupProjection, partitionKey, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return MongoDbReader.GroupBy(groupingCriteria, groupProjection, partitionKey, cancellationToken); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return GroupBy(filter, groupingCriteria, groupProjection, null, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return GroupBy(filter, groupingCriteria, groupProjection, null, cancellationToken); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return GroupBy(filter, groupingCriteria, groupProjection, partitionKey, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + return MongoDbReader.GroupBy(filter, groupingCriteria, groupProjection, partitionKey, cancellationToken); + } + + #endregion Group By TKey + + #region Pagination + + /// + public virtual async Task> GetSortedPaginatedAsync( + Expression> filter, + Expression> sortSelector, + bool ascending = true, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + { + var sorting = ascending + ? Builders.Sort.Ascending(sortSelector) + : Builders.Sort.Descending(sortSelector); + + return await HandlePartitioned(partitionKey) + .Find(filter) + .Sort(sorting) + .Skip(skipNumber) + .Limit(takeNumber) + .ToListAsync(cancellationToken); + } + + /// + public virtual async Task> GetSortedPaginatedAsync( + Expression> filter, + SortDefinition sortDefinition, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + { + return await HandlePartitioned(partitionKey) + .Find(filter) + .Sort(sortDefinition) + .Skip(skipNumber) + .Limit(takeNumber) + .ToListAsync(cancellationToken); + } + + #endregion Pagination } } \ No newline at end of file