示例#1
0
        /// <summary>
        /// The builder helps you configure rules and add them to the validator that you call to execute a set of rules.
        /// - you would set this up once for each project where you want to enforce attributes in one or multiple test projects.
        /// <br/>
        /// Tip: don't use pure text as assembly name, instead use nameof,  like this <see cref="T:ValidatorBuilder(nameof(WebApi))" />, to avoid renaming related issues.
        /// <br/>
        /// Tip: defaultAttributeRequired;  normally you would set the most restrictive attribute
        ///  to avoid giving to low privilege level on controllers/actions
        /// </summary>
        /// <param name="assemblyName">The name of the assembly under test, all controllers will be collected for validation</param>
        /// <param name="defaultAttributeRequired">AllowAnonymous, AuthorizeAttribute, AuthorizeAttribute(Policy = "YourPolicyName")</param>
        public ValidatorBuilder(string assemblyName, Attribute defaultAttributeRequired)
        {
            if (string.IsNullOrEmpty(assemblyName))
            {
                throw new XunitException($"Configuration error, Assembly name is missing");
            }

            _assemblyName            = assemblyName;
            _controllersFromAssembly = new ControllersFromAssembly(_assemblyName);
            _validator = CreateValidator(defaultAttributeRequired);
        }
示例#2
0
 public ValidationRulesContainerTest()
 {
     _defaultControllersFromAssembly       = new ControllersFromAssembly(AssemblyNameDefault);
     _defaultActionsFromAssemblyToValidate = _defaultControllersFromAssembly.AllActions();
 }