public void AcceptsIPropertyInfo()
        {
            var mockTypeProperty = new Mock<IPropertyInfo>();
            mockTypeProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.BadgeType));
            mockTypeProperty.Setup(mp => mp.Name).Returns("Type");

            var newRule = new Rules.CanSetBadgeType(AuthorizationActions.WriteProperty, mockTypeProperty.Object, Common.Enums.BadgeType.Corporate, "");

            Assert.IsNotNull(newRule);
        }
        public void AcceptsIPropertyInfo()
        {
            var mockTypeProperty = new Mock <IPropertyInfo>();

            mockTypeProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.BadgeType));
            mockTypeProperty.Setup(mp => mp.Name).Returns("Type");

            var newRule = new Rules.CanSetBadgeType(AuthorizationActions.WriteProperty, mockTypeProperty.Object, Common.Enums.BadgeType.Corporate, "");

            Assert.IsNotNull(newRule);
        }
        public void StartDateMustBeIPropertyInfo()
        {
            var mockMemberInfoProperty = new Mock<IMemberInfo>();
            mockMemberInfoProperty.Setup(mp => mp.Name).Returns("Type");

            try
            {
                var newRule = new Rules.CanSetBadgeType(AuthorizationActions.WriteProperty, mockMemberInfoProperty.Object, Common.Enums.BadgeType.Corporate, "");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Parameter element must be of type IPropertyInfo.", ex.Message);
                throw;
            }
        }
        public void StartDateMustBeIPropertyInfo()
        {
            var mockMemberInfoProperty = new Mock <IMemberInfo>();

            mockMemberInfoProperty.Setup(mp => mp.Name).Returns("Type");

            try
            {
                var newRule = new Rules.CanSetBadgeType(AuthorizationActions.WriteProperty, mockMemberInfoProperty.Object, Common.Enums.BadgeType.Corporate, "");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Parameter element must be of type IPropertyInfo.", ex.Message);
                throw;
            }
        }
        public void CorrectBadgeTypeNotAllowedForUnauthorizedUser()
        {
            var mockPrincipal = new Mock<ICslaPrincipal>();
            mockPrincipal.Setup(i => i.IsInRole(Common.Enums.PermissionType.Administrator.ToString())).Returns(false);
            Csla.ApplicationContext.User = mockPrincipal.Object;

            var mockTypeProperty = new Mock<IPropertyInfo>();
            mockTypeProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.BadgeType));
            mockTypeProperty.Setup(mp => mp.Name).Returns("Type");

            var newRule = new Rules.CanSetBadgeType(AuthorizationActions.WriteProperty, mockTypeProperty.Object, Common.Enums.BadgeType.Corporate, Common.Enums.PermissionType.Administrator.ToString());
            var targetObject = new Mock<IBadgeEdit>();
            targetObject.Setup(to => to.Type).Returns(Common.Enums.BadgeType.Corporate);

            var ruleContext = new AuthorizationContext(newRule, targetObject.Object, typeof(IBadgeEdit));
            var ruleRunner = (IAuthorizationRule)newRule;

            ruleRunner.Execute(ruleContext);

            Assert.IsFalse(ruleContext.HasPermission);
        }
        public void CorrectBadgeTypeNotAllowedForUnauthorizedUser()
        {
            var mockPrincipal = new Mock <ICslaPrincipal>();

            mockPrincipal.Setup(i => i.IsInRole(Common.Enums.PermissionType.Administrator.ToString())).Returns(false);
            Csla.ApplicationContext.User = mockPrincipal.Object;

            var mockTypeProperty = new Mock <IPropertyInfo>();

            mockTypeProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.BadgeType));
            mockTypeProperty.Setup(mp => mp.Name).Returns("Type");

            var newRule      = new Rules.CanSetBadgeType(AuthorizationActions.WriteProperty, mockTypeProperty.Object, Common.Enums.BadgeType.Corporate, Common.Enums.PermissionType.Administrator.ToString());
            var targetObject = new Mock <IBadgeEdit>();

            targetObject.Setup(to => to.Type).Returns(Common.Enums.BadgeType.Corporate);

            var ruleContext = new AuthorizationContext(newRule, targetObject.Object, typeof(IBadgeEdit));
            var ruleRunner  = (IAuthorizationRule)newRule;

            ruleRunner.Execute(ruleContext);

            Assert.IsFalse(ruleContext.HasPermission);
        }