public void RentCarAtCrossedUsedTime_Exception() { var clientFacade = new ClientFacade("Bob"); var carFacade1 = new CarFacade("Audi"); var carFacade2 = new CarFacade("BMW"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var date3 = new DateTimeOffset(new DateTime(2018, 10, 19)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date1, date3); clientFacade.RentCar(carFacade1, time1); bool hasException = false; try { clientFacade.RentCar(carFacade2, time2); } catch (Exception) { hasException = true; } Assert.IsTrue(hasException); }
public void RentTwoCarsByOnClient_TwoCarsInRentHistory() { var clientFacade = new ClientFacade("Bob"); var carFacade1 = new CarFacade("Audi"); var carFacade2 = new CarFacade("BMW"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var date3 = new DateTimeOffset(new DateTime(2018, 11, 10)); var date4 = new DateTimeOffset(new DateTime(2018, 11, 19)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date3, date4); clientFacade.RentCar(carFacade1, time1); clientFacade.RentCar(carFacade2, time2); var listOfRent = clientFacade.Client.RentHistory.ToList(); Assert.AreEqual(listOfRent[0].Value, carFacade1); Assert.AreEqual(listOfRent[0].Key.StartTime, time1.StartTime); Assert.AreEqual(listOfRent[0].Key.EndTime, time1.EndTime); Assert.AreEqual(listOfRent[1].Value, carFacade2); Assert.AreEqual(listOfRent[1].Key.StartTime, time2.StartTime); Assert.AreEqual(listOfRent[1].Key.EndTime, time2.EndTime); }
public void CreateRentTime_ObjectRentTime() { var data1 = new DateTimeOffset(new DateTime(2018, 10, 07)); var data2 = new DateTimeOffset(new DateTime(2018, 12, 15)); var rentTime = new RentTime(data1, data2); Assert.AreEqual(rentTime.StartTime, data1); Assert.AreEqual(rentTime.EndTime, data2); }
public void IsAtServiceAtFreeTime_False() { var carFacade = new CarFacade("10"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var time = new RentTime(date1, date2); var isAtService = carFacade.IsAtServiceAt(time); Assert.IsFalse(isAtService); }
protected RentTime time; //占用的时间 #endregion Fields #region Constructors public Rent(int id, string name, int classroomId, RentTime time) { this.id = id; this.name = name; this.classroomId = classroomId; this.time = time; if (null == this.time) this.time = new RentTime(); this.Students = new List<int>(); }
public void IsFreeAtFreeTime_True() { var carFacade = new CarFacade("10"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var time = new RentTime(date1, date2); var isFreeAt = carFacade.IsFreeAt(time); Assert.IsTrue(isFreeAt); }
public void RentCar_CarInRentHistory() { var clientFacade = new ClientFacade("Bob"); var carFacade = new CarFacade("Audi"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var time = new RentTime(date1, date2); clientFacade.RentCar(carFacade, time); Assert.AreEqual(carFacade, clientFacade.Client.RentHistory.First().Value); }
public void IsAtRentAtBusyTime_True() { var carFacade = new CarFacade("10"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var time = new RentTime(date1, date2); carFacade.Car.Rents.Add(time); var isAtRent = carFacade.IsAtRentAt(time); Assert.IsTrue(isAtRent); }
public void RentCar10Times_CarAtService() { var carRentCompanyFacade = new CarRentCompanyFacade(); var carFacade = new CarFacade("10"); var clientFacade = new ClientFacade("Bob"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 10, 07)); var date3 = new DateTimeOffset(new DateTime(2018, 10, 08)); var date4 = new DateTimeOffset(new DateTime(2018, 10, 09)); var date5 = new DateTimeOffset(new DateTime(2018, 10, 10)); var date6 = new DateTimeOffset(new DateTime(2018, 10, 11)); var date7 = new DateTimeOffset(new DateTime(2018, 10, 12)); var date8 = new DateTimeOffset(new DateTime(2018, 10, 13)); var date9 = new DateTimeOffset(new DateTime(2018, 10, 14)); var date10 = new DateTimeOffset(new DateTime(2018, 10, 15)); var date11 = new DateTimeOffset(new DateTime(2018, 10, 16)); var date12 = new DateTimeOffset(new DateTime(2018, 10, 17)); var date13 = new DateTimeOffset(new DateTime(2018, 10, 18)); var date14 = new DateTimeOffset(new DateTime(2018, 10, 19)); var date15 = new DateTimeOffset(new DateTime(2018, 10, 20)); var date16 = new DateTimeOffset(new DateTime(2018, 10, 21)); var date17 = new DateTimeOffset(new DateTime(2018, 10, 22)); var date18 = new DateTimeOffset(new DateTime(2018, 10, 23)); var date19 = new DateTimeOffset(new DateTime(2018, 10, 24)); var date20 = new DateTimeOffset(new DateTime(2018, 10, 25)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date3, date4); var time3 = new RentTime(date5, date6); var time4 = new RentTime(date7, date8); var time5 = new RentTime(date9, date10); var time6 = new RentTime(date11, date12); var time7 = new RentTime(date13, date14); var time8 = new RentTime(date15, date16); var time9 = new RentTime(date17, date18); var time10 = new RentTime(date19, date20); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time1); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time2); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time3); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time4); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time5); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time6); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time7); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time8); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time9); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time10); carRentCompanyFacade.SendCarOnService(carFacade, time10.EndTime.AddDays(1)); Assert.AreEqual(carFacade.Car.Services.Count, 1); Assert.AreEqual(carFacade.Car.CountToService, 0); }
public void IsAtRentAtCrossedTime_True() { var carFacade = new CarFacade("10"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var date3 = new DateTimeOffset(new DateTime(2018, 10, 31)); var date4 = new DateTimeOffset(new DateTime(2019, 02, 26)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date3, date4); carFacade.Car.Rents.Add(time1); var isAtRent = carFacade.IsAtRentAt(time2); Assert.IsTrue(isAtRent); }
public void SendCarOnService_CarOnService() { var carRentFacade = new CarRentCompanyFacade(); var clientFacade = new ClientFacade("Bob"); var carFacade = new CarFacade("Lava Kavina"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 07)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 07)); var time = new RentTime(date1, date2); carRentFacade.CarRentCompany.CarRepository.Create(carFacade.Car); carRentFacade.SendCarOnService(carFacade, time.StartTime); Assert.AreEqual(carRentFacade.CarRentCompany.CarRepository.GetItem(0).IsAtServiceAt(time), true); }
public void HasCarAt_False() { var answer = false; var clientFacade = new ClientFacade("Bob"); var carFacade = new CarFacade("Audi"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 06)); var date3 = new DateTimeOffset(new DateTime(2018, 11, 10)); var date4 = new DateTimeOffset(new DateTime(2022, 01, 13)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date3, date4); clientFacade.RentCar(carFacade, time1); var hasCar = clientFacade.HasCarAt(time2); Assert.AreEqual(answer, hasCar); }
public void GetCarsAt_Cars() { var carRentFacade = new CarRentCompanyFacade(); var carFacade1 = new CarFacade("10"); var carFacade2 = new CarFacade("Lava Kavina"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 07)); var date2 = new DateTimeOffset(new DateTime(2018, 11, 07)); var time = new RentTime(date1, date2); carRentFacade.CarRentCompany.CarRepository.Create(carFacade1.Car); carRentFacade.CarRentCompany.CarRepository.Create(carFacade2.Car); var cars = carRentFacade.GetCarsAt(time); Assert.AreEqual(cars.ToArray()[0].Name, carFacade1.Car.Name); Assert.AreEqual(cars.ToArray()[1].Name, carFacade2.Car.Name); }
public void RentLotsOfCars_ClientsWithRentHistory() { var clientFacade1 = new ClientFacade("Bob"); var carFacade1 = new CarFacade("1"); var carFacade2 = new CarFacade("2"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 10, 10)); var date3 = new DateTimeOffset(new DateTime(2018, 10, 30)); var date4 = new DateTimeOffset(new DateTime(2018, 11, 02)); var date5 = new DateTimeOffset(new DateTime(2018, 12, 01)); var date6 = new DateTimeOffset(new DateTime(2018, 12, 31)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date3, date4); var time3 = new RentTime(date5, date6); var clientFacade2 = new ClientFacade("Alice"); var carFacade3 = new CarFacade("3"); var carFacade4 = new CarFacade("4"); var carFacade5 = new CarFacade("5"); var carFacade6 = new CarFacade("6"); var date7 = new DateTimeOffset(new DateTime(2018, 10, 15)); var date8 = new DateTimeOffset(new DateTime(2018, 11, 30)); var date9 = new DateTimeOffset(new DateTime(2018, 12, 06)); var date10 = new DateTimeOffset(new DateTime(2018, 12, 27)); var date11 = new DateTimeOffset(new DateTime(2019, 03, 01)); var date12 = new DateTimeOffset(new DateTime(2019, 04, 14)); var date13 = new DateTimeOffset(new DateTime(2019, 11, 10)); var date14 = new DateTimeOffset(new DateTime(2020, 11, 19)); var time4 = new RentTime(date7, date8); var time5 = new RentTime(date9, date10); var time6 = new RentTime(date11, date12); var time7 = new RentTime(date13, date14); clientFacade1.RentCar(carFacade1, time1); clientFacade1.RentCar(carFacade2, time2); clientFacade1.RentCar(carFacade1, time3); clientFacade2.RentCar(carFacade3, time4); clientFacade2.RentCar(carFacade4, time5); clientFacade2.RentCar(carFacade5, time6); clientFacade2.RentCar(carFacade6, time7); Assert.AreEqual(clientFacade1.GetHistory().Count, 3); Assert.AreEqual(clientFacade2.GetHistory().Count, 4); }
public void CreateWrongRentTime_Exception() { var data1 = new DateTimeOffset(new DateTime(2018, 12, 15)); var data2 = new DateTimeOffset(new DateTime(2018, 10, 07)); bool hasException = false; try { var rentTime = new RentTime(data1, data2); } catch (Exception) { hasException = true; } Assert.IsTrue(hasException); }
public Activity(int id, string name, int classroomId, RentTime time) : base(id, name, classroomId, time) { }
public void SendCarOnRent11Times_Exception() { var carRentCompanyFacade = new CarRentCompanyFacade(); var carFacade = new CarFacade("10"); var clientFacade = new ClientFacade("Bob"); var date1 = new DateTimeOffset(new DateTime(2018, 10, 06)); var date2 = new DateTimeOffset(new DateTime(2018, 10, 07)); var date3 = new DateTimeOffset(new DateTime(2018, 10, 08)); var date4 = new DateTimeOffset(new DateTime(2018, 10, 09)); var date5 = new DateTimeOffset(new DateTime(2018, 10, 10)); var date6 = new DateTimeOffset(new DateTime(2018, 10, 11)); var date7 = new DateTimeOffset(new DateTime(2018, 10, 12)); var date8 = new DateTimeOffset(new DateTime(2018, 10, 13)); var date9 = new DateTimeOffset(new DateTime(2018, 10, 14)); var date10 = new DateTimeOffset(new DateTime(2018, 10, 15)); var date11 = new DateTimeOffset(new DateTime(2018, 10, 16)); var date12 = new DateTimeOffset(new DateTime(2018, 10, 17)); var date13 = new DateTimeOffset(new DateTime(2018, 10, 18)); var date14 = new DateTimeOffset(new DateTime(2018, 10, 19)); var date15 = new DateTimeOffset(new DateTime(2018, 10, 20)); var date16 = new DateTimeOffset(new DateTime(2018, 10, 21)); var date17 = new DateTimeOffset(new DateTime(2018, 10, 22)); var date18 = new DateTimeOffset(new DateTime(2018, 10, 23)); var date19 = new DateTimeOffset(new DateTime(2018, 10, 24)); var date20 = new DateTimeOffset(new DateTime(2018, 10, 25)); var date21 = new DateTimeOffset(new DateTime(2018, 10, 26)); var date22 = new DateTimeOffset(new DateTime(2018, 10, 27)); var time1 = new RentTime(date1, date2); var time2 = new RentTime(date3, date4); var time3 = new RentTime(date5, date6); var time4 = new RentTime(date7, date8); var time5 = new RentTime(date9, date10); var time6 = new RentTime(date11, date12); var time7 = new RentTime(date13, date14); var time8 = new RentTime(date15, date16); var time9 = new RentTime(date17, date18); var time10 = new RentTime(date19, date20); var time11 = new RentTime(date21, date22); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time1); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time2); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time3); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time4); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time5); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time6); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time7); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time8); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time9); carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time10); bool hasException = false; try { carRentCompanyFacade.SendCarOnRent(carFacade, clientFacade.Client, time11); } catch (Exception) { hasException = true; } Assert.IsTrue(hasException); }
private void btnRentBoat_Click(object sender, EventArgs e) { //validating BoatNumber int iBoatNumber = 0; int iBookingNumber = 0; bool isDataValidated = true; DateTime RentTime; 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; } // validating BoatCategory try { iBookingNumber = Convert.ToInt32(this.txtBookingNumber.Text); if (iBookingNumber <= 0) { MessageBox.Show("Booking number should be positive please enter a valid booking number"); isDataValidated = false; } } catch { MessageBox.Show("Please provide an integer for booking number"); isDataValidated = false; } // validating SocialSecurityNumber Regex regxSocialSecurityNumber = new Regex(@"^\d{6}-\d{4}$"); if (!regxSocialSecurityNumber.IsMatch(this.txtSocialSecurityNumber.Text)) { MessageBox.Show("Please provide a valid social security number with format XXXXXX-XXXX"); isDataValidated = false; } // validating Boat Category Combo box if (this.cmbBoatCategory.SelectedIndex < 0) { MessageBox.Show("Please select a valid boat category"); isDataValidated = false; } //Combine date and time input RentTime = this.dtRentDate.Value.Date + this.dtRentTime.Value.TimeOfDay; //CultureInfoConverter cultureInfo = new CultureInfoConverter(); // open connection if (con.State == ConnectionState.Closed) { con.Open(); } //Only save data in database if validation is succesful. if (isDataValidated) { try { string strQuery = "insert into BoatRentals values(@BoatNumber, @BookingNumber, @SocialSecurityNumber, @BoatCategory, @RentalTime, @ReturnTime, @Cost)"; cmd = new SqlCommand(strQuery, con); cmd.Parameters.AddWithValue("@BoatNumber", iBoatNumber); cmd.Parameters.AddWithValue("@BookingNumber", iBookingNumber); cmd.Parameters.AddWithValue("@SocialSecurityNumber", this.txtSocialSecurityNumber.Text); cmd.Parameters.AddWithValue("@BoatCategory", this.cmbBoatCategory.SelectedItem.ToString()); cmd.Parameters.AddWithValue("@RentalTime", RentTime.ToLocalTime()); cmd.Parameters.AddWithValue("@ReturnTime", DBNull.Value); cmd.Parameters.AddWithValue("@Cost", 0); int result = cmd.ExecuteNonQuery(); if (result == 1) { MessageBox.Show("Boat successfully rented."); display(); clearFields(); } } 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); } } }
public Course(int id, string name, int classroomId, RentTime time) : base(id, name, classroomId, time) { }