public void GetMonthMatrixAsyncShouldThrowTicketsCacheApiException()
        {
            SetupMockHttp(ApiEndPoints.MonthMatrix, "Unauthorized");

            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false);

            apiClient.GetMonthMatrixAsync().ShouldThrow(typeof(TicketsCacheApiException));
        }
        public void AcceptEncodingShouldNotBeGzip()
        {
            Fixture    fixture    = new Fixture();
            HttpClient httpClient = new HttpClient();
            var        apiClient  = new TicketsCacheApiClient(fixture.Create <string>(), httpClient, false, false);

            httpClient.DefaultRequestHeaders.AcceptEncoding.Count.ShouldBe(0);
        }
        public void AcceptEncodingShouldBeGzip()
        {
            Fixture    fixture    = new Fixture();
            HttpClient httpClient = new HttpClient();
            var        apiClient  = new TicketsCacheApiClient(fixture.Create <string>(), httpClient, true, false);

            httpClient.DefaultRequestHeaders.AcceptEncoding.Count.ShouldBe(1);
            httpClient.DefaultRequestHeaders.AcceptEncoding.First().Value.ShouldBe(RequestStrings.Gzip);
        }
        public async Task GetMonthMatrixAsyncShouldReturnTicketArray()
        {
            SetupMockHttp(ApiEndPoints.MonthMatrix, "MonthMatrixSuccess");
            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false);

            var tickets = await apiClient.GetMonthMatrixAsync();

            tickets.Length.ShouldBe(1);
            var ticket = tickets[0];

            ticket.Value.ShouldBe(29127);
        }
Exemplo n.º 5
0
        public async Task GetNearestPlacesMatrixAsyncShouldReturnTicketArray()
        {
            SetupMockHttp(ApiEndPoints.NearestPlacesMatrix, "NearestPlacesMatrixSuccess");
            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false);

            var data = await apiClient.GetNearestPlacesMatrixAsync();

            data.Prices.Length.ShouldBe(4);
            var ticket = data.Prices[0];

            ticket.Value.ShouldBe(51155);
        }
        public async Task GetLatestAsyncShouldReturnTicketArray()
        {
            SetupMockHttp(ApiEndPoints.Latest, "LatestSuccess");
            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false);

            var tickets = await apiClient.GetLatestAsync();

            tickets.Length.ShouldBe(1);
            var ticket = tickets[0];

            ticket.Value.ShouldBe(1183);
        }
        public async Task GetLatestAsyncGzipShouldReturnTicketArray()
        {
            mockHttp
            .When(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Latest)
            .Respond("application/gzip", JsonResponseHelper.GetStreamResponse("LatestSuccess.gzip"))
            ;
            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), true, false);

            var tickets = await apiClient.GetLatestAsync();

            tickets.Length.ShouldBe(1);
            var ticket = tickets[0];

            ticket.Value.ShouldBe(1183);
        }
        public async Task GetLatestAsyncShouldContainAllQueryStrings()
        {
            DateTime beginningOfPeriod = new DateTime(2017, 12, 21);
            var      mockHttp          = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Latest)
            .WithExactQueryString(new Dictionary <string, string>()
            {
                { QueryParams.Currency, "Usd" },
                { QueryParams.Origin, "KBP" },
                { QueryParams.Destination, "BKK" },
                { QueryParams.BeginningOfPeriod, beginningOfPeriod.ToString("yyyy-MM-dd") },
                { QueryParams.PeriodType, "month" },
                { QueryParams.OneWay, "true" },
                { QueryParams.Page, "1" },
                { QueryParams.Limit, "10" },
                { QueryParams.ShowToAffiliates, "false" },
                { QueryParams.Sorting, "route" },
                { QueryParams.TripDuration, "2" },
            })
            .WithHeaders(new Dictionary <string, string>
            {
                { RequestStrings.AccessToken, ApiToken },
                { "Accept", RequestStrings.ApplicationJson }
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("LatestSuccess"))
            ;
            var httpClient = mockHttp.ToHttpClient();
            var apiClient  = new TicketsCacheApiClient(ApiToken, httpClient, false, false);

            var tickets = await apiClient.GetLatestAsync(
                currency : Enums.Currency.Usd,
                originIata : "KBP",
                destinationIata : "BKK",
                beginningOfPeriod : beginningOfPeriod,
                periodTypeMonth : true,
                oneWay : true,
                page : 1,
                limit : 10,
                showToAffiliates : false,
                sorting : Enums.Sorting.Route,
                tripDurationInWeeks : 2
                );

            tickets.ShouldNotBeNull();
            mockHttp.VerifyNoOutstandingExpectation();
        }
