public static DictionaryConfigurationSource CreateConfigurationSource()
        {
            DictionaryConfigurationSource source = new DictionaryConfigurationSource();

            DatabaseSettings settings = new DatabaseSettings();

            settings.DefaultDatabase = "Db2Test";
            settings.ProviderMappings.Add(new DbProviderMapping("IBM.Data.DB2.iSeries", "EntLibContrib.Data.IBM.DB2.iSeries.Db2Database, EntLibContrib.Data.IBM.DB2.iSeries, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null"));

            Db2ConnectionSettings db2ConnectionSettings = new Db2ConnectionSettings();
            Db2ConnectionData     data = new Db2ConnectionData();

            db2ConnectionSettings.Db2ConnectionsData.Add(data);

            source.Add(DatabaseSettings.SectionName, settings);
            source.Add(Db2ConnectionSettings.SectionName, db2ConnectionSettings);

            return(source);
        }
コード例 #2
0
        public void CanDeserializeSerializedConfiguration()
        {
            Db2ConnectionSettings rwSettings = new Db2ConnectionSettings();

            Db2ConnectionData rwDb2ConnectionData = new Db2ConnectionData();

            rwDb2ConnectionData.Name = "name0";
            rwSettings.Db2ConnectionsData.Add(rwDb2ConnectionData);
            rwDb2ConnectionData      = new Db2ConnectionData();
            rwDb2ConnectionData.Name = "name1";
            rwSettings.Db2ConnectionsData.Add(rwDb2ConnectionData);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[Db2ConnectionSettings.SectionName] = rwSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            Db2ConnectionSettings roSettings = (Db2ConnectionSettings)configurationSource.GetSection(Db2ConnectionSettings.SectionName);

            Assert.AreEqual(2, roSettings.Db2ConnectionsData.Count);
            Assert.AreEqual("name0", roSettings.Db2ConnectionsData.Get(0).Name);
        }