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);
        }
Exemple #2
0
        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>();
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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, "");
        }
Exemple #10
0
 public Restaurant GetRestaurantById(object id)
 {
     return(restrepo.GetById(id));
 }
Exemple #11
0
 public Task <Restaurant> GetRestaurantById(string id)
 {
     return(RestaurantRepository.GetById(id));
 }