public void Complete_ActivitySpecified_ActivityScheduled() { using (var context = new SimulationContext()){ long waitTime = 10; var activity = new MyActivity(); var instruction = new ScheduleActivityInstruction(activity, waitTime); long?nextTimePeriod; bool canComplete = instruction.CanComplete(context, out nextTimePeriod); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriod); instruction.Complete(context); context.MoveToTimePeriod(0); var process = context.ActiveProcesses.FirstOrDefault(p => p is ActivityHostProcess); var activityHost = process as ActivityHostProcess; Assert.IsNotNull(process); Assert.IsNotNull(activityHost); Assert.AreEqual(waitTime, activityHost.WaitTime); Assert.AreEqual(activity, activityHost.Activity); } }
public void Complete_ActivitySpecified_ActivityScheduled() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ long waitTime = 10; var activity = new Activity(); var instruction = new ScheduleActivityInstruction(activity, waitTime); long? nextTimePeriod; bool canComplete = instruction.CanComplete(context, out nextTimePeriod); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriod); instruction.Complete(context); context.MoveToTimePeriod(0); var process = context.ActiveProcesses.FirstOrDefault(p=>p is ActivityHostProcess); var activityHost = process as ActivityHostProcess; Assert.IsNotNull(process); Assert.IsNotNull(activityHost); Assert.AreEqual(waitTime, activityHost.WaitTime); Assert.AreEqual(activity, activityHost.Activity); } }
public void Complete_ContextPassed_ProcessActivated() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ var testProcess = new InstructionListTestProcess(new WaitInstruction(10)); var enumerator = testProcess.Simulate(); testProcess.SimulationState.InstructionEnumerator = enumerator; context.MoveToTimePeriod(0); Assert.IsTrue(context.ActiveProcesses.Contains(testProcess)); // clear the remaining process queue context.ProcessesRemainingThisTimePeriod.Clear(); enumerator.MoveNext(); var instruction = new InterruptInstruction(testProcess); long? nextTimePeriodCheck = null; bool canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); instruction.Complete(context); Assert.IsTrue(testProcess.SimulationState.IsInterrupted); // the process should be back in the queue Assert.IsTrue(context.ProcessesRemainingThisTimePeriod.Contains(testProcess)); Assert.IsTrue(enumerator.Current.IsInterrupted); Assert.IsFalse(enumerator.Current.IsCompleted); } }
public void CanComplete_BeforeAndAfterEvent_ReturnsTrueOnlyAfterEvent() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ var waitInstruction = new WaitNotificationInstruction<object>(); var process = new InstructionListTestProcess(new List<InstructionBase>(){ waitInstruction}); context.MoveToTimePeriod(0); process.SimulationState.InstructionEnumerator = process.Simulate(); process.SimulationState.InstructionEnumerator.MoveNext(); var testEvent = new TestNotification(); var raiseInstruction = new RaiseNotificationInstruction<object>(testEvent); long? nextTimePeriodCheck; bool canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); raiseInstruction.Complete(context); canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriodCheck); } }
public void Complete_ContextPassed_ProcessActivated() { using (var context = new SimulationContext(isDefaultContextForProcess: true)){ var testProcess = new InstructionListTestProcess(new WaitInstruction(10)); var enumerator = testProcess.Simulate(); testProcess.SimulationState.InstructionEnumerator = enumerator; context.MoveToTimePeriod(0); Assert.IsTrue(context.ActiveProcesses.Contains(testProcess)); // clear the remaining process queue context.ProcessesRemainingThisTimePeriod.Clear(); enumerator.MoveNext(); var instruction = new InterruptInstruction(testProcess); long?nextTimePeriodCheck = null; bool canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); instruction.Complete(context); Assert.IsTrue(testProcess.SimulationState.IsInterrupted); // the process should be back in the queue Assert.IsTrue(context.ProcessesRemainingThisTimePeriod.Contains(testProcess)); Assert.IsTrue(enumerator.Current.IsInterrupted); Assert.IsFalse(enumerator.Current.IsCompleted); } }
public void CanComplete_BeforeAndAfterEvent_ReturnsTrueOnlyAfterEvent() { using (var context = new SimulationContext(isDefaultContextForProcess: true)){ var waitInstruction = new WaitNotificationInstruction <object>(); var process = new InstructionListTestProcess(new List <InstructionBase>() { waitInstruction }); context.MoveToTimePeriod(0); process.SimulationState.InstructionEnumerator = process.Simulate(); process.SimulationState.InstructionEnumerator.MoveNext(); var testEvent = new TestNotification(); var raiseInstruction = new RaiseNotificationInstruction <object>(testEvent); long?nextTimePeriodCheck; bool canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); raiseInstruction.Complete(context); canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriodCheck); } }
public void MoveToTimePeriod_TimePeriodSpecified_ProcessCollectionsInitialised() { using (var context = new SimulationContext()){ var process1 = new Process(context); var process2 = new Process(context); var process3 = new Process(context); var processes = new List <Process>() { process1, process2, process3 }; Assert.AreEqual(0, context.TimePeriod); context.MoveToTimePeriod(1); Assert.AreEqual(1, context.TimePeriod); Assert.AreEqual(processes.Count, context.ActiveProcesses.Count); foreach (var process in processes) { Assert.IsTrue(context.ActiveProcesses.Contains(process)); Assert.IsTrue(context.ProcessesRemainingThisTimePeriod.Contains(process)); } } }
public void CanComplete_ContextPassed_ReturnsFalseUntilTimePeriodChanged() { using (var context = new SimulationContext(isDefaultContextForProcess: true)){ context.MoveToTimePeriod(0); var instruction = new PassInstruction(); long?nextTimePeriodCheck = null; bool canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); context.MoveToTimePeriod(1); canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriodCheck); } }
public void CanComplete_ContextPassed_ReturnsFalseUntilTimePeriodChanged() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ context.MoveToTimePeriod(0); var instruction = new PassInstruction(); long? nextTimePeriodCheck = null; bool canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); context.MoveToTimePeriod(1); canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriodCheck); } }
public void CanComplete_Various_ReturnsFalseUntilWaitTimeElapsed() { using (var context = new SimulationContext()){ long waitPeriods = 10; var instruction = new WaitInstruction(waitPeriods); bool canComplete = false; long?nextTimePeriodCheck; for (int i = 1; i < waitPeriods; i++) { context.MoveToTimePeriod(i); canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.AreEqual(waitPeriods, nextTimePeriodCheck); } context.MoveToTimePeriod(waitPeriods); canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); } }
public void CanComplete_Various_ReturnsFalseUntilWaitTimeElapsed() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ long waitPeriods = 10; var instruction = new WaitInstruction(waitPeriods); bool canComplete = false; long? nextTimePeriodCheck; for(int i=1;i<waitPeriods;i++){ context.MoveToTimePeriod(i); canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.AreEqual(waitPeriods, nextTimePeriodCheck); } context.MoveToTimePeriod(waitPeriods); canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); } }
public void CanComplete_BeforeAndAfterEventWithCondition_ReturnsTrueOnlyAfterEventMatchingCondition() { using (var context = new SimulationContext(isDefaultContextForProcess: true)){ var waitInstruction = new WaitNotificationInstruction <TestNotification>((e) => e.Data > 0); var process = new InstructionListTestProcess(new List <InstructionBase>() { waitInstruction }); context.MoveToTimePeriod(0); process.SimulationState.InstructionEnumerator = process.Simulate(); process.SimulationState.InstructionEnumerator.MoveNext(); var testEvent1 = new TestNotification() { Data = 0 }; var raiseInstruction1 = new RaiseNotificationInstruction <TestNotification>(testEvent1); var testEvent2 = new TestNotification() { Data = 1 }; var raiseInstruction2 = new RaiseNotificationInstruction <TestNotification>(testEvent2); long?nextTimePeriodCheck; bool canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); raiseInstruction1.Complete(context); canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); raiseInstruction2.Complete(context); canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriodCheck); Assert.AreEqual(1, waitInstruction.Notifications.Count); Assert.IsTrue(waitInstruction.Notifications.Contains(testEvent2)); } }
public void Complete_ContextPassed_ProcessDeActivated() { using (var context = new SimulationContext()){ Process testProcess = new Process(context); context.MoveToTimePeriod(0); Assert.IsTrue(context.ActiveProcesses.Contains(testProcess)); var instruction = new DeactivateInstruction(testProcess); long?nextTimePeriodCheck = null; bool canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); instruction.Complete(context); Assert.IsFalse(testProcess.SimulationState.IsActive); Assert.IsFalse(context.ActiveProcesses.Contains(testProcess)); } }
public void Complete_ContextPassed_ProcessDeActivated() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ Process testProcess = new Process(); context.MoveToTimePeriod(0); Assert.IsTrue(context.ActiveProcesses.Contains(testProcess)); var instruction = new DeactivateInstruction(testProcess); long? nextTimePeriodCheck = null; bool canComplete = instruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); instruction.Complete(context); Assert.IsFalse(testProcess.SimulationState.IsActive); Assert.IsFalse(context.ActiveProcesses.Contains(testProcess)); } }
public void CanComplete_BeforeAndAfterEventWithCondition_ReturnsTrueOnlyAfterEventMatchingCondition() { using (var context = new SimulationContext(isDefaultContextForProcess:true)){ var waitInstruction = new WaitNotificationInstruction<TestNotification>((e)=>e.Data > 0); var process = new InstructionListTestProcess(new List<InstructionBase>(){ waitInstruction}); context.MoveToTimePeriod(0); process.SimulationState.InstructionEnumerator = process.Simulate(); process.SimulationState.InstructionEnumerator.MoveNext(); var testEvent1 = new TestNotification() { Data = 0 }; var raiseInstruction1 = new RaiseNotificationInstruction<TestNotification>(testEvent1); var testEvent2 = new TestNotification() { Data = 1 }; var raiseInstruction2 = new RaiseNotificationInstruction<TestNotification>(testEvent2); long? nextTimePeriodCheck; bool canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); raiseInstruction1.Complete(context); canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsFalse(canComplete); Assert.IsNull(nextTimePeriodCheck); raiseInstruction2.Complete(context); canComplete = waitInstruction.CanComplete(context, out nextTimePeriodCheck); Assert.IsTrue(canComplete); Assert.IsNull(nextTimePeriodCheck); Assert.AreEqual(1,waitInstruction.Notifications.Count); Assert.IsTrue(waitInstruction.Notifications.Contains(testEvent2)); } }
public void MoveToTimePeriod_TimePeriodSpecified_ProcessCollectionsInitialised() { using (var context = new SimulationContext(isDefaultContextForProcess: true)){ var process1 = new Process(); var process2 = new Process(); var process3 = new Process(); var processes = new List<Process>(){ process1, process2, process3 }; Assert.AreEqual(0, context.TimePeriod); context.MoveToTimePeriod(1); Assert.AreEqual(1, context.TimePeriod); Assert.AreEqual(processes.Count, context.ActiveProcesses.Count); foreach(var process in processes){ Assert.IsTrue(context.ActiveProcesses.Contains(process)); Assert.IsTrue(context.ProcessesRemainingThisTimePeriod.Contains(process)); } } }