public void CanDeserializeSerializedConfiguration()
        {
            OracleConnectionSettings rwSettings = new OracleConnectionSettings();

            OracleConnectionData rwOracleConnectionData = new OracleConnectionData();
            rwOracleConnectionData.Name = "name0";
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package1", "pref1"));
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package2", "pref2"));
            rwSettings.OracleConnectionsData.Add(rwOracleConnectionData);
            rwOracleConnectionData = new OracleConnectionData();
            rwOracleConnectionData.Name = "name1";
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package3", "pref3"));
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package4", "pref4"));
            rwSettings.OracleConnectionsData.Add(rwOracleConnectionData);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[OracleConnectionSettings.SectionName] = rwSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            OracleConnectionSettings roSettings = (OracleConnectionSettings)configurationSource.GetSection(OracleConnectionSettings.SectionName);
            Assert.AreEqual(2, roSettings.OracleConnectionsData.Count);
            Assert.AreEqual("name0", roSettings.OracleConnectionsData.Get(0).Name);
            Assert.AreEqual(2, roSettings.OracleConnectionsData.Get(0).Packages.Count);
        }
 public OracleConnectionSettings Build()
 {
     oracleConnectionSettings = new OracleConnectionSettings();
     IList<ConfigurationNode> connections = hierarchy.FindNodesByType(typeof(OracleConnectionElementNode));
     for (int index = 0; index < connections.Count; ++index)
     {
         OracleConnectionData data = new OracleConnectionData();
         data.Name = connections[index].Parent.Name;
         foreach (OraclePackageElementNode node in connections[index].Nodes)
         {
             data.Packages.Add(node.OraclePackageElement);
         }
         oracleConnectionSettings.OracleConnectionsData.Add(data);
     }
     return oracleConnectionSettings;
 }
        public void ConfigurationObjectIsNotModifiedIfThereAreNoPolicyOverrides()
        {
            OracleConnectionData connectionData = new OracleConnectionData();
            connectionData.Name = "data1";
            connectionData.Packages.Add(new OraclePackageData("package11", "prefix11"));
            connectionData.Packages.Add(new OraclePackageData("package12", "prefix12"));
            section.OracleConnectionsData.Add(connectionData);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(2, connectionData.Packages.Count);
            Assert.IsNotNull(connectionData.Packages.Get("package11"));
            Assert.AreEqual("prefix11", connectionData.Packages.Get("package11").Prefix);
            Assert.IsNotNull(connectionData.Packages.Get("package12"));
            Assert.AreEqual("prefix12", connectionData.Packages.Get("package12").Prefix);
        }
        public static DictionaryConfigurationSource CreateConfigurationSource()
        {
            DictionaryConfigurationSource source = new DictionaryConfigurationSource();

            DatabaseSettings settings = new DatabaseSettings();
            settings.DefaultDatabase = "Service_Dflt";

            OracleConnectionSettings oracleConnectionSettings = new OracleConnectionSettings();
            OracleConnectionData data = new OracleConnectionData();
            data.Name = "OracleTest";
            data.Packages.Add(new OraclePackageData("TESTPACKAGE", "TESTPACKAGETOTRANSLATE"));
            oracleConnectionSettings.OracleConnectionsData.Add(data);

            source.Add(DatabaseSettings.SectionName, settings);
            source.Add(OracleConnectionSettings.SectionName, oracleConnectionSettings);

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

            DatabaseSettings settings = new DatabaseSettings();
            settings.DefaultDatabase = "Service_Dflt";
            settings.ProviderMappings.Add(new DbProviderMapping("Oracle.ManagedDataAccess.Client", "EntLibContrib.Data.Oracle.ManagedDataAccess.OracleDatabase, EntLibContrib.Data.Oracle.ManagedDataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));

            OracleConnectionSettings oracleConnectionSettings = new OracleConnectionSettings();
            OracleConnectionData data = new OracleConnectionData();
            data.Name = "OracleTest";
            data.Packages.Add(new OraclePackageData("TESTPACKAGE", "TESTPACKAGETOTRANSLATE"));
            data.Packages.Add(new OraclePackageData("PKGNORTHWIND", "NWND_"));
            data.Packages.Add(new OraclePackageData("PKGENTLIB", "RegionSelect"));
            oracleConnectionSettings.OracleConnectionsData.Add(data);

            source.Add(DatabaseSettings.SectionName, settings);
            source.Add(OracleConnectionSettings.SectionName, oracleConnectionSettings);

            return source;
        }
		public void CanGetExtraInformation()
		{
			ConnectionStringSettings data 
				= new ConnectionStringSettings(name, "connection string;");

			OracleConnectionData oracleConnectionData = new OracleConnectionData();
			oracleConnectionData.Name = name;
			oracleConnectionData.Packages.Add(new OraclePackageData("package1", "pref1"));
			oracleConnectionData.Packages.Add(new OraclePackageData("package2", "pref2"));

			OracleConnectionSettings oracleConnectionSettings = new OracleConnectionSettings();
			oracleConnectionSettings.OracleConnectionsData.Add(oracleConnectionData);

			configurationSource.Add(OracleConnectionSettings.SectionName, oracleConnectionSettings);

			OracleDatabase database = (OracleDatabase)assembler.Assemble(data.Name, data, configurationSource);

			Assert.IsNotNull(database);
			Assert.AreSame(typeof(OracleDatabase), database.GetType());

			// can't access the packages - must resort to side effect
			DbCommand dBCommand = database.GetStoredProcCommand(OracleTestStoredProcedureInPackageWithTranslation);
			Assert.AreEqual((object)OracleTestTranslatedStoredProcedureInPackageWithTranslation, dBCommand.CommandText);
		}
 private void EnsureOracleConnectionData()
 {
     if (currentOracleConnectionData != null) return;
     currentOracleConnectionData = new OracleConnectionData() { Name = ConnectionString.Name };
     currentOracleSettings.OracleConnectionsData.Add(currentOracleConnectionData);
 }
        public void ManageabilityProviderGeneratesProperAdmContent()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            OracleConnectionData data1 = new OracleConnectionData();
            section.OracleConnectionsData.Add(data1);
            data1.Name = "data1";
            data1.Packages.Add(new OraclePackageData("name1", "prefix1"));
            data1.Packages.Add(new OraclePackageData("name2", "pre;fix2"));
            OracleConnectionData data2 = new OracleConnectionData();
            section.OracleConnectionsData.Add(data2);
            data2.Name = "data2";

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            provider.AddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp");

            MockAdmContent content = contentBuilder.GetMockContent();
            IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();
            Assert.IsTrue(categoriesEnumerator.MoveNext());
            IEnumerator<AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator();
            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            IEnumerator<AdmPolicy> policiesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator();

            Assert.IsTrue(policiesEnumerator.MoveNext());
            IEnumerator<AdmPart> oracleDataPartsEnumerator = policiesEnumerator.Current.Parts.GetEnumerator();
            Assert.IsTrue(oracleDataPartsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmEditTextPart), oracleDataPartsEnumerator.Current.GetType());
            Assert.IsNull(oracleDataPartsEnumerator.Current.KeyName);
            Assert.AreEqual(OracleConnectionSettingsManageabilityProvider.PackagesPropertyName,
                            oracleDataPartsEnumerator.Current.ValueName);
            IDictionary<String, String> packages = new Dictionary<String, String>();
            KeyValuePairParser.ExtractKeyValueEntries(((AdmEditTextPart)oracleDataPartsEnumerator.Current).DefaultValue, packages);
            Assert.AreEqual(2, packages.Count);
            Assert.AreEqual("prefix1", packages["name1"]);
            Assert.AreEqual("pre;fix2", packages["name2"]);

            Assert.IsFalse(oracleDataPartsEnumerator.MoveNext());
            Assert.IsTrue(policiesEnumerator.MoveNext());
            Assert.IsFalse(policiesEnumerator.MoveNext());

            Assert.IsFalse(subCategoriesEnumerator.MoveNext());
            IEnumerator<AdmPolicy> sectionPoliciesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator();
            Assert.IsFalse(sectionPoliciesEnumerator.MoveNext());
            Assert.IsFalse(categoriesEnumerator.MoveNext());
        }
        public void OracleConnectionWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            OracleConnectionData connectionData1 = new OracleConnectionData();
            connectionData1.Name = "data1";
            section.OracleConnectionsData.Add(connectionData1);
            OracleConnectionData connectionData2 = new OracleConnectionData();
            connectionData2.Name = "data2";
            section.OracleConnectionsData.Add(connectionData2);

            MockRegistryKey machinePackage1Key = new MockRegistryKey(false);
            machineKey.AddSubKey("data1", machinePackage1Key);
            machinePackage1Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false);
            MockRegistryKey machinePackage2Key = new MockRegistryKey(false);
            machineKey.AddSubKey("data2", machinePackage2Key);
            machinePackage2Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, true);
            machinePackage2Key.AddStringValue(OracleConnectionSettingsManageabilityProvider.PackagesPropertyName,
                                              "package24=prefix24");

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual(2, section.OracleConnectionsData.Count);
            Assert.IsNotNull(section.OracleConnectionsData.Get("data1"));
            Assert.IsNotNull(section.OracleConnectionsData.Get("data2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machinePackage1Key, machinePackage2Key));
        }
        public void ConfigurationObjectIsNotModifiedIfThereArePolicyOverridesButGroupPoliciesAreDisabled()
        {
            OracleConnectionData connectionData = new OracleConnectionData();
            connectionData.Name = "data1";
            connectionData.Packages.Add(new OraclePackageData("package11", "prefix11"));
            connectionData.Packages.Add(new OraclePackageData("package12", "prefix12"));
            section.OracleConnectionsData.Add(connectionData);

            MockRegistryKey machinePackageKey = new MockRegistryKey(false);
            machineKey.AddSubKey("data1", machinePackageKey);
            machinePackageKey.AddStringValue(OracleConnectionSettingsManageabilityProvider.PackagesPropertyName,
                                             "package13=prefix13; package14=prefix14; package15=prefix15");

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual(2, connectionData.Packages.Count);
            Assert.IsNotNull(connectionData.Packages.Get("package11"));
            Assert.AreEqual("prefix11", connectionData.Packages.Get("package11").Prefix);
            Assert.IsNotNull(connectionData.Packages.Get("package12"));
            Assert.AreEqual("prefix12", connectionData.Packages.Get("package12").Prefix);

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machinePackageKey));
        }
        public void MultipleConfigurationObjectsAreModifiedIfThereArePolicyOverrides()
        {
            OracleConnectionData connection1Data = new OracleConnectionData();
            connection1Data.Name = "data1";
            connection1Data.Packages.Add(new OraclePackageData("package11", "prefix11"));
            connection1Data.Packages.Add(new OraclePackageData("package12", "prefix12"));
            section.OracleConnectionsData.Add(connection1Data);

            OracleConnectionData connection2Data = new OracleConnectionData();
            connection2Data.Name = "data2";
            connection2Data.Packages.Add(new OraclePackageData("package21", "prefix21"));
            connection2Data.Packages.Add(new OraclePackageData("package22", "prefix22"));
            connection2Data.Packages.Add(new OraclePackageData("package23", "prefix23"));
            section.OracleConnectionsData.Add(connection2Data);

            OracleConnectionData connection3Data = new OracleConnectionData();
            connection3Data.Name = "data3";
            connection3Data.Packages.Add(new OraclePackageData("package31", "prefix31"));
            section.OracleConnectionsData.Add(connection3Data);

            MockRegistryKey machinePackage1Key = new MockRegistryKey(false);
            machineKey.AddSubKey("data1", machinePackage1Key);
            machinePackage1Key.AddStringValue(OracleConnectionSettingsManageabilityProvider.PackagesPropertyName,
                                              "package13=prefix13; package14=prefix14; package15=prefix15");
            MockRegistryKey machinePackage2Key = new MockRegistryKey(false);
            machineKey.AddSubKey("data2", machinePackage2Key);
            machinePackage2Key.AddStringValue(OracleConnectionSettingsManageabilityProvider.PackagesPropertyName,
                                              "package24=prefix24");

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual(3, connection1Data.Packages.Count);
            Assert.IsNotNull(connection1Data.Packages.Get("package13"));
            Assert.AreEqual("prefix13", connection1Data.Packages.Get("package13").Prefix);
            Assert.IsNotNull(connection1Data.Packages.Get("package14"));
            Assert.AreEqual("prefix14", connection1Data.Packages.Get("package14").Prefix);
            Assert.IsNotNull(connection1Data.Packages.Get("package15"));
            Assert.AreEqual("prefix15", connection1Data.Packages.Get("package15").Prefix);

            Assert.AreEqual(1, connection2Data.Packages.Count);
            Assert.IsNotNull(connection2Data.Packages.Get("package24"));
            Assert.AreEqual("prefix24", connection2Data.Packages.Get("package24").Prefix);

            Assert.AreEqual(1, connection3Data.Packages.Count);
            Assert.IsNotNull(connection3Data.Packages.Get("package31"));
            Assert.AreEqual("prefix31", connection3Data.Packages.Get("package31").Prefix);

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machinePackage1Key, machinePackage2Key));
        }
        public void Setup()
        {
            var configSource = new DictionaryConfigurationSource();

            var connectionStrings = new ConnectionStringsSection();
            connectionStrings.ConnectionStrings.Add(
                new ConnectionStringSettings("someSetting", "someConnectionString", "System.Data.OracleClient"));
            configSource.Add("connectionStrings", connectionStrings);

            var oracleConnectionData = new OracleConnectionData { Name = "someSetting" };
            oracleConnectionData.Packages.Add(new OraclePackageData("foo", "bar"));
            var oracleSettings = new OracleConnectionSettings();
            oracleSettings.OracleConnectionsData.Add(oracleConnectionData);
            configSource.Add(OracleConnectionSettings.SectionName, oracleSettings);

            configSettings = new DatabaseSyntheticConfigSettings(configSource);
        }
        public void Given()
        {
            // Setup connection strings
            configurationSource = new DictionaryConfigurationSource();
            var connectionStringsSection = new ConnectionStringsSection();
            connectionStringsSection.ConnectionStrings.Add(
                new ConnectionStringSettings
                    {
                        Name = "myConnectionName",
                        ConnectionString = "myConnectionString",
                        ProviderName = "System.Data.OracleClient"
                    }
                );

            configurationSource.Add("connectionStrings", connectionStringsSection);

            // Setup oracle configuration sections
            var oracleConnectionData = new OracleConnectionData { Name = "myConnectionName" };
            oracleConnectionData.Packages.Add(new OraclePackageData("foo", "bar"));

            var oracleSettings = new OracleConnectionSettings();
            oracleSettings.OracleConnectionsData.Add(oracleConnectionData);
            configurationSource.Add(OracleConnectionSettings.SectionName, oracleSettings);


            settings = new DatabaseSyntheticConfigSettings(configurationSource.GetSection);
        }
        public void Given()
        {
            var configurationSource = new DictionaryConfigurationSource();

            var oracleConnectionData = new OracleConnectionData { Name = "myConnectionName" };
            oracleConnectionData.Packages.Add(new OraclePackageData("foo", "bar"));
            var oracleSettings = new OracleConnectionSettings();
            oracleSettings.OracleConnectionsData.Add(oracleConnectionData);
            configurationSource.Add(OracleConnectionSettings.SectionName, oracleSettings);

            var databaseData = new OracleDatabaseData(
                new ConnectionStringSettings
                    {
                        Name = "myConnectionName",
                        ConnectionString = "myConnectionString",
                        ProviderName = "System.Data.Odbc"
                    },
                configurationSource);

            registration = databaseData.GetRegistrations().First();
        }