Ejemplo n.º 1
0
        public void ShouldAddMissingAppSettings()
        {
            // Arrange
            var appSettings = new AppSettingsSection();
            var coll        = new NameValueCollection()
            {
                { YamlConfigurationBuilder.locationTag, configFileLocation },
                { YamlConfigurationBuilder.modeTag, KeyValueMode.Greedy.ToString() }
            };
            var sut = new YamlConfigurationBuilder();

            sut.Initialize("test", coll);

            // Act
            sut.ProcessConfigurationSection(appSettings);

            // Assert
            Assert.AreEqual(2, appSettings.Settings.Count, "Did not add more add nodes to appSettings");

            // Check for the other three settings
            for (var i = 1; i < 3; i++)
            {
                Assert.IsNotNull(appSettings.Settings[$"setting{i}"], $"Missing setting{i}");
            }
        }
        public void ShouldReadSettingsFromFile()
        {
            // arrange
            var appSettings = new AppSettingsSection();

            appSettings.Settings.Add("setting1", "inlineValue");
            var coll = new NameValueCollection()
            {
                { YamlConfigurationBuilder.locationTag, configFileLocation }
            };
            var sut = new YamlConfigurationBuilder();

            sut.Initialize("test", coll);

            // act
            sut.ProcessConfigurationSection(appSettings);

            // Assert
            Assert.AreEqual("value1", appSettings.Settings["setting1"].Value,
                            "Did not load the value1 setting into the AppSettingsSection");
        }
        public void ShouldReadAllValuesFromOnlyTheSection()
        {
            // arrange
            var appSettings = new AppSettingsSection();

            appSettings.Settings.Add("setting1", "inlineValue");
            var coll = new NameValueCollection()
            {
                { YamlConfigurationBuilder.locationTag, configFileLocation },
                { YamlConfigurationBuilder.sectionTag, "appSettings" },
                { "mode", "greedy" }
            };
            var sut = new YamlConfigurationBuilder();

            sut.Initialize("test", coll);

            // act
            sut.ProcessConfigurationSection(appSettings);
            var keys = appSettings.Settings.AllKeys;

            // assert
            Assert.AreEqual(2, keys.Count(), "Did not find both keys");
        }