public void DeleteMethodOK()
        {
            //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   = 1;
            TestItem.ProductName = "Pokemon";
            TestItem.Price       = 15.00;
            TestItem.Quantity    = 14;
            //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;
            //find the record
            AllProducts.ThisProduct.Find(PrimaryKey);
            //delete the record
            AllProducts.Delete();
            //noe find the record
            Boolean Found = AllProducts.ThisProduct.Find(PrimaryKey);

            //test to see that the value was not found
            Assert.IsFalse(Found);
        }
        public void AddMethodOK()
        {
            //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   = 11;
            TestItem.ProductName = "Batman";
            TestItem.Price       = 15.00;
            TestItem.Quantity    = 13;
            //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;
            //find the record
            AllProducts.ThisProduct.Find(PrimaryKey);
            //test to see that the two values are the same
            Assert.AreEqual(AllProducts.ThisProduct, TestItem);
        }
Exemplo n.º 3
0
    void Add()
    {
        //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);
            //add the record
            ProductBook.Add();
            //redirec to default page
            Response.Redirect("Default.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "There were problems with the data entered " + Error;
        }
    }