private static Model.ScheduledStop Map(ScheduleLocation stop) { var mapper = ToViewProfileConfiguration.CreateMapper(); return((Model.ScheduledStop)mapper.Map(stop, stop.GetType(), typeof(Model.ScheduledStop), o => { o.Items["On"] = TestDate; })); }
public void GetsTocSchedulesHandlesIndividualDodgyServicesAndLogsAsWarning() { var logger = Substitute.For <ILogger>(); var timetable = CreateTimetable(logger); var schedule = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday)); var start = TestSchedules.Ten; var stops = new ScheduleLocation[] { TestScheduleLocations.CreatePass(TestStations.Vauxhall, start.AddMinutes(10)), TestScheduleLocations.CreatePass(TestStations.ClaphamJunction, start.AddMinutes(20)), TestScheduleLocations.CreatePass(TestStations.Wimbledon, start.AddMinutes(20)), }; var dodgySchedule = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "D11111", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday), stops: stops); var schedule3 = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98765", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday)); var found = timetable.GetSchedulesByToc("VT", MondayAugust12, Time.Midnight); var schedules = found.services.Select(s => s.Details).ToArray(); Assert.Contains <ISchedule>(schedule, schedules); Assert.Contains <ISchedule>(schedule3, schedules); Assert.All(found.services, s => { Assert.Equal(MondayAugust12, s.On); }); logger.Received().Warning(Arg.Any <InvalidOperationException>(), Arg.Any <string>(), Arg.Any <IService>()); }
public ActionResult DeleteConfirmed(int id) { ScheduleLocation scheduleLocation = db.ScheduleLocation.Find(id); db.ScheduleLocation.Remove(scheduleLocation); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,TruckID,LocationID,ScheduleID")] ScheduleLocation scheduleLocation) { if (ModelState.IsValid) { db.Entry(scheduleLocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LocationID = new SelectList(db.Location, "ID", "Name", scheduleLocation.LocationID); ViewBag.ScheduleID = new SelectList(db.Schedule, "ID", "ID", scheduleLocation.ScheduleID); ViewBag.TruckID = new SelectList(db.Truck, "ID", "Name", scheduleLocation.TruckID); return(View(scheduleLocation)); }
public void StartsBeforeThrowsInvalidOperationExceptionWhenNoDepartures() { var start = TestSchedules.Ten; var stops = new ScheduleLocation[] { TestScheduleLocations.CreatePass(TestStations.Vauxhall, start.AddMinutes(10)), TestScheduleLocations.CreatePass(TestStations.ClaphamJunction, start.AddMinutes(20)), TestScheduleLocations.CreatePass(TestStations.Wimbledon, start.AddMinutes(20)), }; var service = TestSchedules.CreateScheduleWithService(stops: stops).Service; Assert.Throws <InvalidOperationException>(() => service.StartsBefore(Time.StartRailDay)); }
// GET: ScheduleLocations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ScheduleLocation scheduleLocation = db.ScheduleLocation.Find(id); if (scheduleLocation == null) { return(HttpNotFound()); } return(View(scheduleLocation)); }
// GET: ScheduleLocations/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ScheduleLocation scheduleLocation = db.ScheduleLocation.Find(id); if (scheduleLocation == null) { return(HttpNotFound()); } ViewBag.LocationID = new SelectList(db.Location, "ID", "Name", scheduleLocation.LocationID); ViewBag.ScheduleID = new SelectList(db.Schedule, "ID", "ID", scheduleLocation.ScheduleID); ViewBag.TruckID = new SelectList(db.Truck, "ID", "Name", scheduleLocation.TruckID); return(View(scheduleLocation)); }
private void MapLocations(IEnumerable <IRecord> records, CifSchedule schedule, ResolutionContext context) { var locations = new List <ScheduleLocation>(16); var start = Time.NotValid; var sequence = new Sequence(); foreach (var record in records) { ScheduleLocation working = null; switch (record) { case IntermediateLocation il: working = MapLocation(il); break; case OriginLocation ol: working = MapOrigin(ol); break; case TerminalLocation tl: working = MapDestination(tl); break; case ScheduleChange sc: // _logger.Debug("Unhandled ScheduleChange : {record}", sc); break; default: _logger.Warning("Unhandled record {recordType} : {record}", record.GetType(), record); break; } // Only add stops that we care about i.e. in the MSL if (working?.Location != null) { EnsureTimesGoToTheFuture(working); working.SetParent(schedule); working.Id = sequence.GetNext(); } } ScheduleLocation MapLocation(IntermediateLocation il) { return(il.WorkingPass == null ? (ScheduleLocation)context.Mapper.Map <IntermediateLocation, ScheduleStop>(il, null) : context.Mapper.Map <IntermediateLocation, SchedulePass>(il, null)); } ScheduleLocation MapOrigin(OriginLocation ol) { var origin = context.Mapper.Map <OriginLocation, ScheduleStop>(ol, null); start = origin.Departure.IsBefore(origin.WorkingDeparture) ? origin.Departure : origin.WorkingDeparture; return(origin); } ScheduleLocation MapDestination(TerminalLocation tl) { return(context.Mapper.Map <TerminalLocation, ScheduleStop>(tl, null)); } void EnsureTimesGoToTheFuture(ScheduleLocation scheduleLocation) { if (start.Equals(Time.NotValid)) { _logger.Warning($"ID: {scheduleLocation.Id} Have not set start: {schedule.TimetableUid}"); } scheduleLocation.AddDay(start); } }
public void ToStringOutputsTimePlusLocation(ScheduleLocation location, string expected) { Assert.Equal(expected, location.ToString()); }
private Model.ScheduledStop ConvertToStop(ScheduleLocation scheduleLocation, ResolutionContext context) { return((Model.ScheduledStop)context.Mapper .Map(scheduleLocation, scheduleLocation.GetType(), typeof(Model.ScheduledStop))); }