Esempio n. 1
0
        public void Test_Find_FindsResturantInDatabase()
        {
            //Arrange
            Resturant testResturant = new Resturant("Mow the lawn", "Ello", 1);

            testResturant.Save();

            //Act
            Resturant foundResturant = Resturant.Find(testResturant.GetId());

            //Assert
            Assert.Equal(testResturant, foundResturant);
        }
Esempio n. 2
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
            Resturant testResturant = new Resturant("Mow the lawn", "ello", 1);

            //Act
            testResturant.Save();
            Resturant savedResturant = Resturant.GetAll()[0];

            int result = savedResturant.GetId();
            int testId = testResturant.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Esempio n. 3
0
        public void Test_GetResturants_RetrievesAllResturantsWithCuisine()
        {
            Cuisine testCuisine = new Cuisine("Household chores");

            testCuisine.Save();

            Resturant firstResturant = new Resturant("Mow the lawn", "ello", testCuisine.GetId());

            firstResturant.Save();

            Resturant secondResturant = new Resturant("Do the dishes", "ello", testCuisine.GetId());

            secondResturant.Save();

            List <Resturant> testResturantList = new List <Resturant> {
                firstResturant, secondResturant
            };
            List <Resturant> resultResturantList = testCuisine.GetResturants();

            Assert.Equal(testResturantList, resultResturantList);
        }
Esempio n. 4
0
        public void Test_Delete_DeletesCuisineFromDatabase()
        {
            //Arrange
            string  name1        = "Home stuff";
            Cuisine testCuisine1 = new Cuisine(name1);

            testCuisine1.Save();

            string  name2        = "Work stuff";
            Cuisine testCuisine2 = new Cuisine(name2);

            testCuisine2.Save();

            Resturant testResturant1 = new Resturant("Mow the lawn", "yep", testCuisine1.GetId());

            testResturant1.Save();
            Resturant testResturant2 = new Resturant("Send emails", "stuff", testCuisine2.GetId());

            testResturant2.Save();

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

            List <Resturant> resultResturants  = Resturant.GetAll();
            List <Resturant> testResturantList = new List <Resturant> {
                testResturant2
            };

            //Assert
            Assert.Equal(testCuisineList, resultCategories);
            Assert.Equal(testResturantList, resultResturants);
        }
Esempio n. 5
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Cuisine> AllCuisines = Cuisine.GetAll();
                return(View["index.cshtml", AllCuisines]);
            };
            Get["/resturants"] = _ => {
                List <Resturant> AllResturants = Resturant.GetAll();
                return(View["resturants.cshtml", AllResturants]);
            };
            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["/resturants/new"] = _ => {
                List <Cuisine> AllCuisines = Cuisine.GetAll();
                return(View["resturants_form.cshtml", AllCuisines]);
            };
            Post["/resturants/new"] = _ => {
                DateTime  newDate      = new DateTime(Request.Form["new-year"], Request.Form["new-month"], Request.Form["new-day"]);
                Resturant newResturant = new Resturant(Request.Form["resturant-name"], Request.Form["resturant-location"], Request.Form["cuisine-id"], newDate);
                newResturant.Save();
                return(View["success.cshtml"]);
            };
            Post["/resturants/delete"] = _ => {
                Resturant.DeleteAll();
                return(View["cleared.cshtml"]);
            };
            Post["/cuisines/clear"] = _ => {
                Cuisine.DeleteAll();
                return(View["cuisines_cleared.cshtml"]);
            };

            Get["/cuisines/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedCuisine   = Cuisine.Find(parameters.id);
                var CuisineResturants = SelectedCuisine.GetResturants();
                model.Add("cuisine", SelectedCuisine);
                model.Add("resturants", CuisineResturants);
                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"]);
            };
        }