tests for readonly repositories
This commit is contained in:
@@ -12,16 +12,16 @@ using Xunit;
|
||||
|
||||
namespace CoreUnitTests.KeyedReadOnlyMongoRepositoryTests;
|
||||
|
||||
public class GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
public class GetByMaxAsyncTests : 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 GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, null, CancellationToken.None),
|
||||
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, null, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class GetByMaxAsyncTests : 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 GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, null, token),
|
||||
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, null, token),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class GetByMaxAsyncTests : 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 GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, partitionKey, CancellationToken.None),
|
||||
x => x.GetByMaxAsync<TestDocumentWithKey<int>, int>(filter, selector, partitionKey, CancellationToken.None),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class GetByMaxAsyncTests : 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 GetByMaxAsyncTests : TestKeyedReadOnlyMongoRepositoryContext<Guid>
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEquivalentTo(document);
|
||||
Reader.Verify(
|
||||
x => x.GetByMaxAsync<TestDocument, Guid>(filter, selector, partitionKey, token),
|
||||
x => x.GetByMaxAsync<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.GetByMaxAsync<TestDocument, Guid>(
|
||||
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||
It.IsAny<Expression<Func<TestDocument, object>>>(),
|
||||
x => x.GetByMaxAsync<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);
|
||||
|
||||
Reference in New Issue
Block a user