public void DeleteTheRegValue_WhenCalledWithHKLM() { // Arrange SUT action = new SUT(Tools.GetXmlFragment("DeleteRegValueHKLM32.CustAct")); RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32); RegistryKey targetKey = hklm.OpenSubKey(action.RegKey, true); var finalResult = Tools.GetReturnCodeAction(); // Act if (targetKey == null) { targetKey = hklm.CreateSubKey(action.RegKey); } object valueToDelete = targetKey.GetValue(action.ValueName, null); if (valueToDelete == null) { targetKey.SetValue(action.ValueName, 12, RegistryValueKind.DWord); } valueToDelete = targetKey.GetValue(action.ValueName, null); Assert.IsNotNull(valueToDelete); action.Run(ref finalResult); valueToDelete = targetKey.GetValue(action.ValueName, null); // Assert Assert.IsNull(valueToDelete); }
public void DoNothing_WhenRegValueDoesNotExists() { // Arrange SUT action = new SUT(Tools.GetXmlFragment("DeleteRegValueHKCUNotExists.CustAct")); RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, Microsoft.Win32.RegistryView.Registry32); RegistryKey targetKey = hkcu.OpenSubKey(action.RegKey, true); var finalResult = Tools.GetReturnCodeAction(); // Act if (targetKey == null) { targetKey = hkcu.CreateSubKey(action.RegKey); } object valueToDelete = targetKey.GetValue(action.ValueName, null); Assert.IsNull(valueToDelete); action.Run(ref finalResult); valueToDelete = targetKey.GetValue(action.ValueName, null); // Assert Assert.IsNull(valueToDelete); }