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

            Post["/cuisine"] = _ => {
                Cuisine newcuisine = new Cuisine(Request.Form["cuisine"]);
                newcuisine.Save();
                return(View["cuisine.cshtml", newcuisine]);
            };

            Get["/delete_all"] = _ => {
                Cuisine.DeleteAll();
                return(View["index.cshtml"]);
            };

            Post["/rest_results"] = _ => {
                Restaurant newRestaurant = new Restaurant(Request.Form["restaurant"], Request.Form["cuisine_id"], Request.Form["description"], Request.Form["phone_number"]);
                newRestaurant.Save();
                List <Restaurant> FoundRestaurants = Restaurant.GetByCuisineId(Request.Form["cuisine_id"]);
                return(View["rest_results.cshtml", FoundRestaurants]);
            };

            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["updated_cuisine.cshtml", SelectedCuisine]);
            };

            Delete["/restaurant/delete/{id}"] = parameters => {
                Restaurant SelectedRestaurant = Restaurant.Find(parameters.id);
                SelectedRestaurant.Delete();
                List <Restaurant> allRestaurants = Restaurant.GetAll();
                return(View["rest_del_success.cshtml", allRestaurants]);
            };

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

            Delete["/cuisine_delete/{id}"] = parameters => {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                SelectedCuisine.Delete();
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["cuisines.cshtml", allCuisines]);
            };

            Get["/show_all"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["cuisines.cshtml", allCuisines]);
            };
        }
Beispiel #2
0
        public void Test_DatabaseEmptyAtFirst()
        {
            //Arrange, Act
            int result = Restaurant.GetAll().Count;

            //Assert
            Assert.Equal(0, result);
        }
Beispiel #3
0
        public void Test_DeleteAll_DeletesAllRestaurantsInDatabase()
        {
            //Arrange
            RestaurantTest testRestaurant = new RestaurantTest();

            testRestaurant.Dispose();

            //Act
            int result = Restaurant.GetAll().Count;

            //Assert
            Assert.Equal(0, result);
        }
Beispiel #4
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
            Restaurant testRestaurant = new Restaurant("larrys Hoagies", 1, "awesome hoagies", 5555555);

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

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

            //Assert
            Assert.Equal(testId, result);
        }
Beispiel #5
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
            Restaurant testRestaurant = new Restaurant("Larrys Hoagies", 1, "awesome hoagies", 5555555);

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

            //Assert
            Assert.Equal(testList[0].GetName(), result[0].GetName());
        }