public void UpdateMethodOK() { clsShippingCollection AllShipments = new clsShippingCollection(); //create item of test data clsShipping TestShipment = new clsShipping(); //store primary key Int32 PrimaryKey = 0; //set its properties TestShipment.ShippingType = "Standard"; TestShipment.Price = 4.99m; TestShipment.DateOfDispatch = DateTime.Now.Date; TestShipment.Dispatched = true; //set ThisItem to test data AllShipments.ThisShipment = TestShipment; //add record PrimaryKey = AllShipments.Add(); //set primary key of test data TestShipment.ShippingId = PrimaryKey; //modify test data TestShipment.ShippingType = "Express"; TestShipment.Price = 7.99m; TestShipment.DateOfDispatch = Convert.ToDateTime("2021-04-27"); TestShipment.Dispatched = true; //set record based on new test data AllShipments.ThisShipment = TestShipment; //update record AllShipments.Update(); //find record AllShipments.ThisShipment.Find(PrimaryKey); //test to see ThisItem matches test data Assert.AreEqual(AllShipments.ThisShipment, TestShipment); }
public void DeleteMethodOK() { clsShippingCollection AllShipments = new clsShippingCollection(); //create item of test data clsShipping TestShipment = new clsShipping(); //store primary key Int32 PrimaryKey = 0; //set its properties TestShipment.ShippingType = "Standard"; TestShipment.Price = 4.99m; TestShipment.DateOfDispatch = DateTime.Now.Date; TestShipment.Dispatched = true; //set ThisItem to test data AllShipments.ThisShipment = TestShipment; //add record PrimaryKey = AllShipments.Add(); //set primary key of test data TestShipment.ShippingId = PrimaryKey; //find record AllShipments.ThisShipment.Find(PrimaryKey); //delete record AllShipments.Delete(); //find record now Boolean Found = AllShipments.ThisShipment.Find(PrimaryKey); //test to see record was not found Assert.IsFalse(Found); }
public void AddPropertyOK() { clsShippingCollection AllShipments = new clsShippingCollection(); //create item of test data clsShipping TestShipment = new clsShipping(); //store primary key Int32 PrimaryKey = 0; //set its properties TestShipment.ShippingId = 1; TestShipment.ShippingType = "Standard"; TestShipment.Price = 4.99m; TestShipment.DateOfDispatch = DateTime.Now.Date; TestShipment.Dispatched = true; //set ThisItem to test data AllShipments.ThisShipment = TestShipment; //add record PrimaryKey = AllShipments.Add(); //set primary key of test data TestShipment.ShippingId = PrimaryKey; //find record AllShipments.ThisShipment.Find(PrimaryKey); //test to see values are same Assert.AreEqual(AllShipments.ThisShipment, TestShipment); }
protected void btnOK_Click(object sender, EventArgs e) { lblError.Text = ""; clsShipping AShipment = new clsShipping(); string ShippingType = lstShippingType.Text; string Price = txtPrice.Text; string DateOfDispatch = txtDateOfDispatch.Text; //Error message String Error = ""; Error = AShipment.Valid(DateOfDispatch); if (lstShippingType.SelectedIndex == 0) { Error += "Select a Shipping Type : "; } if (Error == "") { //capture properties AShipment.ShippingId = ShippingId; AShipment.ShippingType = ShippingType; //populate Price field based on Shipping Type selection if (lstShippingType.SelectedIndex == 1 || lstShippingType.SelectedIndex == 2) { AShipment.Price = Decimal.Parse(Price); } //define value of Dispatched boolean based on if a date of dispatch was input if (DateOfDispatch.Length == 0) { DateOfDispatch = null; AShipment.Dispatched = false; } else { AShipment.DateOfDispatch = Convert.ToDateTime(DateOfDispatch); AShipment.Dispatched = true; } clsShippingCollection ShippingList = new clsShippingCollection(); if (ShippingId == -1) { ShippingList.ThisShipment = AShipment; ShippingList.Add(); } else { ShippingList.ThisShipment.Find(ShippingId); ShippingList.ThisShipment = AShipment; ShippingList.Update(); } Response.Redirect("ShippingList.aspx"); } else { lblError.Text = Error; } }