Debian Codegraph @

external/corefx/src/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_GetValue_str.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.Collections.Generic;
7 using Xunit;
8
9 namespace Microsoft.Win32.RegistryTests
10 {
11 public class RegistryKey_GetValue_str : RegistryTestsBase
12 {
13 [Fact]
14 public void NegativeTests()
15 {
16 Assert.Throws<ObjectDisposedException>(() =>
17 {
18 TestRegistryKey.Dispose();
19 TestRegistryKey.GetValue(null);
20 });
21 }
22
23 [Fact]
24 public void GetDefaultValueTest()
25 {
26 Assert.True(TestRegistryKey.SetDefaultValue(TestData.DefaultValue));
27 Assert.Equal(TestData.DefaultValue, TestRegistryKey.GetValue(null));
28 Assert.Equal(TestData.DefaultValue, TestRegistryKey.GetValue(string.Empty));
29 }
30
31 [Fact]
32 public void RegistryKeyGetValueMultiStringDoesNotDiscardZeroLengthStrings()
33 {
34 const string valueName = "Test";
35 string[] expected = { "", "Hello", "", "World", "" };
36
37 TestRegistryKey.SetValue(valueName, expected);
38 Assert.Equal(expected, (string[])TestRegistryKey.GetValue(valueName));
39 TestRegistryKey.DeleteValue(valueName);
40 }
41
42 public static IEnumerable<object[]> TestValueTypes { get { return TestData.TestValueTypes; } }
43
44 [Theory]
45 [MemberData(nameof(TestValueTypes))]
46 public void TestGetValueWithValueTypes(string valueName, object testValue)
47 {
48 TestRegistryKey.SetValue(valueName, testValue);
49 Assert.Equal(testValue.ToString(), TestRegistryKey.GetValue(valueName).ToString());
50 TestRegistryKey.DeleteValue(valueName);
51 }
52
53 [Fact]
54 public void GetStringTest()
55 {
56 const string valueName = "Test";
57 const string expected = "Here is a little test string";
58
59 TestRegistryKey.SetValue(valueName, expected);
60 Assert.Equal(expected, TestRegistryKey.GetValue(valueName).ToString());
61 TestRegistryKey.DeleteValue(valueName);
62 }
63
64 [Fact]
65 public void GetByteArrayTest()
66 {
67 const string valueName = "UBArr";
68 byte[] expected = { 1, 2, 3 };
69
70 TestRegistryKey.SetValue(valueName, expected);
71 Assert.Equal(expected, (byte[])TestRegistryKey.GetValue(valueName));
72 TestRegistryKey.DeleteValue(valueName);
73 }
74
75 [Fact]
76 public void GetStringArrayTest()
77 {
78 const string valueName = "StringArr";
79 string[] expected =
80 {
81 "This is a public",
82 "broadcast intend to test",
83 "lot of things. one of which"
84 };
85
86 TestRegistryKey.SetValue(valueName, expected);
87 Assert.Equal(expected, (string[])TestRegistryKey.GetValue(valueName));
88 TestRegistryKey.DeleteValue(valueName);
89 }
90 }
91 }