public async Task GivenCancellationToken_WhenGet_ThenCollectionFindAsync() { // Arrange var sut = new TestableMongoDbDataStorageService( _mockMongoClient.Object, _configuration); var cancellationTokenSource = new CancellationTokenSource(); // Act await sut.Get(cancellationTokenSource.Token); // Assert _mockCollection.Verify(x => x.FindAsync( It.IsAny <FilterDefinition <TestableStorageEntity> >(), It.IsAny <FindOptions <TestableStorageEntity, TestableStorageEntity> >(), It.Is <CancellationToken>(y => y == cancellationTokenSource.Token)), Times.Once); }
public void GivenService_WhenConstruct_ThenGetDatabase_AndGetEntities() { // Arrange // Nothing to arrange // Act var sut = new TestableMongoDbDataStorageService( _mockMongoClient.Object, _configuration); // Assert Assert.NotNull(sut); _mockMongoClient.Verify(x => x.GetDatabase( It.Is <string>(y => y == _configuration.DatabaseName), It.IsAny <MongoDatabaseSettings>()), Times.Once); _mockDatabase.Verify(x => x.GetCollection <TestableStorageEntity>( It.Is <string>(y => y == _configuration.CollectionName), It.IsAny <MongoCollectionSettings>()), Times.Once); }
public async Task GivenId_AndCancellationToken_WhenRemove_ThenCollectionDeleteOneAsync() { // Arrange var sut = new TestableMongoDbDataStorageService( _mockMongoClient.Object, _configuration); var id = ObjectId.GenerateNewId().ToString(); var cancellationTokenSource = new CancellationTokenSource(); // Act await sut.Remove( id, cancellationTokenSource.Token); // Assert _mockCollection.Verify(x => x.DeleteOneAsync( It.IsAny <FilterDefinition <TestableStorageEntity> >(), // TODO: This needs asserting It.Is <CancellationToken>(y => y == cancellationTokenSource.Token)), Times.Once); }
public async Task GivenEntity_AndCancellationToken_WhenCreate_ThenCollectionInsertOneAsync() { // Arrange var sut = new TestableMongoDbDataStorageService( _mockMongoClient.Object, _configuration); var entity = new TestableStorageEntity(); var cancellationTokenSource = new CancellationTokenSource(); // Act await sut.Create( entity, cancellationTokenSource.Token); // Assert _mockCollection.Verify(x => x.InsertOneAsync( It.Is <TestableStorageEntity>(y => y == entity), It.Is <InsertOneOptions>(y => y == null), It.Is <CancellationToken>(y => y == cancellationTokenSource.Token)), Times.Once); }