public void CanAddReservation() { // arrange IRepo <Customer> customerRepo = new MockContext <Customer>(); IRepo <Car> carRepo = new MockContext <Car>(); IRepo <Reservation> reservationRepo = new MockContext <Reservation>(); IRepo <Location> locationRepo = new MockContext <Location>(); IRepo <Model> modelRepo = new MockContext <Model>(); IRepo <Manufacturer> manufacturerRepo = new MockContext <Manufacturer>(); var controller = new ReservationController(carRepo, customerRepo, reservationRepo, locationRepo, modelRepo, manufacturerRepo); var reservation = new QueryReservation { CarId = 1, CustomerId = 1, StartDate = new DateTime(2020, 9, 1), EndDate = new DateTime(2020, 9, 2), Location = "Brasov" }; // act controller.Create(reservation); Reservation r = reservationRepo.Collection().FirstOrDefault(); // assert Assert.IsNotNull(r); Assert.AreEqual(1, reservationRepo.Collection().Count()); Assert.AreEqual(new DateTime(2020, 9, 1), r.StartDate); }
internal void ManageReservations(bool isCreating) { inAppBehavior.MenuItemEntry("Register new Car Rent", "Update Car Rent", isCreating); int id = 1; if (!isCreating) { id = reader.ReadInt("Reservation ID: "); } DateTime startDate = reader.ReadDate("Start Date: "); DateTime endDate = reader.ReadDate("End Date: "); QueryReservation queryReservation = new QueryReservation { Id = id, StartDate = startDate, EndDate = endDate, IsCreating = isCreating }; if (isCreating) { string plate = reader.ReadString("Car Plate: "); int customerId = reader.ReadInt("Client ID: "); string location = reader.ReadString("City: "); queryReservation.Plate = plate; queryReservation.CustomerId = customerId; queryReservation.Location = location; } PushModel(queryReservation, isCreating, contextManager.ManageReservations, ManageReservations); }
public ActionResult Update(QueryReservation reservation) { if (!ModelState.IsValid) { OverrideErrorMessage("Date should be in format dd-MM-yyyy"); return(View(reservation)); } contextManager.ManageReservations(false, reservation); return(RedirectToAction("Index", "Home")); }
public override bool IsValid(object value) { QueryReservation r = value as QueryReservation; if (r.EndDate < r.StartDate) { this.ErrorMessage = "End Date should be equal or bigger than Start Date"; return(false); } return(true); }
public override bool IsValid(object value) { QueryReservation r = value as QueryReservation; int id = r.Id; if (!r.IsCreating && (id < 1 || id > int.MaxValue)) { this.ErrorMessage = String.Format("Id should be between 1 and {0}", int.MaxValue); return(false); } return(true); }
public void ManageReservations(bool creating, QueryReservation queryReservation) { Reservation r = creating ? new Reservation() : queryReservation.Reservation; if (queryReservation.IsCreating) { r.CarId = queryReservation.CarId; r.CustomerId = (int)queryReservation.CustomerId; r.LocationId = queryReservation.LocationId; } r.StartDate = (DateTime)queryReservation.StartDate; r.EndDate = (DateTime)queryReservation.EndDate; InsertUpdateCommit(creating, r, reservationRepo); }