Example #1
0
        public void TestFromFunctionWithoutParameters()
        {
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithoutParameters),
                _attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #2
0
        public void TestWithDefaultParameter()
        {
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                _attribute);

            Assert.That(helper.GetTypeOfSecurableObject(), Is.SameAs(typeof(SecurableObject)));
        }
Example #3
0
        public void TestWithParameterTypeIsBaseType()
        {
            WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("ShowSpecial", typeof(DerivedSecurableObject));
            WxeDemandMethodPermissionAttributeHelper helper    = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                attribute);

            Assert.That(helper.GetTypeOfSecurableObject(), Is.SameAs(typeof(DerivedSecurableObject)));
        }
Example #4
0
        public void TestWithValidParameterName()
        {
            _attribute.ParameterName = "ThisObject";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                _attribute);

            Assert.That(helper.GetTypeOfSecurableObject(), Is.SameAs(typeof(SecurableObject)));
        }
Example #5
0
        public void TestWithInvalidParameterName()
        {
            _attribute.ParameterName = "Invalid";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                _attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #6
0
        public void TestWithParameterNotImplementingISecurableObject()
        {
            _attribute.ParameterName = "SomeObject";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                _attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #7
0
        public void TestWithParameterNotOfNotMatchingType()
        {
            WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("Show", typeof(OtherSecurableObject));

            attribute.ParameterName = "ThisObject";
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #8
0
        public void TestWithHandle_InheritingHandleAttribute()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleInheritingAttribute"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            var result = helper.GetTypeOfSecurableObject();

            Assert.That(result, Is.SameAs(typeof(SecurableObject)));
        }
Example #9
0
        public void TestWithHandle_PointingToSecurableObjectBase_ShouldReturnTypeDeclaredInInterface()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(DerivedSecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            var result = helper.GetTypeOfSecurableObject();

            Assert.That(result, Is.SameAs(typeof(DerivedSecurableObject)));
        }
Example #10
0
        public void TestWithHandle_PointingToNonSecurableObject_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleWithNonSecurableObject"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            Assert.That(
                () => helper.GetTypeOfSecurableObject(),
                Throws.TypeOf <WxeException>().With.Message.EqualTo(
                    "The parameter 'HandleWithNonSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' does not implement interface "
                    + "'Remotion.Security.ISecurableObject'."));
        }
Example #11
0
        public void TestWithHandle_ReferencedTypeNotMatchingSecurableClass_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(OtherSecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            Assert.That(
                () => helper.GetTypeOfSecurableObject(),
                Throws.TypeOf <WxeException> ().With.Message.EqualTo(
                    "The parameter 'HandleWithSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' is of type "
                    + "'Remotion.Web.UnitTests.Core.Security.Domain.SecurableObject', which is not a base type of type "
                    + "'Remotion.Web.UnitTests.Core.Security.Domain.OtherSecurableObject'."));
        }