Esempio n. 1
0
 public void Execute(SequenceExecutionContext context)
 {
     for (int i = 0; i < _numberOfSends; i++)
     {
         _stepToRepeat.Execute(context);
     }
 }
        public void ExecuteNextStep_ExecutingWhileTriggeringNewSequenceOfEventsAsync_CanHandleAsyncExecuteAndAddNewSequences()
        {
            // Arrange
            var sequence = new TriggeredMessageSequence();

            var executionContext = new SequenceExecutionContext(new List<IMessageSequence> {sequence}, "whatever", new Mock<IMessagePicker>().Object);

            sequence.SetNextStep(new SendMessage(new Mock<ISender>().Object));

            // Act
            IList<Task> tasks = new List<Task>();

            for (int i = 0; i < 1000; i++)
            {
                var execute = new Task(obj => sequence.ExecuteNextStep(obj as SequenceExecutionContext), executionContext);
                var triggerNewSequenceOfEvents = new Task(() => sequence.TriggerNewSequenceOfEvents(new Mock<IMessageInitializerParameterBinder>().Object));

                tasks.Add(execute);
                tasks.Add(triggerNewSequenceOfEvents);

                execute.Start();
                triggerNewSequenceOfEvents.Start();
            }

            foreach (var task in tasks)
            {
                task.Wait();
            }

            // Assert
            Assert.That(tasks.All(task => task.IsCompleted));
        }
        public void ExecuteNextStep_ExecutingWhileTriggeringNewSequenceOfEventsAsync_CanHandleAsyncExecuteAndAddNewSequences()
        {
            // Arrange
            var sequence = new TriggeredMessageSequence();

            var executionContext = new SequenceExecutionContext(new List <IMessageSequence> {
                sequence
            }, "whatever", new Mock <IMessagePicker>().Object);

            sequence.SetNextStep(new SendMessage(new Mock <ISender>().Object));

            // Act
            IList <Task> tasks = new List <Task>();

            for (int i = 0; i < 1000; i++)
            {
                var execute = new Task(obj => sequence.ExecuteNextStep(obj as SequenceExecutionContext), executionContext);
                var triggerNewSequenceOfEvents = new Task(() => sequence.TriggerNewSequenceOfEvents(new Mock <IMessageInitializerParameterBinder>().Object));

                tasks.Add(execute);
                tasks.Add(triggerNewSequenceOfEvents);

                execute.Start();
                triggerNewSequenceOfEvents.Start();
            }

            foreach (var task in tasks)
            {
                task.Wait();
            }

            // Assert
            Assert.That(tasks.All(task => task.IsCompleted));
        }
Esempio n. 4
0
        public void Execute(SequenceExecutionContext context)
        {
            bool expectationHasBeenMet = false;

            while (!expectationHasBeenMet)
            {
                expectationHasBeenMet = TestExpectationIfAnyMessageOnQueue(context);
            }
        }
Esempio n. 5
0
        public bool TestExpectationIfAnyMessageOnQueue(SequenceExecutionContext context)
        {
            object[] nextMessage = context.GetNextMessage(_owningSequence);

            if (nextMessage == null)
                return false;

            return _expectation.Met(nextMessage);
        }
Esempio n. 6
0
        public void Execute(SequenceExecutionContext context)
        {
            bool expectationHasBeenMet = false;

            while (!expectationHasBeenMet)
            {
                expectationHasBeenMet = TestExpectationIfAnyMessageOnQueue(context);
            }
        }
Esempio n. 7
0
        public bool TestExpectationIfAnyMessageOnQueue(SequenceExecutionContext context)
        {
            object[] nextMessage = context.GetNextMessage(_owningSequence);

            if (nextMessage == null)
            {
                return(false);
            }

            return(_expectation.Met(nextMessage));
        }
Esempio n. 8
0
        public void ExecuteNextStep(SequenceExecutionContext executionContext)
        {
            if (Done)
                return;

            if (UpdateExecutionContextWithNextStep(executionContext))
            {
                IStep currentStep = executionContext.GetCurrentStep(this);
                currentStep.Execute(executionContext);
            }
        }
Esempio n. 9
0
        public void ExecuteNextStep(SequenceExecutionContext executionContext)
        {
            if (Done)
            {
                return;
            }

            if (UpdateExecutionContextWithNextStep(executionContext))
            {
                IStep currentStep = executionContext.GetCurrentStep(this);
                currentStep.Execute(executionContext);
            }
        }
Esempio n. 10
0
        private bool UpdateExecutionContextWithNextStep(SequenceExecutionContext executionContext)
        {
            if (executionContext.GetCurrentStep(this) == null)
                executionContext.SetCurrentStep(this, _chain.Root);
            else
            {
                IStep current = executionContext.GetCurrentStep(this);
                IStep next = _chain.GetStepAfter(current);

                if (next == null)
                {
                    executionContext.Cleanup(this);
                    Done = true;
                }
                else
                    executionContext.SetCurrentStep(this, next);
            }

            return !Done;
        }
Esempio n. 11
0
        private bool UpdateExecutionContextWithNextStep(SequenceExecutionContext executionContext)
        {
            if (executionContext.GetCurrentStep(this) == null)
            {
                executionContext.SetCurrentStep(this, _chain.Root);
            }
            else
            {
                IStep current = executionContext.GetCurrentStep(this);
                IStep next    = _chain.GetStepAfter(current);

                if (next == null)
                {
                    executionContext.Cleanup(this);
                    Done = true;
                }
                else
                {
                    executionContext.SetCurrentStep(this, next);
                }
            }

            return(!Done);
        }
Esempio n. 12
0
 public void Execute(SequenceExecutionContext context)
 {
     _sender.Send();
 }
Esempio n. 13
0
 public void Execute(SequenceExecutionContext context)
 {
     for(int i = 0; i < _numberOfSends; i++)
         _stepToRepeat.Execute(context);
 }
Esempio n. 14
0
 public void Execute(SequenceExecutionContext context)
 {
     _sender.Send();
 }