Пример #1
0
        public void Test_Find_FindsReviewsByRestaurantIdInDatabase()
        {
            // Arrange
            Restaurant testRestaurant = new Restaurant("Pizza Factory", "5th Street", "530-816-9999", 0);

            testRestaurant.Save();
            Review testReview = new Review("Their pizza was marvelous", 4, testRestaurant.GetId());

            testReview.Save();
            Review testReview1 = new Review("Their pizza was bland", 2, testRestaurant.GetId());

            testReview1.Save();
            Review testReview2 = new Review("Best pizza ever", 5, testRestaurant.GetId());

            testReview2.Save();
            Review testReview3 = new Review("Great Spaghetti", 3, 0);

            testReview3.Save();

            // Act
            List <Review> checkReviews = new List <Review> {
                testReview, testReview1, testReview2
            };
            List <Review> foundReviews = Review.FindAll(testRestaurant.GetId());

            // Assert
            Assert.Equal(checkReviews, foundReviews);
        }
Пример #2
0
        public void Test_Review_Save_CheckIfSavedReview()
        {
            // Arrange
            Review firstReview = new Review("Their pizza was marvelous", 4, 0);

            firstReview.Save();

            // Act
            Review result = Review.GetAll()[0];

            // Assert
            Assert.Equal(firstReview, result);
        }
Пример #3
0
        public void Test_Review_DeleteFromDatabaseByReviewId()
        {
            // Arrange
            Restaurant testRestaurant = new Restaurant("Pizza Factory", "5th Street", "530-816-9999", 0);

            testRestaurant.Save();
            Review testReview = new Review("Their pizza was marvelous", 4, testRestaurant.GetId());

            testReview.Save();
            Review testReview1 = new Review("First time was great, second time their pizza was bland", 2, testRestaurant.GetId());

            testReview1.Save();

            // Act
            testReview.DeleteReview();

            // Assert
            Assert.Equal(1, Restaurant.GetAll().Count);
        }
Пример #4
0
        public void Test_Review_Update_ChangeReviewInfo()
        {
            // Arrange
            Restaurant testRestaurant = new Restaurant("Pizza Factory", "5th Street", "530-816-9999", 0);

            testRestaurant.Save();
            Review testReview = new Review("Their pizza was marvelous", 4, testRestaurant.GetId());

            testReview.Save();
            Review testReview1 = new Review("First time was great, second time their pizza was bland", 2, testRestaurant.GetId());

            testReview1.Save();

            // Act
            testReview.Update("First time was great, second time their pizza was bland", 2);
            // testReview.SetId(testRestaurant.GetId());
            // testReview1.SetId(testRestaurant.GetId());

            // Assert
            Assert.Equal(testReview.GetReview(), testReview1.GetReview());
        }
Пример #5
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/cuisine/form"] = _ => {
                return(View["cuisine_form.cshtml"]);
            };
            Get["/restaurant/form"] = _ => {
                return(View["restaurant_form.cshtml"]);
            };
            Get["/cuisines"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Post["/cuisines"] = _ => {
                Cuisine newCuisine = new Cuisine(Request.Form["cuisine"]);
                newCuisine.Save();
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/restaurants"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Post["/restaurants"] = _ => {
                if (Cuisine.IsNewCuisine(Request.Form["restaurant-cuisine"]) != -1)
                {
                    Restaurant newRestaurant = new Restaurant(
                        Request.Form["restaurant-name"],
                        Request.Form["restaurant-address"],
                        Request.Form["restaurant-phonenumber"],
                        Cuisine.IsNewCuisine(Request.Form["restaurant-cuisine"]));
                    newRestaurant.Save();
                }
                else
                {
                    Cuisine newCuisine = new Cuisine(Request.Form["restaurant-cuisine"]);
                    newCuisine.Save();
                    Restaurant newRestaurant = new Restaurant(
                        Request.Form["restaurant-name"],
                        Request.Form["restaurant-address"],
                        Request.Form["restaurant-phonenumber"],
                        Cuisine.IsNewCuisine(Request.Form["restaurant-cuisine"]));
                    newRestaurant.Save();
                }

                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/cuisine/{id}"] = parameters =>
            {
                Cuisine newCuisine = Cuisine.Find(parameters.id);
                return(View["cuisine.cshtml", newCuisine]);
            };
            Post["/delete/cuisine/{id}"] = parameters =>
            {
                Cuisine targetCuisine = Cuisine.Find(parameters.id);
                targetCuisine.DeleteCuisineAndRestaurants();
                return(View["index.cshtml", Cuisine.GetAll()]);
            };
            Post["/delete/restaurant/{id}"] = parameters =>
            {
                Restaurant targetRestaurant = Restaurant.Find(parameters.id);
                int        cuisineId        = targetRestaurant.GetCuisineId();
                Restaurant.Delete(parameters.id);
                return(View["cuisine.cshtml", Cuisine.Find(cuisineId)]);
            };
            Get["/review/restaurant/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Restaurant    targetRestaurant    = Restaurant.Find(parameters.id);
                List <Review> allReviews          = Review.FindAll(parameters.id);
                model.Add("restaurant", targetRestaurant);
                model.Add("reviews", allReviews);
                return(View["restaurant.cshtml", model]);
            };
            Post["/review/restaurant/{id}"] = parameters =>
            {
                Review newReview = new Review(Request.Form["review"], Request.Form["stars"], parameters.id);
                newReview.Save();
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Restaurant    targetRestaurant    = Restaurant.Find(parameters.id);
                List <Review> allReviews          = Review.FindAll(parameters.id);
                model.Add("restaurant", targetRestaurant);
                model.Add("reviews", allReviews);
                return(View["restaurant.cshtml", model]);
            };
            Post["/update/cuisine/{id}"] = parameters =>
            {
                Cuisine updatedCuisine = Cuisine.Find(parameters.id);
                updatedCuisine.Update(Request.Form["updated-name"]);
                return(View["cuisine.cshtml", updatedCuisine]);
            };
        }