read only and tests
This commit is contained in:
@@ -4,23 +4,21 @@ using MongoDbGenericRepository.Models;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure.Model;
|
||||
|
||||
|
||||
public class TestDocument : Document
|
||||
{
|
||||
public TestDocument()
|
||||
{
|
||||
Version = 2;
|
||||
Nested = new Nested
|
||||
{
|
||||
SomeDate = DateTime.UtcNow
|
||||
};
|
||||
Nested = new Nested {SomeDate = DateTime.UtcNow};
|
||||
Children = new List<Child>();
|
||||
}
|
||||
|
||||
public int SomeValue { get; set; }
|
||||
|
||||
public string SomeContent { get; set; }
|
||||
|
||||
public string SomeContent2 { get; set; }
|
||||
|
||||
public string SomeContent3 { get; set; }
|
||||
|
||||
public int GroupingKey { get; set; }
|
||||
@@ -29,4 +27,3 @@ public class TestDocument : Document
|
||||
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -7,4 +7,6 @@ public class TestProjection
|
||||
public Guid TestDocumentId { get; set; }
|
||||
|
||||
public DateTime NestedData { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
@@ -16,23 +16,11 @@ public class TestKeyedMongoRepository<TKey> : BaseMongoRepository<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
public void SetIndexHandler(IMongoDbIndexHandler indexHandler)
|
||||
{
|
||||
MongoDbIndexHandler = indexHandler;
|
||||
}
|
||||
public void SetIndexHandler(IMongoDbIndexHandler indexHandler) => MongoDbIndexHandler = indexHandler;
|
||||
|
||||
public void SetDbCreator(IMongoDbCreator creator)
|
||||
{
|
||||
MongoDbCreator = creator;
|
||||
}
|
||||
public void SetDbCreator(IMongoDbCreator creator) => MongoDbCreator = creator;
|
||||
|
||||
public void SetReader(IMongoDbReader reader)
|
||||
{
|
||||
MongoDbReader = reader;
|
||||
}
|
||||
public void SetReader(IMongoDbReader reader) => MongoDbReader = reader;
|
||||
|
||||
public void SetEraser(IMongoDbEraser eraser)
|
||||
{
|
||||
MongoDbEraser = eraser;
|
||||
}
|
||||
public void SetEraser(IMongoDbEraser eraser) => MongoDbEraser = eraser;
|
||||
}
|
||||
@@ -12,13 +12,13 @@ namespace CoreUnitTests.Infrastructure;
|
||||
public class TestKeyedMongoRepositoryContext<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
private readonly Mock<IMongoDatabase> _mongoDatabase;
|
||||
private readonly Mock<IMongoDatabase> mongoDatabase;
|
||||
|
||||
private TestKeyedMongoRepository<TKey> _sut;
|
||||
private TestKeyedMongoRepository<TKey> sut;
|
||||
|
||||
protected TestKeyedMongoRepositoryContext()
|
||||
{
|
||||
_mongoDatabase = new Mock<IMongoDatabase>();
|
||||
mongoDatabase = new Mock<IMongoDatabase>();
|
||||
Fixture = new Fixture();
|
||||
}
|
||||
|
||||
@@ -28,33 +28,33 @@ public class TestKeyedMongoRepositoryContext<TKey>
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_sut != null)
|
||||
if (sut != null)
|
||||
{
|
||||
return _sut;
|
||||
return sut;
|
||||
}
|
||||
|
||||
_sut = new TestKeyedMongoRepository<TKey>(_mongoDatabase.Object);
|
||||
sut = new TestKeyedMongoRepository<TKey>(mongoDatabase.Object);
|
||||
if (IndexHandler != null)
|
||||
{
|
||||
_sut.SetIndexHandler(IndexHandler.Object);
|
||||
sut.SetIndexHandler(IndexHandler.Object);
|
||||
}
|
||||
|
||||
if (Creator != null)
|
||||
{
|
||||
_sut.SetDbCreator(Creator.Object);
|
||||
sut.SetDbCreator(Creator.Object);
|
||||
}
|
||||
|
||||
if (Reader != null)
|
||||
{
|
||||
_sut.SetReader(Reader.Object);
|
||||
sut.SetReader(Reader.Object);
|
||||
}
|
||||
|
||||
if (Eraser != null)
|
||||
{
|
||||
_sut.SetEraser(Eraser.Object);
|
||||
sut.SetEraser(Eraser.Object);
|
||||
}
|
||||
|
||||
return _sut;
|
||||
return sut;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestKeyedReadOnlyMongoRepository<TKey> : ReadOnlyMongoRepository<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public TestKeyedReadOnlyMongoRepository(string connectionString, string databaseName = null)
|
||||
: base(connectionString, databaseName)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public TestKeyedReadOnlyMongoRepository(IMongoDatabase mongoDatabase)
|
||||
: base(mongoDatabase)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public TestKeyedReadOnlyMongoRepository(IMongoDbContext mongoDbContext)
|
||||
: base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetReader(IMongoDbReader reader) => MongoDbReader = reader;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using AutoFixture;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestKeyedReadOnlyMongoRepositoryContext<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
private readonly Mock<IMongoDatabase> mongoDatabase;
|
||||
|
||||
private TestKeyedReadOnlyMongoRepository<TKey> sut;
|
||||
|
||||
protected TestKeyedReadOnlyMongoRepositoryContext()
|
||||
{
|
||||
mongoDatabase = new Mock<IMongoDatabase>();
|
||||
Fixture = new Fixture();
|
||||
}
|
||||
|
||||
protected Fixture Fixture { get; set; }
|
||||
|
||||
protected TestKeyedReadOnlyMongoRepository<TKey> Sut
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sut != null)
|
||||
{
|
||||
return sut;
|
||||
}
|
||||
|
||||
sut = new TestKeyedReadOnlyMongoRepository<TKey>(mongoDatabase.Object);
|
||||
|
||||
if (Reader != null)
|
||||
{
|
||||
sut.SetReader(Reader.Object);
|
||||
}
|
||||
|
||||
return sut;
|
||||
}
|
||||
}
|
||||
|
||||
protected Mock<IMongoDbReader> Reader { get; set; }
|
||||
}
|
||||
@@ -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 : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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,243 @@
|
||||
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 : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+940
-361
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user