public void TestWithParameterNotOfMatchingType()
        {
            WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("Show", typeof(OtherSecurableObject));

            attribute.ParameterName = "ThisObject";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                _functionWithThisObjectAsSecondParamter.GetType(),
                attribute);

            helper.GetSecurableObject(_functionWithThisObjectAsSecondParamter);
        }
        public void TestWithDefaultParameter()
        {
            TestFunctionWithThisObject function = new TestFunctionWithThisObject(_securableObject, null);

            function.ThisObject = _securableObject; // Required because in this test the WxeFunction has not started executing.

            _attribute.ParameterName = null;

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                function.GetType(),
                _attribute);

            Assert.That(helper.GetSecurableObject(function), Is.SameAs(function.ThisObject));
        }
        public void TestWithHandle_PointingToSecurableObject_ShouldReturnValue()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper   = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);
            var function = new TestFunctionWithHandleParameter {
                HandleWithSecurableObject = new Handle <SecurableObject> (_securableObject)
            };

            var result = helper.GetSecurableObject(function);

            Assert.That(result, Is.SameAs(_securableObject));
        }
        public void TestWithHandle_NullHandle_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper   = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);
            var function = new TestFunctionWithHandleParameter {
                HandleWithSecurableObject = null
            };

            Assert.That(
                () => helper.GetSecurableObject(function),
                Throws.TypeOf <WxeException> ().With.Message.EqualTo(
                    "The parameter 'HandleWithSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' is null."));
        }
        public void TestWithHandle_PointingToSecurableObject_ButIncompatibleParameterDeclaration_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(OtherSecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper   = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);
            var function = new TestFunctionWithHandleParameter {
                HandleWithSecurableObject = new Handle <SecurableObject> (_securableObject)
            };

            Assert.That(
                () => helper.GetSecurableObject(function),
                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'."));
        }