| 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 System; |
| 6 |
using System.IO; |
| 7 |
using System.Linq; |
| 8 |
using Xunit; |
| 9 |
|
| 10 |
namespace Microsoft.Win32.RegistryTests |
| 11 |
{ |
| 12 |
public class RegistryKey_GetValueNames : RegistryTestsBase |
| 13 |
{ |
| 14 |
[Fact] |
| 15 |
public void ShoudThrowIfDisposed() |
| 16 |
{ |
| 17 |
Assert.Throws<ObjectDisposedException>(() => |
| 18 |
{ |
| 19 |
TestRegistryKey.Dispose(); |
| 20 |
TestRegistryKey.GetValueNames(); |
| 21 |
}); |
| 22 |
} |
| 23 |
|
| 24 |
[Fact] |
| 25 |
public void ShouldThrowIfRegistryKeyDeleted() |
| 26 |
{ |
| 27 |
Registry.CurrentUser.DeleteSubKeyTree(TestRegistryKeyName); |
| 28 |
Assert.Throws<IOException>(() => TestRegistryKey.GetValueNames()); |
| 29 |
} |
| 30 |
|
| 31 |
[Fact] |
| 32 |
public void TestGetValueNames() |
| 33 |
{ |
| 34 |
// [] Add several values and get the values then check the names |
| 35 |
Assert.Equal(expected: 0, actual: TestRegistryKey.GetValueNames().Length); |
| 36 |
|
| 37 |
string[] expected = { TestRegistryKeyName }; |
| 38 |
foreach (string valueName in expected) |
| 39 |
{ |
| 40 |
TestRegistryKey.SetValue(valueName, 5); |
| 41 |
} |
| 42 |
|
| 43 |
Assert.Equal(expected, TestRegistryKey.GetValueNames()); |
| 44 |
|
| 45 |
TestRegistryKey.DeleteValue(TestRegistryKeyName); |
| 46 |
Assert.Equal(expected: 0, actual: TestRegistryKey.GetValueNames().Length); |
| 47 |
} |
| 48 |
|
| 49 |
[Fact] |
| 50 |
public void TestGetValueNames2() |
| 51 |
{ |
| 52 |
foreach (var testCase in TestData.TestValueTypes) |
| 53 |
{ |
| 54 |
TestRegistryKey.SetValue(testCase[0].ToString(), testCase[1]); |
| 55 |
} |
| 56 |
|
| 57 |
string[] expected = TestData.TestValueTypes.Select(x => x[0].ToString()).ToArray(); |
| 58 |
Assert.Equal(expected, TestRegistryKey.GetValueNames()); |
| 59 |
} |
| 60 |
|
| 61 |
[Fact] |
| 62 |
public static void TestGetValueNamesForPerformanceData() |
| 63 |
{ |
| 64 |
var rk = Registry.PerformanceData; |
| 65 |
string[] names = rk.GetValueNames(); |
| 66 |
Assert.Equal(new string[] { "Global", "Costly" }, names); |
| 67 |
} |
| 68 |
} |
| 69 |
} |