public void AddPurchaseTest() { Vehicle v = new Vehicle("type", "color", 100, "model", "make", true, true, 10, "here"); DBController.Save(v, DBObject.SaveTypes.Insert); DateTime startDate1 = new DateTime(2018, 1, 1); DateTime endDate1 = new DateTime(2018, 1, 2); Vehicle v2 = VehicleControl.FilterCar("type", "color", "make", 99, 101, true, true, "here", startDate1, endDate1).FirstOrDefault(); Assert.IsNotNull(v2); Customer c1 = new Customer("John", "Doe", "username", "password"); DBController.Save(c1, DBObject.SaveTypes.Insert); DateTime startDate = new DateTime(2018, 1, 1); DateTime endDate = new DateTime(2018, 1, 2); Purchase p1 = new Purchase(startDate, "here", v2, c1); PurchaseControl.AddPurchase(p1); Vehicle v3 = VehicleControl.FilterCar("type", "color", "make", 99, 101, true, true, "here", startDate, endDate).FirstOrDefault(); Assert.IsNull(v3); Vehicle v4 = VehicleControl.GetAllVehicles().Where(vehicle => vehicle.VehicleID == p1.VehicleID).FirstOrDefault(); Assert.IsTrue(v4.IsRented); }
public void FilterCarTest() { Vehicle v = VehicleControl.GetAllVehicles().FirstOrDefault(); Vehicle vR = VehicleControl.GetAllVehicles().Where(vehicle => vehicle.IsRented).FirstOrDefault(); string cartype = v.Type; string carcolor = v.Color; string carmake = v.Make; int caryear1 = 0; int caryear2 = 2019; DateTime startDate = new DateTime(2018, 1, 1); DateTime endDate = new DateTime(2018, 1, 2); DateTime startDate2 = new DateTime(2018, 5, 1); DateTime endDate2 = new DateTime(2018, 5, 2); List <Vehicle> lv = VehicleControl.FilterCar(vR.Type, vR.Color, vR.Make, vR.VehicleYear, vR.VehicleYear, vR.RightHandControlled, vR.ManualTransmission, vR.CurrentLocation, startDate2, endDate2); Assert.IsNotNull(lv); lv = VehicleControl.FilterCar(cartype, carcolor, carmake, caryear1, caryear2, false, false, "Madison", startDate, endDate); Assert.IsNotNull(lv); Vehicle v2 = lv.Where(car => car.Type == cartype && car.Color == carcolor && car.VehicleYear >= caryear1 && car.VehicleYear <= caryear2).FirstOrDefault(); Assert.IsNotNull(v2); lv = VehicleControl.FilterCar(null, null, null, 1900, 2020, false, false, null, startDate, endDate); Assert.IsNotNull(lv); }
/// <summary> /// Changes the displayed information in the <seealso cref="ListView"/>. /// </summary> private void UpdateList() { listView1.LargeImageList = imageList1; string carColor = null; string carType = null; string location = null; string makeType = null; DateTime carPickup = pickUpDate.Value.Date; DateTime carDropOff = dropOffDate.Value.Date; if (carTypeCB.SelectedItem != null) { carType = carTypeCB.SelectedItem.ToString(); } if (colorCB.SelectedItem != null) { carColor = colorCB.SelectedItem.ToString(); } if (makeComboBox.SelectedItem != null) { makeType = makeComboBox.SelectedItem.ToString(); } if (PickUpBox.SelectedItem != null) { location = PickUpBox.SelectedItem.ToString(); } int caryearfirst = (Int32)yearBoxFirst.Value; int caryearsecond = (Int32)yearBoxSecond.Value; List <Vehicle> lv = VehicleControl.FilterCar(carType, carColor, makeType, caryearfirst, caryearsecond, RightHandControl.Checked, ManualTransmission.Checked, location, carPickup, carDropOff); listView1.Clear(); foreach (var item in lv) { listItem = new ListViewItem(); listItem.Text = item.ToString(); listItem.Tag = item; if (item.Type == "Sedan") { listItem.ImageKey = "Sedan.png"; listView1.Items.Add(listItem); } else if (item.Type == "Sports Car") { listItem.ImageKey = "Sports Car.bmp"; listView1.Items.Add(listItem); } else if (item.Type == "Luxury") { listItem.ImageKey = "Luxury.bmp"; listView1.Items.Add(listItem); } else if (item.Type == "SUV") { listItem.ImageKey = "SUV.bmp"; listView1.Items.Add(listItem); } else if (item.Type == "Truck") { listItem.ImageKey = "Truck.jpg"; listView1.Items.Add(listItem); } else if (item.Type == "Hatchback") { listItem.ImageKey = "Hatchback.png"; listView1.Items.Add(listItem); } else if (item.Type == "Van") { listItem.ImageKey = "Van.png"; listView1.Items.Add(listItem); } } }