Exemplo n.º 1
0
        public void DispatchTest()
        {
            var ddWrite    = new DynamicDispatch <Writer, Node>("Write");
            var ddMulWrite = new DynamicDispatch <MultiplyWriter, Node>("Write");

            var tree = new BinaryNode
            {
                Left = new BinaryNode
                {
                    Left  = new ValueNode(3),
                    Right = new BinaryNode {
                        Left  = new ValueNode(4),
                        Right = new ValueNode(6)
                    }
                },
                Right = new ValueNode(8)
            };

            var sw = new StringWriter();

            ddWrite.Dispatch(new Writer(sw), tree);
            Assert.AreEqual("3,4,6,8", sw.ToString());

            sw = new StringWriter();
            ddMulWrite.Dispatch(new MultiplyWriter(sw, 2), tree);
            Assert.AreEqual("6,8,12,16", sw.ToString());
        }
Exemplo n.º 2
0
        public void FailureNullValue()
        {
            var element  = new ListSyntax();
            var argument = new Argument(element, null);

            var success = DynamicDispatch.IsAssignableFrom(loaded, typeof(string), null, argument, out var transformed);

            Assert.False(success);
            Assert.Null(transformed);
        }
Exemplo n.º 3
0
        public async Task <Message> Process(Message message)
        {
            var request  = message?.Payload;
            var response = await DynamicDispatch.Dispatch(_mediator, request, _ =>
            {
                throw new HttpResponseException(HttpStatusCodeExtensions.UnprocessableEntity);
            });

            return(response is Unit ? new Message() : new Message(response));
        }
Exemplo n.º 4
0
        public void SuccessfullArrayString(Type targetType)
        {
            var element  = new ListSyntax();
            var value    = new string[] { "first", "second" };
            var argument = new Argument(element, value);

            var success = DynamicDispatch.IsAssignableFrom(loaded, targetType, null, argument, out var transformed);

            Assert.True(success);
            Assert.IsAssignableFrom(targetType, transformed);
        }
Exemplo n.º 5
0
        public void SuccessfullSingleString(Type targetType)
        {
            var element  = new ListSyntax();
            var value    = "stringValue";
            var argument = new Argument(element, value);

            var success = DynamicDispatch.IsAssignableFrom(loaded, targetType, null, argument, out var transformed);

            Assert.True(success);
            Assert.IsAssignableFrom(targetType, transformed);
        }
Exemplo n.º 6
0
 private Task <object> Process(object request)
 {
     using (_mediator.NewScope())
         return(DynamicDispatch.Dispatch(_mediator, request));
 }
 public Task <object> Route(Routed route, object message, IMediator mediator)
 {
     return(DynamicDispatch.Dispatch(mediator, message));
 }