public async Task Test_GetRestaurantListForUserByDeliveryPostcodeAsync_WhenTbodyRequiredTrue_ThrowArgumentNullException() { //Arrange var input = new IJustEatRequest <JustEatRestaurantsBasicRequest> { TbodyRequired = true, RequestBody = null }; //Act Func <Task> act = async() => await _justEatApiIntegrationService.GetRestaurantListForUserByDeliveryPostcodeAsync(input); //Arrange await Assert.ThrowsAsync <ArgumentNullException>(act); }
public async Task Test_GetRestaurantListForUserByDeliveryPostcodeAsync_WhenJsonDeserializationNoSuccess() { //Arrange var input = new IJustEatRequest <JustEatRestaurantsBasicRequest> { TbodyRequired = false, RequestBody = null }; _baseRestApiServiceMock.Mock_SendApiRequestAsync_With_Custom_Response <object, object>(null, null, false); //Act var result = await _justEatApiIntegrationService.GetRestaurantListForUserByDeliveryPostcodeAsync(input); //Arrange Assert.NotNull(result); Assert.NotNull(result.Errors); Assert.Null(result.Restaurants); Assert.False(result.Success); Assert.True(result.Errors.Count > 0); }
public async Task Test_GetRestaurantListForUserByDeliveryPostcodeAsync_WhenBaseRestService_ThrowsException_ResultResponseNotEmptyContainsErrors() { //Arrange var input = new IJustEatRequest <JustEatRestaurantsBasicRequest> { TbodyRequired = false, RequestBody = null }; _baseRestApiServiceMock.Mock_SendApiRequestAsync_SkipTClassInit_ThrowsException(); //Act var result = await _justEatApiIntegrationService.GetRestaurantListForUserByDeliveryPostcodeAsync(input); //Arrange //Arrange Assert.NotNull(result); Assert.NotNull(result.Errors); Assert.Null(result.Restaurants); Assert.False(result.Success); Assert.True(result.Errors.Count > 0); }
public async Task Test_GetRestaurantListForUserByDeliveryPostcodeAsync_WhenJsonDeserializationSuccess_AndRestaurant_ArrayNotNUll_AndResponseIsValid() { //Arrange var input = new IJustEatRequest <JustEatRestaurantsBasicRequest> { TbodyRequired = false, RequestBody = null }; _baseRestApiServiceMock .Mock_SendApiRequestAsync_With_Custom_Response <RestaurantsGeneralData, object>(new RestaurantsGeneralData { Restaurants = new List <RestaurantMainItem>() }, null, true); //Act var result = await _justEatApiIntegrationService.GetRestaurantListForUserByDeliveryPostcodeAsync(input); //Arrange Assert.NotNull(result); Assert.NotNull(result.Restaurants); Assert.Null(result.Errors); Assert.True(result.Success); }
public async Task <JustEatRestarauntResponseData> GetRestaurantListForUserByDeliveryPostcodeAsync(IJustEatRequest <JustEatRestaurantsBasicRequest> request) { if (request == null || (request.TbodyRequired == true && request.RequestBody == null)) { //log throw new ArgumentNullException($"{GetType().Name} {CommonConstants.ErrorMessage_CheckInputData} "); } JustEatRestarauntResponseData result = new JustEatRestarauntResponseData(); try { string urlRequest = $"{request.CoreUrl}/{request.Endpoint}{request.Query}".ToLower(); var apiRequestResult = await _genericRestApiService.SendApiRequestAsync <RestaurantsGeneralData, object>(urlRequest, null, request.Header, request.ApiMethod, doNotDeserializeOutput : false, authRequest : new HttpAuth { AuthType = request.AuthType, Password = request?.RequestBody?.Password, Username = request?.RequestBody?.Username }); if (apiRequestResult.deserializationSuccess && apiRequestResult.responseModel != null) { if (apiRequestResult.responseModel.Restaurants != null) { //returns a list of restaurants that deliver to the outcode xxxxxx, including some basic restaurant information. result.Restaurants = apiRequestResult.responseModel.Restaurants.Select(x => new RestaurantShortDetails { RestaurantAddress = new Address { Street = x.Address, City = x.City, Postcode = x.Postcode, AdditionalDetails = "N/A", Country = "N/A" }, RestaurantLocation = new Location { Latitude = x.Latitude, Longitude = x.Longitude }, RatingDetails = new RatingDetails { NumberOfRatings = x.NumberOfRatings, Score = x.Score, RatingAverage = x.RatingAverage, RatingStars = x.RatingStars }, CuisineTypes = x.CuisineTypes, DisplayId = x.DefaultDisplayRank, LogUrl = (x.Logo != null && x.Logo.Count > 0) ? x.Logo[0].StandardResolutionURL : "", Id = x.Id, Name = x.Name, UniqueName = x.UniqueName }).ToList(); } result.Success = true; } else { //log result.Errors = new List <ErrorData> { new ErrorData { Message = "Unsuccessful context deserialization or service exception", Token = ErrorTokens.ServiceError.ToString() } }; } } catch { //log result.Errors = new List <ErrorData> { new ErrorData { Message = "Exception occurred during integration request execution or response handle", Token = ErrorTokens.ServiceException.ToString() } }; } return(result); }