-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
RegistryKey_GetValue_str.cs
97 lines (83 loc) · 3.19 KB
/
RegistryKey_GetValue_str.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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.Collections.Generic;
using Xunit;
namespace Microsoft.Win32.RegistryTests
{
public class RegistryKey_GetValue_str : RegistryTestsBase
{
[Fact]
public void NegativeTests()
{
Assert.Throws<ObjectDisposedException>(() =>
{
TestRegistryKey.Dispose();
TestRegistryKey.GetValue(null);
});
}
[Fact]
public void GetDefaultValueTest()
{
Assert.True(TestRegistryKey.SetDefaultValue(TestData.DefaultValue));
Assert.Equal(TestData.DefaultValue, TestRegistryKey.GetValue(null));
Assert.Equal(TestData.DefaultValue, TestRegistryKey.GetValue(string.Empty));
}
[Fact]
public void RegistryKeyGetValueMultiStringDoesNotDiscardZeroLengthStrings()
{
const string valueName = "Test";
string[] expected = { "", "Hello", "", "World", "" };
TestRegistryKey.SetValue(valueName, expected);
Assert.Equal(expected, (string[])TestRegistryKey.GetValue(valueName));
TestRegistryKey.DeleteValue(valueName);
}
public static IEnumerable<object[]> TestValueTypes { get { return TestData.TestValueTypes; } }
[Theory]
[MemberData(nameof(TestValueTypes))]
public void TestGetValueWithValueTypes(string valueName, object testValue)
{
TestRegistryKey.SetValue(valueName, testValue);
Assert.Equal(testValue.ToString(), TestRegistryKey.GetValue(valueName).ToString());
TestRegistryKey.DeleteValue(valueName);
}
[Fact]
public void GetStringTest()
{
const string valueName = "Test";
const string expected = "Here is a little test string";
TestRegistryKey.SetValue(valueName, expected);
Assert.Equal(expected, TestRegistryKey.GetValue(valueName).ToString());
TestRegistryKey.DeleteValue(valueName);
}
[Fact]
public void GetByteArrayTest()
{
const string valueName = "UBArr";
byte[] expected = { 1, 2, 3 };
TestRegistryKey.SetValue(valueName, expected);
Assert.Equal(expected, (byte[])TestRegistryKey.GetValue(valueName));
TestRegistryKey.DeleteValue(valueName);
}
[Fact]
public void GetStringArrayTest()
{
const string valueName = "StringArr";
string[] expected =
{
"This is a public",
"broadcast intend to test",
"lot of things. one of which"
};
TestRegistryKey.SetValue(valueName, expected);
Assert.Equal(expected, (string[])TestRegistryKey.GetValue(valueName));
TestRegistryKey.DeleteValue(valueName);
}
[Fact]
public void GetPerformanceKeyValue()
{
string[] counterNames = (string[])Registry.PerformanceData.GetValue("Counter");
Assert.NotEmpty(counterNames);
}
}
}