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