private IRestClient createFakedRestClient(RestaurantDataRoot restaurantDataRoot, HttpStatusCode httpStatusCode) { var mockedRestClient = new Mock <IRestClient>(); mockedRestClient .Setup(restClient => restClient.Execute <RestaurantDataRoot>(It.IsAny <IRestRequest>())) .Returns(new RestResponse <RestaurantDataRoot> { StatusCode = httpStatusCode, Data = restaurantDataRoot }); return(mockedRestClient.Object); }
public void GetRestaurantsByOutcode_Returns_Empty_List_When_API_Call_Fails() { // Given a failed api call, regardless of restaurant data returned var outcode = ""; var restaurantDataRoot = new RestaurantDataRoot(); var fakedRestClient = createFakedRestClient(restaurantDataRoot, HttpStatusCode.NotFound); var fakedRestClientFactory = createFakeRestClientFactory(fakedRestClient); // When we call the service method var restaurantService = new RestaurantService(fakedRestClientFactory, new JustEatRestRequestFactory()); var actual = restaurantService.GetRestaurantsByOutcode(outcode); // Then the restaurant list is empty var expected = new List <Restaurant>(); actual.ShouldBeEquivalentTo(expected); }