public void NewTemporaryRegistryValueTest_RegistryKey_Success() { var testSubKeyPath = "FiveChecks.Tests"; Registry.CurrentUser.DeleteSubKey(testSubKeyPath, false); using (Registry.CurrentUser.CreateSubKey(testSubKeyPath)){} Some <string> valueName = "SomeValueName"; var actual = TemporaryRegistryValue.NewTemporaryRegistryValue(Registry.CurrentUser, testSubKeyPath, valueName, RegistryValueKind.DWord, 0); var val = actual.Match( value => { Assert.IsTrue(actual.IsSuccess, "Expected success"); Assert.IsTrue(RegistryOperations.RegistryValueExists(Registry.CurrentUser, testSubKeyPath, valueName), "Temporary value does not exist."); value.Dispose(); Assert.IsFalse(RegistryOperations.RegistryValueExists(Registry.CurrentUser, testSubKeyPath, valueName.Value), "Temporary value was not deleted."); return(Option <object> .None); }, exception => { Assert.IsFalse(true, exception.Message); return(Option <object> .None); }); //Cleanup Registry.CurrentUser.DeleteSubKey(testSubKeyPath, false); }
public void NewTemporaryRegistryValueTest_RegistryKey_DoesNotExist_ErrorResult() { string nonExistingRegistryKeyPath = @"APathThat\Hardly\Exists"; var actual = TemporaryRegistryValue.NewTemporaryRegistryValue(Registry.CurrentUser, nonExistingRegistryKeyPath, "SomeValueName", RegistryValueKind.DWord, 0); Assert.IsTrue(actual.IsFaulted); var expectedExceptionMessage = $"Sub key '{Registry.CurrentUser.Name}\\{nonExistingRegistryKeyPath}' does not exist."; var val = actual.Match( value => { Assert.IsFalse(actual.IsSuccess); return(Option <object> .None); }, exception => { Assert.AreEqual(expectedExceptionMessage, exception.Message); return(Option <object> .None); }); }