public void Setup() { _registryWrapper = MockRepository.GenerateMock <IRegistryWrapper>(); _registryKey = MockRepository.GenerateStub <IRegistryKeyWrapper>(); _subject = new RegistryKeyValueFinder(_registryWrapper); _keysToCheck = new[] { @"SOFTWARE\App1\SubKey\InstallPath1", @"SOFTWARE\App2\InstallPath2" }; _registryWrapper.Stub(x => x.OpenLocalMachineKey("SOFTWARE")).Return(_registryKey); }
public void Setup() { _registryWrapper = MockRepository.GenerateMock<IRegistryWrapper>(); _registryKey = MockRepository.GenerateStub<IRegistryKeyWrapper>(); _subject = new RegistryKeyValueFinder(_registryWrapper); _keysToCheck = new[] { @"SOFTWARE\App1\SubKey\InstallPath1", @"SOFTWARE\App2\InstallPath2" }; _registryWrapper.Stub(x => x.OpenLocalMachineKey("SOFTWARE")).Return(_registryKey); }
public KeyValuePair <string, string> FindFirstValue(params string[] keysToCheck) { foreach (string keyToCheck in keysToCheck) { string[] parts = keyToCheck.Split(@"\".ToCharArray()); IRegistryKeyWrapper key = _registryWrapper.OpenLocalMachineKey(parts[0]); for (int i = 1; i < parts.Length - 1; i++) { key = key.OpenSubKey(parts[i]); if (key == null) //key is null if it does not exist { break; } } if (key != null) //could open all keys now try to get the value { return(new KeyValuePair <string, string>(key.Name, key.GetValue(parts[parts.Length - 1]).ToString())); } } return(new KeyValuePair <string, string>()); //can't find anything so return an emtpy string }