public async Task get_async_should_return_bucket() { //Arrange var name = "test"; var bucket = new Bucket(Guid.NewGuid(), name); var dto = new BucketDTO { Name = bucket.Name }; var repositoryMock = new Mock <IBucketRepository>(); var mapperMock = new Mock <IMapper>(); repositoryMock.Setup(x => x.GetAsync(name)) .Returns(Task.FromResult(bucket)); mapperMock.Setup(x => x.Map <BucketDTO>(bucket)) .Returns(dto); var service = new BucketService(repositoryMock.Object, mapperMock.Object); //Act var bucketDto = await service.GetAsync(name); repositoryMock.Verify(x => x.GetAsync(name), Times.Once()); mapperMock.Verify(x => x.Map <BucketDTO>(bucket), Times.Once()); }
private async Task Delete_Document_UnitTest(string authKey) { Command deleteResponse = new Command(); IdentityDocument getResponse = new IdentityDocument(); try { if (authKey.Equals("")) { deleteResponse = await _bucketService.DeleteAsync(FirstDocumentId, _logger); getResponse = await _bucketService.GetAsync <IdentityDocument>(FirstDocumentId, _logger); } else { var bucketService = new BucketService(authKey); deleteResponse = await bucketService.DeleteAsync(SecondDocumentId, _logger); getResponse = await bucketService.GetAsync <IdentityDocument>(SecondDocumentId, _logger); } } catch (BlipHttpClientException) { getResponse.Value.ShouldBeNull(); } finally { deleteResponse.Status.ShouldBe(CommandStatus.Success); } }
public async Task GetAsync_ReturnBucket() { Bucket bucket = new Bucket(BucketName); BucketDTO bucketDto = new BucketDTO(); Mock <IBucketRepository> bucketRepository = new Mock <IBucketRepository>(); Mock <IMapper> mapper = new Mock <IMapper>(); bucketRepository .Setup((it) => it.GetAsync(BucketName)) .ReturnsAsync(bucket); mapper .Setup((it) => it.Map <BucketDTO>(bucket)) .Returns(bucketDto); IBucketService bucketService = new BucketService( bucketRepository.Object, mapper.Object ); await bucketService.GetAsync(BucketName); bucketRepository.Verify( (it) => it.GetAsync(BucketName), Times.Once ); mapper.Verify( (it) => it.Map <BucketDTO>(bucket), Times.Once ); }
public async Task BucketGetLogUnitTest_ShouldSucceed() { var client = BuildSenderSubstitute_ReturnsSuccessStatus(); var bucketService = new BucketService(client); var logger = Substitute.For <ILogger>(); var task = bucketService.GetAsync <IdentityDocument>(FirstDocumentId, logger); await TestInfoLogsWithTwoArgs <string, IdentityDocument>(task, 1, logger); await TestInfoLogsWithOneArg <string>(task, 1, logger); }
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); }
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); }
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); }
private async Task Get_Document_UnitTest(string authKey) { IdentityDocument getResponse; var document = new IdentityDocument(IdentityString); if (authKey.Equals("")) { getResponse = await _bucketService.GetAsync <IdentityDocument>(FirstDocumentId, _logger); } else { var bucketService = new BucketService(authKey); getResponse = await bucketService.GetAsync <IdentityDocument>(SecondDocumentId, _logger); } getResponse.Value.Equals(document.Value).ShouldBeTrue(); }
public async Task get_async_should_return_bucket_dto() { var name = "test-bucket"; var bucket = new Bucket(Guid.NewGuid(), name); var bucketDto = new BucketDTO { Name = name }; var repositoryMock = new Mock <IBucketRepository>(); var mapperMock = new Mock <IMapper>(); var service = new BucketService(repositoryMock.Object, mapperMock.Object); repositoryMock.Setup(x => x.GetAsync(name)) .ReturnsAsync(bucket); mapperMock.Setup(x => x.Map <BucketDTO>(bucket)) .Returns(bucketDto); var result = await service.GetAsync(name); result.Should().BeEquivalentTo(bucketDto); }
public async Task BucketGetLogUnitTest_ShouldThrowEx() { var logger = Substitute.For <ILogger>(); var client = BuildSenderSubstitute_ThrowsException(); var bucketService = new BucketService(client); var exceptionThrown = false; try { await bucketService.GetAsync <IdentityDocument>(FirstDocumentId, logger); } catch (Exception ex) { logger.Received(1).Error(ex, Arg.Any <string>(), Arg.Any <string>()); exceptionThrown = true; } finally { exceptionThrown.ShouldBe(true); } }