Example #1
0
        public IActionResult Post([FromBody] FlightDTO flightDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                flightService.CreateEntity(flightDTO);
            }
            catch (ValidationException e)
            {
                return(BadRequest(new { Exception = e.Message }));
            }

            return(Ok(flightDTO));
        }
Example #2
0
        public void CreateEntity_Should_Create_Flight_in_db()
        {
            // Arrange
            FlightDTO flightDTO = new FlightDTO
            {
                Number           = 4444,
                PointOfDeparture = "TestDeparture4",
                Destination      = "London",
                DepartureTime    = new DateTime(2018, 07, 12),
                DestinationTime  = new DateTime(2018, 07, 12)
            };

            // Act
            _flightService.CreateEntity(flightDTO);
            var flightResult = dispatcherContext.Flights.FirstOrDefault(f => f.Number == 4444 && f.PointOfDeparture == "TestDeparture4");

            // Assert
            Assert.IsTrue(flightResult != null);
        }