public void Test_Equal_ReturnsTrueIfNameSame()
        {
            Restaurants firstRestaurants  = new Restaurants("Carl's Jr.", "Canada", new DateTime(1999, 12, 15), "orange", 1);
            Restaurants secondRestaurants = new Restaurants("Carl's Jr.", "Canada", new DateTime(1999, 12, 15), "orange", 1);

            Assert.Equal(firstRestaurants, secondRestaurants);
        }
        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);
        }
        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);
        }
Пример #5
0
 public override bool Equals(System.Object otherRestaurants)
 {
     if (!(otherRestaurants is Restaurants))
     {
         return(false);
     }
     else
     {
         Restaurants newRestaurants    = (Restaurants)otherRestaurants;
         bool        idEquality        = this.GetId() == newRestaurants.GetId();
         bool        idCuisineEquality = this.GetCuisineId() == newRestaurants.GetCuisineId();
         bool        nameEquality      = this.GetName() == newRestaurants.GetName();
         bool        locationEquality  = this.GetLocation() == newRestaurants.GetLocation();
         bool        dateEquality      = this.GetOpeningDate() == newRestaurants.GetOpeningDate();
         bool        colorEquality     = this.GetColor() == newRestaurants.GetColor();
         return(idEquality && nameEquality && locationEquality && dateEquality && colorEquality);
     }
 }
Пример #6
0
        public static Restaurants Find(int id)
        {
            SqlConnection conn = DB.Connection();
            SqlDataReader rdr  = null;

            conn.Open();

            SqlCommand   cmd = new SqlCommand("SELECT * FROM restaurants WHERE id= @RestaurantsId;", conn);
            SqlParameter RestaurantsIdParameter = new SqlParameter();

            RestaurantsIdParameter.ParameterName = "@RestaurantsId";
            RestaurantsIdParameter.Value         = id.ToString();
            cmd.Parameters.Add(RestaurantsIdParameter);
            rdr = cmd.ExecuteReader();

            int      foundRestaurantsId       = 0;
            string   foundRestaurantsName     = null;
            string   foundRestaurantsLocation = null;
            DateTime foundRestaurantsDate     = new DateTime(2016 - 02 - 23);
            string   foundRestaurantsColor    = null;
            int      foundCuisinesId          = 0;

            while (rdr.Read())
            {
                foundRestaurantsId       = rdr.GetInt32(0);
                foundRestaurantsName     = rdr.GetString(1);
                foundRestaurantsLocation = rdr.GetString(2);
                foundRestaurantsColor    = rdr.GetString(3);
                foundRestaurantsDate     = rdr.GetDateTime(4);
                foundCuisinesId          = rdr.GetInt32(5);
            }
            Restaurants foundRestaurants = new Restaurants(foundRestaurantsName, foundRestaurantsLocation, foundRestaurantsDate, foundRestaurantsColor, foundCuisinesId, foundRestaurantsId);

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
            return(foundRestaurants);
        }
        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);
        }
Пример #8
0
        public List <Restaurants> GetRestaurants()
        {
            SqlConnection conn = DB.Connection();
            SqlDataReader rdr  = null;

            conn.Open();

            SqlCommand   cmd = new SqlCommand("SELECT * FROM restaurants WHERE cuisine_Id = @CuisinesId ORDER BY name DESC;", conn);
            SqlParameter CuisinesIdParameter = new SqlParameter();

            CuisinesIdParameter.ParameterName = "@CuisinesId";
            CuisinesIdParameter.Value         = this.GetId();
            cmd.Parameters.Add(CuisinesIdParameter);
            rdr = cmd.ExecuteReader();

            List <Restaurants> restaurants = new List <Restaurants> {
            };

            while (rdr.Read())
            {
                int         RestaurantsId       = rdr.GetInt32(0);
                string      RestaurantsName     = rdr.GetString(1);
                string      RestaurantsLocation = rdr.GetString(2);
                string      RestaurantsColor    = rdr.GetString(4);
                int         cuisineId           = rdr.GetInt32(5);
                DateTime    RestaurantsDate     = rdr.GetDateTime(3);
                Restaurants newRestaurants      = new Restaurants(RestaurantsName, RestaurantsLocation, RestaurantsDate, RestaurantsColor, cuisineId, RestaurantsId);
                restaurants.Add(newRestaurants);
            }
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
            return(restaurants);
        }
Пример #9
0
        public static List <Restaurants> GetAll()
        {
            List <Restaurants> allRestaurants = new List <Restaurants> {
            };

            SqlConnection conn = DB.Connection();
            SqlDataReader rdr  = null;

            conn.Open();

            SqlCommand cmd = new SqlCommand("Select * FROM restaurants ORDER BY name DESC;", conn);

            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int      RestaurantsId        = rdr.GetInt32(0);
                string   RestaurantsName      = rdr.GetString(1);
                string   RestaurantsLocation  = rdr.GetString(2);
                DateTime RestaurantsDate      = rdr.GetDateTime(3);
                string   RestaurantsColor     = rdr.GetString(4);
                int      RestaurantsCuisineId = rdr.GetInt32(5);

                Restaurants newRestaurants = new Restaurants(RestaurantsName, RestaurantsLocation, RestaurantsDate, RestaurantsColor, RestaurantsCuisineId, RestaurantsId);
                allRestaurants.Add(newRestaurants);
            }
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
            return(allRestaurants);
        }
 public void Dispose()
 {
     Restaurants.DeleteAll();
     Cuisines.DeleteAll();
 }
        public void Test_DatabaseEmptyAtFirst()
        {
            int result = Restaurants.GetAll().Count;

            Assert.Equal(0, result);
        }