public void GetCheapAsyncShouldThrowTicketsCacheApiException() { SetupMockHttp(ApiEndPoints.Cheap, "Unauthorized"); var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false); apiClient.GetCheapAsync("IEV").ShouldThrow(typeof(TicketsCacheApiException)); }
public async Task GetCheapAsyncShouldContainTokenQueryString() { var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(ApiEndPoints.ApiBaseUrl + ApiEndPoints.Cheap) .WithExactQueryString(new Dictionary <string, string>() { { QueryParams.Token, ApiToken }, { QueryParams.Origin, Origin }, }) .Respond(RequestStrings.ApplicationJson, JsonResponseHelper.GetJsonResponse("CheapSuccess")) ; var apiClient = new TicketsCacheApiClient(ApiToken, mockHttp.ToHttpClient(), false, true); await apiClient.GetCheapAsync(originIata : Origin); mockHttp.VerifyNoOutstandingExpectation(); }
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)); }
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 void GetCheapAsyncShouldThrowArgumentException() { var apiClient = new TicketsCacheApiClient(GetTokenFixture(), mockHttp.ToHttpClient(), false, false); apiClient.GetCheapAsync(null).ShouldThrow(typeof(ArgumentException)); }