Beispiel #1
0
        public void can_determine_negative_trigger_effect()
        {
            var filter1      = Mock <IPreProcessor>();
            var filter2      = Mock <IPreProcessor>();
            var handlingNode = Stub <IInteractionNode>();
            var sourceNode   = Stub <IInteractionNode>();

            var message = new ActionMessage();

            message.Initialize(sourceNode);

            var target     = new object();
            var parameters = new object[] {
                5, "param"
            };

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, null))
            .Return(parameters);

            filterManager.Stub(x => x.TriggerEffects)
            .Return(new[] {
                filter1, filter2
            }).Repeat.Any();

            filter1.Expect(x => x.Execute(message, handlingNode, parameters))
            .Return(false);

            filter2.Expect(x => x.Execute(message, handlingNode, parameters))
            .Return(true);

            var result = action.ShouldTriggerBeAvailable(message, handlingNode);

            result.ShouldBeFalse();
        }
Beispiel #2
0
        void CreateActionMessage()
        {
            string methodName = "Execute";

            var att = Command.GetType()
                      .GetAttributes <CommandAttribute>(true)
                      .FirstOrDefault();

            if (att != null)
            {
                methodName = att.ExecuteMethod;
            }

            actionMessage = new ActionMessage
            {
                MethodName         = methodName,
                AvailabilityEffect = AvailabilityEffect,
                OutcomePath        = OutcomePath
            };

            actionMessage.Initialize(Source);

            foreach (var parameter in Parameters)
            {
                actionMessage.Parameters.Add(new Parameter(parameter.Value));
            }
        }
        public void can_determine_positive_trigger_effect()
        {
            var filter = Mock<IPreProcessor>();
            var handlingNode = Stub<IInteractionNode>();

            var sourceNode = Stub<IInteractionNode>();
            var message = new ActionMessage();
            message.Initialize(sourceNode);

            var target = new object();
            var parameters = new object[] {
                5, "param"
            };

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, null))
                .Return(parameters);

            filterManager.Stub(x => x.TriggerEffects)
                .Return(new[] {
                    filter
                }).Repeat.Any();

            filter.Expect(x => x.Execute(message, handlingNode, parameters))
                .IgnoreArguments()
                .Return(true);

            var result = action.ShouldTriggerBeAvailable(message, handlingNode);

            Assert.That(result, Is.True);
        }
Beispiel #4
0
        public void when_executing_pre_filters_can_cancel()
        {
            var filter1      = Mock <IPreProcessor>();
            var filter2      = Mock <IPreProcessor>();
            var handlingNode = Stub <IInteractionNode>();

            var sourceNode = Stub <IInteractionNode>();

            var message = new ActionMessage();

            message.Initialize(sourceNode);

            var target     = new object();
            var parameters = new object[] {
                5, "param"
            };
            var context = EventArgs.Empty;

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
            .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
            .Return(new[] {
                filter1, filter2
            });

            filter1.Expect(x => x.Execute(message, handlingNode, parameters))
            .Return(false);

            filter2.Expect(x => x.Execute(message, handlingNode, parameters))
            .Return(true);

            action.Execute(message, handlingNode, context);
        }
        public void can_execute()
        {
            var soureceNode  = Stub <IInteractionNode>();
            var handlingNode = Stub <IInteractionNode>();

            var message = new ActionMessage();

            message.Initialize(soureceNode);

            var target     = new object();
            var parameters = new object[] {
                5, "param"
            };
            var task    = MockRepository.GenerateMock <IBackgroundTask>();
            var context = EventArgs.Empty;
            var handler = Stub <IRoutedMessageHandler>();

            handler.Stub(x => x.Unwrap()).Return(target);
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
            .IgnoreArguments()
            .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
            .Return(new IPreProcessor[] {});

            method.Stub(x => x.CreateBackgroundTask(target, parameters))
            .Return(task);

            task.Expect(x => x.Start(null));

            action.Execute(message, handlingNode, context);
        }
