public void UpdateMethodOK()
        {
            //create an instance of the class
            clsProductsCollection AllProducts = new clsProductsCollection();
            //create the item of test data
            clsProducts TestItem = new clsProducts();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.ProductID   = 12;
            TestItem.ProductName = "game";
            TestItem.Price       = 12.00;
            TestItem.Quantity    = 4;
            //set ThisProduct to test data
            AllProducts.ThisProduct = TestItem;
            //add the record
            PrimaryKey = AllProducts.Add();
            //set the primary key of the test data
            TestItem.ProductID = PrimaryKey;
            //set its new properties
            TestItem.ProductID   = 13;
            TestItem.ProductName = "game 2";
            TestItem.Price       = 11.00;
            TestItem.Quantity    = 7;
            //set the record based on the new test data
            AllProducts.ThisProduct = TestItem;
            //update the record
            AllProducts.Update();
            //find the record
            AllProducts.ThisProduct.Find(PrimaryKey);
            //test to see that the two values are the same
            Assert.AreEqual(AllProducts.ThisProduct, TestItem);
        }
Exemplo n.º 2
0
    void Update()
    {
        //create an instance of product book
        clsProductsCollection ProductBook = new clsProductsCollection();
        //validate the data on the web form
        String Error = ProductBook.ThisProduct.Valid(txtProductID.Text, txtProductName.Text, txtPrice.Text, txtQuantity.Text);

        //if the data is OK then add it to the object
        if (Error == "")
        {
            //get the data entered by user
            ProductBook.ThisProduct.ProductID   = Convert.ToInt32(txtProductID.Text);
            ProductBook.ThisProduct.ProductName = txtProductName.Text;
            ProductBook.ThisProduct.Price       = Convert.ToDouble(txtPrice.Text);
            ProductBook.ThisProduct.Quantity    = Convert.ToInt32(txtQuantity.Text);
            //update the record
            ProductBook.Update();
            //redirec to default page
            Response.Redirect("Default.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "There were problems with the data entered " + Error;
        }
    }