unit tests for add
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoFixture;
|
||||
using CoreUnitTests.Infrastructure;
|
||||
using CoreUnitTests.Infrastructure.Model;
|
||||
using MongoDbGenericRepository.DataAccess.Create;
|
||||
@@ -14,20 +14,64 @@ public class AddManyTests : TestMongoRepositoryContext
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public async Task AddManyAsync_EnsureTokenPassed()
|
||||
public void WithDocument_ShouldAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||
Creator = new Mock<IMongoDbCreator>();
|
||||
var token = new CancellationToken(true);
|
||||
var documents = new List<TestDocument>
|
||||
{
|
||||
new(), new(), new()
|
||||
};
|
||||
|
||||
// Act
|
||||
await Sut.AddManyAsync(documents, token);
|
||||
Sut.AddMany(documents);
|
||||
|
||||
// Assert
|
||||
Creator.Verify(x => x.AddManyAsync<TestDocument, Guid>(documents, token));
|
||||
Creator.Verify(x => x.AddMany<TestDocument, Guid>(documents, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithDocumentAndCancellationToken_ShouldAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var documents = Fixture.CreateMany<TestDocument>().ToList();
|
||||
var token = new CancellationToken(true);
|
||||
Creator = new Mock<IMongoDbCreator>();
|
||||
|
||||
// Act
|
||||
Sut.AddMany(documents, token);
|
||||
|
||||
// Assert
|
||||
Creator.Verify(x => x.AddMany<TestDocument, Guid>(documents, token), Times.Once);
|
||||
}
|
||||
|
||||
#region Keyed
|
||||
|
||||
[Fact]
|
||||
public void Keyed_WithDocument_ShouldAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||
Creator = new Mock<IMongoDbCreator>();
|
||||
|
||||
// Act
|
||||
Sut.AddMany<TestDocumentWithKey<int>, int>(documents);
|
||||
|
||||
// Assert
|
||||
Creator.Verify(x => x.AddMany<TestDocumentWithKey<int>, int>(documents, CancellationToken.None), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Keyed_WithDocumentAndCancellationToken_ShouldAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var documents = Fixture.CreateMany<TestDocumentWithKey<int>>().ToList();
|
||||
var token = new CancellationToken(true);
|
||||
Creator = new Mock<IMongoDbCreator>();
|
||||
|
||||
// Act
|
||||
Sut.AddMany<TestDocumentWithKey<int>, int>(documents, token);
|
||||
|
||||
// Assert
|
||||
Creator.Verify(x => x.AddMany<TestDocumentWithKey<int>, int>(documents, token), Times.Once);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user