public void AddMethodOK() { //Create an instance of the class we want to create clsTicketCollection AllTickets = new clsTicketCollection(); //Create the item of test data clsTicket TestItem = new clsTicket(); //Variable to store the primary kjey Int32 PrimaryKey = 0; //Set its properties TestItem.CustomerID = 1; TestItem.ScreeningID = 1; TestItem.Validated = false; TestItem.Cancelled = false; //Set ThisFilm to the test data AllTickets.ThisTicket = TestItem; //Add the record PrimaryKey = AllTickets.Add(); //Set the primary key of the test data TestItem.TicketID = PrimaryKey; //Find the record AllTickets.ThisTicket.Find(PrimaryKey); //Test to see that the two values are the same Assert.AreEqual(AllTickets.ThisTicket, TestItem); }
//function for adding new records void Add() { //create an instance of the Ticket Book clsTicketCollection TicketBook = new clsTicketCollection(); //validate the data on the web form string Error = TicketBook.ThisTicket.Valid(txtTicketPurchaseDate.Text, txtTicketNo.Text, txtFlightNo.Text, txtSeatNo.Text); //if the data is ok then add it to the object if (Error == "") { //get the data entered by the user TicketBook.ThisTicket.TicketPurchaseDate = Convert.ToDateTime(txtTicketPurchaseDate.Text); TicketBook.ThisTicket.TicketNo = txtTicketNo.Text; TicketBook.ThisTicket.FlightNo = Convert.ToInt32(txtFlightNo.Text); TicketBook.ThisTicket.SeatNo = txtSeatNo.Text; //add the record TicketBook.Add(); //all done so redirect back to the main page Response.Redirect("TicketList.aspx"); } else { //report the error lblError.Text = "There were problems with the data entered " + Error; } }
public void UpdateMethod() { //create an instance of a class clsTicketCollection AllTicket = new clsTicketCollection(); //create the item of test data clsTicket TestItem = new clsTicket(); //var to store the primarykey Int32 PrimaryKey = 0; //set its properties TestItem.TicketPurchaseDate = DateTime.Now.Date; TestItem.TicketNo = "ASD456GH"; TestItem.FlightNo = 535; TestItem.SeatNo = "53B"; //set thisticket to the test data AllTicket.ThisTicket = TestItem; //add the record PrimaryKey = AllTicket.Add(); //set the primary key of the test data TestItem.TicketID = PrimaryKey; //modify the test data TestItem.TicketPurchaseDate = DateTime.Now.Date; TestItem.TicketNo = "HGF3F72"; TestItem.FlightNo = 767; TestItem.SeatNo = "5B"; //Set the record based on the new test data AllTicket.ThisTicket = TestItem; //update the record AllTicket.Update(); //find the record AllTicket.ThisTicket.Find(PrimaryKey); //test to see this ticket matches the test data Assert.AreEqual(AllTicket.ThisTicket, TestItem); }
public void AddMethod() { //create an instance of a class clsTicketCollection AllTicket = new clsTicketCollection(); //create the item of test data clsTicket TestItem = new clsTicket(); //var to store the primarykey Int32 PrimaryKey = 0; //set its properties TestItem.TicketID = 1; TestItem.TicketPurchaseDate = DateTime.Now.Date; TestItem.TicketNo = "ASD456GH"; TestItem.FlightNo = 535; TestItem.SeatNo = "53B"; //set thisticket to the test data AllTicket.ThisTicket = TestItem; //add the record PrimaryKey = AllTicket.Add(); //set the primary key of the test data TestItem.TicketID = PrimaryKey; //find the record AllTicket.ThisTicket.Find(PrimaryKey); //test to see that the two values are the same Assert.AreEqual(AllTicket.ThisTicket, TestItem); }
public void DeleteMethod() { //create an instance of a class clsTicketCollection AllTicket = new clsTicketCollection(); //create the item of test data clsTicket TestItem = new clsTicket(); //var to store the primarykey Int32 PrimaryKey = 0; //set its properties TestItem.TicketID = 1; TestItem.TicketPurchaseDate = DateTime.Now.Date; TestItem.TicketNo = "ASD456GH"; TestItem.FlightNo = 535; TestItem.SeatNo = "53B"; //set thisticket to the test data AllTicket.ThisTicket = TestItem; //add the record PrimaryKey = AllTicket.Add(); //set the primary key of the test data TestItem.TicketID = PrimaryKey; //find the record AllTicket.ThisTicket.Find(PrimaryKey); //delete the record AllTicket.Delete(); //now find the record Boolean Found = AllTicket.ThisTicket.Find(PrimaryKey); //test to see that the record was not found Assert.IsFalse(Found); }