//function for adding new records void Add() { //create an instance of the Location Book clsLocationCollection LocationBook = new clsLocationCollection(); //validate the data on the web form string Error = LocationBook.ThisLocation.Valid(txtCountryDeparture.Text, txtCountryDestination.Text, txtAirportDeparture.Text, txtAirportDestination.Text); //if the data is ok then add it to the object if (Error == "") { //get the data entered by the user LocationBook.ThisLocation.CountryDeparture = txtCountryDeparture.Text; LocationBook.ThisLocation.CountryDestination = txtCountryDestination.Text; LocationBook.ThisLocation.AirportDeparture = txtAirportDeparture.Text; LocationBook.ThisLocation.AirportDestination = txtAirportDestination.Text; //add the record LocationBook.Add(); //all done so redirect back to the main page Response.Redirect("LocationList.aspx"); } else { //report an error lblError.Text = "There are problems with the data entered " + Error; } }
public void AddMethod() { //create an instance of a class clsLocationCollection AllLocation = new clsLocationCollection(); //create the item of test data clsLocation TestItem = new clsLocation(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.LocationID = 1; TestItem.PlaneID = 2; TestItem.CountryDeparture = "Bulgaria"; TestItem.CountryDestination = "Africa"; TestItem.AirportDeparture = "Heathrow"; TestItem.AirportDestination = "Gatwick"; //set this location to the test data AllLocation.ThisLocation = TestItem; //add the record PrimaryKey = AllLocation.Add(); //set the primary key of the test data TestItem.LocationID = PrimaryKey; //find the record AllLocation.ThisLocation.Find(PrimaryKey); //test to see that the two values are the same Assert.AreEqual(AllLocation.ThisLocation, TestItem); }
public void DeleteMethod() { //create an instance of a class clsLocationCollection AllLocation = new clsLocationCollection(); //create the item of test data clsLocation TestItem = new clsLocation(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.LocationID = 1; TestItem.PlaneID = 2; TestItem.CountryDeparture = "Bulgaria"; TestItem.CountryDestination = "Africa"; TestItem.AirportDeparture = "Heathrow"; TestItem.AirportDestination = "Gatwick"; //set this location to the test data AllLocation.ThisLocation = TestItem; //add the record PrimaryKey = AllLocation.Add(); //set the primary key of the test data TestItem.LocationID = PrimaryKey; //find the record AllLocation.ThisLocation.Find(PrimaryKey); //delete the record AllLocation.Delete(); //now find the record Boolean Found = AllLocation.ThisLocation.Find(PrimaryKey); //test to see that the record was not found Assert.IsFalse(Found); }
public void UpdateMethod() { //create an instance of a class clsLocationCollection AllLocation = new clsLocationCollection(); //create the item of test data clsLocation TestItem = new clsLocation(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.PlaneID = 2; TestItem.CountryDeparture = "Bulgaria"; TestItem.CountryDestination = "Africa"; TestItem.AirportDeparture = "Heathrow"; TestItem.AirportDestination = "Gatwick"; //set this location to the test data AllLocation.ThisLocation = TestItem; //add the record PrimaryKey = AllLocation.Add(); //set the primary key of the test data TestItem.LocationID = PrimaryKey; //modify the test data TestItem.PlaneID = 3; TestItem.CountryDeparture = "Belgium"; TestItem.CountryDestination = "Zimbabwe"; TestItem.AirportDeparture = "Lahore"; TestItem.AirportDestination = "Heathrow"; //set the record based on the new test data AllLocation.ThisLocation = TestItem; //update the record AllLocation.Update(); //find the record AllLocation.ThisLocation.Find(PrimaryKey); //test to see thislocation matches the test data Assert.AreEqual(AllLocation.ThisLocation, TestItem); }