unit tests

This commit is contained in:
Sean Garrett
2023-06-15 21:56:47 +01:00
parent 0cf6a7e5d3
commit 54e756c695
18 changed files with 817 additions and 8 deletions
@@ -0,0 +1,34 @@
using System.Threading;
using CoreUnitTests.Infrastructure;
using MongoDB.Bson;
using MongoDB.Driver;
using Moq;
namespace CoreUnitTests.BaseMongoRepositoryTests.IndexTests;
public class BaseIndexTests : TestMongoRepositoryContext
{
protected Mock<IAsyncCursor<BsonDocument>> SetupIndex<TDocument>(BsonDocument index, Mock<IMongoCollection<TDocument>> collection)
{
var asyncCursor = new Mock<IAsyncCursor<BsonDocument>>();
asyncCursor
.SetupSequence(x => x.MoveNextAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(true)
.ReturnsAsync(false);
asyncCursor
.SetupGet(x => x.Current)
.Returns(new[] {index});
var indexManager = new Mock<IMongoIndexManager<TDocument>>();
indexManager
.Setup(x => x.ListAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(asyncCursor.Object);
collection
.SetupGet(x => x.Indexes)
.Returns(indexManager.Object);
return asyncCursor;
}
}