public void TestAddMethod() { // create collection instance clsBrandCollection AllBrands = new clsBrandCollection(); //create brand item clsBrand Brand = new clsBrand(); // PK variable Int32 PK = 0; // set properties Brand.BrandID = 1; Brand.BrandName = "TestBrandInc"; Brand.TopProduct = 2; Brand.LatestProduct = 2; Brand.LastRestock = DateTime.Now.Date; Brand.AvgPrice = 0.00; Brand.IsListed = false; // set ThisAddress to Brand object AllBrands.ThisBrand = Brand; //add record PK = AllBrands.Add(); // set primary key Brand.BrandID = PK; // find the record AllBrands.ThisBrand.Find(PK); // test objects are equal Assert.AreEqual(AllBrands.ThisBrand, Brand); }
public void TestDeleteMethod() { // create collection instance clsBrandCollection AllBrands = new clsBrandCollection(); // create the test brand clsBrand Brand = new clsBrand(); //PK Var Int32 PK = 0; //set brand's fields Brand.BrandName = "Nike"; Brand.TopProduct = 1; Brand.LatestProduct = 2; Brand.LastRestock = DateTime.Now.Date; Brand.AvgPrice = 0.00; // set the collection's thisbrand to the test item. AllBrands.ThisBrand = Brand; // add record to database PK = AllBrands.Add(); // set brand PK Brand.BrandID = PK; // find record AllBrands.ThisBrand.Find(PK); //invoke delete AllBrands.Delete(); Boolean Found = AllBrands.ThisBrand.Find(PK); Assert.IsFalse(Found); }
protected void btnSubmit_Click(object sender, EventArgs e) { // create brand instance clsBrand Brand = new clsBrand(); // retreive field values string BrandName = tbName.Text; string TopProduct = dropTop.SelectedValue; string LatestProduct = dropLatest.SelectedValue; string LastRestock = cdrRestock.SelectedDate.ToString(); // avgPrice property needs to be calculated from a mean of a brand's products //store Brand in session object // if valid passes string ErrorMsg = ""; ErrorMsg = Brand.Valid(BrandName, TopProduct, LatestProduct, LastRestock); if (ErrorMsg == "") { // capture brand id Brand.BrandID = BrandID; Brand.BrandName = BrandName; Brand.TopProduct = int.Parse(TopProduct); Brand.LatestProduct = int.Parse(LatestProduct); Brand.LastRestock = Convert.ToDateTime(LastRestock); Brand.IsListed = cbList.Checked; // create a collection instance clsBrandCollection BrandList = new clsBrandCollection(); //add if (Brand.BrandID == -1) { // set ThisBrand BrandList.ThisBrand = Brand; // add record BrandList.Add(); } // otherwise we update else { BrandList.ThisBrand.Find(BrandID); // set ThisAddress BrandList.ThisBrand = Brand; // update BrandList.Update(); } // redirect back to list Response.Redirect("BrandsList.aspx"); } else { lblValidateError.Visible = true; lblValidateError.Text = ErrorMsg; } }