-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
RegistryKey_GetValueNames.cs
68 lines (58 loc) · 2.1 KB
/
RegistryKey_GetValueNames.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Linq;
using Xunit;
namespace Microsoft.Win32.RegistryTests
{
public class RegistryKey_GetValueNames : RegistryTestsBase
{
[Fact]
public void ShouldThrowIfDisposed()
{
Assert.Throws<ObjectDisposedException>(() =>
{
TestRegistryKey.Dispose();
TestRegistryKey.GetValueNames();
});
}
[Fact]
public void ShouldThrowIfRegistryKeyDeleted()
{
Registry.CurrentUser.DeleteSubKeyTree(TestRegistryKeyName);
Assert.Throws<IOException>(() => TestRegistryKey.GetValueNames());
}
[Fact]
public void TestGetValueNames()
{
// [] Add several values and get the values then check the names
Assert.Equal(expected: 0, actual: TestRegistryKey.GetValueNames().Length);
string[] expected = { TestRegistryKeyName };
foreach (string valueName in expected)
{
TestRegistryKey.SetValue(valueName, 5);
}
Assert.Equal(expected, TestRegistryKey.GetValueNames());
TestRegistryKey.DeleteValue(TestRegistryKeyName);
Assert.Equal(expected: 0, actual: TestRegistryKey.GetValueNames().Length);
}
[Fact]
public void TestGetValueNames2()
{
foreach (var testCase in TestData.TestValueTypes)
{
TestRegistryKey.SetValue(testCase[0].ToString(), testCase[1]);
}
string[] expected = TestData.TestValueTypes.Select(x => x[0].ToString()).ToArray();
Assert.Equal(expected, TestRegistryKey.GetValueNames());
}
[Fact]
public static void TestGetValueNamesForPerformanceData()
{
var rk = Registry.PerformanceData;
string[] names = rk.GetValueNames();
Assert.Equal(new string[] { "Global", "Costly" }, names);
}
}
}