diff --git a/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/CreateCombinedTextIndexAsyncTests.cs b/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/CreateCombinedTextIndexAsyncTests.cs new file mode 100644 index 0000000..425aec9 --- /dev/null +++ b/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/CreateCombinedTextIndexAsyncTests.cs @@ -0,0 +1,295 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure.Model; +using MongoDbGenericRepository.DataAccess.Index; +using MongoDbGenericRepository.Models; +using Moq; +using Xunit; +using CancellationToken = System.Threading.CancellationToken; + +namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests; + +public class CreateCombinedTextIndexAsyncTests : BaseIndexTests +{ + private readonly List>> fieldExpressions = new() {t => t.SomeContent2, t => t.SomeContent3}; + private readonly List, object>>> keyedFieldExpressions = new() {t => t.SomeContent2, t => t.SomeContent3}; + + [Fact] + public async Task WithFieldExpression_CreatesIndex() + { + // Arrange + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync(fieldExpressions, null, null, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndCancellationToken_CreatesIndex() + { + // Arrange + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync(fieldExpressions, null, null, token)); + } + + [Fact] + public async Task WithFieldExpressionAndOptions_CreatesIndex() + { + // Arrange + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, options); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync( + fieldExpressions, options, null, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndOptionsAndCancellationToken_CreatesIndex() + { + // Arrange + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, options, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync( + fieldExpressions, options, null, token)); + } + + [Fact] + public async Task WithFieldExpressionAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync( + fieldExpressions, null, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndPartitionKeyAndCancellationToken_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync( + fieldExpressions, null, partitionKey, token)); + } + + [Fact] + public async Task WithFieldExpressionAndOptionsAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, options, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync( + fieldExpressions, options, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndOptionsAndPartitionKeyAndCancellationToken_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(fieldExpressions, options, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync( + fieldExpressions, options, partitionKey, token)); + } + + #region Keyed + + [Fact] + public async Task Keyed_WithKeyedFieldExpression_CreatesIndex() + { + // Arrange + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, null, null, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndCancellationToken_CreatesIndex() + { + // Arrange + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, null, null, token)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndOptions_CreatesIndex() + { + // Arrange + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, options); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, null, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndOptionsAndCancellationToken_CreatesIndex() + { + // Arrange + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, options, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, null, token)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, null, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndPartitionKeyAndCancellationToken_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, null, partitionKey, token)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndOptionsAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, options, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndOptionsAndPartitionKeyAndCancellationToken_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, options, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, partitionKey, token)); + } + + #endregion +} diff --git a/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/DropIndexAsyncTests.cs b/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/DropIndexAsyncTests.cs new file mode 100644 index 0000000..8995b70 --- /dev/null +++ b/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/DropIndexAsyncTests.cs @@ -0,0 +1,145 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure.Model; +using MongoDbGenericRepository.DataAccess.Index; +using Moq; +using Xunit; + +namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests; + +public class DropIndexAsyncTests: BaseIndexTests +{ + [Fact] + public async Task WitIndexName_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync(indexName); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync(indexName, null, CancellationToken.None)); + } + + [Fact] + public async Task WitIndexNameAndCancellationToken_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync(indexName, token); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync(indexName, null, token)); + } + + [Fact] + public async Task WitIndexNameAndPartitionKey_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync(indexName, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync(indexName, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task WitIndexNameAndPartitionKeyAndCancellationToken_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync(indexName, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync(indexName, partitionKey, token)); + } + + #region Keyed + + [Fact] + public async Task Keyed_WithIndexName_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync, int>(indexName); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, null, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithIndexNameAndCancellationToken_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync, int>(indexName, token); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, null, token)); + } + + [Fact] + public async Task Keyed_WithIndexNameAndPartitionKey_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync, int>(indexName, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithIndexNameAndPartitionKeyAndCancellationToken_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync, int>(indexName, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, partitionKey, token)); + } + + #endregion +} diff --git a/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/CreateCombinedTextIndexAsyncTests.cs b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/CreateCombinedTextIndexAsyncTests.cs new file mode 100644 index 0000000..f1c46cf --- /dev/null +++ b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/CreateCombinedTextIndexAsyncTests.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using MongoDbGenericRepository.DataAccess.Index; +using MongoDbGenericRepository.Models; +using Moq; +using Xunit; + +namespace CoreUnitTests.KeyTypedRepositoryTests.IndexTests; + +public class CreateCombinedTextIndexAsyncTests : TestKeyedMongoRepositoryContext +{ + private readonly List, object>>> keyedFieldExpressions = new() {t => t.SomeContent2, t => t.SomeContent3}; + + [Fact] + public async Task WithFieldExpression_CreatesIndex() + { + // Arrange + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, null, null, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndCancellationToken_CreatesIndex() + { + // Arrange + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>(keyedFieldExpressions, null, null, token)); + } + + [Fact] + public async Task WithFieldExpressionAndOptions_CreatesIndex() + { + // Arrange + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, options); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, null, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndOptionsAndCancellationToken_CreatesIndex() + { + // Arrange + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, options, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, null, token)); + } + + [Fact] + public async Task WithFieldExpressionAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, null, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndPartitionKeyAndCancellationToken_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, null, partitionKey, token)); + } + + [Fact] + public async Task WithFieldExpressionAndOptionsAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, options, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndOptionsAndPartitionKeyAndCancellationToken_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + var indexName = Fixture.Create(); + var options = new IndexCreationOptions { Name = indexName }; + + IndexHandler = new Mock(); + + // Act + await Sut.CreateCombinedTextIndexAsync(keyedFieldExpressions, options, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateCombinedTextIndexAsync, int>( + keyedFieldExpressions, options, partitionKey, token)); + } +} diff --git a/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/DropIndexAsyncTests.cs b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/DropIndexAsyncTests.cs new file mode 100644 index 0000000..16386b1 --- /dev/null +++ b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/DropIndexAsyncTests.cs @@ -0,0 +1,77 @@ +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using MongoDbGenericRepository.DataAccess.Index; +using Moq; +using Xunit; + +namespace CoreUnitTests.KeyTypedRepositoryTests.IndexTests; + +public class DropIndexAsyncTests : TestKeyedMongoRepositoryContext +{ + [Fact] + public async Task WitIndexName_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync>(indexName); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, null, CancellationToken.None)); + } + + [Fact] + public async Task WitIndexNameAndCancellationToken_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync>(indexName, token); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, null, token)); + } + + [Fact] + public async Task WitIndexNameAndPartitionKey_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync>(indexName, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, partitionKey, CancellationToken.None)); + } + + [Fact] + public async Task WitIndexNameAndPartitionKeyAndCancellationToken_DropsIndex() + { + // Arrange + var indexName = Fixture.Create(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.DropIndexAsync>(indexName, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.DropIndexAsync, int>(indexName, partitionKey, token)); + } +} diff --git a/MongoDbGenericRepository/BaseMongoRepository.Index.cs b/MongoDbGenericRepository/BaseMongoRepository.Index.cs index a3eaee0..9ed7e9d 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Index.cs @@ -642,39 +642,183 @@ namespace MongoDbGenericRepository } /// - public async Task CreateCombinedTextIndexAsync( - IEnumerable>> fields, - IndexCreationOptions indexCreationOptions = null, - string partitionKey = null) + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields) where TDocument : IDocument { - return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); + return await CreateCombinedTextIndexAsync(fields, null, null, CancellationToken.None); } /// - public virtual async Task CreateCombinedTextIndexAsync( - IEnumerable>> fields, - IndexCreationOptions indexCreationOptions = null, - string partitionKey = null) + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, null, null, cancellationToken); + } + + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, CancellationToken.None); + } + + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, cancellationToken); + } + + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, null, partitionKey, CancellationToken.None); + } + + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, null, partitionKey, cancellationToken); + } + + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); + return await CreateCombinedTextIndexAsync(fields, null, null, CancellationToken.None); } /// - public async Task DropIndexAsync(string indexName, string partitionKey = null) - where TDocument : IDocument - { - await DropIndexAsync(indexName, partitionKey); - } - - /// - public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey); + return await CreateCombinedTextIndexAsync(fields, null, null, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, CancellationToken.None); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateCombinedTextIndexAsync(fields, null, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateCombinedTextIndexAsync(fields, null, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, cancellationToken); + } + + /// + public async Task DropIndexAsync(string indexName) + where TDocument : IDocument + { + await DropIndexAsync(indexName, null, CancellationToken.None); + } + + /// + public async Task DropIndexAsync(string indexName, CancellationToken cancellationToken) + where TDocument : IDocument + { + await DropIndexAsync(indexName, null, cancellationToken); + } + + /// + public async Task DropIndexAsync(string indexName, string partitionKey) + where TDocument : IDocument + { + await DropIndexAsync(indexName, partitionKey, CancellationToken.None); + } + + /// + public async Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + await DropIndexAsync(indexName, partitionKey, cancellationToken); + } + + /// + public virtual async Task DropIndexAsync(string indexName) + where TDocument : IDocument + where TKey : IEquatable + { + await DropIndexAsync(indexName, null, CancellationToken.None); + } + + /// + public virtual async Task DropIndexAsync(string indexName, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + await DropIndexAsync(indexName, null, cancellationToken); + } + + /// + public virtual async Task DropIndexAsync(string indexName, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + await DropIndexAsync(indexName, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey, cancellationToken); } } } \ No newline at end of file diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs index eaa6372..84abebf 100644 --- a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs @@ -520,6 +520,91 @@ namespace MongoDbGenericRepository where TDocument : IDocument where TKey : IEquatable; + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// Options for creating an index. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// Options for creating an index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Creates a combined text index. /// IndexCreationOptions can be supplied to further specify @@ -531,7 +616,44 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The name of the index + Task DropIndexAsync(string indexName) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The name of the index + /// The cancellation token + Task DropIndexAsync(string indexName, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; @@ -542,7 +664,19 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// The name of the index /// An optional partition key - Task DropIndexAsync(string indexName, string partitionKey = null) + Task DropIndexAsync(string indexName, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The name of the index + /// An optional partition key + /// The cancellation token + Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; } diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs index 145d497..a327965 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs @@ -340,17 +340,87 @@ namespace MongoDbGenericRepository } /// - public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); + return await CreateCombinedTextIndexAsync(fields, null, null, CancellationToken.None); } /// - public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, CancellationToken cancellationToken) where TDocument : IDocument { - await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey); + return await CreateCombinedTextIndexAsync(fields, null, null, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, CancellationToken.None); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, null, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, null, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + { + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, cancellationToken); + } + + /// + public virtual async Task DropIndexAsync(string indexName) + where TDocument : IDocument + { + await DropIndexAsync(indexName, null, CancellationToken.None); + } + + /// + public virtual async Task DropIndexAsync(string indexName, CancellationToken cancellationToken) + where TDocument : IDocument + { + await DropIndexAsync(indexName, null, cancellationToken); + } + + /// + public virtual async Task DropIndexAsync(string indexName, string partitionKey) + where TDocument : IDocument + { + await DropIndexAsync(indexName, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey, cancellationToken); } } } \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs index 9b51ceb..cce8c25 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs @@ -450,6 +450,79 @@ namespace MongoDbGenericRepository Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// Options for creating an index. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// Options for creating an index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + /// /// Creates a combined text index. /// IndexCreationOptions can be supplied to further specify @@ -460,7 +533,38 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The name of the index + Task DropIndexAsync(string indexName) + where TDocument : IDocument; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The name of the index + /// The cancellation token. + Task DropIndexAsync(string indexName, CancellationToken cancellationToken) where TDocument : IDocument; /// @@ -469,7 +573,17 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The name of the index /// An optional partition key - Task DropIndexAsync(string indexName, string partitionKey = null) + Task DropIndexAsync(string indexName, string partitionKey) + where TDocument : IDocument; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The name of the index + /// An optional partition key + /// The cancellation token. + Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; } } \ No newline at end of file