added overloads for delete

This commit is contained in:
Sean Garrett
2023-06-15 21:35:51 +01:00
parent e23f659ffe
commit 0cf6a7e5d3
10 changed files with 545 additions and 237 deletions
+2 -2
View File
@@ -8,8 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
@@ -0,0 +1,6 @@
namespace CoreUnitTests.Infrastructure;
public class TestDocument
{
}
@@ -0,0 +1,6 @@
namespace CoreUnitTests.Infrastructure;
public class TestKeyedMongoRepository : KeyedMongoRepository<TestDocument, TestDocumentKey>
{
}
@@ -0,0 +1,80 @@
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace CoreUnitTests.KeyTypedRepositoryTests.DeleteTests;
public class DeleteOneAsyncTests
{
[Fact]
public async Task DeleteOneAsync_WithDocument_ShouldDeleteOne()
{
// Arrange
var repository = GetNewRepository();
var document = new TestDocument<TKey> {Name = "DeleteOneAsync_WithDocument_ShouldDeleteOne"};
await repository.InsertOneAsync(document);
// Act
var result = await repository.DeleteOneAsync(document);
// Assert
result.Should().Be(1);
}
[Fact]
public async Task DeleteOneAsync_WithDocumentAndCancellationToken_ShouldDeleteOne()
{
// Arrange
var repository = GetNewRepository();
var document = new TestDocument<TKey> {Name = "DeleteOneAsync_WithDocumentAndCancellationToken_ShouldDeleteOne"};
await repository.InsertOneAsync(document);
// Act
var result = await repository.DeleteOneAsync(document, CancellationToken.None);
// Assert
result.Should().Be(1);
}
[Fact]
public async Task DeleteOneAsync_WithDocumentAndCancellationToken_ShouldDeleteOneWithCancellationToken()
{
// Arrange
var repository = GetNewRepository();
var document = new TestDocument<TKey> {Name = "DeleteOneAsync_WithDocumentAndCancellationToken_ShouldDeleteOneWithCancellationToken"};
await repository.InsertOneAsync(document);
// Act
var result = await repository.DeleteOneAsync(document, new CancellationToken(true));
// Assert
result.Should().Be(0);
}
[Fact]
public async Task DeleteOneAsync_WithFilter_ShouldDeleteOne()
{
// Arrange
var repository = GetNewRepository();
var document = new TestDocument<TKey> {Name = "DeleteOneAsync_WithFilter_ShouldDeleteOne"};
await repository.InsertOneAsync(document);
// Act
var result = await repository.DeleteOneAsync(x => x.Name == document.Name);
// Assert
result.Should().Be(1);
}
[Fact]
public async Task DeleteOneAsync_WithFilterAndCancellationToken_ShouldDeleteOne()
{
// Arrange
var repository = GetNewRepository();
var document = new TestDocument<TKey> {Name = "DeleteOneAsync_WithFilterAndCancellationToken_ShouldDeleteOne"};
await repository.InsertOneAsync(document);
// Act
var result = await repository.DeleteOneAsync(x => x
}
}