void Add() { //create an instance of the menu book clsMenuCollection MenuBook = new clsMenuCollection(); //validate the data on the web form String Error = MenuBook.ThisItem.Valid(txtName.Text, txtDescription.Text, Convert.ToInt32(txtRecipe.Text), Convert.ToDouble(txtPrice.Text)); //if the data is OK then add it to the object if (Error == "") { //get the data entrered by the user MenuBook.ThisItem.Name = txtName.Text; MenuBook.ThisItem.Description = txtDescription.Text; MenuBook.ThisItem.RecipeID = Convert.ToInt32(txtRecipe.Text); MenuBook.ThisItem.Price = Convert.ToDouble(txtPrice.Text); //add the record MenuBook.Add(); //all done so redirect back to the main page Response.Redirect("MenuList.aspx"); } else { //report an error lblError.Text = "There were problems with the data entered " + Error; } }
//[TestMethod] public void UpdateMethodOK() { //create an instance of the class we want to create clsMenuCollection AllMenu = new clsMenuCollection(); //create the item of test data clsMenu TestItem = new clsMenu(); //var to store the primary key Int32 PrimaryKey = 0; //set the properties TestItem.Name = "Chees"; TestItem.Description = "Super Cheesy"; TestItem.RecipeID = 1; TestItem.Price = 5.0; //set ThisMenu to test data AllMenu.ThisItem = TestItem; //add the record PrimaryKey = AllMenu.Add(); //set the primary key of the test data TestItem.MenuItemID = PrimaryKey; //modify the data TestItem.Name = "Spicy"; TestItem.Description = "Mouth melting goodness"; TestItem.RecipeID = 5; TestItem.Price = 7.5; //set the record based on the new test data AllMenu.ThisItem = TestItem; //update the record AllMenu.Update(); //find the record AllMenu.ThisItem.Find(PrimaryKey); //test to see this menu matches Assert.AreEqual(AllMenu.ThisItem, TestItem); }
public void AddMethodOK() { //create an instance of the class we want to create clsMenuCollection AllMenu = new clsMenuCollection(); //create the item of test data clsMenu TestItem = new clsMenu(); //var to store the primary key Int32 PrimaryKey = 0; //set the properties TestItem.Name = "Cheesy"; TestItem.Description = "Classic cheese delite!"; TestItem.RecipeID = 1; TestItem.Price = 5.0; //set ThisMenu to test data AllMenu.ThisItem = TestItem; //add the record PrimaryKey = AllMenu.Add(); //set the primary key of the test data TestItem.MenuItemID = PrimaryKey; //find the record AllMenu.ThisItem.Find(PrimaryKey); //test to see that the two values are the same Assert.AreEqual(AllMenu.ThisItem, TestItem); }
public void DeleteMethodOK() { //create an instance of the class we want to create clsMenuCollection AllMenu = new clsMenuCollection(); //create the item of test data clsMenu TestItem = new clsMenu(); //var to store the primary key Int32 PrimaryKey = 0; //set the properties TestItem.MenuItemID = 0; TestItem.Name = "Cheesy"; TestItem.Description = "Classic cheese delite!"; TestItem.RecipeID = 1; TestItem.Price = 5.0; //set ThisMenu to test data AllMenu.ThisItem = TestItem; //add the record PrimaryKey = AllMenu.Add(); //set the primary key of the test data TestItem.MenuItemID = PrimaryKey; //find the record AllMenu.ThisItem.Find(PrimaryKey); //delete the record AllMenu.Delete(); //now find the record Boolean Found = AllMenu.ThisItem.Find(PrimaryKey); //test to see that the record was not found Assert.IsFalse(Found); }