public void Save(CreateGuiaDTO model) { var guia = _mapper.Map <CreateGuiaCommand>(model); var contrato = _contratoService.Get(model.ContratoId); if (contrato.Situcont == "Inativo") { throw new ArgumentException("O contrato do titular está inativo"); } _bus.SendCommand(guia); }
public ActionResult Post([FromBody] CreateGuiaDTO createGuiaDTO) { try { _guiaService.Save(createGuiaDTO); return(Ok()); } catch (Exception e) { string errors = e.Message; return(ValidationProblem(new ValidationProblemDetails() { Type = "Model Validation Error", Detail = errors })); } }
public void When_ContratoIsInativo_Then_ThrowsArgumentException() { var repoMock = new Mock <IRepository <Guia> >(); Guia guiaExpected = null; repoMock.Setup(x => x.Find(It.IsAny <Guid>())).Returns(guiaExpected); var contratoServiceMock = new Mock <IContratoService>(); ContratoDTO contratoExpected = new ContratoDTO(); contratoExpected.Situcont = "Inativo"; contratoServiceMock.Setup(x => x.Get(It.IsAny <Guid>())).Returns(contratoExpected); var mapper = new MapperConfiguration(config => config.AddProfile <MappingProfiles>()).CreateMapper(); var busMock = new Mock <IBus>(); var service = new GuiaService(repoMock.Object, mapper, busMock.Object, contratoServiceMock.Object); CreateGuiaDTO guiaDTO = new CreateGuiaDTO(); Assert.Throws(typeof(ArgumentException), new TestDelegate(() => service.Save(guiaDTO))); }