Exemplo n.º 1
0
        /// <summary>
        /// The Live Pricing Service (flight query) returns all the flights available for a specific route and
        /// date (or single date for one-way searches).
        /// </summary>
        /// <param name="flightQuerySettings">Settings for the query</param>
        /// <param name="interimResultCallback">The callback that is called when interim results are recieved</param>
        /// <returns>The collection of itineraries from SkyScanner</returns>
        public async Task <List <Itinerary> > QueryFlight(
            FlightQuerySettings flightQuerySettings,
            Action <InterimChangeSet <Itinerary> > interimResultCallback,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var interimResultHandler = new InterimResultProvider <FlightResponse, Itinerary>();

            var flightService = new Flight(_apiKey, flightQuerySettings);

            return(await _executionStrategy.Execute(async() =>
            {
                var pinger = await flightService.SendQuery(cancellationToken);

                if (interimResultCallback != null)
                {
                    pinger.OnInterimResultsRecieved += (sender, args) =>
                    {
                        interimResultCallback(interimResultHandler.Calculate(args));
                    };
                }

                var response = await pinger.SendQuery(cancellationToken);
                return response.Itineraries;
            }, cancellationToken));
        }
        public void InterimResultProvider_ShouldReturnDiff_OnSubsequentCall()
        {
            var handler = new InterimResultProvider<FlightResponse, Itinerary>();

            var response1 = DeserializeResponse("response_1.json");
            var response2 = DeserializeResponse("response_2.json");

            var result1 = handler.Calculate(response1);
            var result2 = handler.Calculate(response2);

            Assert.AreEqual(8, result2.All.Count());
            Assert.AreEqual(2, result2.Additions.Count());

            Assert.AreEqual(0, result2.Updates.Count());

            var refEqualCount = result2.All.Count(n => result1.All.Contains(n));
            Assert.AreEqual(6, refEqualCount);
        }
Exemplo n.º 3
0
        public void InterimResultProvider_ShouldReturnDiff_OnSubsequentCall()
        {
            var handler = new InterimResultProvider <FlightResponse, Itinerary>();

            var response1 = DeserializeResponse("response_1.json");
            var response2 = DeserializeResponse("response_2.json");

            var result1 = handler.Calculate(response1);
            var result2 = handler.Calculate(response2);

            Assert.AreEqual(8, result2.All.Count());
            Assert.AreEqual(2, result2.Additions.Count());

            Assert.AreEqual(0, result2.Updates.Count());

            var refEqualCount = result2.All.Count(n => result1.All.Contains(n));

            Assert.AreEqual(6, refEqualCount);
        }
        public void InterimResultProvider_ShouldReturnResponse_OnFirstCall()
        {
            var handler = new InterimResultProvider<FlightResponse, Itinerary>();

            var response = DeserializeResponse("response_1.json");

            var result = handler.Calculate(response);

            Assert.AreEqual(6, result.All.Count());
            Assert.AreEqual(0, result.Additions.Count());
            Assert.AreEqual(0, result.Updates.Count());
        }
Exemplo n.º 5
0
        public void InterimResultProvider_ShouldReturnResponse_OnFirstCall()
        {
            var handler = new InterimResultProvider <FlightResponse, Itinerary>();

            var response = DeserializeResponse("response_1.json");

            var result = handler.Calculate(response);

            Assert.AreEqual(6, result.All.Count());
            Assert.AreEqual(0, result.Additions.Count());
            Assert.AreEqual(0, result.Updates.Count());
        }
        public void InterimResultProvider_ShouldReturnDiff_OnSubsequentCall_Many()
        {
            var handler = new InterimResultProvider<FlightResponse, Itinerary>();

            var response1 = DeserializeResponse("response_1.json");
            var response2 = DeserializeResponse("response_2.json");
            var response3 = DeserializeResponse("response_3.json");
            var response4 = DeserializeResponse("response_4.json");
            var response5 = DeserializeResponse("response_5.json");
            var response6 = DeserializeResponse("response_6.json");

            var ignore = handler.Calculate(response1);
            ignore = handler.Calculate(response2);
            ignore = handler.Calculate(response3);
            ignore = handler.Calculate(response4);
            ignore = handler.Calculate(response5);
            ignore = handler.Calculate(response6);
            // Check test output
        }
Exemplo n.º 7
0
        public void InterimResultProvider_ShouldReturnDiff_OnSubsequentCall_Many()
        {
            var handler = new InterimResultProvider <FlightResponse, Itinerary>();

            var response1 = DeserializeResponse("response_1.json");
            var response2 = DeserializeResponse("response_2.json");
            var response3 = DeserializeResponse("response_3.json");
            var response4 = DeserializeResponse("response_4.json");
            var response5 = DeserializeResponse("response_5.json");
            var response6 = DeserializeResponse("response_6.json");

            var ignore = handler.Calculate(response1);

            ignore = handler.Calculate(response2);
            ignore = handler.Calculate(response3);
            ignore = handler.Calculate(response4);
            ignore = handler.Calculate(response5);
            ignore = handler.Calculate(response6);
            // Check test output
        }