Exemple #1
0
        public void AddRecipie(Recipie newRecipie)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO recipies_tags (tag_id, recipie_id) VALUES (@TagId, @RecipieId);", conn);

            SqlParameter tagIdParameter = new SqlParameter();

            tagIdParameter.ParameterName = "@TagId";
            tagIdParameter.Value         = this.GetId();
            cmd.Parameters.Add(tagIdParameter);

            SqlParameter recipieIdParameter = new SqlParameter();

            recipieIdParameter.ParameterName = "@RecipieId";
            recipieIdParameter.Value         = newRecipie.GetId();
            cmd.Parameters.Add(recipieIdParameter);

            cmd.ExecuteNonQuery();

            if (conn != null)
            {
                conn.Close();
            }
        }
Exemple #2
0
        public void Test_Update_UpdatesInDb()
        {
            Recipie testRecipie = new Recipie("Name", 0);

            testRecipie.Save();
            testRecipie.Update("Other name", 0);

            Recipie newRecipie = new Recipie("Other name", 0, testRecipie.GetId());

            Assert.Equal(testRecipie, newRecipie);
        }
Exemple #3
0
        public void Test_FindFindsRecipieInDatabase()
        {
            //Arrange
            Recipie testRecipie = new Recipie("Name");

            testRecipie.Save();

            //Act
            Recipie result = Recipie.Find(testRecipie.GetId());

            //Assert
            Assert.Equal(testRecipie, result);
        }
Exemple #4
0
 public override bool Equals(System.Object otherRecipie)
 {
     if (!(otherRecipie is Recipie))
     {
         return(false);
     }
     else
     {
         Recipie newRecipie     = (Recipie)otherRecipie;
         bool    idEquality     = this.GetId() == newRecipie.GetId();
         bool    nameEquality   = this.GetName() == newRecipie.GetName();
         bool    ratingEquality = this.GetRating() == newRecipie.GetRating();
         return(idEquality && nameEquality && ratingEquality);
     }
 }
Exemple #5
0
        public void Test_GetInstructions_ReturnsAllRecipieInstructions()
        {
            //Arrange
            Recipie testRecipie = new Recipie("Pizza");

            testRecipie.Save();

            Instruction testInstruction1 = new Instruction("Cheese", testRecipie.GetId());

            testInstruction1.Save();

            Instruction testInstruction2 = new Instruction("Tomato", testRecipie.GetId());

            testInstruction2.Save();

            //Act
            List <Instruction> result   = testRecipie.GetInstructions();
            List <Instruction> testList = new List <Instruction> {
                testInstruction1, testInstruction2
            };

            //Assert
            Assert.Equal(testList, result);
        }
Exemple #6
0
        public void Test_GetIngredients_ReturnsAllRecipieIngredients()
        {
            //Arrange
            Recipie testRecipie = new Recipie("Pizza");

            testRecipie.Save();

            Ingredient testIngredient1 = new Ingredient("Cheese", testRecipie.GetId());

            testIngredient1.Save();

            Ingredient testIngredient2 = new Ingredient("Tomato", testRecipie.GetId());

            testIngredient2.Save();

            //Act
            List <Ingredient> result   = testRecipie.GetIngredients();
            List <Ingredient> testList = new List <Ingredient> {
                testIngredient1, testIngredient2
            };

            //Assert
            Assert.Equal(testList, result);
        }
Exemple #7
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Recipie testRecipie = new Recipie("Name");

            testRecipie.Save();

            //Act
            Recipie savedRecipie = Recipie.GetAll()[0];

            int result = savedRecipie.GetId();
            int testId = testRecipie.GetId();

            //Assert
            Assert.Equal(testId, result);
        }