@@ -33,10 +33,22 @@ namespace ColorSetKit_Test
33
33
[ TestClass ]
34
34
public class Test
35
35
{
36
+ private static string GetAssemblyDirectoryName ( )
37
+ {
38
+ string ? name = System . IO . Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
39
+
40
+ if ( name == null )
41
+ {
42
+ throw new NullReferenceException ( "Cannot get directory name for assembly" ) ;
43
+ }
44
+
45
+ return name ;
46
+ }
47
+
36
48
[ TestMethod ]
37
49
public void TestInitWithPathBinary ( )
38
50
{
39
- string path = System . IO . Path . Combine ( System . IO . Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) , "Colors.colorset" ) ;
51
+ string path = System . IO . Path . Combine ( GetAssemblyDirectoryName ( ) , "Colors.colorset" ) ;
40
52
ColorSet set = new ColorSet ( path ) ;
41
53
42
54
Assert . IsTrue ( set . Colors . Count > 0 ) ;
@@ -45,7 +57,7 @@ public void TestInitWithPathBinary()
45
57
[ TestMethod ]
46
58
public void TestInitWithPathXML ( )
47
59
{
48
- string path = System . IO . Path . Combine ( System . IO . Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) , "Colors-XML.colorset" ) ;
60
+ string path = System . IO . Path . Combine ( GetAssemblyDirectoryName ( ) , "Colors-XML.colorset" ) ;
49
61
ColorSet set = new ColorSet ( path ) ;
50
62
51
63
Assert . IsTrue ( set . Colors . Count > 0 ) ;
@@ -54,7 +66,7 @@ public void TestInitWithPathXML()
54
66
[ TestMethod ]
55
67
public void TestInitWithDataBinary ( )
56
68
{
57
- string path = System . IO . Path . Combine ( System . IO . Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) , "Colors.colorset" ) ;
69
+ string path = System . IO . Path . Combine ( GetAssemblyDirectoryName ( ) , "Colors.colorset" ) ;
58
70
Data data = new Data ( path ) ;
59
71
ColorSet set = new ColorSet ( data ) ;
60
72
@@ -64,7 +76,7 @@ public void TestInitWithDataBinary()
64
76
[ TestMethod ]
65
77
public void TestInitWithDataXML ( )
66
78
{
67
- string path = System . IO . Path . Combine ( System . IO . Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) , "Colors-XML.colorset" ) ;
79
+ string path = System . IO . Path . Combine ( GetAssemblyDirectoryName ( ) , "Colors-XML.colorset" ) ;
68
80
Data data = new Data ( path ) ;
69
81
ColorSet set = new ColorSet ( data ) ;
70
82
@@ -76,11 +88,16 @@ public void TestShared()
76
88
{
77
89
Assert . AreEqual ( ColorSet . Shared . Colors . Count , 2 ) ;
78
90
79
- Assert . IsTrue ( ColorSet . Shared [ "NoVariant" ] != null ) ;
80
- Assert . IsTrue ( ColorSet . Shared [ "Variant" ] != null ) ;
91
+ ColorPair ? p1 = ColorSet . Shared [ "NoVariant" ] ;
92
+ ColorPair ? p2 = ColorSet . Shared [ "Variant" ] ;
81
93
82
- ColorPair p1 = ColorSet . Shared [ "NoVariant" ] ;
83
- ColorPair p2 = ColorSet . Shared [ "Variant" ] ;
94
+ Assert . IsTrue ( p1 != null ) ;
95
+ Assert . IsTrue ( p2 != null ) ;
96
+
97
+ if ( p1 == null || p2 == null )
98
+ {
99
+ return ;
100
+ }
84
101
85
102
{
86
103
if ( p1 . Color is SolidColorBrush c )
@@ -133,8 +150,8 @@ public void TestShared()
133
150
[ TestMethod ]
134
151
public void TestChild ( )
135
152
{
136
- ColorSet set = new ColorSet ( ) ;
137
- ColorSet child = new ColorSet ( ) ;
153
+ ColorSet set = new ColorSet ( ) ;
154
+ ColorSet child = new ColorSet ( ) ;
138
155
SolidColorBrush clear = new SolidColorBrush ( System . Windows . Media . Color . FromArgb ( 0 , 0 , 0 , 0 ) ) ;
139
156
SolidColorBrush red = new SolidColorBrush ( System . Windows . Media . Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
140
157
@@ -147,12 +164,12 @@ public void TestChild()
147
164
child . Add ( red , "foo" ) ;
148
165
149
166
Assert . IsNotNull ( set [ "foo" ] ) ;
150
- Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] . Color , red ) ) ;
167
+ Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] ? . Color , red ) ) ;
151
168
152
169
set . Add ( clear , "foo" ) ;
153
170
154
171
Assert . IsNotNull ( set [ "foo" ] ) ;
155
- Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] . Color , clear ) ) ;
172
+ Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] ? . Color , clear ) ) ;
156
173
}
157
174
158
175
[ TestMethod ]
@@ -177,11 +194,11 @@ public void TestCreate()
177
194
Assert . IsTrue ( set [ "NoVariant" ] != null ) ;
178
195
Assert . IsTrue ( set [ "Variant" ] != null ) ;
179
196
180
- ColorPair p1 = set [ "NoVariant" ] ;
181
- ColorPair p2 = set [ "Variant" ] ;
197
+ ColorPair ? p1 = set [ "NoVariant" ] ;
198
+ ColorPair ? p2 = set [ "Variant" ] ;
182
199
183
200
{
184
- if ( p1 . Color is SolidColorBrush c )
201
+ if ( p1 ? . Color is SolidColorBrush c )
185
202
{
186
203
Assert . AreEqual ( c . Color . R , 50 ) ;
187
204
Assert . AreEqual ( c . Color . G , 100 ) ;
@@ -194,13 +211,13 @@ public void TestCreate()
194
211
}
195
212
}
196
213
197
- if ( p1 . Variant != null )
214
+ if ( p1 ? . Variant != null )
198
215
{
199
216
Assert . Fail ( "No variant should be defined" ) ;
200
217
}
201
218
202
219
{
203
- if ( p2 . Color is SolidColorBrush c )
220
+ if ( p2 ? . Color is SolidColorBrush c )
204
221
{
205
222
Assert . AreEqual ( c . Color . R , 250 ) ;
206
223
Assert . AreEqual ( c . Color . G , 200 ) ;
@@ -214,7 +231,7 @@ public void TestCreate()
214
231
}
215
232
216
233
{
217
- if ( p2 . Variant is SolidColorBrush c )
234
+ if ( p2 ? . Variant is SolidColorBrush c )
218
235
{
219
236
Assert . AreEqual ( c . Color . R , 200 ) ;
220
237
Assert . AreEqual ( c . Color . G , 150 ) ;
0 commit comments