public async Task ValidationMappingPlaneType_when_validate_pilot_OK_then_map() { var validator = new PlaneTypeDTOValidator(); PlaneTypeDTO correct = new PlaneTypeDTO() { Id = 1, Model = "Model" }; PlaneTypeDTO incorrect = new PlaneTypeDTO() { Id = 2, NumberOfSeats = 25 }; bool correctRes = validator.Validate(correct).IsValid; Assert.True(correctRes); var mapped = _mapper.Map <PlaneTypeDTO, PlaneType>(correct); if (correctRes) { await _service.Post(mapped); } bool incorrectRes = validator.Validate(incorrect).IsValid; Assert.False(incorrectRes); var mappedIncorrect = _mapper.Map <PlaneTypeDTO, PlaneType>(incorrect); if (incorrectRes) { await _service.Post(mapped); } }
public HttpResponseMessage Post([FromBody] PlaneTypeDTO planeType) { if (ModelState.IsValid && planeType != null && validator.Validate(planeType).IsValid) { _service.Post <PlaneType>(Mapper.Map <PlaneTypeDTO, PlaneType>(planeType)); _service.SaveChanges(); return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } }