Ejemplo n.º 1
0
        private void DetectInvalidDefinitions(IEnumerable <IDistributedLockDefinition> definitions)
        {
            var dulpicateIds = definitions
                               .GroupBy(e => e.DistributedLockId)
                               .Where(g => g.Count() > 1)
                               .FirstOrDefault();

            if (dulpicateIds != null)
            {
                var message = "Duplicate IDistributedLockDefinition.DistributedLockId: " + dulpicateIds.Key;
                throw new InvalidDistributedLockDefinitionException(message, dulpicateIds.First(), definitions);
            }

            var notValidCode = definitions
                               .Where(d => !SqlCharValidator.IsValid(d.DistributedLockId, 6))
                               .FirstOrDefault();

            if (notValidCode != null)
            {
                var message = notValidCode.GetType().Name + " has an invalid DistributedLockId. The id must be 6 characters in length and can include only non-unicode characters.";
                throw new InvalidDistributedLockDefinitionException(message, notValidCode, definitions);
            }
        }
        private void DetectInvalidDefinitions(IEnumerable <IUserAreaDefinition> definitions)
        {
            var nullCode = definitions
                           .Where(d => string.IsNullOrWhiteSpace(d.UserAreaCode))
                           .FirstOrDefault();

            if (nullCode != null)
            {
                var message = nullCode.GetType().Name + " does not have a definition code specified.";
                throw new InvalidUserAreaDefinitionException(message, nullCode, definitions);
            }

            var duplicateCode = definitions
                                .GroupBy(e => e.UserAreaCode, StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (duplicateCode != null)
            {
                var message = "Duplicate IUserAreaDefinition.UserAreaCode: " + duplicateCode.Key;
                throw new InvalidUserAreaDefinitionException(message, duplicateCode.First(), definitions);
            }

            var notValidCode = definitions
                               .Where(d => !SqlCharValidator.IsValid(d.UserAreaCode, 3))
                               .FirstOrDefault();

            if (notValidCode != null)
            {
                var message = notValidCode.GetType().Name + " has an invalid code. User area codes must be 3 characters and contain only non-unicode characters.";
                throw new InvalidUserAreaDefinitionException(message, notValidCode, definitions);
            }

            var nullName = definitions
                           .Where(d => string.IsNullOrWhiteSpace(d.Name))
                           .FirstOrDefault();

            if (nullName != null)
            {
                var message = nullName.GetType().Name + " does not have a name specified.";
                throw new InvalidUserAreaDefinitionException(message, nullName, definitions);
            }

            var nameTooLong = definitions
                              .Where(d => d.Name.Length > 20)
                              .FirstOrDefault();

            if (nameTooLong != null)
            {
                var message = nameTooLong.GetType().Name + " has a name that is more than 20 characters in length. All user area definition names must be 20 characters or less.";
                throw new InvalidUserAreaDefinitionException(message, nameTooLong, definitions);
            }

            var duplicateName = definitions
                                .GroupBy(e => e.Name, StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (duplicateName != null)
            {
                var message = "Duplicate IUserAreaDefinition.Name: " + duplicateName.Key;
                throw new InvalidUserAreaDefinitionException(message, duplicateName.First(), definitions);
            }

            var defaultUserAreas = definitions
                                   .Where(d => d.IsDefaultAuthScheme);

            var invalidDefaultUserArea = defaultUserAreas.Skip(1).FirstOrDefault();

            if (invalidDefaultUserArea != null)
            {
                var message = $"More than one user area has {nameof(IUserAreaDefinition.IsDefaultAuthScheme)} defined. Only a single default user area can be defined. Duplicates: " + string.Join(", ", defaultUserAreas);
                throw new InvalidUserAreaDefinitionException(message, invalidDefaultUserArea, definitions);
            }
        }
        private void DetectInvalidDefinitions(IEnumerable <IAuthorizedTaskTypeDefinition> definitions)
        {
            var nullCode = definitions
                           .Where(d => string.IsNullOrWhiteSpace(d.AuthorizedTaskTypeCode))
                           .FirstOrDefault();

            if (nullCode != null)
            {
                var message = nullCode.GetType().Name + " does not have a definition code specified.";
                throw new InvalidAuthorizedTaskTypeDefinitionException(message, nullCode, definitions);
            }

            var duplicateCode = definitions
                                .GroupBy(e => e.AuthorizedTaskTypeCode, StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (duplicateCode != null)
            {
                var message = "Duplicate IAuthorizedTaskTypeDefinition.AuthorizedTaskTypeCode: " + duplicateCode.Key;
                throw new InvalidAuthorizedTaskTypeDefinitionException(message, duplicateCode.First(), definitions);
            }

            var notValidCode = definitions
                               .Where(d => !SqlCharValidator.IsValid(d.AuthorizedTaskTypeCode, 6))
                               .FirstOrDefault();

            if (notValidCode != null)
            {
                var message = notValidCode.GetType().Name + " has an invalid AuthorizedTaskTypeCode. The code must be 6 characters in length and can include only non-unicode characters.";
                throw new InvalidAuthorizedTaskTypeDefinitionException(message, notValidCode, definitions);
            }

            var nullName = definitions
                           .Where(d => string.IsNullOrWhiteSpace(d.Name))
                           .FirstOrDefault();

            if (nullName != null)
            {
                var message = nullName.GetType().Name + " does not have a name specified.";
                throw new InvalidAuthorizedTaskTypeDefinitionException(message, nullName, definitions);
            }

            var nameTooLong = definitions
                              .Where(d => d.Name.Length > 20)
                              .FirstOrDefault();

            if (nameTooLong != null)
            {
                var message = nameTooLong.GetType().Name + " has a name that is more than 20 characters in length. All authorization task type definition names must be 20 characters or less.";
                throw new InvalidAuthorizedTaskTypeDefinitionException(message, nameTooLong, definitions);
            }

            var duplicateName = definitions
                                .GroupBy(e => e.Name, StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (duplicateName != null)
            {
                var message = "Duplicate IAuthorizedTaskTypeDefinition.Name: " + duplicateName.Key;
                throw new InvalidAuthorizedTaskTypeDefinitionException(message, duplicateName.First(), definitions);
            }
        }
Ejemplo n.º 4
0
        private static void DetectInvalidDefinitions(IEnumerable <ICustomEntityDefinition> definitions)
        {
            const string WHY_VALID_CODE_MESSAGE = "All custom entity definition codes must be 6 characters and contain only non-unicode characters.";

            var nullCode = definitions
                           .Where(d => string.IsNullOrWhiteSpace(d.CustomEntityDefinitionCode))
                           .FirstOrDefault();

            if (nullCode != null)
            {
                var message = nullCode.GetType().Name + " does not have a definition code specified.";
                throw new InvalidCustomEntityDefinitionException(message, nullCode, definitions);
            }

            var nullName = definitions
                           .Where(d => string.IsNullOrWhiteSpace(d.Name))
                           .FirstOrDefault();

            if (nullName != null)
            {
                var message = nullName.GetType().Name + " does not have a name specified.";
                throw new InvalidCustomEntityDefinitionException(message, nullName, definitions);
            }

            var dulpicateCode = definitions
                                .GroupBy(e => e.CustomEntityDefinitionCode, StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (dulpicateCode != null)
            {
                var message = "Duplicate ICustomEntityDefinition.CustomEntityDefinitionCode: " + dulpicateCode.Key;
                throw new InvalidCustomEntityDefinitionException(message, dulpicateCode.First(), definitions);
            }

            var dulpicateName = definitions
                                .GroupBy(e => e.Name, StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (dulpicateName != null)
            {
                var message = "Duplicate ICustomEntityDefinition.Name: " + dulpicateName.Key;
                throw new InvalidCustomEntityDefinitionException(message, dulpicateName.First(), definitions);
            }

            var nameNot6Chars = definitions
                                .Where(d => d.CustomEntityDefinitionCode.Length != 6)
                                .FirstOrDefault();

            if (nameNot6Chars != null)
            {
                var message = nameNot6Chars.GetType().Name + " has a definition code that is not 6 characters in length. " + WHY_VALID_CODE_MESSAGE;
                throw new InvalidCustomEntityDefinitionException(message, nameNot6Chars, definitions);
            }

            var notValidCode = definitions
                               .Where(d => !SqlCharValidator.IsValid(d.CustomEntityDefinitionCode, 6))
                               .FirstOrDefault();

            if (notValidCode != null)
            {
                var message = notValidCode.GetType().Name + " has an invalid definition code. " + WHY_VALID_CODE_MESSAGE;
                throw new InvalidCustomEntityDefinitionException(message, notValidCode, definitions);
            }
        }
Ejemplo n.º 5
0
        public void IsValid_WhenInvalidLength_ReturnsFalse(string s, int length)
        {
            var result = SqlCharValidator.IsValid(s, length);

            Assert.False(result);
        }
Ejemplo n.º 6
0
        public void IsValid_WithUnicode_ReturnsFalse(string s)
        {
            var result = SqlCharValidator.IsValid(s, s.Length);

            Assert.False(result);
        }
Ejemplo n.º 7
0
        public void IsValid_WhenValid_ReturnsTrue(string s)
        {
            var result = SqlCharValidator.IsValid(s, s.Length);

            Assert.True(result);
        }
Ejemplo n.º 8
0
        public void IsValid_WhenNullOrWhitespace_ReturnsFalse(string s)
        {
            var result = SqlCharValidator.IsValid(s, 6);

            Assert.False(result);
        }
Ejemplo n.º 9
0
        private void DetectInvalidDefinitions(IEnumerable <IRoleDefinition> definitions)
        {
            const string WHY_VALID_CODE_MESSAGE = "All role codes must be 3 characters and contain only non-unicode characters.";

            var nullRoleCode = definitions
                               .Where(d => string.IsNullOrWhiteSpace(d.RoleCode))
                               .FirstOrDefault();

            if (nullRoleCode != null)
            {
                var message = nullRoleCode.GetType().Name + " does not have a role code specified.";
                throw new InvalidRoleDefinitionException(message, nullRoleCode, definitions);
            }

            // The actual user area is validated during the registration process, but here we just need
            // to check for a value to ensure we're validating the constraints properly.
            var nullUserAreaCode = definitions
                                   .Where(d => string.IsNullOrWhiteSpace(d.UserAreaCode))
                                   .FirstOrDefault();

            if (nullUserAreaCode != null)
            {
                var message = nullUserAreaCode.GetType().Name + " does not have a user area code specified.";
                throw new InvalidRoleDefinitionException(message, nullUserAreaCode, definitions);
            }

            var nullTitle = definitions
                            .Where(d => string.IsNullOrWhiteSpace(d.Title))
                            .FirstOrDefault();

            if (nullTitle != null)
            {
                var message = nullTitle.GetType().Name + " does not have a title specified.";
                throw new InvalidRoleDefinitionException(message, nullTitle, definitions);
            }

            var dulpicateCode = definitions
                                .GroupBy(e => CreateLookupKey(e.UserAreaCode, e.RoleCode), StringComparer.OrdinalIgnoreCase)
                                .Where(g => g.Count() > 1)
                                .FirstOrDefault();

            if (dulpicateCode != null)
            {
                var example = dulpicateCode.First();
                var message = $"Duplicate role definitions encountered. { dulpicateCode.Count() } roles defined with the role code '{ example.RoleCode }' in user area { example.UserAreaCode }";
                throw new InvalidRoleDefinitionException(message, dulpicateCode.First(), definitions);
            }

            var dulpicateTitle = definitions
                                 .GroupBy(e => new { e.UserAreaCode, e.Title })
                                 .Where(g => g.Count() > 1)
                                 .FirstOrDefault();

            if (dulpicateTitle != null)
            {
                var message = "Duplicate IRoleDefinition.Title: " + dulpicateTitle.Key;
                throw new InvalidRoleDefinitionException(message, dulpicateTitle.First(), definitions);
            }

            var nameNot3Chars = definitions
                                .Where(d => d.RoleCode.Length != 3)
                                .FirstOrDefault();

            if (nameNot3Chars != null)
            {
                var message = nameNot3Chars.GetType().Name + " has a role code that is not 3 characters in length. " + WHY_VALID_CODE_MESSAGE;
                throw new InvalidRoleDefinitionException(message, nameNot3Chars, definitions);
            }

            var notValidCode = definitions
                               .Where(d => !SqlCharValidator.IsValid(d.RoleCode, 3))
                               .FirstOrDefault();

            if (notValidCode != null)
            {
                var message = notValidCode.GetType().Name + " has an invalid role code. " + WHY_VALID_CODE_MESSAGE;
                throw new InvalidRoleDefinitionException(message, notValidCode, definitions);
            }
        }