Exemplo n.º 1
0
        public void Load_ThrowOnFirstErrorForDuplicateKeys()
        {
            var src = new IniFileConfigurationSource(IniFileOneName)
            {
                DuplicateKeyBehavior = KeyNameBehavior.Error,
                ParsingErrorBehavior = ParsingResultsErrorBehavior.OnFirstError,
                FileProvider         = new PhysicalFileProvider(AppContext.BaseDirectory),
                Optional             = false,
                ReloadOnChange       = false,
            };

            var provider = new IniFileConfigurationProvider(src);

            provider.Invoking(p => p.Load()).Should().ThrowExactly <ArgumentAlreadyDefinedException>(
                "Redefining a key with provider settings {DuplicateKeyBehavior = KeyNameBehavior.Error, ParsingErrorBehavior = ParsingResultsErrorBehavior.ExceptionOnFirstError} must throw an exception for the first error.");
            provider.GetAllKeysAndValuesFromProvider().Should().BeEmpty("When an error occured, parsed details must not be returned.");
        }
Exemplo n.º 2
0
        public void Load_ThrowForAllDuplicateKeyErrors()
        {
            var src = new IniFileConfigurationSource(IniFileOneName)
            {
                DuplicateKeyBehavior = KeyNameBehavior.Error,
                ParsingErrorBehavior = ParsingResultsErrorBehavior.Aggregate,
                FileProvider         = new PhysicalFileProvider(AppContext.BaseDirectory),
                Optional             = false,
                ReloadOnChange       = false,
            };

            var provider = new IniFileConfigurationProvider(src);

            provider.Invoking(p => p.Load()).Should().ThrowExactly <AggregateException>(
                "Redefining a key with provider settings {DuplicateKeyBehavior = KeyNameBehavior.Error, ParsingErrorBehavior = ParsingResultsErrorBehavior.ExceptionForAllErrors} must throw an exception for the first error.")
            .And.InnerExceptions.Should().AllBeOfType <ArgumentAlreadyDefinedException>("Only errors for duplicate keys are expected.").And.HaveCount(2, "Exactly two errors for duplicate keys was expected.");
            provider.GetAllKeysAndValuesFromProvider().Should().BeEmpty("When an error occured, parsed details must not be returned.");
        }