public void Test_Delete_DeletesCuisinesFromDatabase()
        {
            string   name1         = "Ethiopian";
            Cuisines testCuisines1 = new Cuisines(name1);

            testCuisines1.Save();

            string   name2         = "Brazilian";
            Cuisines testCuisines2 = new Cuisines(name2);

            testCuisines2.Save();

            Restaurants testRestaurants1 = new Restaurants("Chipotle", "2nd and Stark", new DateTime(1980, 12, 11), "red", testCuisines1.GetId());

            testRestaurants1.Save();

            Restaurants testRestaurants2 = new Restaurants("BurgerKing", "Division and 95th", new DateTime(1921, 02, 23), "turqoiuse", testCuisines2.GetId());

            testRestaurants2.Save();

            testCuisines1.Delete();
            List <Cuisines> resultCuisines   = Cuisines.GetAll();
            List <Cuisines> testCuisinesList = new List <Cuisines> {
                testCuisines2
            };

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

            Assert.Equal(testCuisinesList, resultCuisines);
            Assert.Equal(testRestaurantsList, resultRestaurants);
        }
Ejemplo n.º 2
0
        public HomeModule()
        {
            Get ["/"] = _ => {
                List <Cuisines> allCuisines = Cuisines.GetAll();
                return(View ["index.cshtml", allCuisines]);
            };
            Get ["/cuisine/new"] = _ => {
                return(View ["cuisine_info.cshtml"]);
            };
            Post["/"] = _ => {
                Cuisines newCuisines = new Cuisines(Request.Form["cuisine-name"]);
                newCuisines.Save();
                List <Cuisines> allCuisines = Cuisines.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/cuisine/ClearAll"] = _ => {
                Cuisines.DeleteAll();
                return(View ["cuisineClearAll.cshtml"]);
            };
            Get["/cuisines/{id}"] = Parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var selectedCuisine   = Cuisines.Find(Parameters.id);
                var Cusinerestaturant = selectedCuisine.GetRestaurants();
                model.Add("cuisine", selectedCuisine);
                model.Add("restaurant", Cusinerestaturant);
                return(View["cuisine.cshtml", model]);
            };

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

            Post["/cuisines/viewRestaurant"] = Parameters => {
                DateTime    dt             = Convert.ToDateTime((string)Request.Form["date"]);
                Restaurants newRestaurants = new Restaurants(Request.Form["name"], Request.Form["location"], dt, Request.Form["color"], Request.Form["cuisines-Id"]);
                newRestaurants.Save();
                return(View["success.cshtml", newRestaurants]);
            };
            Get["cuisines/edit/{id}"] = Parameters => {
                Cuisines SelectedCuisines = Cuisines.Find(Parameters.id);
                return(View["cuisines_edit.cshtml", SelectedCuisines]);
            };

            Patch["/cuisines/edit/{id}"] = Parameters => {
                Cuisines newCusisines = Cuisines.Find(Parameters.id);
                newCusisines.Update(Request.Form["cuisine-name"]);
                return(View ["success.cshtml"]);
            };

            Get["cuisines/delete/{id}"] = parameters => {
                Cuisines SelectedCuisines = Cuisines.Find(parameters.id);
                return(View["cuisineDelete.cshtml", SelectedCuisines]);
            };
            Delete["cuisines/delete/{id}"] = parameters => {
                Cuisines SelectedCuisines = Cuisines.Find(parameters.id);
                SelectedCuisines.Delete();
                return(View["success.cshtml"]);
            };
        }
        public void Test_Save_SaveobjecttoDB()
        {
            Restaurants testingRestaurant = new Restaurants("Gimilis Ale House", "Middle Earth", new DateTime(1753, 2, 2), "Orc Blood", 1);

            testingRestaurant.Save();

            List <Restaurants> results = Restaurants.GetAll();
            List <Restaurants> test    = new List <Restaurants> {
                testingRestaurant
            };

            Assert.Equal(results, test);
        }
        public void Test_GetCuisines_RetrieveAllRestaurantsWithCuisines()
        {
            Cuisines testCuisines = new Cuisines("Indian");

            testCuisines.Save();

            Restaurants firstRestaurant = new Restaurants("TajMaHal", "2nd and Madison", new DateTime(2016, 2, 14), "blue", testCuisines.GetId());

            firstRestaurant.Save();
            Restaurants secondRestaurant = new Restaurants("TajMaBal", "3rd and Madison", new DateTime(2014, 8, 8), "red", testCuisines.GetId());

            secondRestaurant.Save();

            List <Restaurants> testRestaurantsList = new List <Restaurants> {
                firstRestaurant, secondRestaurant
            };
            List <Restaurants> resultRestaurantsList = testCuisines.GetRestaurants();

            Assert.Equal(testRestaurantsList, resultRestaurantsList);
        }