Esempio n. 1
0
        public async Task add_async_should_invoke_repository_methods()
        {
            var name           = "test-bucket";
            var repositoryMock = new Mock <IBucketRepository>();
            var mapperMock     = new Mock <IMapper>();
            var service        = new BucketService(repositoryMock.Object, mapperMock.Object);

            await service.AddAsync(name);

            repositoryMock.Verify(x => x.AddAsync(It.IsAny <Bucket>()), Times.Once);
        }
Esempio n. 2
0
        public async Task AddAsync_CreateNewBucket()
        {
            IBucketService bucketService = new BucketService(
                new InMemoryBucketRepository(), AutoMapperConfig.InitializeMapper()
                );

            await bucketService.AddAsync(BucketName);

            BucketDTO bucketDto = await bucketService.GetAsync(BucketName);

            Assert.Equal(BucketName, bucketDto.Name);
        }
Esempio n. 3
0
        public async Task add_async_should_create_new_bucket()
        {
            var repository = new InMemoryBucketRepository();
            var service    = new BucketService(repository, AutoMapperConfig.GetMapper());
            var name       = "test-bucket";

            await service.AddAsync(name);

            var bucketDto = await service.GetAsync(name);

            bucketDto.Name.Should().BeEquivalentTo(name);
        }
Esempio n. 4
0
        public async Task add_async_should_create_new_bucket()
        {
            //Arrange
            var repository = new InMemoryBucketRepository();
            var service    = new BucketService(repository, AutoMapperConfig.GetMapper());
            var name       = "test";

            //Act
            await service.AddAsync(name);

            //Assert
            var bucketDto = await service.GetAsync(name);

            Assert.Equal(name, bucketDto.Name);
        }
Esempio n. 5
0
        public async Task AddAsync_InvokeRepositoryMethod()
        {
            Mock <IBucketRepository> bucketRepository = new Mock <IBucketRepository>();
            Mock <IMapper>           mapper           = new Mock <IMapper>();
            IBucketService           bucketService    = new BucketService(
                bucketRepository.Object, mapper.Object
                );

            await bucketService.AddAsync(BucketName);

            bucketRepository.Verify(
                (repo) => repo.AddAsync(It.IsAny <Bucket>()),
                Times.Once
                );
        }
        public async Task If_DataStore_is_not_initialized_Add_initializes_it()
        {
            //Arrange
            var dataStore = new Mock <IDataStore <Bucket> >();

            dataStore
            .SetupGet(fake => fake.IsInitialized)
            .Returns(false);

            var service = new BucketService(dataStore.Object);

            var bucket = new Bucket();

            //Act
            await service.AddAsync(bucket);

            //Assert
            dataStore.Verify(mock => mock.InitializeAsync(), Times.Once);
        }
        public async Task Add_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 bucket = new Bucket();

            //Act
            await service.AddAsync(bucket);

            //Assert
            dataStore.Verify(mock => mock.InitializeAsync(), Times.Never);
        }
        public async Task Add_adds_bucket_to_store()
        {
            //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 bucket = new Bucket();

            //Act
            await service.AddAsync(bucket);

            //Assert
            Assert.AreEqual(bucket, addedBucket);
        }