Beispiel #1
0
        public void can_have_a_message_handler()
        {
            var handler = Mock <IRoutedMessageHandler>();

            node.RegisterHandler(handler);

            node.MessageHandler.ShouldBe(handler);
        }
        public void can_execute_a_preview()
        {
            var method    = Mock <IMethod>();
            var target    = new MethodHost();
            var parameter = new object();

            methodFactory.Expect(x => x.CreateFrom(info))
            .Return(method);

            var handlingNode = new InteractionNode(
                new ControlHost(),
                Mock <IRoutedMessageController>()
                );

            handlingNode.RegisterHandler(Mock <IRoutedMessageHandler>());

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

            attribute.Initialize(typeof(MethodHost), null, container);

            method.Stub(x => x.Info).Return(info);

            attribute.Execute(null, handlingNode, new[] {
                parameter
            });

            method.AssertWasCalled(x => x.Invoke(target, parameter));
        }
        public void can_execute_a_callback()
        {
            var method = Mock <IMethod>();
            var target = new MethodHost();
            var result = new object();

            var handlingNode = new InteractionNode(
                new ControlHost(),
                Mock <IRoutedMessageController>()
                );

            handlingNode.RegisterHandler(Mock <IRoutedMessageHandler>());

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

            methodFactory.Expect(x => x.CreateFrom(info))
            .Return(method);

            attribute.Initialize(typeof(MethodHost), null, container);

            method.Expect(x => x.Invoke(target, result)).Return(typeof(string));
            method.Stub(x => x.Info).Return(typeof(object).GetMethod("ToString"));

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

            attribute.Execute(null, handlingNode, outcome);
        }
        public void can_execute_a_callback()
        {
            var method = Mock<IMethod>();
            var target = new MethodHost();
            var result = new object();

            var handlingNode = new InteractionNode(
                new ControlHost(),
                Mock<IRoutedMessageController>()
                );

            handlingNode.RegisterHandler(Mock<IRoutedMessageHandler>());

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

            methodFactory.Expect(x => x.CreateFrom(info))
                .Return(method);

            attribute.Initialize(typeof(MethodHost), null, container);

            method.Expect(x => x.Invoke(target, result)).Return(typeof(string));
            method.Stub(x => x.Info).Return(typeof(object).GetMethod("ToString"));

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

            attribute.Execute(null, handlingNode, outcome);
        }
Beispiel #5
0
        public void can_handle_an_exception()
        {
            var method = Mock<IMethod>();
            method.Stub(x => x.Info).Return(info);

            var target = new MethodHost();
            var exception = new Exception();

            var handlingNode = new InteractionNode(
                new ControlHost(),
                Mock<IRoutedMessageController>()
                );

            handlingNode.RegisterHandler(Mock<IRoutedMessageHandler>());

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

            methodFactory.Expect(x => x.CreateFrom(info))
                .Return(method);

            attribute.Initialize(typeof(MethodHost), null, container);

            attribute.Handle(null, handlingNode, exception);

            method.AssertWasCalled(x => x.Invoke(target, exception));
        }
Beispiel #6
0
        public void can_process_message_if_parent_node_has_handler()
        {
            var context       = new object();
            var message       = new FakeMessage();
            var handler       = Mock <IRoutedMessageHandler>();
            var parentHandler = Mock <IRoutedMessageHandler>();

            node.RegisterHandler(handler);
            parentNode.RegisterHandler(parentHandler);

            handler.Expect(x => x.Handles(message)).Return(false);
            controller.Expect(x => x.GetParent(element)).Return(parentNode);
            parentHandler.Expect(x => x.Handles(message)).Return(true);

            parentHandler.Expect(x => x.Process(message, context));

            node.ProcessMessage(message, context);
        }