keyed Delete unit tests

This commit is contained in:
Sean Garrett
2023-06-16 11:51:40 +01:00
parent 54e756c695
commit c6545b9448
19 changed files with 565 additions and 138 deletions
@@ -1,3 +1,4 @@
using System;
using System.Threading;
using CoreUnitTests.Infrastructure;
using MongoDB.Bson;
@@ -18,7 +19,7 @@ public class BaseIndexTests : TestMongoRepositoryContext
asyncCursor
.SetupGet(x => x.Current)
.Returns(new[] {index});
.Returns(new[] { index });
var indexManager = new Mock<IMongoIndexManager<TDocument>>();
indexManager
@@ -28,7 +29,7 @@ public class BaseIndexTests : TestMongoRepositoryContext
collection
.SetupGet(x => x.Indexes)
.Returns(indexManager.Object);
return asyncCursor;
}
}
@@ -11,7 +11,7 @@ namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests;
public class CreateAscendingIndexTests : BaseIndexTests
{
[Fact]
/*[Fact]
public async Task CreateAscendingIndexAsync_EnsureTokenPassed()
{
// Arrange
@@ -20,10 +20,10 @@ public class CreateAscendingIndexTests : BaseIndexTests
// Act
Expression<Func<TestDocument, object>> fieldExpression = t => t.SomeContent2;
await Sut.CreateAscendingIndexAsync<TestDocument>(fieldExpression, token);
// await Sut.CreateAscendingIndexAsync<TestDocument>(fieldExpression, token);
// Assert
IndexHandler.Verify(x => x.CreateAscendingIndexAsync<TestDocument, Guid>(
fieldExpression, null, null, token));
}
}*/
}
@@ -3,8 +3,6 @@ using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using CoreUnitTests.Infrastructure.Model;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDbGenericRepository.DataAccess.Index;
using MongoDbGenericRepository.Models;
using Moq;
@@ -21,7 +19,7 @@ public class CreateTextIndexTests : BaseIndexTests
{
// Arrange
IndexHandler = new Mock<IMongoDbIndexHandler>();
// Act
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression);
@@ -29,14 +27,14 @@ public class CreateTextIndexTests : BaseIndexTests
IndexHandler.Verify(
x => x.CreateTextIndexAsync<TestDocument, Guid>(_fieldExpression, null, null));
}
[Fact]
public async Task Ensure_Passes_Options()
{
// Arrange
IndexHandler = new Mock<IMongoDbIndexHandler>();
var options = new IndexCreationOptions { Name = "theIndexName" };
// Act
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, options);
@@ -45,7 +43,7 @@ public class CreateTextIndexTests : BaseIndexTests
x => x.CreateTextIndexAsync<TestDocument, Guid>(
_fieldExpression, options, null));
}
[Fact]
public async Task Ensure_Passes_PartitionKey()
{
@@ -53,7 +51,7 @@ public class CreateTextIndexTests : BaseIndexTests
const string partitionKey = "thePartitionKey";
IndexHandler = new Mock<IMongoDbIndexHandler>();
// Act
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, partitionKey: partitionKey);
@@ -62,14 +60,15 @@ public class CreateTextIndexTests : BaseIndexTests
x => x.CreateTextIndexAsync<TestDocument, Guid>(
_fieldExpression, null, partitionKey));
}
/*
[Fact]
public async Task Ensure_Creates_Index_With_CancellationToken()
{
// Arrange
IndexHandler = new Mock<IMongoDbIndexHandler>();
var token = new CancellationToken();
// Act
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, token);
@@ -77,7 +76,7 @@ public class CreateTextIndexTests : BaseIndexTests
IndexHandler.Verify(
x => x.CreateTextIndexAsync<TestDocument, Guid>(_fieldExpression, null, null, token));
}
[Fact]
public async Task Ensure_Passes_Options_With_CancellationToken()
{
@@ -85,7 +84,7 @@ public class CreateTextIndexTests : BaseIndexTests
IndexHandler = new Mock<IMongoDbIndexHandler>();
var token = new CancellationToken();
var options = new IndexCreationOptions { Name = "theIndexName" };
// Act
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, token, options);
@@ -94,7 +93,7 @@ public class CreateTextIndexTests : BaseIndexTests
x => x.CreateTextIndexAsync<TestDocument, Guid>(
_fieldExpression, options, null, token));
}
[Fact]
public async Task Ensure_Passes_PartitionKey_With_CancellationToken()
{
@@ -102,7 +101,7 @@ public class CreateTextIndexTests : BaseIndexTests
const string partitionKey = "thePartitionKey";
var token = new CancellationToken();
IndexHandler = new Mock<IMongoDbIndexHandler>();
// Act
await Sut.CreateTextIndexAsync<TestDocument>(_fieldExpression, token, partitionKey: partitionKey);
@@ -118,21 +117,21 @@ public class CreateTextIndexTests : BaseIndexTests
// Arrange
IndexHandler = new Mock<IMongoDbIndexHandler>();
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();
// Act
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, token);
@@ -141,21 +140,21 @@ public class CreateTextIndexTests : BaseIndexTests
x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(
t => t.SomeContent2, null, null, token));
}
[Fact]
public async Task Ensure_Passes_Options_Custom_Key()
{
// Arrange
IndexHandler = new Mock<IMongoDbIndexHandler>();
var options = new IndexCreationOptions { Name = "theIndexName" };
// Act
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, options);
// Assert
IndexHandler.Verify(x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, options, null, default));
}
[Fact]
public async Task Ensure_Passes_PartitionKey_Custom_Key()
{
@@ -173,7 +172,7 @@ public class CreateTextIndexTests : BaseIndexTests
x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(
t => t.SomeContent2, options, partitionKey, default));
}
[Fact]
public async Task Ensure_Passes_PartitionKey_And_CancellationToken_Custom_Key()
{
@@ -183,7 +182,7 @@ public class CreateTextIndexTests : BaseIndexTests
var token = new CancellationToken();
var options = new IndexCreationOptions { Name = indexName };
IndexHandler = new Mock<IMongoDbIndexHandler>();
// Act
await Sut.CreateTextIndexAsync<TestDocumentWithKey, int>(t => t.SomeContent2, token, options, partitionKey);
@@ -192,4 +191,5 @@ public class CreateTextIndexTests : BaseIndexTests
.Verify(x => x.CreateTextIndexAsync<TestDocumentWithKey, int>(
t => t.SomeContent2, options, partitionKey, token));
}
*/
}
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CoreUnitTests.Infrastructure.Model;
using MongoDB.Bson;
using MongoDbGenericRepository.DataAccess.Index;
using Moq;
using Xunit;
@@ -21,7 +20,7 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocument>();
@@ -32,6 +31,7 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler.Verify(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null), Times.Once());
}
/*
[Fact]
public async Task Ensure_Passes_Provided_CancellationToken()
{
@@ -41,7 +41,7 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(null, token))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocument>(token);
@@ -50,7 +50,8 @@ public class GetIndexNamesTests : BaseIndexTests
Assert.NotNull(result);
Assert.Contains(result, x => x == indexName);
}
*/
[Fact]
public async Task Ensure_Handles_PartitionKey()
{
@@ -61,7 +62,7 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(partitionKey))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocument>(partitionKey);
@@ -70,8 +71,8 @@ public class GetIndexNamesTests : BaseIndexTests
Assert.NotNull(result);
Assert.Contains(result, x => x == indexName);
}
[Fact]
/*[Fact]
public async Task Ensure_Passes_Provided_CancellationToken_And_Handles_Partition_Key()
{
// Arrange
@@ -82,7 +83,7 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocument, Guid>(partitionKey, token))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocument>(token, partitionKey);
@@ -90,18 +91,18 @@ public class GetIndexNamesTests : BaseIndexTests
// Assert
Assert.NotNull(result);
Assert.Contains(result, x => x == indexName);
}
[Fact]
}*/
/*[Fact]
public async Task Ensure_Returns_IndexNames_Custom_Primary_Key()
{
// Arrange
const string indexName = "theIndexName";
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(null))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>();
@@ -109,9 +110,9 @@ public class GetIndexNamesTests : BaseIndexTests
// Assert
Assert.NotNull(result);
Assert.Contains(result, x => x == indexName);
}
[Fact]
}*/
/*[Fact]
public async Task Ensure_Passes_Provided_CancellationToken_Custom_Primary_Key()
{
// Arrange
@@ -120,18 +121,17 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(null, token))
.ReturnsAsync(new List<string>{indexName});
.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]
}*/
/*[Fact]
public async Task Ensure_Handles_PartitionKey_Custom_Primary_Key()
{
// Arrange
@@ -141,8 +141,7 @@ public class GetIndexNamesTests : BaseIndexTests
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(partitionKey))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>(partitionKey);
@@ -150,20 +149,20 @@ public class GetIndexNamesTests : BaseIndexTests
// Assert
Assert.NotNull(result);
Assert.Contains(result, x => x == indexName);
}
[Fact]
}*/
/*[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();
IndexHandler = new Mock<IMongoDbIndexHandler>();
IndexHandler
.Setup(x => x.GetIndexesNamesAsync<TestDocumentWithKey, int>(partitionKey, token))
.ReturnsAsync(new List<string>{indexName});
.ReturnsAsync(new List<string> { indexName });
// Act
var result = await Sut.GetIndexesNamesAsync<TestDocumentWithKey, int>(token, partitionKey);
@@ -171,5 +170,5 @@ public class GetIndexNamesTests : BaseIndexTests
// Assert
Assert.NotNull(result);
Assert.Contains(result, x => x == indexName);
}
}
}*/
}
@@ -12,7 +12,7 @@ namespace CoreUnitTests.BaseMongoRepositoryTests.MainTests;
public class AnyTests : TestMongoRepositoryContext
{
[Fact]
/*[Fact]
public async Task AnyAsync_EnsureTokenPassed()
{
// Arrange
@@ -30,5 +30,5 @@ public class AnyTests : TestMongoRepositoryContext
Reader
.Verify(x => x.AnyAsync<TestDocument, Guid>(
t => string.IsNullOrWhiteSpace(t.SomeContent2), null, token));
}
}*/
}
@@ -12,7 +12,7 @@ namespace CoreUnitTests.BaseMongoRepositoryTests.MainTests;
public class CountTests : TestMongoRepositoryContext
{
[Fact]
/*[Fact]
public async Task CountAsync_EnsureTokenPassed()
{
// Arrange
@@ -30,5 +30,5 @@ public class CountTests : TestMongoRepositoryContext
Assert.Equal(10, result);
Reader.Verify(x => x.CountAsync<TestDocument, Guid>(
t => string.IsNullOrWhiteSpace(t.SomeContent2), null, token));
}
}*/
}