public void InvokePassesOnCall()
        {
            var urn = string.Empty;
            var args = new InvokeArguments();
            var result = new InvokeResult();
            var invokerMock = new Mock<IActionInvoker>(MockBehavior.Strict);
            invokerMock.Setup(i => i.Invoke(urn, args)).Returns(result).Verifiable();

            var channel = new WcfChannel(invokerMock.Object);
            var actual = channel.Invoke(urn, args);
            Assert.AreSame(result, actual);
            invokerMock.Verify();
        }
示例#2
0
        /// <summary>
        /// Invokes an action on an item.
        /// </summary>
        /// <param name="urn">The URN to invoke the action.</param>
        /// <param name="arguments">The arguments for the action.</param>
        /// <returns>
        /// The return message from the action.
        /// </returns>
        public InvokeResult Invoke(string urn, InvokeArguments arguments)
        {
            var result = new InvokeResult();
            var item = this.LocateItem(urn);
            if (item == null)
            {
                logger.Warn("Request made to unknown URN '{0}'", urn);
                result.ResultCode = RemoteResultCode.UnknownUrn;
                return result;
            }

            if (arguments == null)
            {
                result.ResultCode = RemoteResultCode.MissingArguments;
                return result;
            }

            var method = FindAction(item.GetType(), arguments.Action);
            if (method == null)
            {
                logger.Warn("Request made for unknown action '{0}' on '{1}", arguments.Action, urn);
                result.ResultCode = RemoteResultCode.UnknownAction;
                return result;
            }

            // TODO: Validate security

            if (string.IsNullOrEmpty(arguments.Data))
            {
                result.ResultCode = RemoteResultCode.InvalidInput;
                return result;
            }

            var parameters = method.GetParameters();
            var input = MessageSerialiser.Deserialise(arguments.Data);
            if (parameters[0].ParameterType.IsAssignableFrom(input.GetType()))
            {
                var output = method.Invoke(item, new[] { input });
                result.Data = MessageSerialiser.Serialise(output);
            }
            else
            {
                result.ResultCode = RemoteResultCode.InvalidInput;
            }

            return result;
        }