Exemplo n.º 1
0
        public void UpdateMethodOK()
        {
            //create an instance of the class
            clsMenuItemCollection AllMenuItems = new clsMenuItemCollection();
            // create some test data to assign to the property
            clsMenuItem TestItem = new clsMenuItem();
            // var to store the primary key
            Int32 PrimaryKey = 0;

            // set the properties of the test object
            TestItem.MenuItem      = "Grapes";
            TestItem.MenuItemPrice = 4;
            // set this menu item to the test data
            AllMenuItems.ThisMenuItem = TestItem;
            // add the record
            PrimaryKey = AllMenuItems.Add();
            // set the primary key of the test data
            TestItem.MenuItemNo = PrimaryKey;
            // modify the test data
            TestItem.MenuItem      = "Qiwi";
            TestItem.MenuItemPrice = 2;
            // set the record based on the new test data
            AllMenuItems.ThisMenuItem = TestItem;
            // update the record
            AllMenuItems.Update();
            // find the record
            AllMenuItems.ThisMenuItem.Find(PrimaryKey);
            // test to see that the two values are the same
            Assert.AreEqual(AllMenuItems.ThisMenuItem, TestItem);
        }
Exemplo n.º 2
0
        public void DeleteMethodOK()
        {
            //create an instance of the class
            clsMenuItemCollection AllMenuItems = new clsMenuItemCollection();
            // create some test data to assign to the property
            clsMenuItem TestItem = new clsMenuItem();
            // var to store the primary key
            Int32 PrimaryKey = 0;

            // set the properties of the test object
            TestItem.MenuItemNo    = 1;
            TestItem.MenuItem      = "Grapes";
            TestItem.MenuItemPrice = 4;
            // set this menu item to the test data
            AllMenuItems.ThisMenuItem = TestItem;
            // add the record
            PrimaryKey = AllMenuItems.Add();
            // set the primary key of the test data
            TestItem.MenuItemNo = PrimaryKey;
            // find the record
            AllMenuItems.ThisMenuItem.Find(PrimaryKey);
            // delete the record
            AllMenuItems.Delete();
            // now find the record
            Boolean Found = AllMenuItems.ThisMenuItem.Find(PrimaryKey);

            // test to see that the two values are the same
            Assert.IsFalse(Found);
        }
Exemplo n.º 3
0
    //function for add
    void Add()
    {
        // create an instance of the menu item class
        clsMenuItemCollection MenuItemBook = new clsMenuItemCollection();
        // validate the data on the web form
        String Error = MenuItemBook.ThisMenuItem.Valid(txtMenuItem.Text, txtPrice.Text);

        // if the data is OK then add it to the object
        if (Error == "")
        {
            // get the data entered by the user
            MenuItemBook.ThisMenuItem.MenuItem      = txtMenuItem.Text;
            MenuItemBook.ThisMenuItem.MenuItemPrice = Convert.ToInt32(txtPrice.Text);
            // add the record
            MenuItemBook.Add();
            Response.Redirect("MenuDefault.aspx");
        }
        else
        {
            // report the error
            lblError.Text = "There were too many problems with the data entered " + Error;
        }
    }