diff --git a/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/CreateHashedIndexAsyncTests.cs b/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/CreateHashedIndexAsyncTests.cs new file mode 100644 index 0000000..349aadb --- /dev/null +++ b/CoreUnitTests/BaseMongoRepositoryTests/IndexTests/CreateHashedIndexAsyncTests.cs @@ -0,0 +1,294 @@ +using System; +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 CreateHashedIndexAsyncTests : BaseIndexTests +{ + private readonly Expression> fieldExpression = t => t.SomeContent2; + private readonly Expression, object>> keyedFieldExpression = t => t.SomeContent2; + + [Fact] + public async Task WithFieldExpression_CreatesIndex() + { + // Arrange + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync(fieldExpression); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync(fieldExpression, null, null, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndCancellationToken_CreatesIndex() + { + // Arrange + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync(fieldExpression, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync(fieldExpression, 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.CreateHashedIndexAsync(fieldExpression, options); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync( + fieldExpression, 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.CreateHashedIndexAsync(fieldExpression, options, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync( + fieldExpression, options, null, token)); + } + + [Fact] + public async Task WithFieldExpressionAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync(fieldExpression, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync( + fieldExpression, 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.CreateHashedIndexAsync(fieldExpression, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync( + fieldExpression, 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.CreateHashedIndexAsync(fieldExpression, options, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync( + fieldExpression, 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.CreateHashedIndexAsync(fieldExpression, options, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync( + fieldExpression, options, partitionKey, token)); + } + + #region Keyed + + [Fact] + public async Task Keyed_WithKeyedFieldExpression_CreatesIndex() + { + // Arrange + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync, int>(keyedFieldExpression); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>(keyedFieldExpression, null, null, CancellationToken.None)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndCancellationToken_CreatesIndex() + { + // Arrange + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync, int>(keyedFieldExpression, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>(keyedFieldExpression, 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.CreateHashedIndexAsync, int>(keyedFieldExpression, options); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync, int>(keyedFieldExpression, options, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, options, null, token)); + } + + [Fact] + public async Task Keyed_WithKeyedFieldExpressionAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync, int>(keyedFieldExpression, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync, int>(keyedFieldExpression, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync, int>(keyedFieldExpression, options, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync, int>(keyedFieldExpression, options, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, options, partitionKey, token)); + } + + #endregion +} diff --git a/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/CreateHashedIndexAsyncTests.cs b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/CreateHashedIndexAsyncTests.cs new file mode 100644 index 0000000..d2e60dd --- /dev/null +++ b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/CreateHashedIndexAsyncTests.cs @@ -0,0 +1,154 @@ +using System; +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 CreateHashedIndexAsyncTests : TestKeyedMongoRepositoryContext +{ + private readonly Expression, object>> keyedFieldExpression = t => t.SomeContent2; + + [Fact] + public async Task WithFieldExpression_CreatesIndex() + { + // Arrange + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync(keyedFieldExpression); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>(keyedFieldExpression, null, null, CancellationToken.None)); + } + + [Fact] + public async Task WithFieldExpressionAndCancellationToken_CreatesIndex() + { + // Arrange + var token = new CancellationToken(true); + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync(keyedFieldExpression, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>(keyedFieldExpression, 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.CreateHashedIndexAsync(keyedFieldExpression, options); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync(keyedFieldExpression, options, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, options, null, token)); + } + + [Fact] + public async Task WithFieldExpressionAndPartitionKey_CreatesIndex() + { + // Arrange + var partitionKey = Fixture.Create(); + IndexHandler = new Mock(); + + // Act + await Sut.CreateHashedIndexAsync(keyedFieldExpression, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync(keyedFieldExpression, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync(keyedFieldExpression, options, partitionKey); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, 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.CreateHashedIndexAsync(keyedFieldExpression, options, partitionKey, token); + + // Assert + IndexHandler.Verify( + x => x.CreateHashedIndexAsync, int>( + keyedFieldExpression, options, partitionKey, token)); + } +} diff --git a/MongoDbGenericRepository/BaseMongoRepository.Index.cs b/MongoDbGenericRepository/BaseMongoRepository.Index.cs index c8192fd..a3eaee0 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Index.cs @@ -522,24 +522,123 @@ namespace MongoDbGenericRepository } /// - public async Task CreateHashedIndexAsync( - Expression> field, - IndexCreationOptions indexCreationOptions = null, - string partitionKey = null) + public async Task CreateHashedIndexAsync(Expression> field) where TDocument : IDocument { - return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); + return await CreateHashedIndexAsync(field, null, null, CancellationToken.None); } /// - public virtual async Task CreateHashedIndexAsync( - Expression> field, - IndexCreationOptions indexCreationOptions = null, - string partitionKey = null) + public async Task CreateHashedIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, null, null, cancellationToken); + } + + /// + public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, null, CancellationToken.None); + } + + /// + public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, null, cancellationToken); + } + + /// + public async Task CreateHashedIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, null, partitionKey, CancellationToken.None); + } + + /// + public async Task CreateHashedIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, null, partitionKey, cancellationToken); + } + + /// + public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); + return await CreateHashedIndexAsync(field, null, null, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateHashedIndexAsync(field, null, null, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateHashedIndexAsync(field, indexCreationOptions, null, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateHashedIndexAsync(field, indexCreationOptions, null, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateHashedIndexAsync(field, null, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateHashedIndexAsync(field, null, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs index 6d44731..eaa6372 100644 --- a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs @@ -404,6 +404,91 @@ namespace MongoDbGenericRepository where TDocument : IDocument where TKey : IEquatable; + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// Options for creating an index. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// Options for creating an index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Creates a hashed index on the given field. /// IndexCreationOptions can be supplied to further specify @@ -415,7 +500,23 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// 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 field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, 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 7f67270..145d497 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs @@ -284,10 +284,59 @@ namespace MongoDbGenericRepository } /// - public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateHashedIndexAsync(Expression> field) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); + return await CreateHashedIndexAsync(field, null, null, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, null, null, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, null, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, null, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, null, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, null, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + { + return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs index 7b0678f..9b51ceb 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs @@ -350,6 +350,79 @@ namespace MongoDbGenericRepository Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + /// /// Creates a hashed index on the given field. /// IndexCreationOptions can be supplied to further specify @@ -360,7 +433,21 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; ///