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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@ using MongoDbGenericRepository.DataAccess.Read;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace CoreUnitTests.ReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||||
{
|
{
|
||||||
+1
-1
@@ -10,7 +10,7 @@ using MongoDbGenericRepository.DataAccess.Read;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace CoreUnitTests.ReadOnlyMongoRepositoryTests;
|
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||||
|
|
||||||
public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||||
{
|
{
|
||||||
@@ -594,7 +594,7 @@ namespace MongoDbGenericRepository
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
where TDocument : IDocument<TKey>
|
where TDocument : IDocument<TKey>
|
||||||
{
|
{
|
||||||
return MongoDbReader.GetByMax<TDocument, TKey>(filter, maxValueSelector, partitionKey);
|
return MongoDbReader.GetByMax<TDocument, TKey>(filter, maxValueSelector, partitionKey, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in New Issue
Block a user