Delete unit tests for the repos
This commit is contained in:
@@ -0,0 +1,320 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoFixture;
|
||||||
|
using CoreUnitTests.Infrastructure;
|
||||||
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
|
using FluentAssertions;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Delete;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace CoreUnitTests.BaseMongoRepositoryTests.DeleteTests;
|
||||||
|
|
||||||
|
public class DeleteManyAsyncTests : TestMongoRepositoryContext
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task WithDocuments_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocument, Guid>(It.IsAny<IEnumerable<TestDocument>>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync(documents);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocument, Guid>(documents, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithDocumentsAndCancellationToken_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var cancellationToken = new CancellationToken();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocument, Guid>(It.IsAny<IEnumerable<TestDocument>>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync(documents, cancellationToken);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocument, Guid>(documents, cancellationToken), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilter_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocument, Guid>(filter, null, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndCancellationToken_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync(filter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocument, Guid>(filter, null, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndPartitionKey_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndPartitionKeyAndCancellationToken_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocument, Guid>(
|
||||||
|
It.IsAny<Expression<Func<TestDocument, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync(filter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocument, Guid>(filter, partitionKey, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithDocuments_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(It.IsAny<IEnumerable<TestDocumentWithKey<int>>>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync<TestDocumentWithKey<int>, int>(documents);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(documents, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithDocumentsAndCancellationToken_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var cancellationToken = new CancellationToken();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(It.IsAny<IEnumerable<TestDocumentWithKey<int>>>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync<TestDocumentWithKey<int>, int>(documents, cancellationToken);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(documents, cancellationToken), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilter_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCancellationToken_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, null, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKey_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteManyAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using AutoFixture;
|
||||||
|
using CoreUnitTests.Infrastructure;
|
||||||
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
|
using FluentAssertions;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Delete;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace CoreUnitTests.BaseMongoRepositoryTests.DeleteTests;
|
||||||
|
|
||||||
|
public class DeleteManyTests : TestMongoRepositoryContext
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void WithDocuments_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<IEnumerable<TestDocument>>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteMany(documents);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(documents), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilter_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), null))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteMany(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, null), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndPartitionKey_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteMany(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, partitionKey), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithDocuments_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<IEnumerable<TestDocumentWithKey<int>>>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteMany<TestDocumentWithKey<int>, int>(documents);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(documents), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilter_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), null))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteMany<TestDocumentWithKey<int>, int>(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, null), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKey_ShouldDeleteMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteMany<TestDocumentWithKey<int>, int>(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, partitionKey), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoFixture;
|
||||||
|
using CoreUnitTests.Infrastructure;
|
||||||
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
|
using FluentAssertions;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Delete;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace CoreUnitTests.BaseMongoRepositoryTests.DeleteTests;
|
||||||
|
|
||||||
|
public class DeleteOneAsyncTests : TestMongoRepositoryContext
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task WithDocument_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocument, Guid>(It.IsAny<TestDocument>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync(document);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocument, Guid>(document, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithDocumentAndCancellationToken_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocument, Guid>(It.IsAny<TestDocument>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync(document, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocument, Guid>(document, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilter_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocument, Guid>(filter, null, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndCancellationToken_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync(filter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocument, Guid>(filter, null, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndPartitionKey_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocument, Guid>(filter, partitionKey, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFilterAndPartitionKeyAndCancellationToken_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync(filter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocument, Guid>(filter, partitionKey, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithDocument_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(It.IsAny<TestDocumentWithKey<int>>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync<TestDocumentWithKey<int>, int>(document);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(document, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithDocumentAndCancellationToken_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(It.IsAny<TestDocumentWithKey<int>>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync<TestDocumentWithKey<int>, int>(document, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(document, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilter_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, null, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndCancellationToken_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, null, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKey_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithFilterAndPartitionKeyAndCancellationToken_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOneAsync<TestDocumentWithKey<int>, int>(filter, partitionKey, token), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using AutoFixture;
|
||||||
|
using CoreUnitTests.Infrastructure;
|
||||||
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
|
using FluentAssertions;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Delete;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace CoreUnitTests.BaseMongoRepositoryTests.DeleteTests;
|
||||||
|
|
||||||
|
public class DeleteOneTests : TestMongoRepositoryContext
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void WithDocument_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocument>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOne<TestDocument, Guid>(It.IsAny<TestDocument>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteOne(document);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOne<TestDocument, Guid>(document), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilter_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOne<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteOne(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOne<TestDocument, Guid>(filter, null), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithFilterAndPartitionKey_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocument, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOne<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteOne(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOne<TestDocument, Guid>(filter, partitionKey), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithKeyedDocument_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = Fixture.Create<TestDocumentWithKey<int>>();
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOne<TestDocumentWithKey<int>, int>(It.IsAny<TestDocumentWithKey<int>>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteOne<TestDocumentWithKey<int>, int>(document);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOne<TestDocumentWithKey<int>, int>(document), Times.Once);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilter_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOne<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteOne<TestDocumentWithKey<int>, int>(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOne<TestDocumentWithKey<int>, int>(filter, null), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Keyed_WithFilterAndPartitionKey_ShouldDeleteOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var count = Fixture.Create<long>();
|
||||||
|
var content = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
Expression<Func<TestDocumentWithKey<int>, bool>> filter = x => x.SomeContent == content;
|
||||||
|
|
||||||
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
|
Eraser
|
||||||
|
.Setup(x => x.DeleteOne<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>()))
|
||||||
|
.Returns(count);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Sut.DeleteOne<TestDocumentWithKey<int>, int>(filter, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(count);
|
||||||
|
Eraser.Verify(x => x.DeleteOne<TestDocumentWithKey<int>, int>(filter, partitionKey), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using MongoDbGenericRepository;
|
using MongoDbGenericRepository;
|
||||||
using MongoDbGenericRepository.DataAccess.Create;
|
using MongoDbGenericRepository.DataAccess.Create;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Delete;
|
||||||
using MongoDbGenericRepository.DataAccess.Index;
|
using MongoDbGenericRepository.DataAccess.Index;
|
||||||
using MongoDbGenericRepository.DataAccess.Read;
|
using MongoDbGenericRepository.DataAccess.Read;
|
||||||
|
|
||||||
@@ -27,4 +28,9 @@ public class TestMongoRepository : BaseMongoRepository
|
|||||||
{
|
{
|
||||||
MongoDbReader = reader;
|
MongoDbReader = reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetEraser(IMongoDbEraser eraser)
|
||||||
|
{
|
||||||
|
MongoDbEraser = eraser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,11 @@ public class TestMongoRepositoryContext
|
|||||||
{
|
{
|
||||||
_sut.SetReader(Reader.Object);
|
_sut.SetReader(Reader.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Eraser != null)
|
||||||
|
{
|
||||||
|
_sut.SetEraser(Eraser.Object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _sut;
|
return _sut;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public class DeleteManyTests : TestKeyedMongoRepositoryContext<int>
|
|||||||
result.Should().Be(count);
|
result.Should().Be(count);
|
||||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, null), Times.Once);
|
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, null), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFilterAndPartitionKey_ShouldDeleteMany()
|
public void WithFilterAndPartitionKey_ShouldDeleteMany()
|
||||||
{
|
{
|
||||||
@@ -69,7 +70,7 @@ public class DeleteManyTests : TestKeyedMongoRepositoryContext<int>
|
|||||||
Eraser = new Mock<IMongoDbEraser>();
|
Eraser = new Mock<IMongoDbEraser>();
|
||||||
|
|
||||||
Eraser
|
Eraser
|
||||||
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), null))
|
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>()))
|
||||||
.Returns(count);
|
.Returns(count);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading;
|
|
||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
using CoreUnitTests.Infrastructure;
|
using CoreUnitTests.Infrastructure;
|
||||||
using CoreUnitTests.Infrastructure.Model;
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
|
|||||||
@@ -161,6 +161,14 @@ namespace MongoDbGenericRepository
|
|||||||
return MongoDbEraser.DeleteOne<TDocument, TKey>(document);
|
return MongoDbEraser.DeleteOne<TDocument, TKey>(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
||||||
|
where TDocument : IDocument<TKey>
|
||||||
|
where TKey : IEquatable<TKey>
|
||||||
|
{
|
||||||
|
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(TDocument document)
|
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(TDocument document)
|
||||||
where TDocument : IDocument<TKey>
|
where TDocument : IDocument<TKey>
|
||||||
@@ -177,21 +185,6 @@ namespace MongoDbGenericRepository
|
|||||||
return await MongoDbEraser.DeleteOneAsync<TDocument, TKey>(document, cancellationToken);
|
return await MongoDbEraser.DeleteOneAsync<TDocument, TKey>(document, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes a document matching the condition of the LINQ expression filter.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
|
||||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
|
||||||
/// <param name="filter">A LINQ expression filter.</param>
|
|
||||||
/// <param name="partitionKey">An optional partition key.</param>
|
|
||||||
/// <returns>The number of documents deleted.</returns>
|
|
||||||
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
|
||||||
where TDocument : IDocument<TKey>
|
|
||||||
where TKey : IEquatable<TKey>
|
|
||||||
{
|
|
||||||
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter)
|
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter)
|
||||||
where TDocument : IDocument<TKey>
|
where TDocument : IDocument<TKey>
|
||||||
|
|||||||
Reference in New Issue
Block a user