-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
RegistryKey_GetSubKeyCount.cs
58 lines (49 loc) · 1.78 KB
/
RegistryKey_GetSubKeyCount.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
// 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_GetSubKeyCount : RegistryTestsBase
{
[Fact]
public void ShouldThrowIfDisposed()
{
Assert.Throws<ObjectDisposedException>(() =>
{
TestRegistryKey.Dispose();
return TestRegistryKey.SubKeyCount;
});
}
[Fact]
public void ShouldThrowIfRegistryKeyDeleted()
{
Registry.CurrentUser.DeleteSubKeyTree(TestRegistryKeyName);
Assert.Throws<IOException>(() => TestRegistryKey.SubKeyCount);
}
[Fact]
public void SubKeyCountTest()
{
// [] Creating new SubKeys and get count
Assert.Equal(expected: 0, actual: TestRegistryKey.SubKeyCount);
using RegistryKey subkey = TestRegistryKey.CreateSubKey(TestRegistryKeyName);
Assert.NotNull(subkey);
Assert.Equal(expected: 1, actual: TestRegistryKey.SubKeyCount);
TestRegistryKey.DeleteSubKey(TestRegistryKeyName);
Assert.Equal(expected: 0, actual: TestRegistryKey.SubKeyCount);
}
[Fact]
public void SubKeyCountTest2()
{
// [] Add multiple keys and test for SubKeyCount
string[] testSubKeys = Enumerable.Range(1, 9).Select(x => "BLAH_" + x.ToString()).ToArray();
foreach (var subKey in testSubKeys)
{
TestRegistryKey.CreateSubKey(subKey).Dispose();
}
Assert.Equal(testSubKeys.Length, TestRegistryKey.SubKeyCount);
}
}
}