public void GetById_GivenRestaurantId_ReturnsCorrectRestuarant() { var restaurant = new Restaurant { RestaurantId = Guid.NewGuid(), RestaurantPublicId = Guid.NewGuid() }; _textContext.Restaurants.Add(restaurant); _textContext.SaveChanges(); var result = _restaurantRepository.GetById(restaurant.RestaurantPublicId); Assert.AreEqual(restaurant, result); }
public void edit_post_should_return_http_not_found_when_restaurantID_is_not_valid() { //Arrange var restaurantViewModel = Fixture.Create <RestaurantEditViewModel>(); RestaurantRepository.GetById(Arg.Any <int>()).Returns(x => null); //Act var result = RestaurantController.Edit(restaurantViewModel); //Assert result.Should().BeOfType <HttpNotFoundResult>(); }
public void edit_post_should_update_restaurant_when_restaurantId_is_valid() { //Arrange var restaurant = Fixture.Create <Restaurant>(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); var restaurantViewModel = Mapper.Map <RestaurantEditViewModel>(restaurant); //Action var actionResult = RestaurantController.Edit(restaurantViewModel); // Assert RestaurantRepository.Received().Update(Arg.Is <Restaurant>(x => x.Id == restaurant.Id)); }
public void delete_post_should_redirect_to_index_on_success() { //Arrange var restaurant = Fixture.Create <Restaurant>(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); //Act var routeResult = RestaurantController.DeleteConfirmed(restaurant.Id) as RedirectToRouteResult; var routeAction = routeResult.RouteValues["Action"]; //Assert routeAction.ShouldBeEquivalentTo(MVC.Home.Views.ViewNames.Index); }
public void delete_post_should_remove_restaurant() { //Arrange var restaurant = Fixture.Create <Restaurant>(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); //Action RestaurantController.DeleteConfirmed(restaurant.Id); // Assert RestaurantRepository.Received().Delete(restaurant); }
public void delete_restaurant_should_return_view_when_restaurantID_is_valid() { //Arrange var restaurant = Fixture.Create <Restaurant>(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); //Action var result = RestaurantController.Delete(restaurant.Id) as ViewResult; var restaurantViewModel = result.ViewData.Model as RestaurantDeleteViewModel; //Assert restaurantViewModel.ShouldBeEquivalentTo(restaurant); }
public void edit_post_should_redirect_to_index_on_success() { //Arrange var restaurant = Fixture.Create <Restaurant>(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); var restaurantEditPageViewModel = Mapper.Map <RestaurantEditViewModel>(restaurant); //Act var routeResult = RestaurantController.Edit(restaurantEditPageViewModel) as RedirectToRouteResult; var routeAction = routeResult.RouteValues["Action"]; //Assert routeAction.Should().Be(MVC.Home.Views.ViewNames.Index); }
public void edit_should_return_view_with_restaurantViewModel_when_restaurantId_is_valid() { //Arrange var restaurant = Fixture.Create <Restaurant>(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); var viewModelExpected = Mapper.Map <RestaurantEditViewModel>(restaurant); //Action var viewResult = RestaurantController.Edit(restaurant.Id) as ViewResult; var viewModelObtained = viewResult.ViewData.Model as RestaurantEditViewModel; //Assert viewModelObtained.ShouldBeEquivalentTo(viewModelExpected); }
public void edit_post_should_return_default_view_when_modelState_is_not_valid() { //Arrange var restaurant = Fixture.Create <Restaurant>(); var restaurantViewModel = Fixture.Build <RestaurantEditViewModel>() .With(x => x.Id, restaurant.Id) .Create(); RestaurantRepository.GetById(restaurant.Id).Returns(restaurant); RestaurantController.ModelState.AddModelError("Error", "Error"); //Act var result = RestaurantController.Edit(restaurantViewModel) as ViewResult; //Assert Assert.AreEqual(result.ViewName, ""); }
public Restaurant GetRestaurantById(object id) { return(restrepo.GetById(id)); }
public Task <Restaurant> GetRestaurantById(string id) { return(RestaurantRepository.GetById(id)); }