Exemplo n.º 1
0
        public void Recipe_Update_UpdateDatabaseAndLocalObject()
        {
            Recipe testRecipe = new Recipe("Pot Pie", "Microwave it");

            testRecipe.Save();

            testRecipe.Update("Chicken Pot Pie", "Boil it", 4);
            Recipe expectedRecipe = new Recipe("Chicken Pot Pie", "Boil it", 4, testRecipe.GetId());

            Assert.Equal(expectedRecipe, Recipe.Find(testRecipe.GetId()));
        }
Exemplo n.º 2
0
        public void AddRecipe(Recipe newRecipe)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO recipes_categories (recipe_id, category_id) VALUES (@RecipeId, @CategoryId);", conn);

            cmd.Parameters.Add(new SqlParameter("@RecipeId", newRecipe.GetId().ToString()));
            cmd.Parameters.Add(new SqlParameter("@CategoryId", this.GetId().ToString()));
            cmd.ExecuteNonQuery();

            DB.CloseSqlConnection(conn);
        }
Exemplo n.º 3
0
        public void Find_OneRecipeId_ReturnRecipeFromDatabase()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Pot Pie", "Microwave it");

            testRecipe.Save();

            //Act
            Recipe foundRecipe = Recipe.Find(testRecipe.GetId());

            //Assert
            Assert.Equal(testRecipe, foundRecipe);
        }
Exemplo n.º 4
0
        public void Save_OneRecipe_RecipeSavedWithCorrectID()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Pot Pie", "Microwave it");

            testRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];

            //Act
            int output = savedRecipe.GetId();
            int verify = testRecipe.GetId();

            //Assert
            Assert.Equal(verify, output);
        }
Exemplo n.º 5
0
 public override bool Equals(System.Object randomRecipe)
 {
     if (!(randomRecipe is Recipe))
     {
         return(false);
     }
     else
     {
         Recipe newRecipe           = (Recipe)randomRecipe;
         bool   idEquality          = (this.GetId() == newRecipe.GetId());
         bool   nameEquality        = (this.GetName() == newRecipe.GetName());
         bool   instructionEquality = (this.GetInstruction() == newRecipe.GetInstruction());
         bool   ratingEquality      = (this.GetRating() == newRecipe.GetRating());
         return(idEquality && nameEquality && instructionEquality && ratingEquality);
     }
 }