public void GetExcludedMediaLibraries_Returns_Trimmed_Name()
        {
            var stagingConfigurationSettingsOptions = OptionsFactory.CreateOptions <StagingConfigurationSettings>(AppConfigFileName.Untrimmed);
            var appSettingsRepository  = new AppSettingsRepository(stagingConfigurationSettingsOptions);
            var excludedMediaLibraries = appSettingsRepository.GetExcludedMediaLibraries();

            Assert.AreEqual("emailimages", excludedMediaLibraries.FirstOrDefault());
        }
        public void GetExcludedChildTypes_Returns_Expected_List_Count(string configFileName, int expectedCount)
        {
            var stagingConfigurationSettingsOptions = OptionsFactory.CreateOptions <StagingConfigurationSettings>(configFileName);
            var appSettingsRepository = new AppSettingsRepository(stagingConfigurationSettingsOptions);
            var childTypePairs        = appSettingsRepository.GetExcludedChildTypes();

            Assert.AreEqual(expectedCount, childTypePairs.Count);
        }
        public void GetExcludedChildTypes_Returns_Trimmed_Name()
        {
            var stagingConfigurationSettingsOptions = OptionsFactory.CreateOptions <StagingConfigurationSettings>(AppConfigFileName.Untrimmed);
            var appSettingsRepository = new AppSettingsRepository(stagingConfigurationSettingsOptions);
            var childTypePairs        = appSettingsRepository.GetExcludedChildTypes();
            var childTypePair         = childTypePairs.FirstOrDefault();

            Assert.AreEqual("cms.role", childTypePair?.ParentType);
            Assert.AreEqual("cms.userrole", childTypePair?.ChildType);
        }
Esempio n. 4
0
        public TOptions Parse(string[] args)
        {
            _optionsMetadataValidator.Validate();

            OptionPropertyMetadata matchingProperty;

            var parsingContext = new OptionsParsingContext(_optionsMetadata);

            for (var i = 0; i < args.Length; i++)
            {
                if (_optionsMetadata.TryGetSwitchValueByName(args[i], out var switchValue))
                {
                    parsingContext.SetValue(switchValue.PropertyMetadata, switchValue.Value);
                    continue;
                }

                if (_optionsMetadata.TryGetPropertyByIndex(i, out matchingProperty))
                {
                    if (matchingProperty.IsCollection)
                    {
                        ParseAndSetCollectionValue(parsingContext, matchingProperty, args, ref i);
                    }
                    else
                    {
                        ParseAndSetValue(parsingContext, matchingProperty, args[i]);
                    }

                    continue;
                }

                if (_optionsMetadata.TryGetPropertyByOptionName(args[i], out matchingProperty))
                {
                    if (i + 1 >= args.Length || _optionsMetadata.IsKeyword(args[i + 1]))
                    {
                        parsingContext.AddOptionWithoutValueError(args[i]);
                        continue;
                    }

                    if (matchingProperty.IsCollection)
                    {
                        i++; // Skip the option name
                        ParseAndSetCollectionValue(parsingContext, matchingProperty, args, ref i);
                    }
                    else
                    {
                        ParseAndSetValue(parsingContext, matchingProperty, args[i + 1]);
                        i++;
                    }
                    continue;
                }

                parsingContext.AddInvalidOptionError(args[i]);
            }

            var options          = _optionsFactory.CreateOptions(parsingContext.GetValues());
            var validationErrors = _optionsValidator.ValidateOptions(options);

            parsingContext.AddValidationErrors(validationErrors);

            if (parsingContext.HasErrors)
            {
                throw new InvalidOptionsException(parsingContext.Errors);
            }

            return(options);
        }