unit tests
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CoreUnitTests.Infrastructure;
|
||||
using CoreUnitTests.Infrastructure.Model;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace CoreUnitTests.BaseMongoRepositoryTests.MainTests;
|
||||
|
||||
public class AnyTests : TestMongoRepositoryContext
|
||||
{
|
||||
[Fact]
|
||||
public async Task AnyAsync_EnsureTokenPassed()
|
||||
{
|
||||
// Arrange
|
||||
var token = new CancellationToken();
|
||||
|
||||
Reader = new Mock<IMongoDbReader>();
|
||||
Reader
|
||||
.Setup(x => x.AnyAsync<TestDocument, Guid>(It.IsAny<ExpressionFilterDefinition<TestDocument>>(), null, null, token))
|
||||
.ReturnsAsync(true);
|
||||
|
||||
// Act
|
||||
await Sut.AnyAsync<TestDocument>(t => string.IsNullOrWhiteSpace(t.SomeContent2), token);
|
||||
|
||||
// Assert
|
||||
Reader
|
||||
.Verify(x => x.AnyAsync<TestDocument, Guid>(
|
||||
t => string.IsNullOrWhiteSpace(t.SomeContent2), null, token));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CoreUnitTests.Infrastructure;
|
||||
using CoreUnitTests.Infrastructure.Model;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace CoreUnitTests.BaseMongoRepositoryTests.MainTests;
|
||||
|
||||
public class CountTests : TestMongoRepositoryContext
|
||||
{
|
||||
[Fact]
|
||||
public async Task CountAsync_EnsureTokenPassed()
|
||||
{
|
||||
// Arrange
|
||||
var token = new CancellationToken();
|
||||
|
||||
Reader = new Mock<IMongoDbReader>();
|
||||
Reader
|
||||
.Setup(x => x.CountAsync<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), null, token))
|
||||
.ReturnsAsync(10);
|
||||
|
||||
// Act
|
||||
var result = await Sut.CountAsync<TestDocument>(t => string.IsNullOrWhiteSpace(t.SomeContent2), token);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(10, result);
|
||||
Reader.Verify(x => x.CountAsync<TestDocument, Guid>(
|
||||
t => string.IsNullOrWhiteSpace(t.SomeContent2), null, token));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user