示例#1
0
        public void Test_Equal_ReturnsTrueIfDescriptionsAreTheSame()
        {
            //Arrange, Act
            Resturant firstResturant  = new Resturant("Mow the lawn", "ello", 1);
            Resturant secondResturant = new Resturant("Mow the lawn", "ello", 1);

            //Assert
            Assert.Equal(firstResturant, secondResturant);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
0
 //equals override
 public override bool Equals(System.Object otherResturant)
 {
     if (!(otherResturant is Resturant))
     {
         return(false);
     }
     else
     {
         Resturant newResturant     = (Resturant)otherResturant;
         bool      idEquality       = (this.GetId() == newResturant.GetId());
         bool      nameEquality     = (this.GetName() == newResturant.GetName());
         bool      dateTimeEquality = (this.GetNewDate() == newResturant.GetNewDate());
         bool      locationEquality = (this.GetLocation() == newResturant.GetLocation());
         bool      cuisineEquality  = this.GetCuisineId() == newResturant.GetCuisineId();
         return(idEquality && nameEquality && dateTimeEquality && locationEquality && cuisineEquality);
     }
 }
示例#5
0
        //Find Method
        public static Resturant Find(int id)
        {
            SqlConnection conn = DB.Connection();
            SqlDataReader rdr  = null;

            conn.Open();

            SqlCommand   cmd = new SqlCommand("SELECT * FROM resturants WHERE id = @ResturantId;", conn);
            SqlParameter resturantIdParameter = new SqlParameter();

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

            int      foundResturantId       = 0;
            string   foundResturantName     = null;
            DateTime foundResturantDateTime = new DateTime(2099, 12, 31);
            string   foundResturantLocation = null;
            int      foundCuisineId         = 0;

            while (rdr.Read())
            {
                foundResturantId       = rdr.GetInt32(0);
                foundResturantName     = rdr.GetString(1);
                foundResturantDateTime = rdr.GetDateTime(2);
                foundResturantLocation = rdr.GetString(3);
                foundCuisineId         = rdr.GetInt32(4);
            }
            Resturant foundResturant = new Resturant(foundResturantName, foundResturantLocation, foundCuisineId, foundResturantDateTime, foundResturantId);

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return(foundResturant);
        }
示例#6
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);
        }
示例#7
0
        public List <Resturant> GetResturants()
        {
            SqlConnection conn = DB.Connection();
            SqlDataReader rdr  = null;

            conn.Open();

            SqlCommand   cmd = new SqlCommand("SELECT * FROM resturants WHERE cuisine_id = @CuisineId;", conn);
            SqlParameter cuisineIdParameter = new SqlParameter();

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

            List <Resturant> resturants = new List <Resturant> {
            };

            while (rdr.Read())
            {
                int       ResturantId        = rdr.GetInt32(0);
                string    ResturantName      = rdr.GetString(1);
                DateTime  ResturantDateTime  = rdr.GetDateTime(2);
                string    ResturantLocation  = rdr.GetString(3);
                int       ResturantCuisineId = rdr.GetInt32(4);
                Resturant newResturant       = new Resturant(ResturantName, ResturantLocation, ResturantCuisineId, ResturantDateTime, ResturantId);
                resturants.Add(newResturant);
            }
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
            return(resturants);
        }
示例#8
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);
        }
示例#9
0
        //GetAll Method
        public static List <Resturant> GetAll()
        {
            List <Resturant> allResturants = new List <Resturant> {
            };

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

            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT * FROM resturants;", conn); // ORDER BY new_date cut out of SqlCommand

            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int       ResturantId        = rdr.GetInt32(0);
                string    ResturantName      = rdr.GetString(1);
                DateTime  ResturantDateTime  = rdr.GetDateTime(2);
                string    ResturantLocation  = rdr.GetString(3);
                int       ResturantCuisineId = rdr.GetInt32(4);
                Resturant newResturant       = new Resturant(ResturantName, ResturantLocation, ResturantCuisineId, ResturantDateTime, ResturantId);
                allResturants.Add(newResturant);
            }

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return(allResturants);
        }
示例#10
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"]);
            };
        }
示例#11
0
 public void Dispose()
 {
     Resturant.DeleteAll();
     Cuisine.DeleteAll();
 }
示例#12
0
        public void Test_DatabaseEmptyAtFirst()
        {
            int result = Resturant.GetAll().Count;

            Assert.Equal(0, result);
        }