From 86d9ea6990ac43f7c00cc9a33a28313efa05c5da Mon Sep 17 00:00:00 2001 From: Sean Garrett Date: Sat, 17 Jun 2023 23:42:10 +0100 Subject: [PATCH] added unit tests for MongoDBCreator and missing CancellationTokens --- .../MongoDbCreatorTests/AddManyAsyncTests.cs | 161 ++++++++++++++++++ .../MongoDbCreatorTests/AddManyTests.cs | 161 ++++++++++++++++++ .../MongoDbCreatorTests/AddOneAsyncTests.cs | 153 +++++++++++++++++ .../MongoDbCreatorTests/AddOneTests.cs | 152 +++++++++++++++++ .../DataAccess/Create/IMongoDbCreator.cs | 6 +- .../DataAccess/Create/MongoDbCreator.cs | 77 +++------ .../DataAccess/Delete/IMongoDbEraser.cs | 16 +- .../DataAccess/Delete/MongoDbEraser.cs | 2 +- 8 files changed, 665 insertions(+), 63 deletions(-) create mode 100644 CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyAsyncTests.cs create mode 100644 CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyTests.cs create mode 100644 CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneAsyncTests.cs create mode 100644 CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneTests.cs diff --git a/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyAsyncTests.cs b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyAsyncTests.cs new file mode 100644 index 0000000..a310fa4 --- /dev/null +++ b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyAsyncTests.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository; +using MongoDbGenericRepository.DataAccess.Create; +using Moq; +using Xunit; + +namespace CoreUnitTests.DataAccessTests.MongoDbCreatorTests; + +public class AddManyAsyncTests : GenericTestContext +{ + [Fact] + public async Task WithDocuments_AddsMany() + { + // Arrange + var documents = Fixture.CreateMany().ToList(); + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddManyAsync(documents); + + // Assert + collection.Verify( + x => x.InsertManyAsync( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + default), + Times.Once()); + } + + [Fact] + public async Task WithDocumentsHavingNoId_SetsId() + { + // Arrange + var documents = Fixture + .Build>() + .Without(x => x.Id) + .CreateMany() + .ToList(); + var context = MockOf(); + var collection = MockOf>>(); + + context + .Setup(x => x.GetCollection>(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddManyAsync, string>(documents); + + // Assert + collection.Verify( + x => x.InsertManyAsync( + It.Is>>(l => l.All(d => documents.Contains(d))), + null, + default), + Times.Once()); + + documents.Should().AllSatisfy(d => d.Id.Should().NotBeNull()); + } + + [Fact] + public async Task WithPartitionedDocument_AddsMany() + { + // Arrange + var partitionKey = Fixture.Create(); + var documents = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .CreateMany() + .ToList(); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddManyAsync(documents); + + // Assert + collection.Verify( + x => x.InsertManyAsync( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + default), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } + + [Fact] + public async Task WithDocumentsAndCancellationToken_AddsMany() + { + // Arrange + var documents = Fixture.CreateMany().ToList(); + var context = MockOf(); + var collection = MockOf>(); + var token = new CancellationToken(true); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddManyAsync(documents, token); + + // Assert + collection.Verify( + x => x.InsertManyAsync( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + token), + Times.Once()); + } + + [Fact] + public async Task WithPartitionedDocumentAndCancellationToken_AddsOne() + { + // Arrange + var partitionKey = Fixture.Create(); + var documents = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .CreateMany() + .ToList(); + var token = new CancellationToken(true); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddManyAsync(documents, token); + + // Assert + collection.Verify( + x => x.InsertManyAsync( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + token), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } +} diff --git a/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyTests.cs b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyTests.cs new file mode 100644 index 0000000..db00290 --- /dev/null +++ b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddManyTests.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository; +using MongoDbGenericRepository.DataAccess.Create; +using Moq; +using Xunit; + +namespace CoreUnitTests.DataAccessTests.MongoDbCreatorTests; + +public class AddManyTests : GenericTestContext +{ + [Fact] + public void WithDocuments_AddsMany() + { + // Arrange + var documents = Fixture.CreateMany().ToList(); + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddMany(documents); + + // Assert + collection.Verify( + x => x.InsertMany( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + default), + Times.Once()); + } + + [Fact] + public void WithDocumentsHavingNoId_SetsId() + { + // Arrange + var documents = Fixture + .Build>() + .Without(x => x.Id) + .CreateMany() + .ToList(); + var context = MockOf(); + var collection = MockOf>>(); + + context + .Setup(x => x.GetCollection>(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddMany, string>(documents); + + // Assert + collection.Verify( + x => x.InsertMany( + It.Is>>(l => l.All(d => documents.Contains(d))), + null, + default), + Times.Once()); + + documents.Should().AllSatisfy(d => d.Id.Should().NotBeNull()); + } + + [Fact] + public void WithPartitionedDocument_AddsMany() + { + // Arrange + var partitionKey = Fixture.Create(); + var documents = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .CreateMany() + .ToList(); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddMany(documents); + + // Assert + collection.Verify( + x => x.InsertMany( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + default), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } + + [Fact] + public void WithDocumentsAndCancellationToken_AddsMany() + { + // Arrange + var documents = Fixture.CreateMany().ToList(); + var context = MockOf(); + var collection = MockOf>(); + var token = new CancellationToken(true); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddMany(documents, token); + + // Assert + collection.Verify( + x => x.InsertMany( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + token), + Times.Once()); + } + + [Fact] + public void WithPartitionedDocumentAndCancellationToken_AddsOne() + { + // Arrange + var partitionKey = Fixture.Create(); + var documents = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .CreateMany() + .ToList(); + var token = new CancellationToken(true); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddMany(documents, token); + + // Assert + collection.Verify( + x => x.InsertMany( + It.Is>(l => l.All(d => documents.Contains(d))), + null, + token), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } +} diff --git a/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneAsyncTests.cs b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneAsyncTests.cs new file mode 100644 index 0000000..7589225 --- /dev/null +++ b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneAsyncTests.cs @@ -0,0 +1,153 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository; +using MongoDbGenericRepository.DataAccess.Create; +using Moq; +using Xunit; + +namespace CoreUnitTests.DataAccessTests.MongoDbCreatorTests; + +public class AddOneAsyncTests : GenericTestContext +{ + [Fact] + public async Task WithDocument_AddsOne() + { + // Arrange + var document = new TestDocument(); + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddOneAsync(document); + + // Assert + collection.Verify( + x => x.InsertOneAsync( + It.Is(d => d == document), + null, + default), + Times.Once()); + } + + [Fact] + public async Task WithDocumentHavingNoId_SetsId() + { + // Arrange + var document = new TestDocumentWithKey(); + var context = MockOf(); + var collection = MockOf>>(); + + context + .Setup(x => x.GetCollection>(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddOneAsync, string>(document); + + // Assert + collection.Verify( + x => x.InsertOneAsync( + It.Is>(d => d == document), + null, + default), + Times.Once()); + + document.Id.Should().NotBeNull(); + } + + [Fact] + public async Task WithPartitionedDocument_AddsOne() + { + // Arrange + var partitionKey = Fixture.Create(); + var document = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .Create(); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddOneAsync(document); + + // Assert + collection.Verify( + x => x.InsertOneAsync( + It.Is(d => d == document), + null, + default), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } + + [Fact] + public async Task WithDocumentAndCancellationToken_AddsOne() + { + // Arrange + var document = new TestDocument(); + var context = MockOf(); + var collection = MockOf>(); + var token = new CancellationToken(true); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddOneAsync(document, token); + + // Assert + collection.Verify( + x => x.InsertOneAsync( + It.Is(d => d == document), + null, + token), + Times.Once()); + } + + [Fact] + public async Task WithPartitionedDocumentAndCancellationToken_AddsOne() + { + // Arrange + var partitionKey = Fixture.Create(); + var document = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .Create(); + var token = new CancellationToken(true); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + await Sut.AddOneAsync(document, token); + + // Assert + collection.Verify( + x => x.InsertOneAsync( + It.Is(d => d == document), + null, + token), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } +} diff --git a/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneTests.cs b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneTests.cs new file mode 100644 index 0000000..9df43d1 --- /dev/null +++ b/CoreUnitTests/DataAccessTests/MongoDbCreatorTests/AddOneTests.cs @@ -0,0 +1,152 @@ +using System; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository; +using MongoDbGenericRepository.DataAccess.Create; +using Moq; +using Xunit; + +namespace CoreUnitTests.DataAccessTests.MongoDbCreatorTests; + +public class AddOneTests : GenericTestContext +{ + [Fact] + public void WithDocument_AddsOne() + { + // Arrange + var document = new TestDocument(); + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddOne(document); + + // Assert + collection.Verify( + x => x.InsertOne( + It.Is(d => d == document), + null, + default), + Times.Once()); + } + + [Fact] + public void WithDocumentHavingNoId_SetsId() + { + // Arrange + var document = new TestDocumentWithKey(); + var context = MockOf(); + var collection = MockOf>>(); + + context + .Setup(x => x.GetCollection>(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddOne, string>(document); + + // Assert + collection.Verify( + x => x.InsertOne( + It.Is>(d => d == document), + null, + default), + Times.Once()); + + document.Id.Should().NotBeNull(); + } + + [Fact] + public void WithPartitionedDocument_AddsOne() + { + // Arrange + var partitionKey = Fixture.Create(); + var document = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .Create(); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddOne(document); + + // Assert + collection.Verify( + x => x.InsertOne( + It.Is(d => d == document), + null, + default), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } + + [Fact] + public void WithDocumentAndCancellationToken_AddsOne() + { + // Arrange + var document = new TestDocument(); + var context = MockOf(); + var collection = MockOf>(); + var token = new CancellationToken(true); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddOne(document, token); + + // Assert + collection.Verify( + x => x.InsertOne( + It.Is(d => d == document), + null, + token), + Times.Once()); + } + + [Fact] + public void WithPartitionedDocumentAndCancellationToken_AddsOne() + { + // Arrange + var partitionKey = Fixture.Create(); + var document = Fixture.Build() + .With(x => x.PartitionKey, partitionKey) + .Create(); + var token = new CancellationToken(true); + + var context = MockOf(); + var collection = MockOf>(); + + context + .Setup(x => x.GetCollection(It.IsAny())) + .Returns(collection.Object); + + // Act + Sut.AddOne(document, token); + + // Assert + collection.Verify( + x => x.InsertOne( + It.Is(d => d == document), + null, + token), + Times.Once()); + + context.Verify(x => x.GetCollection(partitionKey), Times.Once()); + } +} diff --git a/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs b/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs index 00b299e..b90bfea 100644 --- a/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs +++ b/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs @@ -31,7 +31,8 @@ namespace MongoDbGenericRepository.DataAccess.Create /// The type representing a Document. /// The type of the primary key for a Document. /// The document you want to add. - void AddOne(TDocument document) + /// An optional cancellation Token. + void AddOne(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -54,7 +55,8 @@ namespace MongoDbGenericRepository.DataAccess.Create /// The type representing a Document. /// The type of the primary key for a Document. /// The documents you want to add. - void AddMany(IEnumerable documents) + /// An optional cancellation Token. + void AddMany(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; } diff --git a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs index 30f8693..4be9bf1 100644 --- a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs +++ b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs @@ -1,74 +1,54 @@ -using MongoDbGenericRepository.DataAccess.Base; -using MongoDbGenericRepository.Models; -using MongoDbGenericRepository.Utils; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MongoDbGenericRepository.DataAccess.Base; +using MongoDbGenericRepository.Models; +using MongoDbGenericRepository.Utils; namespace MongoDbGenericRepository.DataAccess.Create { /// - /// A class to insert MongoDb document. + /// A class to insert MongoDb document. /// public class MongoDbCreator : DataAccessBase, IMongoDbCreator { /// - /// The construct of the MongoDbCreator class. + /// The construct of the MongoDbCreator class. /// - /// A instance. + /// A instance. public MongoDbCreator(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } - #region Create TKey - - /// - /// Asynchronously adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to add. - /// An optional cancellation Token. + /// public virtual async Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { FormatDocument(document); - await HandlePartitioned(document).InsertOneAsync(document, null, cancellationToken); + await HandlePartitioned(document) + .InsertOneAsync(document, null, cancellationToken); } - /// - /// Adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to add. - public virtual void AddOne(TDocument document) + /// + public virtual void AddOne(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { FormatDocument(document); - HandlePartitioned(document).InsertOne(document); + HandlePartitioned(document) + .InsertOne(document, null, cancellationToken); } - /// - /// Asynchronously adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The documents you want to add. - /// An optional cancellation Token. + /// public virtual async Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { var documentsList = documents.ToList(); - + if (!documentsList.Any()) { return; @@ -82,7 +62,7 @@ namespace MongoDbGenericRepository.DataAccess.Create // cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5 if (documentsList.Any(e => e is IPartitionedDocument)) { - foreach (var group in documentsList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) + foreach (var group in documentsList.GroupBy(e => ((IPartitionedDocument) e).PartitionKey)) { await HandlePartitioned(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken); } @@ -93,14 +73,8 @@ namespace MongoDbGenericRepository.DataAccess.Create } } - /// - /// Adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The documents you want to add. - public virtual void AddMany(IEnumerable documents) + /// + public virtual void AddMany(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -119,21 +93,19 @@ namespace MongoDbGenericRepository.DataAccess.Create // cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5 if (documentList.Any(e => e is IPartitionedDocument)) { - foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) + foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument) e).PartitionKey)) { - HandlePartitioned(group.FirstOrDefault()).InsertMany(group.ToList()); + HandlePartitioned(group.FirstOrDefault()).InsertMany(group.ToList(), cancellationToken: cancellationToken); } } else { - GetCollection().InsertMany(documentList.ToList()); + GetCollection().InsertMany(documentList.ToList(), cancellationToken: cancellationToken); } } - #endregion - /// - /// Sets the value of the document Id if it is not set already. + /// Sets the value of the document Id if it is not set already. /// /// The document type. /// The type of the primary key. @@ -146,6 +118,7 @@ namespace MongoDbGenericRepository.DataAccess.Create { throw new ArgumentNullException(nameof(document)); } + var defaultTKey = default(TKey); if (document.Id == null || (defaultTKey != null @@ -155,4 +128,4 @@ namespace MongoDbGenericRepository.DataAccess.Create } } } -} +} \ No newline at end of file diff --git a/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs b/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs index f56873b..c1fc2f5 100644 --- a/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs +++ b/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs @@ -21,7 +21,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// The document you want to delete. /// An optional cancellation token /// The number of documents deleted. - long DeleteOne(TDocument document, CancellationToken cancellationToken) + long DeleteOne(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -34,7 +34,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// An optional partition key. /// An optional cancellation token /// The number of documents deleted. - long DeleteOne(Expression> filter, string partitionKey, CancellationToken cancellationToken) + long DeleteOne(Expression> filter, string partitionKey = default, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -46,7 +46,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// The document you want to delete. /// The cancellation token /// The number of documents deleted. - Task DeleteOneAsync(TDocument document, CancellationToken cancellationToken) + Task DeleteOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -59,7 +59,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// An optional partition key. /// The cancellation token /// The number of documents deleted. - Task DeleteOneAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + Task DeleteOneAsync(Expression> filter, string partitionKey = default, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -72,7 +72,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// An optional partition key. /// The cancellation token /// The number of documents deleted. - Task DeleteManyAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + Task DeleteManyAsync(Expression> filter, string partitionKey = default, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -84,7 +84,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// The list of documents to delete. /// The cancellation token. /// The number of documents deleted. - Task DeleteManyAsync(IEnumerable documents, CancellationToken cancellationToken) + Task DeleteManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -96,7 +96,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// The list of documents to delete. /// The cancellation token /// The number of documents deleted. - long DeleteMany(IEnumerable documents, CancellationToken cancellationToken) + long DeleteMany(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -109,7 +109,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete /// An optional partition key. /// The Cancellation Token /// The number of documents deleted. - long DeleteMany(Expression> filter, string partitionKey, CancellationToken cancellationToken) + long DeleteMany(Expression> filter, string partitionKey = default, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; } diff --git a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs index 7136261..27ff63a 100644 --- a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs +++ b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs @@ -24,7 +24,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete #region Delete TKey /// - public virtual long DeleteOne(TDocument document, CancellationToken cancellationToken) + public virtual long DeleteOne(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable {