public void GetParameterDeclarations_DuplciateParameterIndex_ThrowsWxeException()
 {
     Assert.That(
         () => WxeVariablesContainer.GetParameterDeclarations(typeof(TestFunctionWithDuplicateParameterIndices)),
         Throws.TypeOf <WxeException>().With.Message.EqualTo(
             "'Remotion.Web.UnitTests.Core.ExecutionEngine.TestFunctions.TestFunctionWithDuplicateParameterIndices' declares WxeParameters 'Parameter1' and 'Parameter2' with the same index. "
             + "The index of a WxeParameter must be unique within a type."));
 }
        public void GetParameterDeclarations_ParametersDeclaredOnType_ReturnsParametersSortedByIndex()
        {
            var parameters = WxeVariablesContainer.GetParameterDeclarations(typeof(TestBaseFunctionWithParameters));

            Assert.That(parameters.Length, Is.EqualTo(2));
            Assert.That(parameters[0].Name, Is.EqualTo("Parameter1"));
            Assert.That(parameters[1].Name, Is.EqualTo("Parameter2"));
        }
 public void GetParameterDeclarations_ParametersDeclaredOnOverride_ThrowsWxeException()
 {
     Assert.That(
         () => WxeVariablesContainer.GetParameterDeclarations(typeof(TestFunctionWithOverriddenParameter)),
         Throws.TypeOf <WxeException>()
         .With.Message.EqualTo(
             "Property 'Parameter1', overridden by 'Remotion.Web.UnitTests.Core.ExecutionEngine.TestFunctions.TestFunctionWithOverriddenParameter', has a WxeParameterAttribute applied. "
             + "The WxeParameterAttribute may only be applied to the original declaration of a property."));
 }
        public void GetParameterDeclarations_ParametersDeclaredOnTypeAndBaseType_ReturnsParametersSortedByHierarchyAndIndex()
        {
            var parameters = WxeVariablesContainer.GetParameterDeclarations(typeof(TestDerivedFunctionWithParameters));

            Assert.That(parameters.Length, Is.EqualTo(4));
            Assert.That(parameters[0].Name, Is.EqualTo("Parameter1"));
            Assert.That(parameters[1].Name, Is.EqualTo("Parameter2"));
            Assert.That(parameters[2].Name, Is.EqualTo("Parameter3"));
            Assert.That(parameters[3].Name, Is.EqualTo("Parameter4"));
        }
Exemple #5
0
        /// <summary>
        ///   Gets the permanent URL for the <see cref="WxeFunction"/> defined by the
        ///   <see cref="Command.WxeFunctionCommandInfo"/>.
        /// </summary>
        /// <param name="additionalUrlParameters">
        ///   The <see cref="NameValueCollection"/> containing additional url parameters.
        ///   Must not be <see langword="null"/>.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///   <para>
        ///     Thrown if called while the <see cref="Type"/> is not set to <see cref="CommandType.WxeFunction"/>.
        ///   </para><para>
        ///     Thrown if neither the <see cref="Command.WxeFunctionCommandInfo.MappingID"/> nor the
        ///     <see cref="Command.WxeFunctionCommandInfo.TypeName"/> are set.
        ///   </para><para>
        ///     Thrown if the <see cref="Command.WxeFunctionCommandInfo.MappingID"/> and
        ///     <see cref="Command.WxeFunctionCommandInfo.TypeName"/> specify different functions.
        ///   </para>
        /// </exception>
        public virtual string GetWxeFunctionPermanentUrl(NameValueCollection additionalUrlParameters)
        {
            ArgumentUtility.CheckNotNull("additionalUrlParameters", additionalUrlParameters);

            if (Type != CommandType.WxeFunction)
            {
                throw new InvalidOperationException("Call to ExecuteWxeFunction not allowed unless Type is set to CommandType.WxeFunction.");
            }

            Type functionType = WxeFunctionCommand.ResolveFunctionType();

            WxeParameterDeclaration[] parameterDeclarations = WxeVariablesContainer.GetParameterDeclarations(functionType);
            object[] parameterValues = WxeVariablesContainer.ParseActualParameters(
                parameterDeclarations, WxeFunctionCommand.Parameters, CultureInfo.InvariantCulture);

            NameValueCollection queryString = WxeVariablesContainer.SerializeParametersForQueryString(parameterDeclarations, parameterValues);

            queryString.Set(WxeHandler.Parameters.WxeReturnToSelf, true.ToString());
            NameValueCollectionUtility.Append(queryString, additionalUrlParameters);

            return(WxeContext.GetPermanentUrl(new HttpContextWrapper(HttpContext.Current), functionType, queryString));
        }
        public Type GetTypeOfSecurableObject()
        {
            WxeParameterDeclaration[] parameterDeclarations = WxeVariablesContainer.GetParameterDeclarations(_functionType);
            WxeParameterDeclaration   parameterDeclaration  = GetParameterDeclaration(parameterDeclarations);

            var actualParameterType = GetActualParameterType(parameterDeclaration.Type);

            if (!typeof(ISecurableObject).IsAssignableFrom(actualParameterType))
            {
                throw new WxeException(string.Format(
                                           "The parameter '{1}' specified by the {0} applied to WxeFunction '{2}' does not implement interface '{3}'.",
                                           _attribute.GetType().Name, parameterDeclaration.Name, _functionType.FullName, typeof(ISecurableObject).FullName));
            }

            if (SecurableClass == null)
            {
                return(actualParameterType);
            }

            CheckParameterDeclarationMatchesSecurableClass(actualParameterType, parameterDeclaration.Name);

            return(SecurableClass);
        }