7
7
8
8
namespace Microsoft . Win32 . RegistryTests
9
9
{
10
- public class Registry_SetValue_str_str_obj : TestSubKey
10
+ public class Registry_SetValue_str_str_obj : RegistryTestsBase
11
11
{
12
- private const string TestKey = "CM2001_TEST" ;
13
-
14
- public Registry_SetValue_str_str_obj ( )
15
- : base ( TestKey )
16
- {
17
- }
18
-
19
12
[ Fact ]
20
13
public void Test01 ( )
21
14
{
22
15
// [] Passing in null should throw ArgumentNullException
23
16
//UPDATE: This sets the default value. We should move this test to a newly defined reg key so as not to screw up the system
24
17
const string expected = "This is a test" ;
25
- Registry . SetValue ( _testRegistryKey . Name , null , expected ) ;
26
- Assert . Equal ( expected , _testRegistryKey . GetValue ( null ) ) ;
18
+ Registry . SetValue ( TestRegistryKey . Name , null , expected ) ;
19
+ Assert . Equal ( expected , TestRegistryKey . GetValue ( null ) ) ;
27
20
}
28
21
29
22
[ Fact ]
30
23
public void NegativeTests ( )
31
24
{
32
25
// Should throw if passed value is null
33
- Assert . Throws < ArgumentNullException > ( ( ) => Registry . SetValue ( _testRegistryKey . Name , "test" , value : null ) ) ;
26
+ Assert . Throws < ArgumentNullException > ( ( ) => Registry . SetValue ( TestRegistryKey . Name , "test" , value : null ) ) ;
34
27
35
28
// Should throw if passed keyName is null
36
29
Assert . Throws < ArgumentNullException > ( ( ) => Registry . SetValue ( keyName : null , valueName : "test" , value : "test" ) ) ;
@@ -43,14 +36,14 @@ public void NegativeTests()
43
36
44
37
// Should throw if key length above 255 characters but prior to V4, the limit is 16383
45
38
const int maxValueNameLength = 16383 ;
46
- Assert . Throws < ArgumentException > ( ( ) => Registry . SetValue ( _testRegistryKey . Name , new string ( 'a' , maxValueNameLength + 1 ) , 5 ) ) ;
39
+ Assert . Throws < ArgumentException > ( ( ) => Registry . SetValue ( TestRegistryKey . Name , new string ( 'a' , maxValueNameLength + 1 ) , 5 ) ) ;
47
40
48
41
// Should throw if passed value is array with uninitialized elements
49
- Assert . Throws < ArgumentException > ( ( ) => Registry . SetValue ( _testRegistryKey . Name , "StringArr" , value : new string [ 1 ] ) ) ;
42
+ Assert . Throws < ArgumentException > ( ( ) => Registry . SetValue ( TestRegistryKey . Name , "StringArr" , value : new string [ 1 ] ) ) ;
50
43
51
44
// Should throw because only String[] (REG_MULTI_SZ) and byte[] (REG_BINARY) are supported.
52
45
// RegistryKey.SetValue does not support arrays of type UInt32[].
53
- Assert . Throws < ArgumentException > ( ( ) => Registry . SetValue ( _testRegistryKey . Name , "IntArray" , new [ ] { 1 , 2 , 3 } ) ) ;
46
+ Assert . Throws < ArgumentException > ( ( ) => Registry . SetValue ( TestRegistryKey . Name , "IntArray" , new [ ] { 1 , 2 , 3 } ) ) ;
54
47
}
55
48
56
49
public static IEnumerable < object [ ] > TestValueTypes { get { return TestData . TestValueTypes ; } }
@@ -59,9 +52,9 @@ public void NegativeTests()
59
52
[ MemberData ( "TestValueTypes" ) ]
60
53
public void SetValueWithValueTypes ( string valueName , object testValue )
61
54
{
62
- Registry . SetValue ( _testRegistryKey . Name , valueName , testValue ) ;
63
- Assert . Equal ( testValue . ToString ( ) , _testRegistryKey . GetValue ( valueName ) . ToString ( ) ) ;
64
- _testRegistryKey . DeleteValue ( valueName ) ;
55
+ Registry . SetValue ( TestRegistryKey . Name , valueName , testValue ) ;
56
+ Assert . Equal ( testValue . ToString ( ) , TestRegistryKey . GetValue ( valueName ) . ToString ( ) ) ;
57
+ TestRegistryKey . DeleteValue ( valueName ) ;
65
58
}
66
59
67
60
[ Fact ]
@@ -70,9 +63,9 @@ public void SetValueWithInt32()
70
63
const string testValueName = "Int32" ;
71
64
const int expected = - 5 ;
72
65
73
- Registry . SetValue ( _testRegistryKey . Name , testValueName , expected ) ;
74
- Assert . Equal ( expected , ( int ) _testRegistryKey . GetValue ( testValueName ) ) ;
75
- _testRegistryKey . DeleteValue ( testValueName ) ;
66
+ Registry . SetValue ( TestRegistryKey . Name , testValueName , expected ) ;
67
+ Assert . Equal ( expected , ( int ) TestRegistryKey . GetValue ( testValueName ) ) ;
68
+ TestRegistryKey . DeleteValue ( testValueName ) ;
76
69
}
77
70
78
71
[ Fact ]
@@ -82,9 +75,9 @@ public void SetValueWithUInt64()
82
75
const string testValueName = "UInt64" ;
83
76
const ulong expected = ulong . MaxValue ;
84
77
85
- Registry . SetValue ( _testRegistryKey . Name , testValueName , expected ) ;
86
- Assert . Equal ( expected , Convert . ToUInt64 ( _testRegistryKey . GetValue ( testValueName ) ) ) ;
87
- _testRegistryKey . DeleteValue ( testValueName ) ;
78
+ Registry . SetValue ( TestRegistryKey . Name , testValueName , expected ) ;
79
+ Assert . Equal ( expected , Convert . ToUInt64 ( TestRegistryKey . GetValue ( testValueName ) ) ) ;
80
+ TestRegistryKey . DeleteValue ( testValueName ) ;
88
81
}
89
82
90
83
[ Fact ]
@@ -94,9 +87,9 @@ public void SetValueWithByteArray()
94
87
const string testValueName = "UBArr" ;
95
88
byte [ ] expected = { 1 , 2 , 3 } ;
96
89
97
- Registry . SetValue ( _testRegistryKey . Name , testValueName , expected ) ;
98
- Assert . Equal ( expected , ( byte [ ] ) _testRegistryKey . GetValue ( testValueName ) ) ;
99
- _testRegistryKey . DeleteValue ( testValueName ) ;
90
+ Registry . SetValue ( TestRegistryKey . Name , testValueName , expected ) ;
91
+ Assert . Equal ( expected , ( byte [ ] ) TestRegistryKey . GetValue ( testValueName ) ) ;
92
+ TestRegistryKey . DeleteValue ( testValueName ) ;
100
93
}
101
94
102
95
[ Fact ]
@@ -111,9 +104,9 @@ public void SetValueWithMultiString()
111
104
"lot of things. one of which"
112
105
} ;
113
106
114
- Registry . SetValue ( _testRegistryKey . Name , testValueName , expected ) ;
115
- Assert . Equal ( expected , ( string [ ] ) _testRegistryKey . GetValue ( testValueName ) ) ;
116
- _testRegistryKey . DeleteValue ( testValueName ) ;
107
+ Registry . SetValue ( TestRegistryKey . Name , testValueName , expected ) ;
108
+ Assert . Equal ( expected , ( string [ ] ) TestRegistryKey . GetValue ( testValueName ) ) ;
109
+ TestRegistryKey . DeleteValue ( testValueName ) ;
117
110
}
118
111
119
112
public static IEnumerable < object [ ] > TestEnvironment { get { return TestData . TestEnvironment ; } }
@@ -123,12 +116,12 @@ public void SetValueWithMultiString()
123
116
public void SetValueWithEnvironmentVariable ( string valueName , string envVariableName , string expectedVariableValue )
124
117
{
125
118
string value = "%" + envVariableName + "%" ;
126
- Registry . SetValue ( _testRegistryKey . Name , valueName , value ) ;
119
+ Registry . SetValue ( TestRegistryKey . Name , valueName , value ) ;
127
120
128
- string result = ( string ) _testRegistryKey . GetValue ( valueName ) ;
121
+ string result = ( string ) TestRegistryKey . GetValue ( valueName ) ;
129
122
//we don't expand for the user, REG_SZ_EXPAND not supported
130
123
Assert . Equal ( expectedVariableValue , Environment . ExpandEnvironmentVariables ( result ) ) ;
131
- _testRegistryKey . DeleteValue ( valueName ) ;
124
+ TestRegistryKey . DeleteValue ( valueName ) ;
132
125
}
133
126
134
127
[ Fact ]
@@ -138,9 +131,9 @@ public void SetValueWithEmptyString()
138
131
const string testValueName = "test_122018" ;
139
132
string expected = string . Empty ;
140
133
141
- Registry . SetValue ( _testRegistryKey . Name , testValueName , expected ) ;
142
- Assert . Equal ( expected , ( string ) _testRegistryKey . GetValue ( testValueName ) ) ;
143
- _testRegistryKey . DeleteValue ( testValueName ) ;
134
+ Registry . SetValue ( TestRegistryKey . Name , testValueName , expected ) ;
135
+ Assert . Equal ( expected , ( string ) TestRegistryKey . GetValue ( testValueName ) ) ;
136
+ TestRegistryKey . DeleteValue ( testValueName ) ;
144
137
}
145
138
}
146
139
}
0 commit comments