Beispiel #1
0
        public void Test_Delete_DeletesCuisineAndAssociatedRestaurantsFromDatabase()
        {
            Cuisine cuisine1 = new Cuisine("Japanese");
            Cuisine cuisine2 = new Cuisine("Italian");

            cuisine1.Save();
            cuisine2.Save();

            Restaurant restaurant1 = new Restaurant("Tako", "Not a place to get tacos.", "$", cuisine1.GetId());
            Restaurant restaurant2 = new Restaurant("Mario\'s", "Fresh pasta, fresher sauce.", "$$", cuisine2.GetId());
            Restaurant restaurant3 = new Restaurant("Peperoncini", "Focused on the flavor of tasty peperoncini.", "$", cuisine2.GetId());

            restaurant1.Save();
            restaurant2.Save();
            restaurant3.Save();

            cuisine2.Delete();
            List <Cuisine> expectedCuisines = new List <Cuisine> {
                cuisine1
            };
            List <Cuisine> cuisineResults = Cuisine.GetAll();

            List <Restaurant> expectedRestaurants = new List <Restaurant> {
                restaurant1
            };
            List <Restaurant> restaurantResults = Restaurant.GetAll();

            Assert.Equal(expectedCuisines, cuisineResults);
            Assert.Equal(expectedRestaurants, restaurantResults);
        }
        public void Test_SaveAssignsIdtoObject()
        {
            Restaurant testRestaurant = new Restaurant("GreatWall", "Buffet", 1);

            testRestaurant.Save();

            Restaurant savedRestaurant = Restaurant.GetAll()[0];

            int result = savedRestaurant.GetId();
            int testId = testRestaurant.GetId();

            Assert.Equal(testId, result);
        }
        public void Test_Save()
        {
            Restaurant testRestaurant = new Restaurant("GreatWall", "Buffet", 1);

            testRestaurant.Save();

            List <Restaurant> result   = Restaurant.GetAll();
            List <Restaurant> testList = new List <Restaurant> {
                testRestaurant
            };

            Assert.Equal(testList, result);
        }
        public void Test_Save_AssignsIdToRestaurantObject()
        {
            Restaurant testRestaurant = new Restaurant("Tako", "Not a place to get tacos.", "$", 1);

            testRestaurant.Save();

            Restaurant savedRestaurant = Restaurant.GetAll()[0];

            int testId = testRestaurant.GetId();
            int result = savedRestaurant.GetId();

            Assert.Equal(testId, result);
        }
        public void Test_Save_SavesRestaurantToDatabase()
        {
            Restaurant testRestaurant = new Restaurant("Tako", "Not a place to get tacos.", "$", 1);

            testRestaurant.Save();

            List <Restaurant> result   = Restaurant.GetAll();
            List <Restaurant> testList = new List <Restaurant> {
                testRestaurant
            };

            Assert.Equal(testList, result);
        }
        public void Test_Save_AssignsIdToRestaurantObject()
        {
            //Arrange
            Restaurant testRestaurant = new Restaurant("Departure", "desc2", 2);

            testRestaurant.Save();

            //Act
            Restaurant savedRestaurant = Restaurant.GetAll()[0];

            int result = savedRestaurant.GetId();
            int testId = testRestaurant.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
        public void Test_Save_SavesRestaurantToDatabase()
        {
            //Arrange
            Restaurant testRestaurant = new Restaurant("Killer burger", "desc1", 1);

            testRestaurant.Save();

            //Act
            List <Restaurant> result   = Restaurant.GetAll();
            List <Restaurant> testList = new List <Restaurant> {
                testRestaurant
            };

            //Assert
            Assert.Equal(testList, result);
        }
        public void Test_Delete_RestaurantName()
        {
            Restaurant testRestaurant1 = new Restaurant("Chinese Food", "buffet", 1);

            testRestaurant1.Save();
            Restaurant testRestaurant2 = new Restaurant("Indian Food", "buffet", 1);

            testRestaurant2.Save();
            testRestaurant2.Delete();

            List <Restaurant> testCousineList = new List <Restaurant> {
                testRestaurant1
            };
            List <Restaurant> testCousineList2 = Restaurant.GetAll();

            Assert.Equal(testCousineList, testCousineList2);
        }
        public void Test_Delete_DeletesIndividualRestaurantFromDatabase()
        {
            Restaurant restaurant1 = new Restaurant("Tako", "Not a place to get tacos.", "$", 1);
            Restaurant restaurant2 = new Restaurant("Mario\'s", "Fresh pasta, fresher sauce.", "$$", 1);
            Restaurant restaurant3 = new Restaurant("Peperoncini", "Focused on the flavor of tasty peperoncini.", "$", 1);

            restaurant1.Save();
            restaurant2.Save();
            restaurant3.Save();

            restaurant2.Delete();
            List <Restaurant> expectedRestaurants = new List <Restaurant> {
                restaurant1, restaurant3
            };
            List <Restaurant> restaurantResults = Restaurant.GetAll();

            Assert.Equal(expectedRestaurants, restaurantResults);
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Restaurant> allRestaurants = Restaurant.GetAll();
                return(View["index.cshtml", allRestaurants]);
            };

            Get["/cuisines/new"] = _ => {
                return(View["cuisine_form.cshtml"]);
            };

            Post["/cuisines/added"] = _ => {
                string cuisineName = Request.Form["cuisine-name"];

                Cuisine newCuisine = new Cuisine(cuisineName);
                return(View["cuisine_added.cshtml", newCuisine]);
            };

            Get["/restaurants/new"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["restaurant_form.cshtml", allCuisines]);
            };

            Post["/restaurants/added"] = _ => {
                string restaurantName        = Request.Form["restaurant-name"];
                string restaurantDescription = Request.Form["restaurant-description"];
                string restaurantPrice       = Request.Form["restaurant-price"];
                int    restaurantCuisineId   = Request.Form["restaurant-cuisine"];

                Restaurant newRestaurant = new Restaurant(restaurantName, restaurantDescription, restaurantPrice, restaurantCuisineId);
                newRestaurant.Save();
                return(View["restaurant_added.cshtml", newRestaurant]);
            };

            Get["/cuisines"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["cuisines.cshtml", allCuisines]);
            };
        }
        public void Test_Update_UpdatesRestaurantInDatabase()
        {
            string     name           = "Tako";
            string     description    = "Not a place to get tacos.";
            string     price          = "$$";
            int        cuisineId      = 1;
            Restaurant testRestaurant = new Restaurant(name, description, price, cuisineId);

            testRestaurant.Save();

            string newName        = "Mario\'s";
            string newDescription = "Fresh pasta, fresh sauce.";
            string newPrice       = "$";
            int    newCuisineId   = 2;

            testRestaurant.Update(newName, newDescription, newPrice, newCuisineId);

            Restaurant result               = Restaurant.GetAll()[0];
            int        compareId            = result.GetId();
            Restaurant comparisonRestaurant = new Restaurant(newName, newDescription, newPrice, newCuisineId, compareId);

            Assert.Equal(comparisonRestaurant, result);
        }
        public void Test_RestaurantsEmptyAtFirst_0()
        {
            int result = Restaurant.GetAll().Count;

            Assert.Equal(0, result);
        }
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };

            Get["/restaurants"] = _ =>
            {
                List <Restaurant> allRestaurants = Restaurant.GetAll();
                return(View["restaurants.cshtml", allRestaurants]);
            };

            Get["/cuisines"] = _ =>
            {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["cuisines.cshtml", allCuisines]);
            };

            Get["/cuisines/new"] = _ =>
            {
                return(View["cuisines_form.cshtml"]);
            };

            Post["/cuisines/new"] = _ =>
            {
                Cuisine newCuisine = new Cuisine(Request.Form["cuisine-name"]);
                newCuisine.Save();
                return(View["success.cshtml"]);
            };

            Get["/review/new"] = _ =>
            {
                List <Restaurant> allRestaurants = Restaurant.GetAll();
                return(View["review_form.cshtml", allRestaurants]);
            };

            Post["/review/new"] = _ =>
            {
                Review newReview = new Review(Request.Form["review-description"], Request.Form["restaurant-id"]);
                newReview.Save();
                return(View["success.cshtml"]);
            };

            Get["/restaurants/new"] = _ =>
            {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["restaurants_form.cshtml", allCuisines]);
            };

            Post["/restaurants/new"] = _ =>
            {
                Restaurant newRestaurant = new Restaurant(Request.Form["restaurant-name"], Request.Form["restaurant-description"], Request.Form["cuisine-id"]);
                newRestaurant.Save();
                return(View["success.cshtml"]);
            };

            Post["/restaurants/delete"] = _ =>
            {
                Restaurant.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            Get["/restaurant/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedRestaurant            = Restaurant.Find(parameters.id);
                var RestaurantReviews             = SelectedRestaurant.GetReviews();
                model.Add("restaurant", SelectedRestaurant);
                model.Add("review", RestaurantReviews);
                return(View["restaurant.cshtml", model]);
            };

            Get["/cuisines/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedCuisine    = Cuisine.Find(parameters.id);
                var CuisineRestaurants = SelectedCuisine.GetRestaurants();
                model.Add("cuisine", SelectedCuisine);
                model.Add("restaurants", CuisineRestaurants);
                return(View["cuisine.cshtml", model]);
            };

            Post["/cuisines/delete"] = _ =>
            {
                Cuisine.DeleteAll();
                return(View["cleraed.cshtml"]);
            };

            Get["cuisine/edit/{id}"] = parameters =>
            {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                return(View["cuisine_edit.cshtml", SelectedCuisine]);
            };

            Patch["cuisine/edit/{id}"] = parameters =>
            {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                SelectedCuisine.Update(Request.Form["cuisine-name"]);
                return(View["success.cshtml"]);
            };

            Get["cuisine/delete/{id}"] = parameters =>
            {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                return(View["cuisine_delete.cshtml", SelectedCuisine]);
            };

            Delete["cuisine/delete/{id}"] = parameters =>
            {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                SelectedCuisine.Delete();
                return(View["success.cshtml"]);
            };

            Get["restaurant/edit/{id}"] = parameters =>
            {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                return(View["restaurant_edit.cshtml", SelectedRestaurant]);
            };

            Patch["restaurant/edit/{id}"] = parameters =>
            {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                SelectedRestaurant.Update(Request.Form["restaurant-name"], Request.Form["restaurant-description"]);
                return(View["success.cshtml"]);
            };

            Get["restaurant/delete/{id}"] = parameters =>
            {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                return(View["restaurant_delete.cshtml", SelectedRestaurant]);
            };

            Delete["restaurant/delete/{id}"] = parameters =>
            {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                SelectedRestaurant.Delete();
                return(View["success.cshtml"]);
            };

            Get["review/edit/{id}"] = parameters =>
            {
                Review selectedReview = Review.Find(parameters.id);
                return(View["review_edit.cshtml", selectedReview]);
            };

            Patch["review/edit/{id}"] = parameters =>
            {
                Review selectedReview = Review.Find(parameters.id);
                selectedReview.Update(Request.Form["review-description"]);
                return(View["success.cshtml"]);
            };

            Get["review/delete/{id}"] = parameters =>
            {
                Review selectedReview = Review.Find(parameters.id);
                return(View["review_delete.cshtml", selectedReview]);
            };

            Delete["review/delete/{id}"] = parameters =>
            {
                Review selectedReview = Review.Find(parameters.id);
                selectedReview.Delete();
                return(View["success.cshtml"]);
            };
        }