public void GetLatestAsyncShouldThrowTicketsCacheApiException() { SetupMockHttp(ApiEndPoints.Latest, "Unauthorized"); var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false); apiClient.GetLatestAsync().ShouldThrow(typeof(TicketsCacheApiException)); }
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(); }
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(); }
public async Task GetLatestAsyncShouldContainOriginAndDestinationQueryStrings() { var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Latest) .WithExactQueryString(new Dictionary <string, string>() { { QueryParams.Origin, "KBP" }, { QueryParams.Destination, "BKK" }, { QueryParams.PeriodType, "year" }, }) .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("LatestSuccess")) ; var httpClient = mockHttp.ToHttpClient(); var apiClient = new TicketsCacheApiClient(ApiToken, httpClient, false, false); var tickets = await apiClient.GetLatestAsync(originIata : "KBP", destinationIata : "BKK", periodTypeMonth : false); tickets.ShouldNotBeNull(); mockHttp.VerifyNoOutstandingExpectation(); }