Esempio n. 1
0
 public HttpResponseMessage Post([FromBody] DepartureDTO departure)
 {
     if (ModelState.IsValid && departure != null && validator.Validate(departure).IsValid)
     {
         _service.Post <Departure>(Mapper.Map <DepartureDTO, Departure>(departure));
         _service.SaveChanges();
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     else
     {
         return(new HttpResponseMessage(HttpStatusCode.BadRequest));
     }
 }
Esempio n. 2
0
        public async Task ValidationMappingDeparture_when_validate_pilot_OK_then_map()
        {
            var          validator = new DepartureDTOValidator();
            DepartureDTO correct   = new DepartureDTO()
            {
                Id              = 1,
                Crew            = new CrewDTO(),
                Flight          = new FlightDTO(),
                Plane           = new PlaneDTO(),
                TimeOfDeparture = new System.DateTime(2018, 10, 10)
            };

            DepartureDTO incorrect = new DepartureDTO()
            {
                Id    = 2,
                Crew  = new CrewDTO(),
                Plane = new PlaneDTO()
            };

            bool correctRes = validator.Validate(correct).IsValid;

            Assert.True(correctRes);
            var mapped = _mapper.Map <DepartureDTO, Departure>(correct);

            if (correctRes)
            {
                await _service.Post(mapped);
            }

            bool incorrectRes = validator.Validate(incorrect).IsValid;

            Assert.False(incorrectRes);
            var mappedIncorrect = _mapper.Map <DepartureDTO, Departure>(incorrect);

            if (incorrectRes)
            {
                await _service.Post(mapped);
            }
        }