/// <summary> /// Determines which TNSNAMES.ORA file to update based on task input and the current system environment. /// </summary> /// <returns>The path of the TNSNAMES.ORA file that will be used by the task.</returns> /// <exclude /> public string GetEffectivePathToTnsNamesFile() { if (!String.IsNullOrEmpty(tnsNamesFile)) { return(tnsNamesFile); } string[] oracleHomes = registry.GetSubKeys(RegistryHive.LocalMachine, ORACLE_REGISTRY); foreach (string home in oracleHomes) { string homePathKey = String.Format(@"HKEY_LOCAL_MACHINE\{0}\{1}", ORACLE_REGISTRY, home); Log.LogMessage(MessageImportance.Low, Properties.Resources.OracleHomeCheck, homePathKey); string homePath = registry.GetValue(homePathKey, ORACLE_HOME) as string; if (homePath == null) { continue; } string tnsNamesPath = Path.Combine(homePath, TNSNAMES_PATH); Log.LogMessage(MessageImportance.Low, Properties.Resources.TnsNamesFileCheck, tnsNamesPath); if (fileSystem.FileExists(tnsNamesPath)) { return(tnsNamesPath); } } return(null); }
public void The_tnsnames_file_in_the_oracle_home_should_be_used_when_the_TnsNamesFile_property_is_not_set() { string lastUsedOracleHome = @"c:\oracle\product\10"; string tnsnamesFileInOracleHome = @"c:\oracle\product\10\NETWORK\ADMIN\tnsnames.ora"; string[] oracleSubKeys = new string[] { "OraHome" }; using (mocks.Record()) { SetupResult.For(registry.GetSubKeys(RegistryHive.LocalMachine, @"SOFTWARE\ORACLE")).Return(oracleSubKeys); SetupResult.For(registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OraHome", "ORACLE_HOME")).Return(lastUsedOracleHome); SetupResult.For(fileSystem.FileExists(tnsnamesFileInOracleHome)).Return(true); } string fileBeingUpdated = task.GetEffectivePathToTnsNamesFile(); Assert.AreEqual(tnsnamesFileInOracleHome, fileBeingUpdated); }