Beispiel #6
0
        public void can_throw_exception_on_execute()
        {
            var handlingNode = Stub <IInteractionNode>();
            var sourceNode   = Stub <IInteractionNode>();

            var message = new ActionMessage();

            message.Initialize(sourceNode);

            var target     = new object();
            var parameters = new object[] {
                5, "param"
            };
            var returnValue = new object();
            var context     = EventArgs.Empty;

            var handler = Stub <IRoutedMessageHandler>();

            handler.Stub(x => x.Unwrap()).Return(new object());
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
            .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
            .Return(new IPreProcessor[] {});

            method.Expect(x => x.Invoke(target, parameters))
            .Return(returnValue);

            filterManager.Stub(x => x.PostProcessors)
            .Return(new IPostProcessor[] {});

            filterManager.Stub(x => x.Rescues)
            .Return(new IRescue[] {});

            messageBinder.Expect(x => x.CreateResult(new MessageProcessingOutcome(
                                                         null,
                                                         method.Info.ReturnType,
                                                         false
                                                         ))).IgnoreArguments().Throw(new InvalidOperationException("test exception"));

            try
            {
                action.Execute(message, handlingNode, context);
            }
            catch (InvalidOperationException inex)
            {
                inex.StackTrace.Contains("Rhino.Mocks.Expectations.AbstractExpectation.ReturnOrThrow").ShouldBeTrue();
                return;
            }

            true.ShouldBeFalse();
        }
