//function for updating new records void Update() { //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; //update the record LocationBook.Update(); //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 ListAndCount() { //create an instance of a class clsLocationCollection AllLocation = new clsLocationCollection(); //create some test data to assign to the property //in this case the data needs to be a list of objects List <clsLocation> TestList = new List <clsLocation>(); //add an item to the list //create the item of test data clsLocation TestItem = new clsLocation(); //set its properties TestItem.LocationID = 1; TestItem.PlaneID = 2; TestItem.CountryDeparture = "Bulgaria"; TestItem.CountryDestination = "Africa"; TestItem.AirportDeparture = "Heathrow"; TestItem.AirportDestination = "Gatwick"; //add the item to the test list TestList.Add(TestItem); //assign the data to the property AllLocation.LocationList = TestList; //test to see that the two values are the same Assert.AreEqual(AllLocation.Count, TestList.Count); }
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 ReportByCountryDepartureTestDataFound() { //create an instance of the class containing unfiltered results clsLocationCollection FilteredLocation = new clsLocationCollection(); //var to store outcome Boolean OK = true; //apply a name that does not exist FilteredLocation.ReportByCountryDeparture("India"); //check that the correct number of records are found if (FilteredLocation.Count == 2) { //Check that the first record is ID 23 if (FilteredLocation.LocationList[0].LocationID != 1) { OK = false; } //Check that the first record is ID 24 if (FilteredLocation.LocationList[1].LocationID != 9) { OK = false; } } else { OK = false; } //test to see that there are no record Assert.IsTrue(OK); }
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 InstanceOK() { //create an instance of a class clsLocationCollection AllLocation = new clsLocationCollection(); //test to see that it exists Assert.IsNotNull(AllLocation); }
public void ReportByCountryDepartureNoneFound() { //create an instance of the class containing unfiltered results clsLocationCollection FilteredLocation = new clsLocationCollection(); //apply a country of departure that dont exist FilteredLocation.ReportByCountryDeparture("XXXXXXX"); //test to see that there are no records Assert.AreEqual(0, FilteredLocation.Count); }
void DeleteLocation() { //function to delete the selected record //create a new instance of the Booking book clsLocationCollection LocationBook = new clsLocationCollection(); //find the record to delete LocationBook.ThisLocation.Find(LocationID); //delete the record LocationBook.Delete(); }
public void ReportByCountryDepartureMethod() { //create an instance of the class containing unfiltered results clsLocationCollection AllLocation = new clsLocationCollection(); //create an instance of the filtered data clsLocationCollection FilteredLocation = new clsLocationCollection(); //apply a blank string (should return all records) FilteredLocation.ReportByCountryDeparture(""); //test to see that the two values are the same Assert.AreEqual(AllLocation.Count, FilteredLocation.Count); }
void DisplayLocation() { //create an instance of a class clsLocationCollection LocationBook = new clsLocationCollection(); //find the record to update LocationBook.ThisLocation.Find(LocationID); //display the record for this record txtCountryDeparture.Text = LocationBook.ThisLocation.CountryDeparture; txtCountryDestination.Text = LocationBook.ThisLocation.CountryDestination; txtAirportDeparture.Text = LocationBook.ThisLocation.AirportDeparture; txtAirportDestination.Text = LocationBook.ThisLocation.AirportDestination; }
public void ThisLocationProperty() { //create an instance of a class clsLocationCollection AllLocation = new clsLocationCollection(); //create some test data to assign to the property clsLocation TestLocation = new clsLocation(); //set the properties of the test object TestLocation.LocationID = 1; TestLocation.PlaneID = 2; TestLocation.CountryDeparture = "Bulgaria"; TestLocation.CountryDestination = "Africa"; TestLocation.AirportDeparture = "Heathrow"; TestLocation.AirportDestination = "Gatwick"; //assign the data to the property AllLocation.ThisLocation = TestLocation; //test to see that the two values are the same Assert.AreEqual(AllLocation.ThisLocation, TestLocation); }
Int32 DisplayLocation(string CountryDepartureFilter) { //var to store the CountryDeparture string CountryDeparture; //var to store the AirportDestination string AirportDestination; //create an instance of location collection class clsLocationCollection Location = new clsLocationCollection(); Location.ReportByCountryDeparture(CountryDepartureFilter); //var to store the count of records Int32 RecordCount; //var to store the index for the loop Int32 Index = 0; //get the count of records RecordCount = Location.Count; //clear the list box lstLocation.Items.Clear(); //while there are records while (Index < RecordCount) { //get the CountryDeparture CountryDeparture = Location.LocationList[Index].CountryDeparture; //get the AirportDestination AirportDestination = Location.LocationList[Index].AirportDestination; //create a new entry for th list box ListItem NewEntry = new ListItem(CountryDeparture + " " + AirportDestination.ToString()); //add the customer to the list lstLocation.Items.Add(NewEntry); //move the index to the next record Index++; } //return to the count of records found return(RecordCount); }
//this function handles the load object for the page protected void Page_Load(object sender, EventArgs e) { //if this is the first time the page is displayed if (IsPostBack == false) { //update the list box DisplayLocation(); } void DisplayLocation() { //create an instance of the Location collection clsLocationCollection Location = new clsLocationCollection(); //set the data source to the list of Locations in the collection lstLocation.DataSource = Location.LocationList; //set the name of the primary key lstLocation.DataValueField = "LocationID"; //set the data field to display lstLocation.DataTextField = "CountryDeparture"; //bind the data source to the list lstLocation.DataBind(); } }
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); }