Exemple #1
0
        public static List<Cuisine> GetAll()
        {
            List<Cuisine> allCuisines = new List<Cuisine>{};

              SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM cuisines;", conn);
              SqlDataReader rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            int cuisineId = rdr.GetInt32(0);
            string cuisineName = rdr.GetString(1);
            Cuisine newCuisine = new Cuisine(cuisineName, cuisineId);
            allCuisines.Add(newCuisine);
              }

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

              return allCuisines;
        }
Exemple #2
0
        public static Cuisine Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM cuisines WHERE id= @CuisineId;", conn);
              SqlParameter cuisineIdParameter = new SqlParameter();
              cuisineIdParameter.ParameterName = "@CuisineId";
              cuisineIdParameter.Value = id.ToString();
              cmd.Parameters.Add(cuisineIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              int foundCuisineId = 0;
              string foundCuisineName = null;

              while (rdr.Read())
              {
            foundCuisineId = rdr.GetInt32(0);
            foundCuisineName = rdr.GetString(1);
              }
              Cuisine foundCuisine = new Cuisine(foundCuisineName,foundCuisineId);

              if(rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundCuisine;
        }
Exemple #3
0
 public void Test2_Equal_ReturnsTrueForSameName()
 {
     //arange,act
       Cuisine firstCuisine = new Cuisine("Sushi", 1);
       Cuisine secondCuisine = new Cuisine("Sushi", 1);
      //Assert
      Assert.Equal(firstCuisine, secondCuisine);
 }
Exemple #4
0
 public void Test5_Find_FindsCuisineInDatabase()
 {
     //arrange
       Cuisine testCuisine = new Cuisine("Sushi", 1);
       testCuisine.Save();
       //act
       Cuisine foundCuisine = Cuisine.Find(testCuisine.GetId());
       //Assert
       Assert.Equal(testCuisine, foundCuisine);
 }
Exemple #5
0
 public void Test3_Save_SavesCuisineToDatabase()
 {
     //arrange
       Cuisine testCuisine = new Cuisine("Sushi", 1);
       testCuisine.Save();
       //act
       List<Cuisine> result = Cuisine.GetAll();
       List<Cuisine> testList = new List<Cuisine>{testCuisine};
       //Assert
       Assert.Equal(testList, result);
 }
Exemple #6
0
        public void Test4_Save_AssignsIdToCuisineObject()
        {
            //arrange
              Cuisine testCuisine = new Cuisine("Sushi", 1);
              testCuisine.Save();
              //act
              Cuisine savedCuisine = Cuisine.GetAll()[0];

              int result = savedCuisine.GetId();
              int testId = testCuisine.GetId();
              //Assert
              Assert.Equal(testId, result);
        }
Exemple #7
0
 public HomeModule()
 {
     Get ["/"] = _ => {
     List<Cuisine> AllCuisines = Cuisine.GetAll();
     return View["index.cshtml", AllCuisines];
       };
       Get["/restaurants"] = _ => {
     List<Restaurant> AllRestaurants = Restaurant.GetAll();
     return View["restaurants.cshtml", AllRestaurants];
       };
       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["/restaurants/new"] = _ => {
     List<Cuisine> AllCuisines = Cuisine.GetAll();
     return View["restaurants_form.cshtml", AllCuisines];
       };
       Post["/restaurants/new"] = _ => {
     Restaurant newRestaurant = new Restaurant(Request.Form["restaurant-name"], Request.Form["restaurant-city"], Request.Form["cuisine-id"]);
     newRestaurant.Save();
     return View["success.cshtml"];
       };
       Post["/restaurants/delete"] = _ => {
     Restaurant.DeleteAll();
     return View["cleared.cshtml"];
       };
       Get["/cuisines/{id}"] = parameters => {
     Dictionary<string, object> model = new Dictionary<string, object>();
     var SelectedCuisine = Cuisine.Find(parameters.id);
     var CuisineRestaurants = SelectedCuisine.GetRestaurants();
     model.Add("restaurants", CuisineRestaurants);
     return View["cuisine.cshtml", model];
       };
 }
Exemple #8
0
 public void Test6_EqualOverrideTrueForSameDescription()
 {
     //arrange, act
       Cuisine firstCuisine = new Cuisine("Sushi", 1);
       Cuisine secondCuisine = new Cuisine("Sushi", 1);
       //Assert
       Assert.Equal(firstCuisine, secondCuisine);
 }
Exemple #9
0
        public void Test8_GetRestaurants_RetrievesAllRestaurantsWithCategory()
        {
            Cuisine testCuisine = new Cuisine("Sushi");
              testCuisine.Save();

              Restaurant firstRestaurant = new Restaurant("Burger King", "Seattle", testCuisine.GetId());
              firstRestaurant.Save();
              Restaurant secondRestaurant = new Restaurant("Trappers", "Bonney Lake", testCuisine.GetId());
              secondRestaurant.Save();

              List<Restaurant> testRestaurantList = new List<Restaurant> {firstRestaurant, secondRestaurant};
              List<Restaurant> resultRestaurantList = testCuisine.GetRestaurants();

              Assert.Equal(testRestaurantList, resultRestaurantList);
        }