public void AddMethodOK() //Add Method { //create an instance of the class we want to create clsPhoneCollection AllPhones = new clsPhoneCollection(); //create the item of test data clsPhone TestItem = new clsPhone(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.Active = true; TestItem.PhoneID = 1; TestItem.Capacity = 128; TestItem.Price = 100; TestItem.Colour = "red"; TestItem.DateAdded = DateTime.Now.Date; TestItem.Description = "This is the latest phone."; TestItem.Make = "Apple"; TestItem.Model = "C3500"; TestItem.StockStatus = true; //set ThisPhone to the test data AllPhones.ThisPhone = TestItem; //add the record PrimaryKey = AllPhones.Add(); //set the primary key of the test data TestItem.PhoneID = PrimaryKey; //find the record AllPhones.ThisPhone.Find(PrimaryKey); //test to see that the two values are the same Assert.AreEqual(AllPhones.ThisPhone, TestItem); }
public void AddMethodOk() { //create an instance of the class we want to create clsPhoneCollection AllPhones = new clsPhoneCollection(); //create the item of test data clsPhone TestItem = new clsPhone(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.PhoneId = 1; TestItem.Make = "Apple"; TestItem.Model = "Iphone X"; TestItem.PhoneNo = "07749493975"; TestItem.Price = "500"; TestItem.ScreenSize = "7"; TestItem.CameraQuality = "HD"; //set ThisPhone to the test data AllPhones.ThisPhone = TestItem; //add the record PrimaryKey = AllPhones.Add(); //set the primary key of the test data TestItem.PhoneId = PrimaryKey; //find the record AllPhones.ThisPhone.Find(PrimaryKey); //test to see that the two values are the same Assert.AreEqual(AllPhones.ThisPhone, TestItem); }
public void DeleteMethodOk() { //create an instance of the class we want to create clsPhoneCollection AllPhones = new clsPhoneCollection(); //create the item of test data clsPhone TestItem = new clsPhone(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.PhoneId = 1; TestItem.Make = "Apple"; TestItem.Model = "Iphone X"; TestItem.PhoneNo = "07749493975"; TestItem.Price = "500"; TestItem.ScreenSize = "7"; TestItem.CameraQuality = "HD"; //set ThisPhone to the test data AllPhones.ThisPhone = TestItem; //add the record PrimaryKey = AllPhones.Add(); //set the primary key of the test data TestItem.PhoneId = PrimaryKey; //find the record AllPhones.ThisPhone.Find(PrimaryKey); //delete the record AllPhones.Delete(); //now find the record Boolean Found = AllPhones.ThisPhone.Find(PrimaryKey); //test to see that the record was not found Assert.IsFalse(Found); }
void Add() { //create an instance of the Phone book clsPhoneCollection PhoneBook = new clsPhoneCollection(); //validate the data on the web form String Error = PhoneBook.ThisPhone.Valid(txtMake.Text, txtModel.Text, txtPhoneNo.Text, txtPrice.Text, txtScreenSize.Text, txtCameraQuality.Text); //if the data is okay then add it to the object if (Error == "") { //get the data entered by the user PhoneBook.ThisPhone.Make = txtMake.Text; PhoneBook.ThisPhone.Model = txtModel.Text; PhoneBook.ThisPhone.PhoneNo = txtPhoneNo.Text; PhoneBook.ThisPhone.Price = txtPrice.Text; PhoneBook.ThisPhone.ScreenSize = txtScreenSize.Text; PhoneBook.ThisPhone.CameraQuality = txtCameraQuality.Text; //add the record PhoneBook.Add(); //all done so redirect to default Response.Redirect("Default.aspx"); } else { //report an error lblError.Text = "There were problems with the data entered " + Error; } }
protected void btnOK_Click(object sender, EventArgs e) { //create an instance of the phone page class clsPhone ThisPhone = new clsPhone(); //var to store any error messages string ErrorMessage; //test the data on the web form ErrorMessage = ThisPhone.PhoneValid( txtPhoneName.Text, txtBrand.Text, txtScreenSize.Text, txtOperatingSystem.Text, txtBackCamera.Text, txtBatterySize.Text, txtReleaseDate.Text); if (ErrorMessage == "") { //create a new instance of the phone collection class clsPhoneCollection PhoneCollection = new clsPhoneCollection(); //do something with the data - insert or update // //if the Phone Number is -1 if (PhoneNo == -1) { //copy the data from the interface to the object ThisPhone.PhoneName = txtPhoneName.Text; ThisPhone.Brand = txtBrand.Text; ThisPhone.ScreenSize = txtScreenSize.Text; ThisPhone.OperatingSystem = txtOperatingSystem.Text; ThisPhone.BackCamera = txtBackCamera.Text; ThisPhone.BatterySize = txtBatterySize.Text; ThisPhone.CompanyNo = Convert.ToInt32(ddlCompany.SelectedValue); ThisPhone.ReleaseDate = Convert.ToDateTime(txtReleaseDate.Text); //add the new record PhoneCollection.Add(); } else { //this is an existing record //copy the data from the interface to the object ThisPhone.PhoneNo = Convert.ToInt32(PhoneNo); ThisPhone.PhoneName = txtPhoneName.Text; ThisPhone.Brand = txtBrand.Text; ThisPhone.ScreenSize = txtScreenSize.Text; ThisPhone.OperatingSystem = txtOperatingSystem.Text; ThisPhone.BackCamera = txtBackCamera.Text; ThisPhone.BatterySize = txtBatterySize.Text; ThisPhone.CompanyNo = Convert.ToInt32(ddlCompany.SelectedValue); ThisPhone.ReleaseDate = Convert.ToDateTime(txtReleaseDate.Text); //update the exisiting record PhoneCollection.Update(); } //redirect back to the main page Response.Redirect("Default.aspx"); } else { //display the error message lblError.Text = ErrorMessage; } }