Пример #1
0
        public void Test_Delete_DeletesRestaurantFromDatabase()
        {
            //Arrange
            string  name1        = "Thai";
            Cuisine testCuisine1 = new Cuisine(name1);

            testCuisine1.Save();

            string  name2        = "Italian";
            Cuisine testCuisine2 = new Cuisine(name2);

            testCuisine2.Save();

            Restaurant testRestaurants1 = new Restaurant("RedLobster", "happyStreet", "333444343", testCuisine1.GetId());

            testRestaurants1.Save();
            Restaurant testRestaurants2 = new Restaurant("GreenLobster", "happyStreet", "333444343", testCuisine2.GetId());

            testRestaurants2.Save();

            //Act
            testRestaurants1.Delete();
            // List<Cuisine> resultCuisines = Cuisine.GetAll();
            // List<Cuisine> testCuisineList = new List<Cuisine> {testCuisine2};

            List <Restaurant> resultRestaurants   = Restaurant.GetAll();
            List <Restaurant> testRestaurantsList = new List <Restaurant> {
                testRestaurants2
            };

            //Assert
            // Assert.Equal(testCuisineList, resultCuisines);
            Assert.Equal(testRestaurantsList, resultRestaurants);
        }
Пример #2
0
        public void Test_Find_FindsRestaurantInDatabase()
        {
            //Arrange
            Restaurant testRestaurant = new Restaurant("Red Lobster", "SW Funtime Lane", "503-555-5555", 3);

            testRestaurant.Save();

            //Act
            Restaurant foundRestaurant = Restaurant.Find(testRestaurant.getID());

            //Assert
            Assert.Equal(testRestaurant, foundRestaurant);
        }
Пример #3
0
        public void Test_To_Assign_ID()
        {
            //Arrange, Act
            Restaurant restaurant = new Restaurant("Red Lobster", "SW Funtime Lane", "503-555-5555", 3);

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

            int testID = restaurant.getID();
            int result = savedRestaurant.getID();

            //Assert
            Assert.Equal(testID, result);
        }
Пример #4
0
        public void Test_To_Find_if_Restaurant_is_saving()
        {
            //Arrange, Act
            Restaurant firstRestaurant = new Restaurant("Red Lobster", "SW Funtime Lane", "503-555-5555", 3);

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

            //Assert
            Assert.Equal(testList, result);
        }
Пример #5
0
        public void Test_Update_UpdatesCuisineInDatabase()
        {
            string  name1        = "Thai";
            Cuisine testCuisine1 = new Cuisine(name1);

            testCuisine1.Save();
            //Arrange
            string     name           = "RedLobster";
            Restaurant testRestaurant = new Restaurant(name, "happyStreet", "333444343", testCuisine1.GetId());

            testRestaurant.Save();
            string newName = "GreenLobster";

            //Act
            testRestaurant.UpdateName(newName);

            string result = testRestaurant.getName();

            //Assert
            Assert.Equal(newName, result);
        }
Пример #6
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

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

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

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

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

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

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

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

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

            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["/restaurants/edit/{id}"] = parameters => {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                return(View["restaurant_edit.cshtml", SelectedRestaurant]);
            };
            Patch["/restaurants/edit/{id}"] = parameters => {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                SelectedRestaurant.UpdateName(Request.Form["edit"]);
                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["/restaurant/{id}/reviews"] = parameters => {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                return(View["review_form.cshtml", SelectedRestaurant]);
            };

            Post["/restaurant/{id}/reviews"] = parameters => {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                int        id        = SelectedRestaurant.getID();
                Review     newReview = new Review(Request.Form["reviewNumber"], id);
                newReview.Save();
                return(View["success.cshtml"]);
            };
        }