Exemplo n.º 1
0
        public async Task TestCreateFlight()
        {
            // Arrange
            string   testId   = "100";
            Flight   flight   = GetTestFlights().FirstOrDefault(p => p.Id == testId);
            Aircraft aircraft = GetTestAircrafts().FirstOrDefault(p => p.Id == testId);

            FlightModel   flightmodel   = GetTestFlightsModels().FirstOrDefault(p => p.Id == testId);
            AircraftModel aircraftmodel = GetTestAircraftsModels().FirstOrDefault(p => p.Id == testId);

            var testAircraft     = GetTestAircrafts();
            var mockRepoAircraft = new Mock <IAircraftRepository>();
            var mockRepoFlight   = new Mock <IFlightRepository>();

            mockRepoFlight.Setup(c => c.Add(flight));
            mockRepoAircraft.Setup(c => c.Add(aircraft));
            var controller = new FlightController(mockRepoFlight.Object, mockRepoAircraft.Object);

            // Act
            var result = controller.Post(flightmodel);

            // Assert
            var actionResult = Assert.IsType <OkResult>(result);

            var model = Assert.IsType <OkResult>(actionResult);
        }
Exemplo n.º 2
0
        public void GetFlightsReturnsMulitpleFlightRecords()
        {
            // Arrange
            var flightRepository = new FlightRepository(flightServiceMock.Object, mapper);
            var flightController = new FlightController(flightRepository);
            var flightSearch     = new FlightSearch()
            {
                FromAirport = "SEA",
                ToAirport   = "LAX"
            };

            // Act
            var flights = flightController.Post(flightSearch);

            // Assert
            Assert.AreEqual(2, flights.Count());
        }
Exemplo n.º 3
0
        public void GetFlightsReturnsIEnumerableFlightViewModelObject()
        {
            // Arrange
            var flightRepository = new FlightRepository(flightServiceMock.Object, mapper);
            var flightController = new FlightController(flightRepository);
            var flightSearch     = new FlightSearch()
            {
                FromAirport = "SEA",
                ToAirport   = "LAX"
            };

            // Act
            var flights = flightController.Post(flightSearch);

            // Assert
            Assert.IsInstanceOfType(flights, typeof(IEnumerable <FlightViewModel>));
        }
Exemplo n.º 4
0
        public void GetFlightsWithSameAirportReturnsEmptyResults()
        {
            // Arrange
            var flightRepository = new FlightRepository(flightServiceMock.Object, mapper);
            var flightController = new FlightController(flightRepository);
            var flightSearch     = new FlightSearch()
            {
                FromAirport = "SEA",
                ToAirport   = "SEA"
            };

            // Act
            var results     = flightController.Post(flightSearch);
            var resultsData = results as List <FlightViewModel>;

            // Assert
            Assert.AreEqual(0, resultsData.Count);
        }
Exemplo n.º 5
0
        public void GetFlightsFromSeaToLasReturnsAFlightObject()
        {
            // Arrange
            var flightRepository = new FlightRepository(flightServiceMock.Object, mapper);
            var flightController = new FlightController(flightRepository);
            var flightSearch     = new FlightSearch()
            {
                FromAirport = "SEA",
                ToAirport   = "LAS"
            };

            // Act
            var flights    = flightController.Post(flightSearch);
            var flightData = flights as List <FlightViewModel>;

            // Assert
            Assert.AreEqual(1, flightData.Count);
            Assert.AreEqual("SEA", flightData[0].From);
            Assert.AreEqual("LAS", flightData[0].To);
        }