tests for readonly repositories

This commit is contained in:
Sean Garrett
2023-07-04 22:38:01 +01:00
parent b09b359867
commit dc7a4dc67b
56 changed files with 10877 additions and 1212 deletions
@@ -12,16 +12,16 @@ using Xunit;
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<int>
{
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
private readonly Expression<Func<TestDocument, object>> selector = document => document.SomeValue;
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
private readonly Expression<Func<TestDocumentWithKey<int>, object>> selector = document => document.SomeValue;
[Fact]
public async Task WithFilterAndSelector_GetsOne()
{
// Arrange
var document = Fixture.Create<TestDocument>();
var document = Fixture.Create<TestDocumentWithKey<int>>();
SetupReader(document);
@@ -32,7 +32,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, null, CancellationToken.None),
Times.Once);
}
@@ -40,7 +40,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public async Task WithFilterAndSelectorAndCancellationToken_GetsOne()
{
// Arrange
var document = Fixture.Create<TestDocument>();
var document = Fixture.Create<TestDocumentWithKey<int>>();
var token = new CancellationToken(true);
SetupReader(document);
@@ -52,7 +52,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, null, token),
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, null, token),
Times.Once);
}
@@ -60,7 +60,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public async Task WithFilterAndSelectorAndPartitionKey_GetsOne()
{
// Arrange
var document = Fixture.Create<TestDocument>();
var document = Fixture.Create<TestDocumentWithKey<int>>();
var partitionKey = Fixture.Create<string>();
SetupReader(document);
@@ -72,7 +72,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, CancellationToken.None),
Times.Once);
}
@@ -80,7 +80,7 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public async Task WithFilterAndSelectorAndPartitionKeyAndCancellationToken_GetsOne()
{
// Arrange
var document = Fixture.Create<TestDocument>();
var document = Fixture.Create<TestDocumentWithKey<int>>();
var partitionKey = Fixture.Create<string>();
var token = new CancellationToken(true);
@@ -93,18 +93,18 @@ public class GetByMinAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetByMinAsync<TestDocument, Guid>(filter, selector, partitionKey, token),
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, token),
Times.Once);
}
private void SetupReader(TestDocument document)
private void SetupReader(TestDocumentWithKey<int> document)
{
Reader = new Mock<IMongoDbReader>();
Reader
.Setup(
x => x.GetByMinAsync<TestDocument, Guid>(
It.IsAny<Expression<Func<TestDocument, bool>>>(),
It.IsAny<Expression<Func<TestDocument, object>>>(),
x => x.GetByMinAsync<TestDocumentWithKey<int>, int>(
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
It.IsAny<Expression<Func<TestDocumentWithKey<int>, object>>>(),
It.IsAny<string>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(document);