unit tests for Create and Get Indexes
This commit is contained in:
@@ -1,21 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AutoFixture;
|
||||||
using CoreUnitTests.Infrastructure.Model;
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
using MongoDbGenericRepository.DataAccess.Index;
|
using MongoDbGenericRepository.DataAccess.Index;
|
||||||
using MongoDbGenericRepository.Models;
|
using MongoDbGenericRepository.Models;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using CancellationToken = System.Threading.CancellationToken;
|
||||||
|
|
||||||
namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests;
|
namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests;
|
||||||
|
|
||||||
public class CreateTextIndexTests : BaseIndexTests
|
public class CreateTextIndexTests : BaseIndexTests
|
||||||
{
|
{
|
||||||
private readonly Expression<Func<TestDocument, object>> fieldExpression = t => t.SomeContent2;
|
private readonly Expression<Func<TestDocument, object>> fieldExpression = t => t.SomeContent2;
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> keyedFieldExpression = t => t.SomeContent2;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WhenFieldExpression_CreatesIndex()
|
public async Task WithFieldExpression_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
@@ -29,11 +31,27 @@ public class CreateTextIndexTests : BaseIndexTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_Options()
|
public async Task WithFieldExpressionAndCancellationToken_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(fieldExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocument, Guid>(fieldExpression, null, null, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndOptions_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
var options = new IndexCreationOptions { Name = "theIndexName" };
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync(fieldExpression, options);
|
await Sut.CreateTextIndexAsync(fieldExpression, options);
|
||||||
@@ -45,15 +63,32 @@ public class CreateTextIndexTests : BaseIndexTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_PartitionKey()
|
public async Task WithFieldExpressionAndOptionsAndCancellationToken_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string partitionKey = "thePartitionKey";
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
var token = new CancellationToken(true);
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync(fieldExpression, partitionKey: partitionKey);
|
await Sut.CreateTextIndexAsync(fieldExpression, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocument, Guid>(
|
||||||
|
fieldExpression, options, null, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndPartitionKey_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(fieldExpression, partitionKey);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IndexHandler.Verify(
|
IndexHandler.Verify(
|
||||||
@@ -61,135 +96,199 @@ public class CreateTextIndexTests : BaseIndexTests
|
|||||||
fieldExpression, null, partitionKey, CancellationToken.None));
|
fieldExpression, null, partitionKey, CancellationToken.None));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[Fact]
|
|
||||||
public async Task Ensure_Creates_Index_With_CancellationToken()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
|
||||||
var token = new CancellationToken(true);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await Sut.CreateTextIndexAsync<TestDocument>(fieldExpression, token);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
IndexHandler.Verify(
|
|
||||||
x => x.CreateTextIndexAsync<TestDocument, Guid>(_fieldExpression, null, null, token));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_Options_With_CancellationToken()
|
public async Task WithFieldExpressionAndPartitionKeyAndCancellationToken_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
var options = new IndexCreationOptions { Name = "theIndexName" };
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, token, options);
|
await Sut.CreateTextIndexAsync(fieldExpression, partitionKey, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IndexHandler.Verify(
|
IndexHandler.Verify(
|
||||||
x => x.CreateTextIndexAsync<TestDocument, Guid>(
|
x => x.CreateTextIndexAsync<TestDocument, Guid>(
|
||||||
_fieldExpression, options, null, token));
|
fieldExpression, null, partitionKey, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_PartitionKey_With_CancellationToken()
|
public async Task WithFieldExpressionAndOptionsAndPartitionKey_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string partitionKey = "thePartitionKey";
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, token, partitionKey: partitionKey);
|
await Sut.CreateTextIndexAsync(fieldExpression, options, partitionKey);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IndexHandler.Verify(
|
IndexHandler.Verify(
|
||||||
x => x.CreateTextIndexAsync<TestDocument, Guid>(
|
x => x.CreateTextIndexAsync<TestDocument, Guid>(
|
||||||
_fieldExpression, null, partitionKey, token));
|
fieldExpression, options, partitionKey, CancellationToken.None));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Creates_Index_Custom_Key()
|
public async Task WithFieldExpressionAndOptionsAndPartitionKeyAndCancellationToken_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
var partitionKey = Fixture.Create<string>();
|
||||||
Expression<Func<TestDocumentWithKey, object>> fieldExpression = t => t.SomeContent2;
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(fieldExpression);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
IndexHandler.Verify(x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(fieldExpression, null, null, default));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task Ensure_Passes_CancellationToken_Custom_Key()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, token);
|
await Sut.CreateTextIndexAsync(fieldExpression, options, partitionKey, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IndexHandler.Verify(
|
IndexHandler.Verify(
|
||||||
x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(
|
x => x.CreateTextIndexAsync<TestDocument, Guid>(
|
||||||
t => t.SomeContent2, null, null, token));
|
fieldExpression, options, partitionKey, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Keyed
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_Options_Custom_Key()
|
public async Task Keyed_WithKeyedFieldExpression_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
var options = new IndexCreationOptions { Name = "theIndexName" };
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, options);
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression);
|
||||||
|
|
||||||
// Assert
|
|
||||||
IndexHandler.Verify(x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, options, null, default));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task Ensure_Passes_PartitionKey_Custom_Key()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
const string partitionKey = "thePartitionKey";
|
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
|
||||||
var options = new IndexCreationOptions { Name = "theIndexName" };
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, options, partitionKey);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IndexHandler.Verify(
|
IndexHandler.Verify(
|
||||||
x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, null, null, CancellationToken.None));
|
||||||
t => t.SomeContent2, options, partitionKey, default));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_PartitionKey_And_CancellationToken_Custom_Key()
|
public async Task Keyed_WithKeyedFieldExpressionAndCancellationToken_CreatesIndex()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string partitionKey = "thePartitionKey";
|
|
||||||
const string indexName = "theIndexName";
|
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, null, null, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithKeyedFieldExpressionAndOptions_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
var options = new IndexCreationOptions { Name = indexName };
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, token, options, partitionKey);
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, options);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IndexHandler
|
IndexHandler.Verify(
|
||||||
.Verify(x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
t => t.SomeContent2, options, partitionKey, token));
|
keyedFieldExpression, options, null, CancellationToken.None));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithKeyedFieldExpressionAndOptionsAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, null, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithKeyedFieldExpressionAndPartitionKey_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, null, partitionKey, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithKeyedFieldExpressionAndPartitionKeyAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, null, partitionKey, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithKeyedFieldExpressionAndOptionsAndPartitionKey_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, partitionKey, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithKeyedFieldExpressionAndOptionsAndPartitionKeyAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, partitionKey, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AutoFixture;
|
||||||
using CoreUnitTests.Infrastructure.Model;
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
using MongoDbGenericRepository.DataAccess.Index;
|
using MongoDbGenericRepository.DataAccess.Index;
|
||||||
using Moq;
|
using Moq;
|
||||||
@@ -12,11 +13,11 @@ namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests;
|
|||||||
public class GetIndexNamesTests : BaseIndexTests
|
public class GetIndexNamesTests : BaseIndexTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Returns_IndexNames()
|
public async Task WithNoParameters_ReturnsIndexNames()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
const string indexName = "theIndexName";
|
var indexName = Fixture.Create<string>();
|
||||||
|
|
||||||
IndexHandler
|
IndexHandler
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
@@ -31,16 +32,16 @@ public class GetIndexNamesTests : BaseIndexTests
|
|||||||
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null, CancellationToken.None), Times.Once());
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null, CancellationToken.None), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_Provided_CancellationToken()
|
public async Task WithCancellationToken_ReturnsIndexNames()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string indexName = "theIndexName";
|
|
||||||
var token = new CancellationToken(true);
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
IndexHandler
|
IndexHandler
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null, token))
|
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -49,17 +50,17 @@ public class GetIndexNamesTests : BaseIndexTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Contains(result, x => x == indexName);
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null, token), Times.Once());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Handles_PartitionKey()
|
public async Task WithPartitionKey_ReturnsIndexNames()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string partitionKey = "thePartitionKey";
|
|
||||||
const string indexName = "theIndexName";
|
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
IndexHandler
|
IndexHandler
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
@@ -70,105 +71,112 @@ public class GetIndexNamesTests : BaseIndexTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Contains(result, x => x == indexName);
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocument, Guid>(partitionKey, CancellationToken.None), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_Provided_CancellationToken_And_Handles_Partition_Key()
|
public async Task WithPartitionKeyAndCancellationToken_ReturnsIndexNames()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string partitionKey = "thePartitionKey";
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
const string indexName = "theIndexName";
|
var indexName = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
|
||||||
IndexHandler
|
IndexHandler
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(partitionKey, token))
|
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetIndexesNamesAsync<TestDocument>(token, partitionKey);
|
var result = await Sut.GetIndexesNamesAsync<TestDocument>(partitionKey, token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Contains(result, x => x == indexName);
|
Assert.Contains(result, x => x == indexName);
|
||||||
}*/
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocument, Guid>(partitionKey, token), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
/*[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Returns_IndexNames_Custom_Primary_Key()
|
public async Task Keyed_WithNoParameters_ReturnsIndexNames()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string indexName = "theIndexName";
|
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
|
||||||
IndexHandler
|
IndexHandler
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(null))
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>();
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Contains(result, x => x == indexName);
|
Assert.Contains(result, x => x == indexName);
|
||||||
}*/
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(null, CancellationToken.None), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
/*[Fact]
|
[Fact]
|
||||||
public async Task Ensure_Passes_Provided_CancellationToken_Custom_Primary_Key()
|
public async Task Keyed_WithCancellationToken_ReturnsIndexNames()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const string indexName = "theIndexName";
|
|
||||||
var token = new CancellationToken(true);
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
IndexHandler
|
var indexName = Fixture.Create<string>();
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(null, token))
|
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>(token);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.NotNull(result);
|
|
||||||
Assert.Contains(result, x => x == indexName);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*[Fact]
|
|
||||||
public async Task Ensure_Handles_PartitionKey_Custom_Primary_Key()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
const string indexName = "theIndexName";
|
|
||||||
const string partitionKey = "thePartitionKey";
|
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
|
||||||
IndexHandler
|
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(partitionKey))
|
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>(partitionKey);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.NotNull(result);
|
|
||||||
Assert.Contains(result, x => x == indexName);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*[Fact]
|
|
||||||
public async Task Ensure_Passes_Provided_CancellationToken_And_Handles_Partition_Key_Custom_Primary_Key()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
const string indexName = "theIndexName";
|
|
||||||
const string partitionKey = "thePartitionKey";
|
|
||||||
var token = new CancellationToken(true);
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
|
||||||
IndexHandler
|
IndexHandler
|
||||||
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(partitionKey, token))
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(new List<string> { indexName });
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>(token, partitionKey);
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(token);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Contains(result, x => x == indexName);
|
Assert.Contains(result, x => x == indexName);
|
||||||
}*/
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(null, token), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithPartitionKey_ReturnsIndexNames()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
IndexHandler
|
||||||
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(partitionKey, CancellationToken.None), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Keyed_WithPartitionKeyAndCancellationToken_ReturnsIndexNames()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
IndexHandler
|
||||||
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(partitionKey, token), Times.Once());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 CreateTextIndexAsyncTests : TestKeyedMongoRepositoryContext<int>
|
||||||
|
{
|
||||||
|
private readonly Expression<Func<TestDocumentWithKey<int>, object>> keyedFieldExpression = t => t.SomeContent2;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpression_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, null, null, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(keyedFieldExpression, null, null, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndOptions_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, options);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, null, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndOptionsAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, options, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, null, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndPartitionKey_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, null, partitionKey, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndPartitionKeyAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, null, partitionKey, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndOptionsAndPartitionKey_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, options, partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, partitionKey, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithFieldExpressionAndOptionsAndPartitionKeyAndCancellationToken_CreatesIndex()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var options = new IndexCreationOptions { Name = indexName };
|
||||||
|
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await Sut.CreateTextIndexAsync(keyedFieldExpression, options, partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IndexHandler.Verify(
|
||||||
|
x => x.CreateTextIndexAsync<TestDocumentWithKey<int>, int>(
|
||||||
|
keyedFieldExpression, options, partitionKey, token));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,98 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoFixture;
|
||||||
using CoreUnitTests.Infrastructure;
|
using CoreUnitTests.Infrastructure;
|
||||||
|
using CoreUnitTests.Infrastructure.Model;
|
||||||
|
using MongoDbGenericRepository.DataAccess.Index;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
namespace CoreUnitTests.KeyTypedRepositoryTests.IndexTests;
|
namespace CoreUnitTests.KeyTypedRepositoryTests.IndexTests;
|
||||||
|
|
||||||
public class GetIndexNamesAsyncTests : TestKeyedMongoRepositoryContext<int>
|
public class GetIndexNamesAsyncTests : TestKeyedMongoRepositoryContext<int>
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task WithNoParameters_ReturnsIndexNames()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
|
||||||
|
IndexHandler
|
||||||
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(null, CancellationToken.None), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithCancellationToken_ReturnsIndexNames()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
IndexHandler
|
||||||
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>>(token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(null, token), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithPartitionKey_ReturnsIndexNames()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
|
||||||
|
IndexHandler
|
||||||
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>>(partitionKey);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(partitionKey, CancellationToken.None), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithPartitionKeyAndCancellationToken_ReturnsIndexNames()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
IndexHandler = new Mock<IMongoDbIndexHandler>();
|
||||||
|
var indexName = Fixture.Create<string>();
|
||||||
|
var partitionKey = Fixture.Create<string>();
|
||||||
|
var token = new CancellationToken(true);
|
||||||
|
|
||||||
|
IndexHandler
|
||||||
|
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||||
|
.ReturnsAsync(new List<string> { indexName });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey<int>>(partitionKey, token);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Contains(result, x => x == indexName);
|
||||||
|
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocumentWithKey<int>, int>(partitionKey, token), Times.Once());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user