Exemplo n.º 9
0
        public async Task GetNearestPlacesMatrixAsyncShouldContainAllQueryStrings()
        {
            DateTime departDate = new DateTime(2017, 12, 21);
            DateTime returnDate = new DateTime(2018, 1, 21);
            var      mockHttp   = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.NearestPlacesMatrix)
            .WithExactQueryString(new Dictionary <string, string>()
            {
                { QueryParams.Currency, "Usd" },
                { QueryParams.Origin, "KBP" },
                { QueryParams.Destination, "BKK" },
                { QueryParams.ShowToAffiliates, "false" },
                { QueryParams.DepartDate, departDate.ToString("yyyy-MM-dd") },
                { QueryParams.ReturnDate, returnDate.ToString("yyyy-MM-dd") },
                { QueryParams.Distance, "100" },
                { QueryParams.Limit, "10" },
                { QueryParams.Flexibilty, "7" },
            })
            .WithHeaders(new Dictionary <string, string>
            {
                { "X-Access-Token", ApiToken },
                { "Accept", RequestStrings.ApplicationJson }
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("NearestPlacesMatrixSuccess"))
            ;
            var httpClient = mockHttp.ToHttpClient();
            var apiClient  = new TicketsCacheApiClient(ApiToken, httpClient, false, false);

            var tickets = await apiClient.GetNearestPlacesMatrixAsync(
                currency : Enums.Currency.Usd,
                originIata : "KBP",
                destinationIata : "BKK",
                showToAffiliates : false,
                departDate : departDate,
                returnDate : returnDate,
                distance : 100,
                limit : 10,
                flexibility : 7
                );

            tickets.ShouldNotBeNull();
            mockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task GetLatestAsyncShouldContainTokenQueryString()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Latest)
            .WithExactQueryString(new Dictionary <string, string>()
            {
                { QueryParams.Token, ApiToken },
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("LatestSuccess"))
            ;
            var apiClient = new TicketsCacheApiClient(ApiToken, mockHttp.ToHttpClient(), false, true);

            await apiClient.GetLatestAsync();

            mockHttp.VerifyNoOutstandingExpectation();
        }
Exemplo n.º 11
0
        public async Task GetCheapAsyncShouldReturnTicketArray()
        {
            SetupMockHttp(ApiEndPoints.Cheap, "CheapSuccess");
            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false);

            var data = await apiClient.GetCheapAsync("IEV");

            data.Count.ShouldBe(1);
            data.Keys.First().ShouldBe("HKT");
            var destinationDictionary = data.Values.First();
            var firstTicket           = destinationDictionary["0"];

            firstTicket.Price.ShouldBe(35443);
            firstTicket.Airline.ShouldBe("UN");
            firstTicket.FlightNumber.ShouldBe(571);
            firstTicket.DepartureAt.ShouldBe(new DateTime(2015, 6, 9, 21, 20, 0));
            firstTicket.ReturnAt.ShouldBe(new DateTime(2015, 7, 15, 12, 40, 0));
            firstTicket.ExpiresAt.ShouldBe(new DateTime(2015, 1, 8, 18, 30, 40));
        }
Exemplo n.º 12
0
        public async Task GetNearestPlacesMatrixAsyncShouldNotContainQueryStrings()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.NearestPlacesMatrix)
            .WithHeaders(new Dictionary <string, string>
            {
                { "X-Access-Token", ApiToken },
                { "Accept", RequestStrings.ApplicationJson }
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("NearestPlacesMatrixSuccess"))
            ;
            var apiClient = new TicketsCacheApiClient(ApiToken, mockHttp.ToHttpClient(), false, false);

            await apiClient.GetNearestPlacesMatrixAsync();

            mockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task GetCheapAsyncShouldContainOriginAndDestinationQueryStrings()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Cheap)
            .WithExactQueryString(new Dictionary <string, string>()
            {
                { QueryParams.Origin, "KBP" },
                { QueryParams.Destination, "BKK" },
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("CheapSuccess"))
            ;
            var httpClient = mockHttp.ToHttpClient();
            var apiClient  = new TicketsCacheApiClient(ApiToken, httpClient, false, false);

            var tickets = await apiClient.GetCheapAsync(originIata : "KBP", destinationIata : "BKK");

            tickets.ShouldNotBeNull();
            mockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task GetCheapAsyncShouldContainAllQueryStrings()
        {
            DateTime departDate = new DateTime(2017, 12, 21);
            DateTime returnDate = new DateTime(2017, 12, 25);
            var      mockHttp   = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Cheap)
            .WithExactQueryString(new Dictionary <string, string>()
            {
                { QueryParams.Currency, "Usd" },
                { QueryParams.Origin, "KBP" },
                { QueryParams.Destination, "BKK" },
                { QueryParams.DepartDate, departDate.ToString("yyyy-MM-dd") },
                { QueryParams.ReturnDate, returnDate.ToString("yyyy-MM-dd") },
                { QueryParams.Page, "1" },
            })
            .WithHeaders(new Dictionary <string, string>
            {
                { RequestStrings.AccessToken, ApiToken },
                { "Accept", RequestStrings.ApplicationJson }
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("CheapSuccess"))
            ;
            var httpClient = mockHttp.ToHttpClient();
            var apiClient  = new TicketsCacheApiClient(ApiToken, httpClient, false, false);

            var tickets = await apiClient.GetCheapAsync(
                currency : Enums.Currency.Usd,
                originIata : "KBP",
                destinationIata : "BKK",
                departDate : departDate,
                returnDate : returnDate,
                page : 1
                );

            tickets.ShouldNotBeNull();
            mockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task GetCheapAsyncShouldContainOriginQueryStrings()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Cheap)
            .WithExactQueryString(new Dictionary <string, string>()
            {
                { QueryParams.Origin, Origin },
            })
            .WithHeaders(new Dictionary <string, string>
            {
                { RequestStrings.AccessToken, ApiToken },
                { "Accept", RequestStrings.ApplicationJson }
            })
            .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("CheapSuccess"))
            ;
            var apiClient = new TicketsCacheApiClient(ApiToken, mockHttp.ToHttpClient(), false, false);

            await apiClient.GetCheapAsync(originIata : Origin);

            mockHttp.VerifyNoOutstandingExpectation();
        }
Exemplo n.º 16
0
        public void GetCheapAsyncShouldThrowArgumentException()
        {
            var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false);

            apiClient.GetCheapAsync(null).ShouldThrow(typeof(ArgumentException));
        }