Esempio n. 1
0
    void Update()
    {
        //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 == "")
        {
            //find the record to update
            MenuBook.ThisItem.Find(MenuID);
            //get the data entered 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);
            //update the record
            MenuBook.Update();
            //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);
        }