public void Can_load_full_4_levels()
        {
            var provider    = new HierarchicalXmlSettingProvider(new XmlFilePathBuilder());
            var mockSetting = new MockAppSetting("TestApp");

            mockSetting.Initialize(provider);

            Assert.NotNull(mockSetting.SettingItem);
        }
예제 #2
0
        public void Can_read_from_xml_string()
        {
            string xml        = @"<settings><child>child value</child></settings>";
            var    appSetting = new MockAppSetting("TestApplication");
            var    provider   = new XmlSettingProvider();

            provider.Read(appSetting, xml);

            Assert.NotNull(appSetting.SettingItem);
        }
        public void Can_load_full_4_levels_with_value()
        {
            var provider    = new HierarchicalXmlSettingProvider(new XmlFilePathBuilder());
            var mockSetting = new MockAppSetting("TestApp");

            mockSetting.Initialize(provider);

            Assert.True(mockSetting.SettingItem.HasChildren);
            Assert.Equal("Level4", mockSetting.SettingItem["level"].Value);
        }
예제 #4
0
        public void Can_read_multiple_item_with_same_name_but_has_different_unique_key_attribute()
        {
            string xml        = @"<settings><child _key=""key1"">child value1</child><child _key=""key2"">child value2</child></settings>";
            var    appSetting = new MockAppSetting("TestApplication");
            var    provider   = new XmlSettingProvider();

            provider.Read(appSetting, xml);

            Assert.NotEmpty(appSetting.SettingItem.Children);
            Assert.Equal(2, appSetting.SettingItem.Children.Count());
        }
예제 #5
0
        public void Can_overwrite_attribute_value_of_2_elements_have_same_name_but_not_unique_key()
        {
            string xml        = @"<settings><child>child value1</child><child>child value2</child></settings>";
            var    appSetting = new MockAppSetting("TestApplication");
            var    provider   = new XmlSettingProvider();

            provider.Read(appSetting, xml);

            Assert.Equal(1, appSetting.SettingItem.Children.Count());
            Assert.Equal("child value2", appSetting.SettingItem["child"].Value);
        }
예제 #6
0
        public void Can_initialize_app_setting_with_xml_setting_provider()
        {
            var appSetting = new MockAppSetting("TestApplication");
            var provider   = GetProvider();

            Assert.Equal(false, appSetting.IsInitialized);

            appSetting.Initialize(provider);

            Assert.Equal(true, appSetting.IsInitialized);

            Assert.NotNull(appSetting.SettingItem);
        }
예제 #7
0
        public void Can_merge_attributes_of_two_item_has_same_name()
        {
            string xml        = @"<settings><child format=""MMddyyyy"">child value1</child><child culture=""en-GB"">child value2</child></settings>";
            var    appSetting = new MockAppSetting("TestApplication");
            var    provider   = new XmlSettingProvider();

            provider.Read(appSetting, xml);

            Assert.Equal(1, appSetting.SettingItem.Children.Count());
            Assert.Equal("child value2", appSetting.SettingItem["child"].Value);

            var itemGroup = appSetting.SettingItem["child"] as SettingItemGroup;

            Assert.NotNull(itemGroup);
            Assert.True(itemGroup.HasAttributes);
            Assert.Equal(2, itemGroup.Attributes.Count());
            Assert.NotNull(itemGroup.GetAttribute("format"));
            Assert.NotNull(itemGroup.GetAttribute("culture"));
            Assert.Equal("MMddyyyy", itemGroup.GetAttribute("format").Value);
            Assert.Equal("en-GB", itemGroup.GetAttribute("culture").Value);
        }