tests for readonly repositories
This commit is contained in:
@@ -25,6 +25,8 @@ public class TestDocument : Document
|
|||||||
|
|
||||||
public int GroupingKey { get; set; }
|
public int GroupingKey { get; set; }
|
||||||
|
|
||||||
|
public Guid OtherGroupingKey { get; set; }
|
||||||
|
|
||||||
public Nested Nested { get; set; }
|
public Nested Nested { get; set; }
|
||||||
|
|
||||||
public List<Child> Children { get; set; }
|
public List<Child> Children { get; set; }
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public class TestDocumentWithKey<TKey> : IDocument<TKey>
|
|||||||
|
|
||||||
public int SomeValue { get; set; }
|
public int SomeValue { get; set; }
|
||||||
|
|
||||||
|
public int SomeDecimalValue { get; set; }
|
||||||
|
|
||||||
public string SomeContent { get; set; }
|
public string SomeContent { get; set; }
|
||||||
public string SomeContent2 { get; set; }
|
public string SomeContent2 { get; set; }
|
||||||
public string SomeContent3 { get; set; }
|
public string SomeContent3 { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MongoDbGenericRepository;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Read;
|
||||||
|
|
||||||
|
namespace CoreUnitTests.Infrastructure;
|
||||||
|
|
||||||
|
public class TestReadOnlyMongoRepository : ReadOnlyMongoRepository
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public TestReadOnlyMongoRepository(string connectionString, string databaseName = null)
|
||||||
|
: base(connectionString, databaseName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public TestReadOnlyMongoRepository(IMongoDatabase mongoDatabase)
|
||||||
|
: base(mongoDatabase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public TestReadOnlyMongoRepository(IMongoDbContext mongoDbContext)
|
||||||
|
: base(mongoDbContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetReader(IMongoDbReader reader) => MongoDbReader = reader;
|
||||||
|
}
|
||||||
@@ -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<IMongoDatabase> mongoDatabase;
|
||||||
|
|
||||||
|
private TestReadOnlyMongoRepository sut;
|
||||||
|
|
||||||
|
protected TestReadOnlyMongoRepositoryContext()
|
||||||
|
{
|
||||||
|
mongoDatabase = new Mock<IMongoDatabase>();
|
||||||
|
Fixture = new Fixture().Customize(new AutoMoqCustomization());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IFixture Fixture { get; set; }
|
||||||
|
|
||||||
|
protected TestReadOnlyMongoRepository Sut
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (sut != null)
|
||||||
|
{
|
||||||
|
return sut;
|
||||||
|
}
|
||||||
|
|
||||||
|
sut = Fixture.Create<TestReadOnlyMongoRepository>();
|
||||||
|
|
||||||
|
if (Reader != null)
|
||||||
|
{
|
||||||
|
sut.SetReader(Reader.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sut;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Mock<IMongoDbReader> Reader { get; set; }
|
||||||
|
|
||||||
|
protected Mock<T> MockOf<T>()
|
||||||
|
where T : class =>
|
||||||
|
Fixture.Freeze<Mock<T>>();
|
||||||
|
}
|
||||||
@@ -12,9 +12,9 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilter_GetsResult()
|
public async Task WithFilter_GetsResult()
|
||||||
@@ -28,7 +28,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.AnyAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.AnyAsync<TestDocument, Guid>(filter, null, token),
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.AnyAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.AnyAsync<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +92,8 @@ public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.AnyAsync<TestDocument, Guid>(
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(true);
|
.ReturnsAsync(true);
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilter_GetsResult()
|
public void WithFilter_GetsResult()
|
||||||
@@ -27,7 +27,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Any<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.Any<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Any<TestDocument, Guid>(filter, null, token),
|
x => x.Any<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Any<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.Any<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Any<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.Any<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,8 +91,8 @@ public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.Any<TestDocument, Guid>(
|
x => x.Any<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilter_GetsOne()
|
public async Task WithFilter_GetsOne()
|
||||||
@@ -32,7 +32,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.CountAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.CountAsync<TestDocument, Guid>(filter, null, token),
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.CountAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.CountAsync<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +99,8 @@ public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.CountAsync<TestDocument, Guid>(
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(count);
|
.ReturnsAsync(count);
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilter_GetsOne()
|
public void WithFilter_GetsOne()
|
||||||
@@ -29,7 +29,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Count<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.Count<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Count<TestDocument, Guid>(filter, null, token),
|
x => x.Count<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Count<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.Count<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.Count<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.Count<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +96,8 @@ public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.Count<TestDocument, Guid>(
|
x => x.Count<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(count);
|
.Returns(count);
|
||||||
|
|||||||
@@ -14,15 +14,15 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilter_GetsOne()
|
public async Task WithFilter_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAllAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndCancellationToken_GetsOne()
|
public async Task WithFilterAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -53,7 +53,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAllAsync<TestDocument, Guid>(filter, null, token),
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndPartitionKey_GetsOne()
|
public async Task WithFilterAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -73,7 +73,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAllAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -94,17 +94,17 @@ public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAllAsync<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(List<TestDocument> documents)
|
private void SetupReader(List<TestDocumentWithKey<int>> documents)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetAllAsync<TestDocument, Guid>(
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(documents);
|
.ReturnsAsync(documents);
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilter_GetsOne()
|
public void WithFilter_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAll<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndCancellationToken_GetsOne()
|
public void WithFilterAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -52,7 +52,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAll<TestDocument, Guid>(filter, null, token),
|
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndPartitionKey_GetsOne()
|
public void WithFilterAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -72,7 +72,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAll<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -93,17 +93,17 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetAll<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(List<TestDocument> documents)
|
private void SetupReader(List<TestDocumentWithKey<int>> documents)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetAll<TestDocument, Guid>(
|
x => x.GetAll<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(documents);
|
.Returns(documents);
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
@@ -13,24 +10,24 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithId_Gets()
|
public async Task WithId_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetByIdAsync<TestDocument>(document.Id);
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>>(document.Id);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, null, CancellationToken.None),
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,19 +35,19 @@ public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithIdAndCancellationToken_Gets()
|
public async Task WithIdAndCancellationToken_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetByIdAsync<TestDocument>(document.Id, token);
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>>(document.Id, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, null, token),
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,19 +55,19 @@ public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithIdAndPartitionKey_Gets()
|
public async Task WithIdAndPartitionKey_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetByIdAsync<TestDocument>(document.Id, partitionKey);
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>>(document.Id, partitionKey);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, partitionKey, CancellationToken.None),
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,30 +75,30 @@ public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithIdAndPartitionKeyAndCancellationToken_Gets()
|
public async Task WithIdAndPartitionKeyAndCancellationToken_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetByIdAsync<TestDocument>(document.Id, partitionKey, token);
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>>(document.Id, partitionKey, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, partitionKey, token),
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetByIdAsync<TestDocument, Guid>(
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Guid>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(document);
|
.ReturnsAsync(document);
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
using CoreUnitTests.Infrastructure;
|
using CoreUnitTests.Infrastructure;
|
||||||
using CoreUnitTests.Infrastructure.Model;
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
@@ -13,24 +9,24 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithId_Gets()
|
public void WithId_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = Sut.GetById<TestDocument>(document.Id);
|
var result = Sut.GetById<TestDocumentWithKey<int>>(document.Id);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetById<TestDocument, Guid>(document.Id, null, CancellationToken.None),
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,19 +34,19 @@ public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithIdAndCancellationToken_Gets()
|
public void WithIdAndCancellationToken_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = Sut.GetById<TestDocument>(document.Id, token);
|
var result = Sut.GetById<TestDocumentWithKey<int>>(document.Id, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetById<TestDocument, Guid>(document.Id, null, token),
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,19 +54,19 @@ public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithIdAndPartitionKey_Gets()
|
public void WithIdAndPartitionKey_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = Sut.GetById<TestDocument>(document.Id, partitionKey);
|
var result = Sut.GetById<TestDocumentWithKey<int>>(document.Id, partitionKey);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetById<TestDocument, Guid>(document.Id, partitionKey, CancellationToken.None),
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,30 +74,30 @@ public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithIdAndPartitionKeyAndCancellationToken_Gets()
|
public void WithIdAndPartitionKeyAndCancellationToken_Gets()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = Sut.GetById<TestDocument>(document.Id, partitionKey, token);
|
var result = Sut.GetById<TestDocumentWithKey<int>>(document.Id, partitionKey, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetById<TestDocument, Guid>(document.Id, partitionKey, token),
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetById<TestDocument, Guid>(
|
x => x.GetById<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Guid>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(document);
|
.Returns(document);
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilterAndSelector_GetsOne()
|
public async Task WithFilterAndSelector_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
|
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -52,7 +52,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, null, token),
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
|
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -72,7 +72,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -93,18 +93,18 @@ public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, partitionKey, token),
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetByMaxAsync<TestDocument, Guid>(
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(document);
|
.ReturnsAsync(document);
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndSelector_GetsOne()
|
public void WithFilterAndSelector_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMax<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndSelectorAndCancellationToken_GetsOne()
|
public void WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -51,7 +51,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMax<TestDocument, Guid>(filter, selector, null, token),
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndSelectorAndPartitionKey_GetsOne()
|
public void WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -71,7 +71,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMax<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -92,18 +92,18 @@ public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMax<TestDocument, Guid>(filter, selector, partitionKey, token),
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetByMax<TestDocument, Guid>(
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(document);
|
.Returns(document);
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilterAndSelector_GetsOne()
|
public async Task WithFilterAndSelector_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
|
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -52,7 +52,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, null, token),
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
|
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -72,7 +72,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -93,18 +93,18 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, partitionKey, token),
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetByMinAsync<TestDocument, Guid>(
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(document);
|
.ReturnsAsync(document);
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndSelector_GetsOne()
|
public void WithFilterAndSelector_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMin<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndSelectorAndCancellationToken_GetsOne()
|
public void WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -51,7 +51,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMin<TestDocument, Guid>(filter, selector, null, token),
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndSelectorAndPartitionKey_GetsOne()
|
public void WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -71,7 +71,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMin<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -92,18 +92,18 @@ public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetByMin<TestDocument, Guid>(filter, selector, partitionKey, token),
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetByMin<TestDocument, Guid>(
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(document);
|
.Returns(document);
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilterAndSelector_GetsMaxValue()
|
public async Task WithFilterAndSelector_GetsMaxValue()
|
||||||
@@ -31,7 +31,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValueAsync<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValueAsync<TestDocument, Guid, int>(filter, selector, null, token),
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValueAsync<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValueAsync<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,9 +98,9 @@ public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetMaxValueAsync<TestDocument, Guid, int>(
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(value);
|
.ReturnsAsync(value);
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndSelector_GetsMaxValue()
|
public void WithFilterAndSelector_GetsMaxValue()
|
||||||
@@ -30,7 +30,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValue<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValue<TestDocument, Guid, int>(filter, selector, null, token),
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValue<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMaxValue<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +97,9 @@ public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetMaxValue<TestDocument, Guid, int>(
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(value);
|
.Returns(value);
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilterAndSelector_GetsMaxValue()
|
public async Task WithFilterAndSelector_GetsMaxValue()
|
||||||
@@ -31,7 +31,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValueAsync<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValueAsync<TestDocument, Guid, int>(filter, selector, null, token),
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValueAsync<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValueAsync<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,9 +98,9 @@ public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetMinValueAsync<TestDocument, Guid, int>(
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(value);
|
.ReturnsAsync(value);
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndSelector_GetsMinValue()
|
public void WithFilterAndSelector_GetsMinValue()
|
||||||
@@ -30,7 +30,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValue<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(filter, selector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValue<TestDocument, Guid, int>(filter, selector, null, token),
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(filter, selector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValue<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetMinValue<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(filter, selector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +97,9 @@ public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetMinValue<TestDocument, Guid, int>(
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(value);
|
.Returns(value);
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilter_GetsOne()
|
public async Task WithFilter_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOneAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndCancellationToken_GetsOne()
|
public async Task WithFilterAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -51,7 +51,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOneAsync<TestDocument, Guid>(filter, null, token),
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndPartitionKey_GetsOne()
|
public async Task WithFilterAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -71,7 +71,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOneAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -92,17 +92,17 @@ public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOneAsync<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetOneAsync<TestDocument, Guid>(
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(document);
|
.ReturnsAsync(document);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
using CoreUnitTests.Infrastructure;
|
using CoreUnitTests.Infrastructure;
|
||||||
using CoreUnitTests.Infrastructure.Model;
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
@@ -12,15 +11,15 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithId_GetsOne()
|
public void WithFilter_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
|
|
||||||
@@ -31,15 +30,15 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOne<TestDocument, Guid>(filter, null, CancellationToken.None),
|
x => x.GetOne<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithIdAndCancellationToken_GetsOne()
|
public void WithFilterAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -51,15 +50,15 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOne<TestDocument, Guid>(filter, null, token),
|
x => x.GetOne<TestDocumentWithKey<int>, int>(filter, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithIdAndPartitionKey_GetsOne()
|
public void WithFilterAndPartitionKey_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
SetupReader(document);
|
SetupReader(document);
|
||||||
@@ -71,15 +70,15 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOne<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
x => x.GetOne<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithIdAndPartitionKeyAndCancellationToken_GetsOne()
|
public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var document = Fixture.Create<TestDocument>();
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
var partitionKey = Fixture.Create<string>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
@@ -92,17 +91,17 @@ public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(document);
|
result.Should().BeEquivalentTo(document);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetOne<TestDocument, Guid>(filter, partitionKey, token),
|
x => x.GetOne<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupReader(TestDocument document)
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
{
|
{
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GetOne<TestDocument, Guid>(
|
x => x.GetOne<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(document);
|
.Returns(document);
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.GroupingKey == 1;
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.GroupingKey == 1;
|
||||||
private readonly Expression<Func<TestDocument, object>> selector = document => document.GroupingKey;
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> selector = document => document.GroupingKey;
|
||||||
private readonly SortDefinition<TestDocument> sortDefinition = Builders<TestDocument>.Sort.Ascending(document => document.GroupingKey);
|
private readonly SortDefinition<TestDocumentWithKey<int>> sortDefinition = Builders<TestDocumentWithKey<int>>.Sort.Ascending(document => document.GroupingKey);
|
||||||
|
|
||||||
private const bool DefaultAscending = true;
|
private const bool DefaultAscending = true;
|
||||||
private const int DefaultSkipNumber = 0;
|
private const int DefaultSkipNumber = 0;
|
||||||
@@ -178,15 +178,15 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont
|
|||||||
VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, token);
|
VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TestDocument> SetupReaderWithSortSelector()
|
private List<TestDocumentWithKey<int>> SetupReaderWithSortSelector()
|
||||||
{
|
{
|
||||||
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
x => x.GetSortedPaginatedAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
It.IsAny<bool>(),
|
It.IsAny<bool>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
@@ -196,12 +196,12 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont
|
|||||||
return documents;
|
return documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifySelector(List<TestDocument> result, List<TestDocument> documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken)
|
private void VerifySelector(List<TestDocumentWithKey<int>> result, List<TestDocumentWithKey<int>> documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(documents);
|
result.Should().BeEquivalentTo(documents);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
x => x.GetSortedPaginatedAsync<TestDocumentWithKey<int>, int>(
|
||||||
filter,
|
filter,
|
||||||
selector,
|
selector,
|
||||||
ascending,
|
ascending,
|
||||||
@@ -212,15 +212,15 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont
|
|||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TestDocument> SetupReaderWithSortDefinition()
|
private List<TestDocumentWithKey<int>> SetupReaderWithSortDefinition()
|
||||||
{
|
{
|
||||||
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
x => x.GetSortedPaginatedAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<SortDefinition<TestDocument>>(),
|
It.IsAny<SortDefinition<TestDocumentWithKey<int>>>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
@@ -229,12 +229,12 @@ public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryCont
|
|||||||
return documents;
|
return documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDefinition(List<TestDocument> result, List<TestDocument> documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken)
|
private void VerifyDefinition(List<TestDocumentWithKey<int>> result, List<TestDocumentWithKey<int>> documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(documents);
|
result.Should().BeEquivalentTo(documents);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
x => x.GetSortedPaginatedAsync<TestDocumentWithKey<int>, int>(
|
||||||
filter,
|
filter,
|
||||||
sortDefinition,
|
sortDefinition,
|
||||||
skipNumber,
|
skipNumber,
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, int>> grouping = document => document.GroupingKey;
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> grouping = document => document.GroupingKey;
|
||||||
private readonly Expression<Func<IGrouping<int, TestDocument>, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()};
|
private readonly Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()};
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.GroupingKey == 1;
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.GroupingKey == 1;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithGroupingCriteriaAndProjection_Groups()
|
public void WithGroupingCriteriaAndProjection_Groups()
|
||||||
@@ -26,9 +26,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -40,7 +40,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, null, CancellationToken.None),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(grouping, projection, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +54,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
|
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -68,7 +68,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, null, token),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(grouping, projection, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +82,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
|
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -96,7 +96,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, partitionKey, CancellationToken.None),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(grouping, projection, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,9 +111,9 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
|
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -125,7 +125,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, partitionKey, token),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(grouping, projection, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,10 +137,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -152,7 +152,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, null, CancellationToken.None),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(filter, grouping, projection, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,10 +165,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -180,7 +180,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, null, token),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(filter, grouping, projection, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,10 +193,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -208,7 +208,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, partitionKey, CancellationToken.None),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(filter, grouping, projection, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,10 +222,10 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
Reader.Setup(
|
Reader.Setup(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
@@ -237,7 +237,7 @@ public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.Should().BeEquivalentTo(projections);
|
result.Should().BeEquivalentTo(projections);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, partitionKey, token),
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(filter, grouping, projection, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilterAndProjection_Projects()
|
public async Task WithFilterAndProjection_Projects()
|
||||||
@@ -33,7 +33,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
filter,
|
filter,
|
||||||
projection,
|
projection,
|
||||||
null,
|
null,
|
||||||
@@ -56,7 +56,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,9 +104,9 @@ public class ProjectManyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Gui
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(projections);
|
.ReturnsAsync(projections);
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndProjection_Projects()
|
public void WithFilterAndProjection_Projects()
|
||||||
@@ -32,7 +32,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectMany<TestDocument, TestProjection, Guid>(
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
filter,
|
filter,
|
||||||
projection,
|
projection,
|
||||||
null,
|
null,
|
||||||
@@ -55,7 +55,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectMany<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectMany<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().OnlyContain(x => projections.Contains(x));
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectMany<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +103,9 @@ public class ProjectManyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.ProjectMany<TestDocument, TestProjection, Guid>(
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(projections);
|
.Returns(projections);
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WithFilterAndProjection_Projects()
|
public async Task WithFilterAndProjection_Projects()
|
||||||
@@ -31,7 +31,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
filter,
|
filter,
|
||||||
projection,
|
projection,
|
||||||
null,
|
null,
|
||||||
@@ -54,7 +54,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,9 +102,9 @@ public class ProjectOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(result);
|
.ReturnsAsync(result);
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndProjection_Projects()
|
public void WithFilterAndProjection_Projects()
|
||||||
@@ -30,7 +30,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOne<TestDocument, TestProjection, Guid>(
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
filter,
|
filter,
|
||||||
projection,
|
projection,
|
||||||
null,
|
null,
|
||||||
@@ -53,7 +53,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOne<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOne<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.ProjectOne<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(filter, projection, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,9 +101,9 @@ public class ProjectOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.ProjectOne<TestDocument, TestProjection, Guid>(
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.Returns(result);
|
.Returns(result);
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ using Xunit;
|
|||||||
|
|
||||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
private readonly Expression<Func<TestDocument, int>> intSelector = document => document.SomeValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> intSelector = document => document.SomeValue;
|
||||||
private readonly Expression<Func<TestDocument, decimal>> decimalSelector = document => document.SomeDecimalValue;
|
private readonly Expression<Func<TestDocumentWithKey<int>, decimal>> decimalSelector = document => document.SomeDecimalValue;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Int_WithFilterAndSelector_Sums()
|
public async Task Int_WithFilterAndSelector_Sums()
|
||||||
@@ -32,7 +32,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, intSelector, null, CancellationToken.None),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, intSelector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, intSelector, null, token),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, intSelector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, intSelector, partitionKey, CancellationToken.None),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, intSelector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, intSelector, partitionKey, token),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, intSelector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, decimalSelector, null, CancellationToken.None),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, decimalSelector, null, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, decimalSelector, null, token),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, decimalSelector, null, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, decimalSelector, partitionKey, CancellationToken.None),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, decimalSelector, partitionKey, CancellationToken.None),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
Reader.Verify(
|
Reader.Verify(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(filter, decimalSelector, partitionKey, token),
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(filter, decimalSelector, partitionKey, token),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,9 +175,9 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument,int>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,int>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(expected);
|
.ReturnsAsync(expected);
|
||||||
@@ -188,9 +188,9 @@ public class SumByAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
|||||||
Reader = new Mock<IMongoDbReader>();
|
Reader = new Mock<IMongoDbReader>();
|
||||||
Reader
|
Reader
|
||||||
.Setup(
|
.Setup(
|
||||||
x => x.SumByAsync<TestDocument, Guid>(
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(
|
||||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
It.IsAny<Expression<Func<TestDocument, decimal>>>(),
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, decimal>>>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<CancellationToken>()))
|
It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(expected);
|
.ReturnsAsync(expected);
|
||||||
|
|||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.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<TestDocument, Guid>(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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync(expression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region keyed
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpression_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SetupKeyedReaderWithExpression();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilter_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedFilter, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedFilter, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCountOptionsAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var options = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCountOptionsAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithExpression()
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter()
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.AnyAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<CountOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void SetupReader()
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.AnyAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> 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<TestDocument, Guid>(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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any(expression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader()
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.Any<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(document => document.SomeContent, "SomeContent");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpression_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SetupKeyedReaderWithExpression();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilter_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndOptions_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var options = new CountOptions();
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedFilter, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, 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<TestDocumentWithKey<int>, int>(keyedFilter, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedFilter, options, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndOptionsAndPartitionKey_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var options = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndOptionsAndPartitionKeyAndCancellationToken_GetsResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Any<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithExpression()
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter()
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.Any<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<CountOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpression_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
SetupReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync(expression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocument, Guid>(expression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(long count)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.CountAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(document => document.Id, 1);
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpression_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithExpression(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilter_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCountOptions_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCountOptionsAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCountOptionsAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCountOptionsPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithExpression(long count)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter(long count)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.CountAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<CountOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpression_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
SetupReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count(expression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocument, Guid>(expression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count(expression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(long count)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.Count<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(
|
||||||
|
document => document.SomeContent,
|
||||||
|
"SomeContent");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpression_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
SetupKeyedReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedExpression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(long count)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilter_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, null, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
result.Should().Be(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCountOptions_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
result.Should().Be(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCountOptionsAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCountOptionsAndPartitionKey_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCountOptionsAndPartitionKeyAndCancellationToken_Counts()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var countOptions = new CountOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(keyedFilter, countOptions, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter(long count)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.Count<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<CountOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpression_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync(expression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocument, Guid>(expression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(List<TestDocument> documents)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetAllAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(document => document.SomeContent, "SomeContent");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpression_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilter_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndOptions_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReaderWithFilter(List<TestDocumentWithKey<int>> documents)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<FindOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(List<TestDocumentWithKey<int>> documents)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetAllAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpression_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll(expression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocument, Guid>(expression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(List<TestDocument> documents)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetAll<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(document => document.SomeContent, "SomeContent");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpression_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilter_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, null, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptions_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter(List<TestDocumentWithKey<int>> documents)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<FindOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(List<TestDocumentWithKey<int>> documents)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetAll<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocument>(document.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithIdAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocument>(document.Id, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithIdAndPartitionKey_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocument>(document.Id, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithIdAndPartitionKeyAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocument>(document.Id, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocument, Guid>(document.Id, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByIdAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Guid>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithId_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithIdAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithIdAndPartitionKey_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithIdAndPartitionKeyAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(document.Id, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByIdAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocument>(document.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocument, Guid>(document.Id, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithIdAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocument>(document.Id, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocument, Guid>(document.Id, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithIdAndPartitionKey_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocument>(document.Id, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocument, Guid>(document.Id, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithIdAndPartitionKeyAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocument>(document.Id, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocument, Guid>(document.Id, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetById<TestDocument, Guid>(
|
||||||
|
It.IsAny<Guid>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithId_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocumentWithKey<int>, int>(document.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithIdAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocumentWithKey<int>, int>(document.Id, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithIdAndPartitionKey_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocumentWithKey<int>, int>(document.Id, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithIdAndPartitionKeyAndCancellationToken_Gets()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetById<TestDocumentWithKey<int>, int>(document.Id, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetById<TestDocumentWithKey<int>, int>(document.Id, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetById<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMaxAsync(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMaxAsync(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMaxAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMax(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMax<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMax(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMax<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMax<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMax<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMinAsync(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMinAsync(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMinAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMin(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMin<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMin(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMin<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMin<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelector_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetByMin<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelector_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMaxValueAsync(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValueAsync<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKey_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMaxValueAsync(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValueAsync<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMaxValueAsync<TestDocument, Guid, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelector_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMaxValueAsync<TestDocumentWithKey<int>, int, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelector_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMaxValue(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValue<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKey_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMaxValue(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValue<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMaxValue<TestDocument, Guid, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelector_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMaxValue<TestDocumentWithKey<int>, int, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelector_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMinValueAsync(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValueAsync<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKey_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMinValueAsync(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValueAsync<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMinValueAsync<TestDocument, Guid, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelector_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKey_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMaxValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMinValueAsync<TestDocumentWithKey<int>, int, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, int>> selector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelector_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMinValue(filter, selector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValue<TestDocument, Guid, int>(filter, selector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndCancellationToken_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKey_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMinValue(filter, selector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValue<TestDocument, Guid, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid, int>(filter, selector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMinValue<TestDocument, Guid, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> keyedSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelector_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndCancellationToken_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKey_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsMinValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(value);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(keyedFilter, keyedSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(int value)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetMinValue<TestDocumentWithKey<int>, int, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpression_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync(expression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocument, Guid>(expression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithExpressionAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetOneAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(document => document.SomeContent, "SomeContent");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpression_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilter_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptions_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter,null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter,options, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter,null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(keyedFilter,options, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<FindOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetOneAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> expression = document => document.SomeContent == "SomeContent";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpression_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne(expression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocument, Guid>(expression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
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<TestDocument, Guid>(expression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne(expression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocument, Guid>(expression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithExpressionAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(expression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestDocument document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetOne<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedExpression = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly FilterDefinition<TestDocumentWithKey<int>> keyedFilter = Builders<TestDocumentWithKey<int>>.Filter.Eq(document => document.SomeContent, "SomeContent");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpression_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithExpressionAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedExpression, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilter_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, null, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptions_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, null, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptionsAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptionsAndPartitionKey_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, null, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndFindOptionsAndPartitionKeyAndCancellationToken_GetsOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var options = new FindOptions();
|
||||||
|
|
||||||
|
SetupKeyedReaderWithFilter(document);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(document);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(keyedFilter, options, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderWithFilter(TestDocumentWithKey<int> document)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GetOne<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<FilterDefinition<TestDocumentWithKey<int>>>(),
|
||||||
|
It.IsAny<FindOptions>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.GroupingKey == 1;
|
||||||
|
private readonly Expression<Func<TestDocument, object>> selector = document => document.GroupingKey;
|
||||||
|
private readonly SortDefinition<TestDocument> sortDefinition = Builders<TestDocument>.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<bool>();
|
||||||
|
|
||||||
|
// 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<int>();
|
||||||
|
|
||||||
|
// 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<bool>();
|
||||||
|
var takeNumber = Fixture.Create<int>();
|
||||||
|
|
||||||
|
// 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<string>();
|
||||||
|
|
||||||
|
// 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<int>();
|
||||||
|
|
||||||
|
// 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<int>();
|
||||||
|
|
||||||
|
// 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<string>();
|
||||||
|
|
||||||
|
// 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<TestDocument> SetupReaderWithSortSelector()
|
||||||
|
{
|
||||||
|
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
||||||
|
It.IsAny<bool>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(documents);
|
||||||
|
return documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void VerifySelector(List<TestDocument> result, List<TestDocument> documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(documents);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
||||||
|
filter,
|
||||||
|
selector,
|
||||||
|
ascending,
|
||||||
|
skipNumber,
|
||||||
|
takeNumber,
|
||||||
|
partitionKey,
|
||||||
|
cancellationToken),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TestDocument> SetupReaderWithSortDefinition()
|
||||||
|
{
|
||||||
|
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<SortDefinition<TestDocument>>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(documents);
|
||||||
|
return documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void VerifyDefinition(List<TestDocument> result, List<TestDocument> documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(documents);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GetSortedPaginatedAsync<TestDocument, Guid>(
|
||||||
|
filter,
|
||||||
|
sortDefinition,
|
||||||
|
skipNumber,
|
||||||
|
takeNumber,
|
||||||
|
partitionKey,
|
||||||
|
cancellationToken),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, int>> grouping = document => document.GroupingKey;
|
||||||
|
private readonly Expression<Func<IGrouping<int, TestDocument>, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()};
|
||||||
|
private readonly Expression<Func<TestDocument, bool>> filter = document => document.GroupingKey == 1;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithGroupingCriteriaAndProjection_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(grouping, projection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithGroupingCriteriaAndProjectionAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(grouping, projection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithGroupingCriteriaAndProjectionAndPartitionKey_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(grouping, projection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(grouping, projection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(grouping, projection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndGroupingCriteriaAndProjection_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(filter, grouping, projection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndGroupingCriteriaAndProjectionAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(filter, grouping, projection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndGroupingCriteriaAndProjectionAndPartitionKey_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy(filter, grouping, projection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(projections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocument, int, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocument>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.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<TestDocument, int, TestProjection, Guid>(filter, grouping, projection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> keyedGrouping = document => document.GroupingKey;
|
||||||
|
private readonly Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>> keyedProjection = documents => new TestProjection {Count = documents.Count()};
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.GroupingKey == 1;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithGroupingCriteriaAndProjection_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithGroupingCriteriaAndProjectionAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithGroupingCriteriaAndProjectionAndPartitionKey_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedGrouping, keyedProjection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndGroupingCriteriaAndProjection_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndGroupingCriteriaAndProjectionAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndGroupingCriteriaAndProjectionAndPartitionKey_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
|
||||||
|
Reader.Setup(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, int>>>(),
|
||||||
|
It.IsAny<Expression<Func<IGrouping<int, TestDocumentWithKey<int>>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.Should().BeEquivalentTo(keyedProjections);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.GroupBy<TestDocumentWithKey<int>, int, TestProjection, int>(keyedFilter, keyedGrouping, keyedProjection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
|
||||||
|
SetupReader(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectManyAsync(filter, projection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(
|
||||||
|
filter,
|
||||||
|
projection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().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<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectManyAsync(filter, projection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(List<TestProjection> projections)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectManyAsync<TestDocument, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(projections);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
keyedFilter,
|
||||||
|
keyedProjection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(List<TestProjection> keyedProjections)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectManyAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(keyedProjections);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
|
||||||
|
SetupReader(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectMany(filter, projection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectMany<TestDocument, TestProjection, Guid>(
|
||||||
|
filter,
|
||||||
|
projection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().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<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(projections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectMany(filter, projection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => projections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectMany<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var projections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(List<TestProjection> projections)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectMany<TestDocument, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(projections);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
keyedFilter,
|
||||||
|
keyedProjection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var keyedProjections = Fixture.CreateMany<TestProjection>().ToList();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(keyedProjections);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().OnlyContain(x => keyedProjections.Contains(x));
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(List<TestProjection> keyedProjections)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectMany<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(keyedProjections);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
|
||||||
|
SetupReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectOneAsync(filter, projection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(
|
||||||
|
filter,
|
||||||
|
projection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
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<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectOneAsync(filter, projection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestProjection result)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectOneAsync<TestDocument, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
keyedFilter,
|
||||||
|
keyedProjection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(TestProjection result)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectOneAsync<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, TestProjection>> projection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
|
||||||
|
SetupReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectOne(filter, projection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOne<TestDocument, TestProjection, Guid>(
|
||||||
|
filter,
|
||||||
|
projection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
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<TestDocument, TestProjection, Guid>(filter, projection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectOne(filter, projection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOne<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, TestProjection, Guid>(filter, projection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReader(TestProjection result)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectOne<TestDocument, TestProjection, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, TestProjection>> keyedProjection = document => new TestProjection {NestedData = document.Nested.SomeDate};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjection_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
keyedFilter,
|
||||||
|
keyedProjection,
|
||||||
|
null,
|
||||||
|
CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjectionAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjectionAndPartitionKey_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndProjectionAndPartitionKeyAndCancellationToken_Projects()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<TestProjection>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReader(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(keyedFilter, keyedProjection, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReader(TestProjection result)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.ProjectOne<TestDocumentWithKey<int>, TestProjection, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, TestProjection>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.Returns(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -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<Func<TestDocument, decimal>> decimalSelector = document => document.SomeDecimalValue;
|
||||||
|
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocument, int>> intSelector = document => document.SomeValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Int_WithFilterAndSelector_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupReaderInt(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync(filter, intSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocument, Guid>(filter, intSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Int_WithFilterAndSelectorAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
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<TestDocument, Guid>(filter, intSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Int_WithFilterAndSelectorAndPartitionKey_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReaderInt(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync(filter, intSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocument, Guid>(filter, intSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Int_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(filter, intSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Decimal_WithFilterAndSelector_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
|
||||||
|
SetupReaderDecimal(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync(filter, decimalSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocument, Guid>(filter, decimalSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Decimal_WithFilterAndSelectorAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
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<TestDocument, Guid>(filter, decimalSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Decimal_WithFilterAndSelectorAndPartitionKey_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupReaderDecimal(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync(filter, decimalSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocument, Guid>(filter, decimalSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Decimal_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
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<TestDocument, Guid>(filter, decimalSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReaderInt(int expected)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.SumByAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupReaderDecimal(decimal expected)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.SumByAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocument, decimal>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> keyedFilter = document => document.SomeContent == "SomeContent";
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, int>> keyedIntSelector = document => document.SomeValue;
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, decimal>> keyedDecimalSelector = document => document.SomeDecimalValue;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Int_WithFilterAndSelector_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
|
||||||
|
SetupKeyedReaderInt(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Int_WithFilterAndSelectorAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderInt(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Int_WithFilterAndSelectorAndPartitionKey_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderInt(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Int_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<int>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderInt(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedIntSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Decimal_WithFilterAndSelector_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
|
||||||
|
SetupKeyedReaderDecimal(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, null, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Decimal_WithFilterAndSelectorAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderDecimal(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, null, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Decimal_WithFilterAndSelectorAndPartitionKey_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
SetupKeyedReaderDecimal(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, partitionKey, CancellationToken.None),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_Decimal_WithFilterAndSelectorAndPartitionKeyAndCancellationToken_Sums()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Fixture.Create<decimal>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
SetupKeyedReaderDecimal(expected);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(expected);
|
||||||
|
Reader.Verify(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(keyedFilter, keyedDecimalSelector, partitionKey, token),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderInt(int expected)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>,int>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKeyedReaderDecimal(decimal expected)
|
||||||
|
{
|
||||||
|
Reader = new Mock<IMongoDbReader>();
|
||||||
|
Reader
|
||||||
|
.Setup(
|
||||||
|
x => x.SumByAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, decimal>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user