public void Test_SaveAssignsIdToObject() { //Arrange firstCategory.Save(); //Act Category testCategory = Category.GetAllCategories()[0]; int result = firstCategory.GetCategoryId(); int testId = testCategory.GetCategoryId(); //Assert Assert.Equal(testId, result); }
public void AddCategory(Category newCategory) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO categories_recipes (categories_id, recipes_id) VALUES (@CategoryId, @RecipeId);", conn); SqlParameter categoryIdParameter = new SqlParameter("@CategoryId", newCategory.GetCategoryId()); cmd.Parameters.Add(categoryIdParameter); SqlParameter recipeIdParameter = new SqlParameter("@RecipeId", this.GetRecipeId()); cmd.Parameters.Add(recipeIdParameter); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }