public void Should_Insert_Professional_With_Success() { //Arrange var professionalDto = new ProfessionalDto { ProfessionalId = 2, Code = Guid.Parse("1b92f96f-6a71-4655-a0b9-93c5f6ad9637"), Address = new Address("Rua teste", "98765", "APT 9876", new ZipCode("23156478")), Email = "*****@*****.**", Name = "Jose da Silva", Phone = "58962348", Specialties = new List <SpecialtyDto> { new SpecialtyDto { Id = 1, Description = "Anestesiologia" } } }; //Act var result = _professionalAppService.CreateProfessional(professionalDto); //Assert Assert.False(LocalNotification.HasNotification()); result.ProfessionalId.ShouldBe(2); }
public void MapTo_ProfessionalDto_To_ProfessionalPoco() { var dto = new ProfessionalDto { Address = new Address("Rua de teste", "123", "Complemento", new ZipCode("12345678")), Code = Guid.NewGuid(), Email = "*****@*****.**", Name = "Professional teste", Phone = "988765541", ProfessionalId = 1, Specialties = new List <SpecialtyDto> { new SpecialtyDto { Id = 1, Description = "Especialidade" } } }; var mappPoco = dto.MapTo <ProfessionalPoco>(); Assert.NotNull(mappPoco); Assert.Equal(dto.ProfessionalId, mappPoco.ProfessionalId); Assert.Equal(dto.Code, mappPoco.Code); Assert.Equal(dto.Name, mappPoco.Name); Assert.Equal(dto.Email, mappPoco.Email); Assert.Equal(dto.Phone, mappPoco.Phone); Assert.NotNull(mappPoco.Address); Assert.Equal(dto.Address.Complement, mappPoco.AddressComplement); Assert.Equal(dto.Address.Number, mappPoco.AddressNumber); Assert.Equal(dto.Address.Street, mappPoco.Address); Assert.Equal(dto.Address.ZipCode.Number, mappPoco.ZipCode); Assert.Null(mappPoco.ProfessionalSpecialties); }
public async Task Post_Professional_With_Success() { //Arrange var professionalDto = new ProfessionalDto() { ProfessionalId = 1, Address = new Address("Rua do comercio", "123", "APT 123", new ZipCode("99888777")), Email = "*****@*****.**", Name = "João da Silva", Phone = "55998765432" }; // Act var response = await PostResponseAsObjectAsync <ProfessionalDto, ProfessionalDto>( $"/{RouteConsts.Professional}", professionalDto ); // Assert Assert.Equal(response.Name, "João da Silva"); Assert.Equal(response.Address.Street, "Rua Do Comercio"); Assert.Equal(response.Address.Number, "123"); Assert.Equal(response.Address.Complement, "APT 123"); Assert.Equal(response.Address.ZipCode.Number, "99888777"); }
public ProfessionalDto CreateProfessional(ProfessionalDto professional) { if (professional == null) { RaiseNotification(nameof(professional)); } if (Notification.HasNotification()) { return(new ProfessionalDto()); } var professionalBuilder = new ProfessionalBuilder(Notification) .WithProfessionalId(professional.ProfessionalId) .WithCode(professional.Code) .WithName(professional.Name) .WithPhone(professional.Phone) .WithEmail(professional.Email) .WithAddress(professional.Address) .WithSpecialties(professional.Specialties.Select(s => new SpecialtyBuilder(Notification).WithId(s.Id).WithDescription(s.Description).Build()).ToList()); var id = _service.CreateProfessional(professionalBuilder); professional.ProfessionalId = id.SecundaryKey; professional.Code = id.PrimaryKey; return(professional); }
public IActionResult Put(decimal professionalId, Guid code, [FromBody] ProfessionalDto professional) { var response = _professionalAppService.UpdateProfessional(new ComposeKey <Guid, decimal>(code, professionalId), professional); return(CreateResponse <ProfessionalDto, ComposeKey <Guid, decimal> >() .FromErrorEnum(ProfessionalDto.Error.PutProfessional) .WithMessage(AppConsts.LocalizationSourceName, ProfessionalDto.Error.PutProfessional) .WithDto(response) .Build()); }
public IActionResult Post([FromBody] ProfessionalDto professional) { var response = _professionalAppService.CreateProfessional(professional); return(CreateResponse <ProfessionalDto, ComposeKey <Guid, decimal> >() .FromErrorEnum(ProfessionalDto.Error.PostProfessional) .WithMessage(AppConsts.LocalizationSourceName, ProfessionalDto.Error.PostProfessional) .WithDto(response) .Build()); }
public async Task <bool> SaveProfessional(ProfessionalDto professionalDto) { var result = await _repository.SaveProfessional(_mapper.Map <Professional>(professionalDto)); if (result > 0) { return(true); } return(false); }
public async Task <ActionResult> CreateProfessional(ProfessionalDto professionalDto) { var result = await _professionalPersistence.SaveProfessional(professionalDto); if (result) { return(Ok($"{professionalDto.Name} salvo com sucesso!")); } return(BadRequest($"Não foi possivel salvar {professionalDto.Name}!")); }
public async Task Post_Professional_Should_Be_Insert_And_Update_Item() { //Arrange var professionalDto = new ProfessionalDto() { ProfessionalId = 2, Address = new Address("Rua teste", "98765", "APT 9876", new ZipCode("23156478")), Email = "*****@*****.**", Name = "Jose da Silva", Phone = "58962348", Specialties = new List <SpecialtyDto>() { new SpecialtyDto() { Id = 1, Description = "Anestesiologia" } } }; // Act var response = await PostResponseAsObjectAsync <ProfessionalDto, ProfessionalDto>( $"/{RouteConsts.Professional}", professionalDto ); // Assert response.ProfessionalId.ShouldBe(2); response.Specialties.Clear(); var updateParam = new ProfessionalDto() { Address = response.Address, Email = response.Email, Name = "Nome Alterado Teste", Phone = response.Phone }; // Act await PutResponseAsObjectAsync <ProfessionalDto, ProfessionalDto>( $"/{RouteConsts.Professional}/{response.ProfessionalId}/{response.Code}", updateParam ); response = await GetResponseAsObjectAsync <ProfessionalDto>( $"/{RouteConsts.Professional}/{response.ProfessionalId}/{response.Code}" ); //Assert response.Name.ShouldBe("Nome Alterado Teste"); }
public ProfessionalDto UpdateProfessional(ComposeKey <Guid, decimal> keys, ProfessionalDto professional) { var professionalId = keys.SecundaryKey; var code = keys.PrimaryKey; if (professionalId <= 0) { RaiseNotification(nameof(professionalId)); } if (code == Guid.Empty) { RaiseNotification(nameof(code)); } if (professional == null) { RaiseNotification(nameof(professional)); } if (Notification.HasNotification()) { return(new ProfessionalDto()); } var professionalBuilder = new ProfessionalBuilder(Notification) .WithProfessionalId(keys.SecundaryKey) .WithCode(keys.PrimaryKey) .WithName(professional.Name) .WithPhone(professional.Phone) .WithEmail(professional.Email) .WithAddress(professional.Address) .WithSpecialties(professional.Specialties.Select(s => new SpecialtyBuilder(Notification).WithId(s.Id).WithDescription(s.Description).Build()).ToList()); _service.UpdateProfessional(professionalBuilder); professional.ProfessionalId = keys.SecundaryKey; professional.Code = keys.PrimaryKey; return(professional); }
public async Task Put_Professional_With_Success() { //Arrange var professionalDto = new ProfessionalDto { Address = new Address("Rua do comercio", "123", "APT 123", new ZipCode("99888777")), Email = "*****@*****.**", Name = "João da Silva", Phone = "55998765432" }; // Act var response = await PutResponseAsObjectAsync <ProfessionalDto, ProfessionalDto>( $"/{RouteConsts.Professional}/1/1b92f96f-6a71-4655-a0b9-93c5f6ad9637", professionalDto ); // Assert Assert.Equal(response.ProfessionalId, 1); Assert.Equal(response.Code.ToString(), "1b92f96f-6a71-4655-a0b9-93c5f6ad9637"); Assert.Equal(response.Name, "João da Silva"); }
public async Task Put_Professional_When_Not_Exists_Return_Not_Found() { //Arrange var professionalDto = new ProfessionalDto() { Address = new Address("Rua do comercio", "123", "APT 123", new ZipCode("99888777")), Email = "*****@*****.**", Name = "João da Silva", Phone = "55998765432" }; // Act var response = await PutResponseAsObjectAsync <ProfessionalDto, ErrorResponse>( $"{RouteConsts.Professional}/99/{Guid.NewGuid()}", professionalDto, HttpStatusCode.NotFound ); // Assert response.Message.ShouldBe("PutProfessional"); response.DetailedMessage.ShouldBe("PutProfessional"); Assert.True(response.Details.Any(a => a.Message == Professional.Error.CouldNotFindProfessional.ToString())); }