public void GetFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(1);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is Flight);
                var flight = objectResult.Value as Flight;
                Assert.AreEqual(1, flight.Number);
                Assert.AreEqual(1, flight.Capacity);
            }
        }
        public void GetAvailableFlightWithStartAndEndDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetAvailableFlightWithEndDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(new DateTime(2018, 5, 10), new DateTime(2018, 5, 10), null);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is IList <AvailableFlight>);
                var flights = (objectResult.Value as IList <AvailableFlight>).ToList();
                Assert.AreEqual(1, flights.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), flights[0].Date);
                Assert.AreEqual(1, flights[0].RemainingCapacity);
                Assert.AreEqual(1, flights[0].Flight.Number);
            }
        }
Beispiel #3
0
        public void FlightCount()
        {
            var result = flightController.Get();
            var okObj  = result as OkObjectResult;
            var model  = okObj.Value as List <FlightDTO>;


            Assert.AreNotEqual(0, model.Count);
        }
        public void GetAvailableFlightWithInvalidCapacity()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetAvailableFlightWithInvalidCapacity")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(new DateTime(2018, 5, 10), new DateTime(2018, 5, 10), -1);
                Assert.IsTrue(result is BadRequestResult);
            }
        }
        public void GetAvailableFlightWithStartDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetAvailableFlightWithStartDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(new DateTime(2018, 5, 10), DateTime.MinValue, null);
                Assert.IsTrue(result is BadRequestResult);
            }
        }
Beispiel #6
0
        public void WhenValidInputNoRouteExists_Get_ReturnsNotRoute()
        {
            // Arrange
            var controller = new FlightController(_flightServiceMock.Object);

            _flightServiceMock.Setup(s => s.GetShortestPath(It.IsAny <string>(), It.IsAny <string>())).Returns((IEnumerable <string>)null);

            // Act
            var response = controller.Get(new RouteRequest {
                Destination = "YYZ", Origin = "ORD"
            }) as NotFoundObjectResult;

            // Assert

            Assert.AreEqual(response.Value, "No route found between YYZ and ORD");
        }
Beispiel #7
0
        public void WhenInvalidInput_Get_ReturnsNotFound()
        {
            // Arrange
            var controller = new FlightController(_flightServiceMock.Object);

            _flightServiceMock.Setup(s => s.GetShortestPath(It.IsAny <string>(), It.IsAny <string>())).Returns((IEnumerable <string>)null);

            // Act
            var response = controller.Get(new RouteRequest {
                Destination = "test", Origin = "Test"
            });

            // Assert

            Assert.IsInstanceOfType(response, typeof(NotFoundObjectResult));
        }
Beispiel #8
0
        public void WhenValidInput_Get_ReturnsShortestPath()
        {
            // Arrange
            var controller       = new FlightController(_flightServiceMock.Object);
            var expectedResponse = new List <string>
            {
                "YYZ", "JFK", "LAX", "YVR"
            };

            _flightServiceMock.Setup(s => s.GetShortestPath(It.IsAny <string>(), It.IsAny <string>())).Returns(expectedResponse);

            // Act
            var response = controller.Get(new RouteRequest {
                Destination = "test", Origin = "Test"
            }) as OkObjectResult;

            // Assert

            Assert.AreEqual(response.Value, expectedResponse);
        }
        public void GetInvalidFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetInvalidFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(2);
                Assert.IsTrue(result is NotFoundResult);
            }
        }