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));
        }
        private SendAfterEndpointEventConfiguration CallsInternal(VoidDelegate voidDelegate)
        {
            var sequence = new TriggeredMessageSequence();
            var trigger  = new InvocationTriggeringSequenceOfEvents(_invocationMatcher, sequence);

            _wcfProxy.AddInvocation(trigger, voidDelegate);

            return(new SendAfterEndpointEventConfiguration(sequence, _service));
        }
        private SendAfterEndpointEventConfiguration ReturnsInternal(IInvocationReturnValueProducer returnValueProducer)
        {
            var sequence = new TriggeredMessageSequence();
            var trigger  = new InvocationTriggeringSequenceOfEvents(_invocationMatcher, sequence);

            _wcfProxy.AddInvocation(trigger, returnValueProducer);

            return(new SendAfterEndpointEventConfiguration(sequence, _service));
        }
Example #5
0
        public SendAfterEndpointEventConfiguration Returns <T1, T2, T3, T4, T5, T6, T7, T8>(Func <T1, T2, T3, T4, T5, T6, T7, T8, R> returnValueProducer)
        {
            var sequence  = new TriggeredMessageSequence();
            var inspector = new RouteInvocationTriggeringSequenceOfEvents(_route, _matcher, sequence);

            _route.AddReturn(inspector, new ProduceDelegateReturnValue(returnValueProducer, new MapRequestToDelegateHeuristic(_route.Route, returnValueProducer)));

            return(new SendAfterEndpointEventConfiguration(sequence, _service));
        }
Example #6
0
        public SendAfterEndpointEventConfiguration Returns(R returnValue)
        {
            var sequence  = new TriggeredMessageSequence();
            var inspector = new RouteInvocationTriggeringSequenceOfEvents(_route, _matcher, sequence);

            _route.AddReturn(inspector, new ProduceStaticReturnValue(returnValue));

            return(new SendAfterEndpointEventConfiguration(sequence, _service));
        }
        public ReturnFromPostInvocationConfiguration With(IPostInvocationConfiguration configuration)
        {
            var sequence = new TriggeredMessageSequence();
            var inspector = new RouteInvocationTriggeringSequenceOfEvents(_route, configuration.CreateInvocationInspector(_route), sequence);

            var returnValueProxy = new NullOrInvocationReturnValueProducer();
            _route.AddReturn(inspector, returnValueProxy);

            return new ReturnFromPostInvocationConfiguration(sequence, _service, returnValueProxy);
        }
Example #8
0
        public SendAfterEndpointEventConfiguration Setup(Expression <Action <T> > methodSignatureExpectation)
        {
            IInvocationMatcher invocationMatcher = _parser.Parse(methodSignatureExpectation);

            var sequence = new TriggeredMessageSequence();
            var trigger  = new InvocationTriggeringSequenceOfEvents(invocationMatcher, sequence);

            _serviceImplementation.AddInvocation(trigger, new ProduceNullReturnValue());

            return(new SendAfterEndpointEventConfiguration(sequence, _service));
        }
Example #9
0
        public ReturnFromPostInvocationConfiguration With(IPostInvocationConfiguration configuration)
        {
            var sequence  = new TriggeredMessageSequence();
            var inspector = new RouteInvocationTriggeringSequenceOfEvents(_route, configuration.CreateInvocationInspector(_route), sequence);

            var returnValueProxy = new NullOrInvocationReturnValueProducer();

            _route.AddReturn(inspector, returnValueProxy);

            return(new ReturnFromPostInvocationConfiguration(sequence, _service, returnValueProxy));
        }
 public InvocationTriggeringSequenceOfEvents(IInvocationMatcher matcher, TriggeredMessageSequence sequence)
 {
     _matcher = matcher;
     _sequence = sequence;
 }
 public RouteInvocationTriggeringSequenceOfEvents(IRouteTemplate routeOwningUrl, IInvocationMatcher matcher, TriggeredMessageSequence sequence)
 {
     _routeOwningUrl = routeOwningUrl;
     _matcher = matcher;
     _sequence = sequence;
 }
 public RouteInvocationTriggeringSequenceOfEvents(IRouteTemplate routeOwningUrl, IInvocationMatcher matcher, TriggeredMessageSequence sequence)
 {
     _routeOwningUrl = routeOwningUrl;
     _matcher        = matcher;
     _sequence       = sequence;
 }
Example #13
0
 public ReturnFromPostInvocationConfiguration(TriggeredMessageSequence sequenceBeingConfigured, ServiceStub componentBeingConfigured, NullOrInvocationReturnValueProducer returnValueProxy) : base(sequenceBeingConfigured, componentBeingConfigured)
 {
     _sequenceBeingConfigured  = sequenceBeingConfigured;
     _componentBeingConfigured = componentBeingConfigured;
     _returnValueProxy         = returnValueProxy;
 }
 public InvocationTriggeringSequenceOfEvents(IInvocationMatcher matcher, TriggeredMessageSequence sequence)
 {
     _matcher  = matcher;
     _sequence = sequence;
 }