@@ -33,10 +33,22 @@ namespace ColorSetKit_Test
3333 [ TestClass ]
3434 public class Test
3535 {
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+
3648 [ TestMethod ]
3749 public void TestInitWithPathBinary ( )
3850 {
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" ) ;
4052 ColorSet set = new ColorSet ( path ) ;
4153
4254 Assert . IsTrue ( set . Colors . Count > 0 ) ;
@@ -45,7 +57,7 @@ public void TestInitWithPathBinary()
4557 [ TestMethod ]
4658 public void TestInitWithPathXML ( )
4759 {
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" ) ;
4961 ColorSet set = new ColorSet ( path ) ;
5062
5163 Assert . IsTrue ( set . Colors . Count > 0 ) ;
@@ -54,7 +66,7 @@ public void TestInitWithPathXML()
5466 [ TestMethod ]
5567 public void TestInitWithDataBinary ( )
5668 {
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" ) ;
5870 Data data = new Data ( path ) ;
5971 ColorSet set = new ColorSet ( data ) ;
6072
@@ -64,7 +76,7 @@ public void TestInitWithDataBinary()
6476 [ TestMethod ]
6577 public void TestInitWithDataXML ( )
6678 {
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" ) ;
6880 Data data = new Data ( path ) ;
6981 ColorSet set = new ColorSet ( data ) ;
7082
@@ -76,11 +88,16 @@ public void TestShared()
7688 {
7789 Assert . AreEqual ( ColorSet . Shared . Colors . Count , 2 ) ;
7890
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" ] ;
8193
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+ }
84101
85102 {
86103 if ( p1 . Color is SolidColorBrush c )
@@ -133,8 +150,8 @@ public void TestShared()
133150 [ TestMethod ]
134151 public void TestChild ( )
135152 {
136- ColorSet set = new ColorSet ( ) ;
137- ColorSet child = new ColorSet ( ) ;
153+ ColorSet set = new ColorSet ( ) ;
154+ ColorSet child = new ColorSet ( ) ;
138155 SolidColorBrush clear = new SolidColorBrush ( System . Windows . Media . Color . FromArgb ( 0 , 0 , 0 , 0 ) ) ;
139156 SolidColorBrush red = new SolidColorBrush ( System . Windows . Media . Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
140157
@@ -147,12 +164,12 @@ public void TestChild()
147164 child . Add ( red , "foo" ) ;
148165
149166 Assert . IsNotNull ( set [ "foo" ] ) ;
150- Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] . Color , red ) ) ;
167+ Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] ? . Color , red ) ) ;
151168
152169 set . Add ( clear , "foo" ) ;
153170
154171 Assert . IsNotNull ( set [ "foo" ] ) ;
155- Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] . Color , clear ) ) ;
172+ Assert . IsTrue ( ReferenceEquals ( set [ "foo" ] ? . Color , clear ) ) ;
156173 }
157174
158175 [ TestMethod ]
@@ -177,11 +194,11 @@ public void TestCreate()
177194 Assert . IsTrue ( set [ "NoVariant" ] != null ) ;
178195 Assert . IsTrue ( set [ "Variant" ] != null ) ;
179196
180- ColorPair p1 = set [ "NoVariant" ] ;
181- ColorPair p2 = set [ "Variant" ] ;
197+ ColorPair ? p1 = set [ "NoVariant" ] ;
198+ ColorPair ? p2 = set [ "Variant" ] ;
182199
183200 {
184- if ( p1 . Color is SolidColorBrush c )
201+ if ( p1 ? . Color is SolidColorBrush c )
185202 {
186203 Assert . AreEqual ( c . Color . R , 50 ) ;
187204 Assert . AreEqual ( c . Color . G , 100 ) ;
@@ -194,13 +211,13 @@ public void TestCreate()
194211 }
195212 }
196213
197- if ( p1 . Variant != null )
214+ if ( p1 ? . Variant != null )
198215 {
199216 Assert . Fail ( "No variant should be defined" ) ;
200217 }
201218
202219 {
203- if ( p2 . Color is SolidColorBrush c )
220+ if ( p2 ? . Color is SolidColorBrush c )
204221 {
205222 Assert . AreEqual ( c . Color . R , 250 ) ;
206223 Assert . AreEqual ( c . Color . G , 200 ) ;
@@ -214,7 +231,7 @@ public void TestCreate()
214231 }
215232
216233 {
217- if ( p2 . Variant is SolidColorBrush c )
234+ if ( p2 ? . Variant is SolidColorBrush c )
218235 {
219236 Assert . AreEqual ( c . Color . R , 200 ) ;
220237 Assert . AreEqual ( c . Color . G , 150 ) ;
0 commit comments