コード例 #1
0
        public async Task <IActionResult> CaculateDistance([FromBody] DistanceInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var sourceAir = await _service.GetAirport(model.SourceCode) ?? throw new Exception("Source entry is null");

            var targetAir = await _service.GetAirport(model.TargetCode) ?? throw new Exception("Target entry is null");

            var betweenDist = sourceAir.location.GetDistance(targetAir.location);

            return(Ok(betweenDist));
        }
コード例 #2
0
        public async Task GetAirport_ValidIATACode_ReturnsAirport()
        {
            //arrange
            Mock <IHttpService> httpServiceMock = new Mock <IHttpService>();
            var    settingsMock = new Mock <ITeleportServicesSettings>();
            string url          = "https://example/";

            var getRequestResult = new AirportResponse
            {
                Location = new Location
                {
                    Latitude  = 5,
                    Longitude = 5
                }
            };

            httpServiceMock.SetupSequence(x => x.GetRequestAsync <AirportResponse>(It.IsAny <string>())).ReturnsAsync <AirportResponse>(getRequestResult);
            settingsMock.SetupGet <string>(x => x.CTeleportAiportDataUrl).Returns(url);

            AirportService airportService = new AirportService(httpServiceMock.Object, settingsMock.Object);

            //act
            AirportResponse airportResponse = await airportService.GetAirport("AMS");

            //assert
            Assert.Same(airportResponse, getRequestResult);
        }
コード例 #3
0
        public async Task GetLocation()
        {
            string          url             = "https://places-dev.cteleport.com/airports/";
            string          IATACode        = "GYD";
            AirportService  airportService  = new AirportService();
            AirportResponse airportResponse = await airportService.GetAirport(url, IATACode);

            Assert.Equal(50.05039D, airportResponse.Location.Longitude, 10);
        }
コード例 #4
0
        public async Task  WillFindAirport()
        {
            var airports = await _service.GetAirport("Moscow");

            Assert.True(airports.Length > 0);
        }