unit tests for keyed readonly repo
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class AnyAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilter_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = await Sut.AnyAsync(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.AnyAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndCancellationToken_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = await Sut.AnyAsync(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.AnyAsync<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndPartitionKey_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = await Sut.AnyAsync(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.AnyAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = await Sut.AnyAsync(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.AnyAsync<TestDocument, Guid>(filter, partitionKey, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
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,100 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class AnyTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public void WithFilter_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = Sut.Any(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.Any<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndCancellationToken_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = Sut.Any(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.Any<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKey_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = Sut.Any(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.Any<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKeyAndCancellationToken_GetsResult()
|
||||
{
|
||||
// Arrange
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader();
|
||||
|
||||
// Act
|
||||
var result = Sut.Any(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
Reader.Verify(
|
||||
x => x.Any<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class CountAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilter_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = await Sut.CountAsync(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.CountAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = await Sut.CountAsync(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.CountAsync<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndPartitionKey_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = await Sut.CountAsync(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.CountAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = await Sut.CountAsync(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.CountAsync<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class CountTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public void WithFilter_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.Count(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.Count<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.Count(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.Count<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKey_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.Count(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.Count<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var count = Fixture.Create<long>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.Count(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Reader.Verify(
|
||||
x => x.Count<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetAllAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilter_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = await Sut.GetAllAsync(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAllAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = await Sut.GetAllAsync(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAllAsync<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndPartitionKey_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = await Sut.GetAllAsync(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAllAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||
{
|
||||
// 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(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAllAsync<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public void WithFilter_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetAll(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAll<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetAll(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAll<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKey_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetAll(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAll<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetAll(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetAll<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoFixture;
|
||||
using CoreUnitTests.Infrastructure;
|
||||
using CoreUnitTests.Infrastructure.Model;
|
||||
using FluentAssertions;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByIdAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoFixture;
|
||||
using CoreUnitTests.Infrastructure;
|
||||
using CoreUnitTests.Infrastructure.Model;
|
||||
using FluentAssertions;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByIdTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByMaxTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByMinTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetMaxValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetMaxValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetMinValueAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetMinValueTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetOneAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public async Task WithId_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = await Sut.GetOneAsync(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOneAsync<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithIdAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = await Sut.GetOneAsync(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOneAsync<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithIdAndPartitionKey_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = await Sut.GetOneAsync(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOneAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithIdAndPartitionKeyAndCancellationToken_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(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOneAsync<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetOneTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
{
|
||||
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
|
||||
|
||||
[Fact]
|
||||
public void WithId_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetOne(filter);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOne<TestDocument, Guid>(filter, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithIdAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetOne(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOne<TestDocument, Guid>(filter, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithIdAndPartitionKey_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetOne(filter, partitionKey);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOne<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithIdAndPartitionKeyAndCancellationToken_GetsOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = Fixture.Create<TestDocument>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
SetupReader(document);
|
||||
|
||||
// Act
|
||||
var result = Sut.GetOne(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetOne<TestDocument, Guid>(filter, 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);
|
||||
}
|
||||
}
|
||||
@@ -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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
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.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user