public async Task <PresidentDto> UpdatePresidentAsync(string id, PresidentDto dto) { if (string.IsNullOrEmpty(id)) { RaiseNotification(nameof(id)); } if (dto == null) { RaiseNotification(nameof(dto)); } if (Notification.HasNotification()) { return(new PresidentDto()); } var builder = new PresidentBuilder(Notification) .WithId(id) .WithName(dto.Name) .WithAddress(dto.Address); await _whiteHouserService.UpdatePresidentAsync(builder); dto.Id = id; return(dto); }
public async Task Post_President_Should_Be_Insert_And_Update_Item() { //Arrange var presidentDto = new PresidentDto() { Id = "4", Name = "Lula", Address = new Address("Rua de teste", "123", "APT 12", new ZipCode("74125306")) }; // Act var response = await PostResponseAsObjectAsync <PresidentDto, PresidentDto>( $"/{RouteConsts.WhiteHouse}", presidentDto ); var updateParam = new PresidentDto() { Address = response.Address, Name = "Nome Alterado Teste" }; await PutResponseAsObjectAsync <PresidentDto, PresidentDto>( $"/{RouteConsts.WhiteHouse}/{response.Id}", updateParam ); response = await GetResponseAsObjectAsync <PresidentDto>( $"/{RouteConsts.WhiteHouse}/{response.Id}" ); //Assert response.Name.ShouldBe("Nome Alterado Teste"); }
public async Task <IActionResult> Put(string id, [FromBody] PresidentDto president) { var response = await _whiteHouseAppService.UpdatePresidentAsync(id, president); return(CreateResponse <PresidentDto, string>() .FromErrorEnum(PresidentDto.Error.PutPresident) .WithMessage(AppConsts.LocalizationSourceName, PresidentDto.Error.PutPresident) .WithDto(response) .Build()); }
public async Task Put_President_When_Not_Exists_Return_Not_Found() { //Arrange var presidentDto = new PresidentDto("99", "Ronald Reagan", new Address("Rua de teste", "123", "APT 12", new ZipCode("74125306"))); // Act var response = await PutResponseAsObjectAsync <PresidentDto, ErrorResponse>( $"{RouteConsts.WhiteHouse}/99", presidentDto, HttpStatusCode.NotFound ); // Assert response.Message.ShouldBe("PutPresident"); response.DetailedMessage.ShouldBe("PutPresident"); Assert.True(response.Details.Any(a => a.Message == President.Error.CouldNotFindPresident.ToString())); }
public async Task Put_President_With_Success() { //Arrange var presidentDto = new PresidentDto("6", "Ronald Reagan", new Address("Rua de teste", "123", "APT 12", new ZipCode("74125306"))); // Act await PutResponseAsObjectAsync <PresidentDto, PresidentDto>( $"{RouteConsts.WhiteHouse}/6", presidentDto ); var response = await GetResponseAsObjectAsync <PresidentDto>( $"{RouteConsts.WhiteHouse}/6" ); // Assert Assert.Equal(response.Id, "6"); Assert.Equal(response.Name, "Ronald Reagan"); }
public async Task Post_President_With_Success() { //Arrange var presidentDto = new PresidentDto() { Id = "7", Name = "Lula", Address = new Address("Rua de teste", "123", "APT 12", new ZipCode("74125306")) }; // Act var response = await PostResponseAsObjectAsync <PresidentDto, PresidentDto>( $"{RouteConsts.WhiteHouse}", presidentDto ); // Assert Assert.Equal(response.Name, "Lula"); }
public void MapTo_PresidentDto_To_PresidentPoco() { var dto = new PresidentDto { Id = "1234", Name = "George", Address = new Address("Rua de teste", "123", "APT 12", new ZipCode("12345678")) }; var mappPoco = dto.MapTo <PresidentPoco>(); Assert.NotNull(mappPoco); Assert.Equal(dto.Id, mappPoco.Id); Assert.Equal(dto.Name, mappPoco.Name); Assert.NotNull(mappPoco.Address); Assert.Equal(dto.Address.Complement, mappPoco.Address.Complement); Assert.Equal(dto.Address.Number, mappPoco.Address.Number); Assert.Equal(dto.Address.Street, mappPoco.Address.Street); Assert.Equal(dto.Address.ZipCode.Number, mappPoco.Address.ZipCode.Number); }
public async Task <PresidentDto> InsertPresidentAsync(PresidentDto dto) { if (dto == null) { RaiseNotification(nameof(dto)); } if (Notification.HasNotification()) { return(new PresidentDto()); } var builder = new PresidentBuilder(Notification) .WithId(dto.Id) .WithName(dto.Name) .WithAddress(dto.Address); dto.Id = await _whiteHouserService.InsertPresidentAsync(builder); return(dto); }
public override void PreInitialize() { // Mock repositories Configuration.ReplaceService <ILogger>(() => { IocManager.IocContainer.Register( Component .For <ILogger>() .Instance(Substitute.For <ILogger>()) .LifestyleTransient() ); }); Configuration.ReplaceService <IWhiteHouseRepository>(() => { var instance = Substitute.For <IWhiteHouseRepository>(); var presidentDto = new PresidentDto("1", "New President", new Address("Rua de teste", "123", "APT 12", new ZipCode("55833479"))); var president = new President { Id = presidentDto.Id, Name = presidentDto.Name, Address = presidentDto.Address }; var presidentsToGetAll = new ListDto <PresidentDto, string>(); presidentsToGetAll.Items.Add(presidentDto); presidentsToGetAll.Items.Add(presidentDto); instance.GetPresidentById(Arg.Is <RequestDto <string> >(p => p.GetId() == "1")) .Returns(Task.FromResult(president)); instance.InsertPresidentsAsync(Arg.Any <President>()) .Returns(Task.FromResult(presidentDto.Id)); instance.UpdatePresidentsAsync(Arg.Is <President>(p => p.Id == "1")) .Returns(Task.FromResult(president)); instance.DeletePresidentsAsync("1") .Returns(Task.FromResult(true)); IocManager.IocContainer.Register( Component .For <IWhiteHouseRepository>() .Instance(instance) .LifestyleTransient() ); }); Configuration.ReplaceService <IWhiteHouseReadRepository>(() => { var instance = Substitute.For <IWhiteHouseReadRepository>(); var presidentDto = new PresidentDto("1", "New President", new Address("Rua de teste", "123", "APT 12", new ZipCode("55833479"))); var presidentsToGetAll = new ListDto <PresidentDto, string>(); presidentsToGetAll.Items.Add(presidentDto); presidentsToGetAll.Items.Add(presidentDto); instance.GetAllPresidents(Arg.Any <GetAllPresidentsDto>()) .Returns(Task.FromResult(presidentsToGetAll)); IocManager.IocContainer.Register( Component .For <IWhiteHouseReadRepository>() .Instance(instance) .LifestyleTransient() ); }); }