public void BoatTestG() { //Arrange string boatCategoryF = "jolly-boat"; int totminsF = 60; int expectedF = 60; //Act int actualF = CostCalculationsHelper.TotalCost(boatCategoryF, totminsF); //Assert Assert.AreEqual(expectedF, actualF); }
public void TestHoursB() { //Arrange int rentMinutes = 23; //0 hour 23 minutes according to the requirements should be considered 1 hour int expected = 1; //Act int actual = CostCalculationsHelper.TotalHours(rentMinutes); //Assert Assert.AreEqual(expected, actual); }
public void BoatTestE() { //Arrange string boatCategoryE = "< 40 feet"; int totminsE = 500; int expectedE = 177; //Act int actualE = CostCalculationsHelper.TotalCost(boatCategoryE, totminsE); //Assert Assert.AreEqual(expectedE, actualE); }
public void BoatTestF() { //Arrange string boatCategoryF = ">= 40 feet"; int totminsF = 1000; int expectedF = 313; //Act int actualF = CostCalculationsHelper.TotalCost(boatCategoryF, totminsF); //Assert Assert.AreEqual(expectedF, actualF); }
public void BoatTestD() { //Arrange string boatCategoryD = "jolly-boat"; int totminsD = 23; int expectedD = 60; //Act int actualD = CostCalculationsHelper.TotalCost(boatCategoryD, totminsD); //Assert Assert.AreEqual(expectedD, actualD); }
public void BoatTestC() { //Arrange string boatCategoryC = ">= 40 feet"; int totminsC = 130; int expectedC = 117; //Act int actualC = CostCalculationsHelper.TotalCost(boatCategoryC, totminsC); //Assert Assert.AreEqual(expectedC, actualC); }
public void BoatTestB() { //Arrange string boatCategoryB = "< 40 feet"; int totminsB = 140; int expectedB = 99; //Act int actualB = CostCalculationsHelper.TotalCost(boatCategoryB, totminsB); //Assert Assert.AreEqual(expectedB, actualB); }
public void BoatTestA() { //Arrange string boatCategoryA = "jolly-boat"; int totminsA = 123; int expectedA = 80; //Act int actualA = CostCalculationsHelper.TotalCost(boatCategoryA, totminsA); //Assert Assert.AreEqual(expectedA, actualA); }
public void TestHoursA() { //Arrange int rentMinutes = 123; //123 minutes is equivalent to 2hours 3 minutes which according to the requirements should be considered 3 hours int expected = 3; //Act int actual = CostCalculationsHelper.TotalHours(rentMinutes); //Assert Assert.AreEqual(expected, actual); }
public void TestHoursC() { //Arrange int rentMinutes = 500; //8 hours 20minutes according to the requirements should be considered 9 hours int expected = 9; //Act int actual = CostCalculationsHelper.TotalHours(rentMinutes); //Assert Assert.AreEqual(expected, actual); }
private void btnBoatReturned_Click(object sender, EventArgs e) { //validating BoatNumber int iBoatNumber = 0; bool isDataValidated = true; DateTime dtReturnTime; DateTime dtRentTime = DateTime.Now; string strBoatCategory = ""; int iTotalCost = 0; int iMinutes = 0; try { iBoatNumber = Convert.ToInt32(this.txtBoatNumber.Text); if (iBoatNumber <= 0) { MessageBox.Show("Please choose a valid boat number greater than 0"); } } catch { MessageBox.Show("Booking number should be positive please enter a valid booking number"); isDataValidated = false; } //Combine date and time input dtReturnTime = this.dtReturnDate.Value.Date + this.dtReturnTime.Value.TimeOfDay; // open connection if (con.State == ConnectionState.Closed) { con.Open(); } //Getting rented boats details SqlCommand command = new SqlCommand("Select RentalTime, BoatCategory from BoatRentals where BoatNumber=@bNumber and Cost=0", con); command.Parameters.AddWithValue("@bNumber", iBoatNumber); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { if (reader.HasRows) { dtRentTime = DateTime.Parse(reader["RentalTime"].ToString()).ToLocalTime(); strBoatCategory = reader["BoatCategory"].ToString(); } else { MessageBox.Show("This boat has not been rented out."); isDataValidated = false; } } } if (dtReturnTime < dtRentTime) { MessageBox.Show("This boat rental time is after return time, which is invalid"); isDataValidated = false; } TimeSpan span = dtReturnTime.Subtract(dtRentTime); //Calculating the minutes between the two rented and return dates; iMinutes = (int)span.TotalMinutes; iTotalCost = CostCalculationsHelper.TotalCost(strBoatCategory.TrimEnd(), iMinutes); //Only save data in database if validation is succesful. if (isDataValidated) { try { SqlCommand cmdUpdate = new SqlCommand("Update BoatRentals Set ReturnTime = @returnTime, Cost = @cost where BoatNumber = @bNumber and Cost=0", con); cmdUpdate.Parameters.AddWithValue("@returnTime", dtReturnTime.ToLocalTime()); cmdUpdate.Parameters.AddWithValue("@cost", iTotalCost); cmdUpdate.Parameters.AddWithValue("@bNumber", iBoatNumber); int result = cmdUpdate.ExecuteNonQuery(); if (result == 1) { MessageBox.Show("Boat returned and record succesfully updated."); display(); clearFields(); this.lblCost.Text = iTotalCost.ToString() + " SEK"; } } catch (Exception ex) { MessageBox.Show("Please make sure all information is provided correctly.\nIf you still get an error then contact NackaBoatRentals support. Error message:" + ex.Message); } } }