public void AddMethod() { //create an instance of a class clsPlaneCollection AllPlane = new clsPlaneCollection(); //create the item of test data clsPlane TestItem = new clsPlane(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.PlaneID = 1; TestItem.LocationID = 2; TestItem.PlaneName = "Emirates"; TestItem.HoursFly = 12; //set thisplane to the test data AllPlane.ThisPlane = TestItem; //add the record PrimaryKey = AllPlane.Add(); //set the primary key of the test data TestItem.PlaneID = PrimaryKey; //find the record AllPlane.ThisPlane.Find(PrimaryKey); //test to see that the two values are the same Assert.AreEqual(AllPlane.ThisPlane, TestItem); }
public void DeleteMethod() { //create an instance of a class clsPlaneCollection AllPlane = new clsPlaneCollection(); //create the item of test data clsPlane TestItem = new clsPlane(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.PlaneID = 1; TestItem.LocationID = 2; TestItem.PlaneName = "Emirates"; TestItem.HoursFly = 12; //set thisplane to the test data AllPlane.ThisPlane = TestItem; //add the record PrimaryKey = AllPlane.Add(); //set the primary key of the test data TestItem.PlaneID = PrimaryKey; //find the record AllPlane.ThisPlane.Find(PrimaryKey); //delete the record AllPlane.Delete(); //now find the record Boolean Found = AllPlane.ThisPlane.Find(PrimaryKey); //test to see that the record was not found Assert.IsFalse(Found); }
public void UpdateMethod() { //create an instance of a class clsPlaneCollection AllPlane = new clsPlaneCollection(); //create the item of test data clsPlane TestItem = new clsPlane(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.LocationID = 2; TestItem.PlaneName = "Emirates"; TestItem.HoursFly = 12; //set thisplane to the test data AllPlane.ThisPlane = TestItem; //add the record PrimaryKey = AllPlane.Add(); //set the primary key of the test data TestItem.PlaneID = PrimaryKey; //modify the test data TestItem.LocationID = 3; TestItem.PlaneName = "FlyDubai"; TestItem.HoursFly = 2; //set the record based on the new test data AllPlane.ThisPlane = TestItem; //update the record AllPlane.Update(); //find the record AllPlane.ThisPlane.Find(PrimaryKey); //test to see thisplane matches the test data Assert.AreEqual(AllPlane.ThisPlane, TestItem); }
//function for adding new records void Add() { //create an instance of a class clsPlaneCollection PlaneBook = new clsPlaneCollection(); //validate the data on the web form string Error = PlaneBook.ThisPlane.Valid(txtPlaneName.Text, txtHoursFly.Text); //if the data is ok then add it to the object if (Error == "") { //get the data entered by the user PlaneBook.ThisPlane.PlaneName = txtPlaneName.Text; PlaneBook.ThisPlane.HoursFly = Convert.ToInt32(txtHoursFly.Text); //add the record PlaneBook.Add(); //all done so redirect back to the main page Response.Redirect("PlaneList.aspx"); } else { //report the error lblError.Text = "There were problems with the data entered " + Error; } }