public void UpdateMethodOK() { clsItemsCollection AllItems = new clsItemsCollection(); clsItems TestItems = new clsItems(); Int32 PrimaryKey = 0; TestItems.ItemDescription = "test"; TestItems.ItemQuantity = 1; TestItems.ItemPricePerUnit = 1; TestItems.ItemDateOfAvailability = DateTime.Now.Date; TestItems.ItemAvailability = true; AllItems.ThisItem = TestItems; PrimaryKey = AllItems.Add(); TestItems.ItemNo = PrimaryKey; //modify the test data TestItems.ItemDescription = "another item"; TestItems.ItemQuantity = 9; TestItems.ItemPricePerUnit = 5; TestItems.ItemDateOfAvailability = DateTime.Now.Date; TestItems.ItemAvailability = false; //set the record based on the new test data AllItems.ThisItem = TestItems; AllItems.Update(); AllItems.ThisItem.Find(PrimaryKey); //test to see ThisItem matches the test data Assert.AreEqual(AllItems.ThisItem, TestItems); }
protected void btnOK_Click(object sender, EventArgs e) { clsItems AnItem = new clsItems(); string ItemDescription = TxtItemDescription.Text; string ItemQuantity = TxtItemQuantity.Text; string ItemPricePerUnit = TxtItemPricePerUnit.Text; string ItemDateOfAvailability = TxtItemDateOfAvailability.Text; string Error = ""; Error = AnItem.Valid(ItemDescription, ItemQuantity, ItemPricePerUnit, ItemDateOfAvailability); if (Error == "") { AnItem.ItemNo = ItemNo; AnItem.ItemDescription = ItemDescription; AnItem.ItemQuantity = Convert.ToInt32(ItemQuantity); AnItem.ItemPricePerUnit = Convert.ToDecimal(ItemPricePerUnit); AnItem.ItemDateOfAvailability = Convert.ToDateTime(ItemDateOfAvailability); AnItem.ItemAvailability = ItemAvailability.Checked; clsItemsCollection ItemsList = new clsItemsCollection(); if (ItemNo == -1) { ItemsList.ThisItem = AnItem; ItemsList.Add(); } else { ItemsList.ThisItem.Find(ItemNo); ItemsList.ThisItem = AnItem; ItemsList.Update(); } Response.Redirect("ItemsList.aspx"); } else { lblError.Text = Error; } }