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());
        }
        public void TestGetParameterBlock()
        {
            string actionExpression       = "HasRightInInstitute(#user, 'parameterwert')";
            string expectedParameterBlock = "#user, 'parameterwert'";
            string parameterBlock         = PreAuthorizeAttribute.GetParameterBlock(actionExpression);

            Assert.AreEqual(expectedParameterBlock, parameterBlock);
        }
        public void TestFindMethodName()
        {
            string actionExpression   = "HasRightInInstitute(#user, 'parameterwert')";
            string expectedMethodName = "HasRightInInstitute";

            string methodeName = PreAuthorizeAttribute.ParseMethodeName(actionExpression);

            Assert.AreEqual(expectedMethodName, methodeName);
        }
        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));
        }
        public void TestParseMethodNameWithoutParams()
        {
            string actionExpression = "hasRight";

            Assert.Throws <InvalidOperationException>(() => PreAuthorizeAttribute.ParseMethodeName(actionExpression));
        }
        public void TestToShortMethodName()
        {
            string actionExpression = "a(#uhuhuhuhuh, #sdsdsd)";

            Assert.Throws <InvalidOperationException>(() => PreAuthorizeAttribute.ParseMethodeName(actionExpression));
        }