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'.")); }