Пример #1
0
        public async Task <IActionResult> Get(string airportCodeA, string airportCodeB)
        {
            try
            {
                var airportService = new AirportService(_airportRest);

                var airportDistanceResponse = await airportService.CalculeDistance(airportCodeA, airportCodeB);

                if (String.IsNullOrEmpty(airportDistanceResponse.Item2))
                {
                    var airportDistanceVM = new AirportDistanceViewModel
                    {
                        AirportCodeA = airportCodeA,
                        AirportCodeB = airportCodeB,
                        Distance     = airportDistanceResponse.Item1
                    };

                    return(Ok(airportDistanceVM));
                }
                else
                {
                    return(NotFound(airportDistanceResponse.Item2));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }
Пример #2
0
        public async Task AirportService_CalculeDistance_ShoudBeReturnNotFoundAirPortB()
        {
            // Arrange
            var airportA = new Airport()
            {
                Iata     = "AMS",
                Location = new Location
                {
                    Lat = 52.309069,
                    Lon = 4.763385
                }
            };

            var airportB = new Airport()
            {
                Iata = "TTTT",
            };

            var airportRest = new Mock <IAirportRest>();

            airportRest.Setup(r => r.GetAirport(airportA.Iata))
            .ReturnsAsync(airportA);

            airportRest.Setup(r => r.GetAirport(airportB.Iata))
            .ReturnsAsync((Airport)null);

            var airportService = new AirportService(airportRest.Object);

            // Act
            var distance = await airportService.CalculeDistance(airportA.Iata, airportB.Iata);

            // Assert
            Assert.Equal(0, distance.Item1);
            Assert.Equal("Airport B Not Found", distance.Item2);
        }
Пример #3
0
        public async Task AirportService_CalculeDistance_ShoudBeReturnValid()
        {
            // Arrange
            var airportA = new Airport()
            {
                Iata     = "AMS",
                Location = new Location
                {
                    Lat = 52.309069,
                    Lon = 4.763385
                }
            };


            var airportB = new Airport()
            {
                Iata     = "CWB",
                Location = new Location
                {
                    Lat = -25.535763,
                    Lon = -49.173298
                }
            };

            var airportRest = new Mock <IAirportRest>();

            airportRest.Setup(r => r.GetAirport(airportA.Iata))
            .ReturnsAsync(airportA);

            airportRest.Setup(r => r.GetAirport(airportB.Iata))
            .ReturnsAsync(airportB);

            var airportService = new AirportService(airportRest.Object);

            // Act
            var distance = await airportService.CalculeDistance(airportA.Iata, airportB.Iata);

            // Assert
            Assert.NotEqual(0, distance.Item1);
            Assert.Empty(distance.Item2);
            Assert.Equal(6285.129234929529, distance.Item1);
            airportRest.Verify(r => r.GetAirport("AMS"), Times.Once);
        }
Пример #4
0
        public async Task AirportService_CalculeDistance_ReturnDifferentThanExcepted(double expected)
        {
            // Arrange
            var airportA = new Airport()
            {
                Iata     = "AMS",
                Location = new Location
                {
                    Lat = 52.309069,
                    Lon = 4.763385
                }
            };


            var airportB = new Airport()
            {
                Iata     = "CWB",
                Location = new Location
                {
                    Lat = -25.535763,
                    Lon = -49.173298
                }
            };

            var airportRest = new Mock <IAirportRest>();

            airportRest.Setup(r => r.GetAirport(airportA.Iata))
            .ReturnsAsync(airportA);

            airportRest.Setup(r => r.GetAirport(airportB.Iata))
            .ReturnsAsync(airportB);

            var airportService = new AirportService(airportRest.Object);

            // Act
            var distance = await airportService.CalculeDistance(airportA.Iata, airportB.Iata);

            // Assert
            Assert.NotEqual(expected, distance.Item1);
            Assert.Empty(distance.Item2);
            airportRest.Verify(r => r.GetAirport("AMS"), Times.Once);
        }