Beispiel #7
0
        public void alters_return_with_post_execute_filters()
        {
            var handlingNode = Stub <IInteractionNode>();
            var sourceNode   = Stub <IInteractionNode>();
            var result       = Mock <IResult>();

            var message = new ActionMessage();

            message.Initialize(sourceNode);

            var target     = new object();
            var parameters = new object[] {
                5, "param"
            };
            var returnValue = new object();
            var filter      = MockRepository.GenerateMock <IPostProcessor>();
            var context     = EventArgs.Empty;

            var handler = Stub <IRoutedMessageHandler>();

            handler.Stub(x => x.Unwrap()).Return(new object());
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
            .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
            .Return(new IPreProcessor[] {});

            method.Expect(x => x.Invoke(target, parameters))
            .Return(returnValue);

            filterManager.Stub(x => x.PostProcessors)
            .Return(new[] {
                filter
            });

            var outcome = new MessageProcessingOutcome(returnValue, returnValue.GetType(), false);

            filter.Expect(x => x.Execute(message, handlingNode, outcome));

            messageBinder.Expect(x => x.CreateResult(outcome))
            .IgnoreArguments()
            .Return(result);

            result.Expect(x => x.Execute(null)).IgnoreArguments();

            action.Execute(message, handlingNode, context);
        }
        public void alters_return_with_post_execute_filters()
        {
            var handlingNode = Stub<IInteractionNode>();
            var sourceNode = Stub<IInteractionNode>();
            var result = Mock<IResult>();

            var message = new ActionMessage();
            message.Initialize(sourceNode);

            var target = new object();
            var parameters = new object[] {
                5, "param"
            };
            var returnValue = new object();
            var filter = MockRepository.GenerateMock<IPostProcessor>();
            var context = EventArgs.Empty;

            var handler = Stub<IRoutedMessageHandler>();
            handler.Stub(x => x.Unwrap()).Return(new object());
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
                .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
                .Return(new IPreProcessor[] {});

            method.Expect(x => x.Invoke(target, parameters))
                .Return(returnValue);

            filterManager.Stub(x => x.PostProcessors)
                .Return(new[] {
                    filter
                });

            var outcome = new MessageProcessingOutcome(returnValue, returnValue.GetType(), false);

            filter.Expect(x => x.Execute(message, handlingNode, outcome));

            messageBinder.Expect(x => x.CreateResult(outcome))
                .IgnoreArguments()
                .Return(result);

            result.Expect(x => x.Execute(null)).IgnoreArguments();

            action.Execute(message, handlingNode, context);
        }
        public void can_process_an_action_message()
        {
            var handlingNode = Stub <IInteractionNode>();
            var sourceNode   = Stub <IInteractionNode>();
            var context      = new object();

            var message = new ActionMessage {
                MethodName = MethodName
            };

            message.Initialize(sourceNode);

            var action = Mock <IAction>();

            host.Expect(x => x.GetAction(message)).Return(action);
            action.Expect(x => x.Execute(message, handlingNode, context));

            handler.Process(message, context);
        }
        private void CreateActionMessage()
        {
            string methodName = "Execute";

            var att = Command.GetType()
                .GetAttributes<CommandAttribute>(true)
                .FirstOrDefault();

            if(att != null)
                methodName = att.ExecuteMethod;

            actionMessage = new ActionMessage
            {
                MethodName = methodName,
                AvailabilityEffect = AvailabilityEffect,
                OutcomePath = OutcomePath
            };

            actionMessage.Initialize(Source);

            foreach(var parameter in Parameters)
            {
                actionMessage.Parameters.Add(new Parameter(parameter.Value));
            }
        }
        public void can_process_an_action_message()
        {
            var handlingNode = Stub<IInteractionNode>();
            var sourceNode = Stub<IInteractionNode>();
            var context = new object();

            var message = new ActionMessage {MethodName = _methodName};
            message.Initialize(sourceNode);

            var action = Mock<IAction>();

            _host.Expect(x => x.GetAction(message)).Return(action);
            action.Expect(x => x.Execute(message, handlingNode, context));

            _handler.Process(message, context);
        }
        public void when_executing_pre_filters_can_cancel()
        {
            var filter1 = Mock<IPreProcessor>();
            var filter2 = Mock<IPreProcessor>();

            var sourceNode = Stub<IInteractionNode>();
            var message = new ActionMessage();
            message.Initialize(sourceNode);

            var handlingNode = Stub<IInteractionNode>();
            var parameters = new object[] {
                5, "param"
            };
            var context = EventArgs.Empty;
            var handler = Stub<IRoutedMessageHandler>();
            handler.Stub(x => x.Unwrap()).Return(new object());
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
                .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
                .Return(new[] {
                    filter1, filter2
                });

            filter1.Expect(x => x.Execute(message, handlingNode, parameters))
                .Return(false);

            filter2.Expect(x => x.Execute(message, handlingNode, parameters))
                .Return(true);

            action.Execute(message, handlingNode, context);
        }
        public void can_execute()
        {
            var soureceNode = Stub<IInteractionNode>();
            var handlingNode = Stub<IInteractionNode>();

            var message = new ActionMessage();
            message.Initialize(soureceNode);

            var target = new object();
            var parameters = new object[] {
                5, "param"
            };
            var task = MockRepository.GenerateMock<IBackgroundTask>();
            var context = EventArgs.Empty;
            var handler = Stub<IRoutedMessageHandler>();
            handler.Stub(x => x.Unwrap()).Return(target);
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
                .IgnoreArguments()
                .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
                .Return(new IPreProcessor[] {});

            method.Stub(x => x.CreateBackgroundTask(target, parameters))
                .Return(task);

            task.Expect(x => x.Start(null));

            action.Execute(message, handlingNode, context);
        }
        public void can_throw_exception_on_execute()
        {
            var handlingNode = Stub<IInteractionNode>();
            var sourceNode = Stub<IInteractionNode>();

            var message = new ActionMessage();
            message.Initialize(sourceNode);

            var target = new object();
            var parameters = new object[] {
                5, "param"
            };
            var returnValue = new object();
            var context = EventArgs.Empty;

            var handler = Stub<IRoutedMessageHandler>();
            handler.Stub(x => x.Unwrap()).Return(new object());
            handlingNode.Stub(x => x.MessageHandler).Return(handler);

            messageBinder.Expect(x => x.DetermineParameters(message, null, handlingNode, context))
                .Return(parameters);

            filterManager.Stub(x => x.PreProcessors)
                .Return(new IPreProcessor[] {});

            method.Expect(x => x.Invoke(target, parameters))
                .Return(returnValue);

            filterManager.Stub(x => x.PostProcessors)
                .Return(new IPostProcessor[] {});

            filterManager.Stub(x => x.Rescues)
                .Return(new IRescue[] {});

            messageBinder.Expect(x => x.CreateResult(new MessageProcessingOutcome(
                null,
                method.Info.ReturnType,
                false
                ))).IgnoreArguments().Throw(new InvalidOperationException("test exception"));

            try
            {
                action.Execute(message, handlingNode, context);
            }
            catch(InvalidOperationException inex)
            {
                Assert.That(inex.StackTrace.Contains("Rhino.Mocks.Expectations.AbstractExpectation.ReturnOrThrow"));
                return;
            }

            Assert.Fail("The test exception was not fired");
        }