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
@@ -13,15 +13,15 @@ using Xunit;
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<int>
{
private readonly Expression<Func<TestDocument, bool>> filter = document => document.SomeContent == "SomeContent";
private readonly Expression<Func<TestDocumentWithKey<int>, bool>> filter = document => document.SomeContent == "SomeContent";
[Fact]
public void WithFilter_GetsOne()
{
// Arrange
var document = Fixture.CreateMany<TestDocument>().ToList();
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
SetupReader(document);
@@ -32,7 +32,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetAll<TestDocument, Guid>(filter, null, CancellationToken.None),
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None),
Times.Once);
}
@@ -40,7 +40,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public void WithFilterAndCancellationToken_GetsOne()
{
// Arrange
var document = Fixture.CreateMany<TestDocument>().ToList();
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
var token = new CancellationToken(true);
SetupReader(document);
@@ -52,7 +52,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetAll<TestDocument, Guid>(filter, null, token),
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, null, token),
Times.Once);
}
@@ -60,7 +60,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public void WithFilterAndPartitionKey_GetsOne()
{
// Arrange
var document = Fixture.CreateMany<TestDocument>().ToList();
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
var partitionKey = Fixture.Create<string>();
SetupReader(document);
@@ -72,7 +72,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetAll<TestDocument, Guid>(filter, partitionKey, CancellationToken.None),
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None),
Times.Once);
}
@@ -80,7 +80,7 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
public void WithFilterAndPartitionKeyAndCancellationToken_GetsOne()
{
// Arrange
var document = Fixture.CreateMany<TestDocument>().ToList();
var document = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
var partitionKey = Fixture.Create<string>();
var token = new CancellationToken(true);
@@ -93,17 +93,17 @@ public class GetAllTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
result.Should().NotBeNull();
result.Should().BeEquivalentTo(document);
Reader.Verify(
x => x.GetAll<TestDocument, Guid>(filter, partitionKey, token),
x => x.GetAll<TestDocumentWithKey<int>, int>(filter, partitionKey, token),
Times.Once);
}
private void SetupReader(List<TestDocument> documents)
private void SetupReader(List<TestDocumentWithKey<int>> documents)
{
Reader = new Mock<IMongoDbReader>();
Reader
.Setup(
x => x.GetAll<TestDocument, Guid>(
It.IsAny<Expression<Func<TestDocument, bool>>>(),
x => x.GetAll<TestDocumentWithKey<int>, int>(
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
It.IsAny<string>(),
It.IsAny<CancellationToken>()))
.Returns(documents);