added cancellation tokens to sync deletes and added more unit tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using AutoFixture;
|
||||
using CoreUnitTests.Infrastructure;
|
||||
using CoreUnitTests.Infrastructure.Model;
|
||||
@@ -23,7 +24,7 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<IEnumerable<TestDocument>>()))
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<IEnumerable<TestDocument>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
@@ -31,7 +32,28 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(documents), Times.Once);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(documents, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithDocumentsAndCancellationToken_ShouldDeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var count = Fixture.Create<long>();
|
||||
var token = new CancellationToken(true);
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<IEnumerable<TestDocument>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.DeleteMany(documents, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(documents, token), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -46,7 +68,7 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), null))
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
@@ -54,7 +76,31 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, null), Times.Once);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, null, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndCancellationToken_ShouldDeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var content = Fixture.Create<string>();
|
||||
var count = Fixture.Create<long>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
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>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.DeleteMany(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, null, token), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +116,7 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>()))
|
||||
.Setup(x => x.DeleteMany<TestDocument, Guid>(It.IsAny<Expression<Func<TestDocument, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
@@ -78,7 +124,32 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, partitionKey), Times.Once);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, partitionKey, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFilterAndPartitionKeyAndCancellationToken_ShouldDeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var content = Fixture.Create<string>();
|
||||
var count = Fixture.Create<long>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
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>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.DeleteMany(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocument, Guid>(filter, partitionKey, token), Times.Once);
|
||||
}
|
||||
|
||||
#region Keyed
|
||||
@@ -92,7 +163,7 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<IEnumerable<TestDocumentWithKey<int>>>()))
|
||||
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<IEnumerable<TestDocumentWithKey<int>>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
@@ -100,7 +171,28 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(documents), Times.Once);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(documents, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Keyed_WithDocumentsAndCancellationToken_ShouldDeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||
var count = Fixture.Create<long>();
|
||||
var token = new CancellationToken(true);
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<IEnumerable<TestDocumentWithKey<int>>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.DeleteMany<TestDocumentWithKey<int>, int>(documents, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(documents, token), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -115,7 +207,7 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
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>>>(), null, CancellationToken.None))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
@@ -123,7 +215,31 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
|
||||
// Assert
|
||||
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, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Keyed_WithFilterAndCancellationToken_ShouldDeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var content = Fixture.Create<string>();
|
||||
var count = Fixture.Create<long>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
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>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.DeleteMany<TestDocumentWithKey<int>, int>(filter, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, null, token), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -139,7 +255,7 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
Eraser = new Mock<IMongoDbEraser>();
|
||||
|
||||
Eraser
|
||||
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>()))
|
||||
.Setup(x => x.DeleteMany<TestDocumentWithKey<int>, int>(It.IsAny<Expression<Func<TestDocumentWithKey<int>, bool>>>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
@@ -147,8 +263,32 @@ public class DeleteManyTests : TestMongoRepositoryContext
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, partitionKey), Times.Once);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, partitionKey, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Keyed_WithFilterAndPartitionKeyAndCancellationToken_ShouldDeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var content = Fixture.Create<string>();
|
||||
var count = Fixture.Create<long>();
|
||||
var partitionKey = Fixture.Create<string>();
|
||||
var token = new CancellationToken(true);
|
||||
|
||||
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>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(count);
|
||||
|
||||
// Act
|
||||
var result = Sut.DeleteMany<TestDocumentWithKey<int>, int>(filter, partitionKey, token);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(count);
|
||||
Eraser.Verify(x => x.DeleteMany<TestDocumentWithKey<int>, int>(filter, partitionKey, token), Times.Once);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user