コード例 #1
0
        public void CanInvokeVoidMethod()
        {
            string  input     = "Hello";
            dynamic dynoAgent = _serviceAgent;

            Action <ActionCallInfo> assertCallInfo = info =>
            {
                Assert.IsNotNull(info);
                Assert.AreEqual("VoidMethod", info.MethodName);
                Assert.IsNull(info.ReturnType);
                Assert.AreEqual(1, info.UnnamedArguments.Count);
                Assert.AreEqual(input, info.UnnamedArguments.First());
            };

            _listenerMock.Setup(x => x.CanHandle(It.IsAny <ActionCallInfo>()))
            .Callback(assertCallInfo)
            .Returns(true);
            _listenerMock.Setup(x => x.Handle(It.IsAny <ActionListenerContext>()))
            .Callback <ActionListenerContext>(context =>
            {
                ActionCallInfo info = context.CallInfo;
                assertCallInfo(info);
            })
            .Returns(true);

            dynoAgent.VoidMethod(input);

            _listenerMock.VerifyAll();
        }
コード例 #2
0
        public void CanInvokeFuncMethod()
        {
            string  input     = "Testing func";
            string  output    = "This is output";
            dynamic dynoAgent = _serviceAgent;

            Action <ActionCallInfo> assertCallInfo = info =>
            {
                Assert.IsNotNull(info);
                Assert.AreEqual("FuncMethod", info.MethodName);
                Assert.AreEqual(typeof(string), info.ReturnType);
                Assert.AreEqual(1, info.UnnamedArguments.Count);
                Assert.AreEqual(input, info.UnnamedArguments.First());
            };

            _listenerMock.Setup(x => x.CanHandle(It.IsAny <ActionCallInfo>()))
            .Callback(assertCallInfo)
            .Returns(true);
            _listenerMock.Setup(x => x.Handle(It.IsAny <ActionListenerContext>()))
            .Callback <ActionListenerContext>(context =>
            {
                ActionCallInfo info = context.CallInfo;
                assertCallInfo(info);
                context.Result = output;
            })
            .Returns(true);

            string result = dynoAgent.FuncMethod(input);

            Assert.AreEqual(output, result);

            _listenerMock.VerifyAll();
        }
コード例 #3
0
        public object ExecuteListeners(ActionCallInfo callInfo)
        {
            object[] actionListeners = _resolvingService.ResolveAll(typeof(IActionListener));
            IEnumerable <IActionListener> handlers = actionListeners.Cast <IActionListener>().Where(h => h.CanHandle(callInfo));
            var  context    = new ActionListenerContext(callInfo);
            bool wasHandled = handlers.Any(actionListener => actionListener.Handle(context));

            if (!wasHandled)
            {
                throw new InvalidOperationException("No handler for call");
            }
            return(context.Result);
        }
コード例 #4
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var callInfo = new ActionCallInfo
            {
                NamedArguments = binder.CallInfo
                                 .ArgumentNames
                                 .Reverse()
                                 .Zip(args.Reverse(), (x, y) => new Tuple <string, object>(x, y))
                                 .ToList(),
                UnnamedArguments = args.Take(binder.CallInfo.ArgumentCount - binder.CallInfo.ArgumentNames.Count).ToList(),
                MethodName       = binder.Name
            };

            result = binder.ResultDiscarded()
                                        ? ExecuteListeners(callInfo)
                                        : new ServiceAgent(_resolvingService)
            {
                CallInfo = callInfo
            };
            return(true);
        }
コード例 #5
0
 public bool CanHandle(ActionCallInfo callInfo)
 {
     return(callInfo.NamedArguments.Any(x => x.Item1.Equals("log", StringComparison.OrdinalIgnoreCase)));
 }
コード例 #6
0
 public ActionListenerContext(ActionCallInfo callInfo)
 {
     CallInfo = callInfo;
 }
コード例 #7
0
 public bool CanHandle(ActionCallInfo callInfo)
 {
     return(callInfo.UnnamedArguments.Any(x => x is string));
 }
コード例 #8
0
 public ActionListenerContext(ActionCallInfo callInfo)
 {
     CallInfo = callInfo;
 }
コード例 #9
0
 public bool CanHandle(ActionCallInfo callInfo)
 {
     return(true);
 }