public void ExecuteWithUnknownSchedule() { var distributor = new ScheduleDistributor( ScheduleStorage.CreateInstanceWithoutTimeline(), (s, id, e) => null); Assert.Throws <UnknownScheduleException>(() => distributor.Execute(new ScheduleId())); }
public void ExecuteWithAlreadyRunningSchedule() { var action1 = new ScheduleElementId(); var action2 = new ScheduleElementId(); var exitCondition = new ScheduleElementId(); var passThroughCondition = new ScheduleElementId(); var subSchedule = new ScheduleId(); var schedule = BuildSchedule( action1, action2, subSchedule, exitCondition, passThroughCondition); var knownSchedules = ScheduleStorage.CreateInstanceWithoutTimeline(); var scheduleInfo = knownSchedules.Add( schedule, "a", "b"); var executor = new Mock <IExecuteSchedules>(); int index = 0; Func <ISchedule, ScheduleId, ScheduleExecutionInfo, IExecuteSchedules> builder = (s, id, e) => { index++; return(executor.Object); }; var distributor = new ScheduleDistributor(knownSchedules, builder); var returnedExecutor = distributor.Execute(scheduleInfo.Id); Assert.AreSame(executor.Object, returnedExecutor); Assert.AreEqual(1, index); var otherReturnedExecutor = distributor.Execute(scheduleInfo.Id); Assert.AreSame(executor.Object, otherReturnedExecutor); Assert.AreEqual(1, index); }
public void ExecuteInProcess() { var action1 = new ScheduleElementId(); var action2 = new ScheduleElementId(); var exitCondition = new ScheduleElementId(); var passThroughCondition = new ScheduleElementId(); var subSchedule = new ScheduleId(); var schedule = BuildSchedule( action1, action2, subSchedule, exitCondition, passThroughCondition); var knownSchedules = ScheduleStorage.CreateInstanceWithoutTimeline(); var scheduleInfo = knownSchedules.Add( schedule, "a", "b"); ISchedule storedSchedule = null; var executor = new Mock <IExecuteSchedules>(); Func <ISchedule, ScheduleId, ScheduleExecutionInfo, IExecuteSchedules> builder = (s, i, e) => { storedSchedule = s; return(executor.Object); }; var distributor = new ScheduleDistributor(knownSchedules, builder); var returnedExecutor = distributor.Execute(scheduleInfo.Id); Assert.AreSame(executor.Object, returnedExecutor); VerifySchedule(schedule, storedSchedule); }