コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        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));
            }
        }