예제 #1
0
        public void TestGetMethodeParameters()
        {
            string    actionExpression                    = "HasRightInInstitute(#user, 'parameterwert')";
            string    parameterBlock                      = PreAuthorizeAttribute.GetParameterBlock(actionExpression);
            TestClass expectedMethodParameter             = new TestClass("objekt1");
            Dictionary <string, object> callingParameters = new Dictionary <string, object>();

            callingParameters.Add("user", expectedMethodParameter);
            callingParameters.Add("otherParam", new TestClass("wrongObject"));

            List <MethodParameter> expectedMethodParameters = new List <MethodParameter>();

            expectedMethodParameters.Add(new MethodParameter()
            {
                ParameterName = "user", ParameterType = typeof(TestClass), ParameterValue = expectedMethodParameter
            });
            expectedMethodParameters.Add(new MethodParameter()
            {
                ParameterType = typeof(string), ParameterValue = "parameterwert"
            });


            IList <MethodParameter> methodeParameters = PreAuthorizeAttribute.GetMethodParameters(parameterBlock, callingParameters);

            CollectionAssert.AreEqual(expectedMethodParameters, methodeParameters.ToList());
        }
예제 #2
0
        public void TestGetMethodeParametersFailingParameter()
        {
            string    actionExpression                    = "HasRightInInstitute(#user, #institute, 'parameterwert')";
            string    parameterBlock                      = PreAuthorizeAttribute.GetParameterBlock(actionExpression);
            TestClass expectedMethodParameter             = new TestClass("objekt1");
            Dictionary <string, object> callingParameters = new Dictionary <string, object>();

            callingParameters.Add("user", expectedMethodParameter);
            callingParameters.Add("otherParam", new TestClass("wrongObject"));

            Assert.Throws <KeyNotFoundException>(() => PreAuthorizeAttribute.GetMethodParameters(parameterBlock, callingParameters));
        }