public async Task If_DataStore_is_not_initialized_Update_initializes_it() { //Arrange var dataStore = new Mock <IDataStore <Bucket> >(); dataStore .SetupGet(fake => fake.IsInitialized) .Returns(false); var service = new BucketService(dataStore.Object); var id = 3; var bucket = new Bucket { Id = id }; //Act await service.UpdateAsync(id, bucket); //Assert dataStore.Verify(mock => mock.InitializeAsync(), Times.Once); }
public async Task Update_only_initializes_datastore_if_needed() { //Arrange var dataStore = new Mock <IDataStore <Bucket> >(); dataStore .SetupGet(fake => fake.IsInitialized) .Returns(true); var service = new BucketService(dataStore.Object); var id = 3; var bucket = new Bucket { Id = id }; //Act await service.UpdateAsync(id, bucket); //Assert dataStore.Verify(mock => mock.InitializeAsync(), Times.Never); }
public async Task Update_sends_bucket_to_datastore() { //Arrange Bucket addedBucket = null; var dataStore = new Mock <IDataStore <Bucket> >(); dataStore .Setup(mock => mock.AddOrUpdateAsync(It.IsAny <IEnumerable <Bucket> >())) .Callback((IEnumerable <Bucket> buckets) => addedBucket = buckets.Single()); var service = new BucketService(dataStore.Object); var id = 3; var bucket = new Bucket { Id = id }; //Act await service.UpdateAsync(id, bucket); //Assert dataStore.Verify(mock => mock.UpdateAsync(id, bucket), Times.Once); }