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 void Create_Valid_Professional() { // Arrange var builder = new ProfessionalBuilder(LocalNotification) .WithName("Professional 1") .WithAddress("Rua do comercio", "123", "APT 1", new ZipCode("12345678")) .WithEmail("*****@*****.**") .WithPhone("5563524178"); // Act builder.Build(); // Assert Assert.False(LocalNotification.HasNotification()); }
public void Professional_Service_Insert_Valid_Professional() { // Arrange var professionalBuilder = new ProfessionalBuilder(LocalNotification) .WithName("João da Silva") .WithPhone("15398264438") .WithEmail("*****@*****.**") .WithAddress(new Address("Rua do comercio 2", "1233", "APT 1234", new ZipCode("22888888"))); // Act var responseBase = _profissionalService.CreateProfessional(professionalBuilder); // Assert Assert.False(LocalNotification.HasNotification()); Assert.NotEqual(responseBase.PrimaryKey, Guid.Empty); Assert.NotEqual(responseBase.SecundaryKey, 0); }
public void Professional_Service_Update_Valid_Professional() { // Arrange var professionalBuilder = new ProfessionalBuilder(LocalNotification) .WithProfessionalId(1) .WithCode(Guid.Parse("1b92f96f-6a71-4655-a0b9-93c5f6ad9637")) .WithName("João da Silva") .WithPhone("15398264438") .WithEmail("*****@*****.**") .WithAddress(new Address("Rua do comercio 2", "1233", "APT 1234", new ZipCode("22888888"))); // Act _profissionalService.UpdateProfessional(professionalBuilder); // Assert Assert.False(LocalNotification.HasNotification()); }
public void Create_Professional_With_Invalid_Address_Number() { // Arrange var builder = new ProfessionalBuilder(LocalNotification) .WithName("Professional 1") .WithAddress("Rua do comercio", null, "APT 1", new ZipCode("12345678")) .WithEmail("*****@*****.**") .WithPhone("5563524178"); // Act builder.Build(); // Assert Assert.True(LocalNotification.HasNotification()); var notifications = LocalNotification.GetAll(); Assert.True(notifications.Any(a => a.Message == Professional.Error.ProfessionalAddressNumberMustHaveValue.ToString())); }
public void Professional_Service_Update_Not_Accept_Non_Existing_Professional() { // Arrange var professionalBuilder = new ProfessionalBuilder(LocalNotification) .WithProfessionalId(99) .WithCode(Guid.NewGuid()) .WithName("João da Silva") .WithPhone("15398264438") .WithEmail("*****@*****.**") .WithAddress(new Address("Rua do comercio 2", "1233", "APT 1234", new ZipCode("22888888"))); // Act _profissionalService.UpdateProfessional(professionalBuilder); // Assert Assert.True(LocalNotification.HasNotification()); var notifications = LocalNotification.GetAll(); Assert.True(notifications.Any(a => a.Message == Professional.Error.CouldNotFindProfessional.ToString())); }
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); }