-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
RegistryKey_GetSubKeyNames.cs
50 lines (44 loc) · 1.48 KB
/
RegistryKey_GetSubKeyNames.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
// 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_GetSubKeyNames : RegistryTestsBase
{
[Fact]
public void ShouldThrowIfDisposed()
{
Assert.Throws<ObjectDisposedException>(() =>
{
TestRegistryKey.Dispose();
TestRegistryKey.GetSubKeyNames();
});
}
[Fact]
public void ShouldThrowIfRegistryKeyDeleted()
{
Registry.CurrentUser.DeleteSubKeyTree(TestRegistryKeyName);
Assert.Throws<IOException>(() => TestRegistryKey.GetSubKeyNames());
}
[Fact]
public void GetSubKeyNamesTest()
{
// [] Creating new SubKeys and get the names
string[] expectedSubKeyNames = Enumerable.Range(1, 9).Select(x => "BLAH_" + x.ToString()).ToArray();
foreach (var subKeyName in expectedSubKeyNames)
{
TestRegistryKey.CreateSubKey(subKeyName).Dispose();
}
Assert.Equal(expectedSubKeyNames, TestRegistryKey.GetSubKeyNames());
}
[Fact]
public void GetSubKeyNamesTest2()
{
// [] Check that zero length array is returned for no subkeys
Assert.Empty(TestRegistryKey.GetSubKeyNames());
}
}
}