tests for readonly repositories
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user