public void QueryPassesOnCall()
        {
            var urn = string.Empty;
            var args = new QueryArguments();
            var result = new QueryResult();
            var invokerMock = new Mock<IActionInvoker>(MockBehavior.Strict);
            invokerMock.Setup(i => i.Query(urn, args)).Returns(result).Verifiable();

            var channel = new WcfChannel(invokerMock.Object);
            var actual = channel.Query(urn, args);
            Assert.AreSame(result, actual);
            invokerMock.Verify();
        }
示例#2
0
        /// <summary>
        /// Queries the details on an item action.
        /// </summary>
        /// <param name="urn">The URN to query for actions.</param>
        /// <param name="arguments">The arguments for the query.</param>
        /// <returns>
        /// The allowed actions on the URN.
        /// </returns>
        public QueryResult Query(string urn, QueryArguments arguments)
        {
            var result = new QueryResult();
            arguments = arguments ?? new QueryArguments();

            var item = this.LocateItem(urn);
            if (item == null)
            {
                logger.Warn("Request made to unknown URN '{0}'", urn);
                result.ResultCode = RemoteResultCode.UnknownUrn;
                return result;
            }

            var itemType = item.GetType();
            var actions = new List<RemoteActionDefinition>();
            var filterRegex = (arguments == null) || string.IsNullOrEmpty(arguments.FilterPattern) ?
                null :
                new Regex(arguments.FilterPattern);
            var messageFormats = new Dictionary<Type, string>();
            var namespaces = new Dictionary<string, string>();
            foreach (var method in itemType.GetMethods(BindingFlags.Instance | BindingFlags.Public))
            {
                var actionAttributes = method.GetCustomAttributes(
                    typeof(RemoteActionAttribute), false);
                if ((actionAttributes.Length > 0) &&
                    ((filterRegex == null) || filterRegex.IsMatch(method.Name)))
                {
                    // TODO: Validate security here

                    var definition = GenerateDefinition(arguments, method, messageFormats, namespaces);
                    actions.Add(definition);
                }
            }

            // Generate the result
            result.Actions = actions.ToArray();
            return result;
        }