public void Index() { // Arrange var mockClient = new Mock<IRestClient>(); var restaurantService = new RestaurantService(mockClient.Object); var controller = new HomeController(restaurantService); // Act var result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void GetRestaurantsByOutcode_Should_Returns_Data_For_The_Outcode_SE19() { // Given a valid outcode var outcode = "SE19"; // When we call the service var client = new RestSharpClient(); var restaurantService = new RestaurantService(client); var results = restaurantService.GetRestaurantsByOutcode(outcode); // Then the restaurant list is not null and not empty Assert.IsNotNull(results); Assert.Greater(results.Count, 0); }
public void GetRestaurantsByOutcode_Should_Returns_Restaurants_When_API_Call_Succeeds() { // Given a valid outcode var outcode = "SE19"; // When we call the service var mockClient = new Mock<IRestClient>(); var dummyRestaurants = GetDummyListOfRestaurants(); mockClient.Setup(r => r.Execute<List<Restaurant>>("restaurants", "Restaurants", RestMethod.Get, It.IsAny<Dictionary<string,object>>(), It.IsAny<Dictionary<string, string>>())) .Returns(dummyRestaurants); var restaurantService = new RestaurantService(mockClient.Object); var actual = restaurantService.GetRestaurantsByOutcode(outcode); // Then the restaurant list is not null and not empty Assert.IsNotNull(actual); Assert.Greater(actual.Count, 0); // And the restaurant list is as expected var expected = dummyRestaurants; actual.ShouldBeEquivalentTo(expected); }