Debian Codegraph @

external/corefx/src/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_GetSubKeyCount.cs

raw
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_GetSubKeyCount : RegistryTestsBase
13 {
14 [Fact]
15 public void ShoudThrowIfDisposed()
16 {
17 Assert.Throws<ObjectDisposedException>(() =>
18 {
19 TestRegistryKey.Dispose();
20 return TestRegistryKey.SubKeyCount;
21 });
22 }
23
24 [Fact]
25 public void ShouldThrowIfRegistryKeyDeleted()
26 {
27 Registry.CurrentUser.DeleteSubKeyTree(TestRegistryKeyName);
28 Assert.Throws<IOException>(() => TestRegistryKey.SubKeyCount);
29 }
30
31 [Fact]
32 public void SubKeyCountTest()
33 {
34 // [] Creating new SubKeys and get count
35
36 Assert.Equal(expected: 0, actual: TestRegistryKey.SubKeyCount);
37 Assert.NotNull(TestRegistryKey.CreateSubKey(TestRegistryKeyName));
38 Assert.Equal(expected: 1, actual: TestRegistryKey.SubKeyCount);
39
40 TestRegistryKey.DeleteSubKey(TestRegistryKeyName);
41 Assert.Equal(expected: 0, actual: TestRegistryKey.SubKeyCount);
42 }
43
44 [Fact]
45 public void SubKeyCountTest2()
46 {
47 // [] Add multiple keys and test for SubKeyCount
48 string[] testSubKeys = Enumerable.Range(1, 9).Select(x => "BLAH_" + x.ToString()).ToArray();
49 foreach (var subKey in testSubKeys)
50 {
51 TestRegistryKey.CreateSubKey(subKey);
52 }
53
54 Assert.Equal(testSubKeys.Length, TestRegistryKey.SubKeyCount);
55 }
56 }
57 }