public void Initialize_WithMethodNameEnumAndSecurableClass() { WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute(SecurableObject.Method.Show, typeof(DerivedSecurableObject)); Assert.That(attribute.MethodType, Is.EqualTo(MethodType.Instance)); Assert.That(attribute.MethodName, Is.EqualTo("Show")); Assert.That(attribute.SecurableClass, Is.SameAs(typeof(DerivedSecurableObject))); }
public void Initialize_WithMethodName() { WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("Show"); Assert.That(attribute.MethodType, Is.EqualTo(MethodType.Instance)); Assert.That(attribute.MethodName, Is.EqualTo("Show")); Assert.That(attribute.SecurableClass, Is.Null); }
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))); }
public void TestWithParameterNotOfNotMatchingType() { WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("Show", typeof(OtherSecurableObject)); attribute.ParameterName = "ThisObject"; WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper( typeof(TestFunctionWithThisObjectAsSecondParameter), attribute); helper.GetTypeOfSecurableObject(); }
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))); }
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))); }
public void SetUp() { _attribute = new WxeDemandTargetMethodPermissionAttribute("Read"); object someObject = new object(); _securableObject = new SecurableObject(null); _functionWithThisObjectAsSecondParamter = new TestFunctionWithThisObjectAsSecondParameter(someObject, _securableObject); _functionWithThisObjectAsSecondParamter.SomeObject = someObject; // Required because in this test the WxeFunction has not started executing. _functionWithThisObjectAsSecondParamter.ThisObject = _securableObject; // Required because in this test the WxeFunction has not started executing. }
public void InitializeWithMethodTypeInstanceAndMethodEnum() { WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute(SecurableObject.Method.Show); WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper( typeof(TestFunctionWithThisObject), attribute); Assert.That(helper.FunctionType, Is.SameAs(typeof(TestFunctionWithThisObject))); Assert.That(helper.MethodType, Is.EqualTo(MethodType.Instance)); Assert.That(helper.SecurableClass, Is.SameAs(typeof(SecurableObject))); Assert.That(helper.MethodName, Is.EqualTo("Show")); }
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'.")); }
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_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'.")); }
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'.")); }
public void SetUp() { _attribute = new WxeDemandTargetMethodPermissionAttribute("Show"); }