-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
RegistryKey_Flush.cs
54 lines (47 loc) · 2.1 KB
/
RegistryKey_Flush.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace Microsoft.Win32.RegistryTests
{
public class RegistryKey_Flush : RegistryTestsBase
{
// [] Flush is called if the state of the registry key is dirty - modifiable operation has occurred in the key - and the
// registry key is still a valid handle. From the MSDN
/**
It is not necessary to call RegFlushKey to change a key. Registry changes are flushed to disk by the registry using its lazy flusher.
Lazy flushing occurs automatically and regularly after a system-specified interval of time. Registry changes are also flushed to disk at
system shutdown. Unlike RegCloseKey, the RegFlushKey function returns only when all the data has been written to the registry.
The RegFlushKey function may also write out parts of or all of the other keys. Calling this function excessively can have a negative effect
on an application's performance. An application should only call RegFlushKey if it requires absolute certainty that registry changes are on
disk.
In general, RegFlushKey rarely, if ever, need be used.
**/
[Fact]
public void FlushNewlyOpenedKey()
{
TestRegistryKey.Flush();
}
[Fact]
public void FlushRegistryKeyAfterClosing()
{
TestRegistryKey.Dispose();
TestRegistryKey.Flush();
}
[Fact]
public void SetValueAndFlush()
{
const string valueName = "Key";
const string expectedValue = "Value";
TestRegistryKey.SetValue(valueName, expectedValue);
//Now we call Flush but this is really redundant
TestRegistryKey.Flush();
Assert.Equal(expectedValue, TestRegistryKey.GetValue(valueName));
}
[Fact]
public void FlushDeletedRegistryKey()
{
Registry.CurrentUser.DeleteSubKeyTree(TestRegistryKeyName);
TestRegistryKey.Flush();
}
}
}