added overloads for delete
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user