22using NanoXLSX . Colors ;
33using NanoXLSX . Exceptions ;
44using NanoXLSX . Styles ;
5+ using NanoXLSX . Themes ;
56using NanoXLSX . Utils ;
67using Xunit ;
78using static NanoXLSX . Styles . Fill ;
@@ -260,7 +261,7 @@ public void PatternFillTest(PatternValue value)
260261 Assert . Equal ( value , fill . PatternFill ) ;
261262 }
262263
263- [ Theory ( DisplayName = "Test of the SetColor function" ) ]
264+ [ Theory ( DisplayName = "Test of the SetColor function, when using a ARGB value " ) ]
264265 [ InlineData ( "FFAABBCC" , FillType . FillColor , "FFAABBCC" , "FF000000" ) ]
265266 [ InlineData ( "FF112233" , FillType . PatternColor , "FF000000" , "FF112233" ) ]
266267 public void SetColorTest ( string color , FillType fillType , string expectedForeground , string expectedBackground )
@@ -277,6 +278,179 @@ public void SetColorTest(string color, FillType fillType, string expectedForegro
277278 Assert . Equal ( expectedBackground , fill . BackgroundColor ) ;
278279 }
279280
281+ [ Theory ( DisplayName = "Test of the SetColor function, when using a sRGB color object" ) ]
282+ [ InlineData ( "FFAABBCC" , FillType . FillColor , "FFAABBCC" , "FF000000" ) ]
283+ [ InlineData ( "FF112233" , FillType . PatternColor , "FF000000" , "FF112233" ) ]
284+ public void SetColorTest2 ( string colorValue , FillType fillType , string expectedForeground , string expectedBackground )
285+ {
286+ Fill fill = new Fill ( ) ;
287+ SrgbColor color = new SrgbColor ( colorValue ) ;
288+ Assert . Equal ( Fill . DefaultColor , fill . ForegroundColor ) ;
289+ Assert . Equal ( Fill . DefaultColor , fill . BackgroundColor ) ;
290+ Assert . Equal ( PatternValue . None , fill . PatternFill ) ;
291+ fill . SetColor ( color , fillType ) ;
292+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
293+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
294+ Assert . Equal ( PatternValue . Solid , fill . PatternFill ) ;
295+ Assert . Equal ( expectedForeground , fill . ForegroundColor ) ;
296+ Assert . Equal ( expectedBackground , fill . BackgroundColor ) ;
297+ }
298+
299+ [ Theory ( DisplayName = "Test of the SetColor function, when using an indexed color object" ) ]
300+ [ InlineData ( IndexedColor . Value . Black , FillType . FillColor , true , "FF000000" ) ]
301+ [ InlineData ( IndexedColor . Value . Black , FillType . PatternColor , false , "FF000000" ) ]
302+ [ InlineData ( IndexedColor . Value . Blue4 , FillType . FillColor , true , "FF000000" ) ]
303+ [ InlineData ( IndexedColor . Value . Indigo , FillType . PatternColor , false , "FF000000" ) ]
304+ [ InlineData ( IndexedColor . Value . SystemBackground , FillType . FillColor , true , "FF000000" ) ]
305+ [ InlineData ( IndexedColor . Value . SystemForeground , FillType . PatternColor , false , "FF000000" ) ]
306+ public void SetColorTest3 ( IndexedColor . Value indexedValue , FillType fillType , bool expectedForegroundHasColor , string expectedOppositeColor )
307+ {
308+ Fill fill = new Fill ( ) ;
309+ IndexedColor color = new IndexedColor ( indexedValue ) ;
310+ Assert . Equal ( Fill . DefaultColor , fill . ForegroundColor ) ;
311+ Assert . Equal ( Fill . DefaultColor , fill . BackgroundColor ) ;
312+ Assert . Equal ( PatternValue . None , fill . PatternFill ) ;
313+ fill . SetColor ( color , fillType ) ;
314+ if ( expectedForegroundHasColor )
315+ {
316+ Assert . Equal ( Color . ColorType . Indexed , fill . ForegroundColor . Type ) ;
317+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
318+ Assert . Equal ( color . GetArgbValue ( ) , fill . ForegroundColor . GetArgbValue ( ) ) ;
319+ Assert . Equal ( expectedOppositeColor , fill . BackgroundColor ) ;
320+ }
321+ else
322+ {
323+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
324+ Assert . Equal ( Color . ColorType . Indexed , fill . BackgroundColor . Type ) ;
325+ Assert . Equal ( expectedOppositeColor , fill . ForegroundColor ) ;
326+ Assert . Equal ( color . GetArgbValue ( ) , fill . BackgroundColor . GetArgbValue ( ) ) ;
327+ }
328+ Assert . Equal ( PatternValue . Solid , fill . PatternFill ) ;
329+ }
330+
331+ [ Theory ( DisplayName = "Test of the SetColor function, when using a theme color object" ) ]
332+ [ InlineData ( Theme . ColorSchemeElement . Accent1 , FillType . FillColor , true , "FF000000" ) ]
333+ [ InlineData ( Theme . ColorSchemeElement . Accent1 , FillType . PatternColor , false , "FF000000" ) ]
334+ [ InlineData ( Theme . ColorSchemeElement . Dark1 , FillType . FillColor , true , "FF000000" ) ]
335+ [ InlineData ( Theme . ColorSchemeElement . Light1 , FillType . PatternColor , false , "FF000000" ) ]
336+ [ InlineData ( Theme . ColorSchemeElement . Hyperlink , FillType . FillColor , true , "FF000000" ) ]
337+ [ InlineData ( Theme . ColorSchemeElement . FollowedHyperlink , FillType . PatternColor , false , "FF000000" ) ]
338+ public void SetColorTest4 ( Theme . ColorSchemeElement themeValue , FillType fillType , bool expectedForegroundHasColor , string expectedOppositeColor )
339+ {
340+ Fill fill = new Fill ( ) ;
341+ ThemeColor color = new ThemeColor ( themeValue ) ;
342+ Assert . Equal ( Fill . DefaultColor , fill . ForegroundColor ) ;
343+ Assert . Equal ( Fill . DefaultColor , fill . BackgroundColor ) ;
344+ Assert . Equal ( PatternValue . None , fill . PatternFill ) ;
345+ fill . SetColor ( color , fillType ) ;
346+ if ( expectedForegroundHasColor )
347+ {
348+ Assert . Equal ( Color . ColorType . Theme , fill . ForegroundColor . Type ) ;
349+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
350+ Assert . Equal ( color . StringValue , fill . ForegroundColor . ThemeColor . StringValue ) ;
351+ Assert . Equal ( expectedOppositeColor , fill . BackgroundColor ) ;
352+ }
353+ else
354+ {
355+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
356+ Assert . Equal ( Color . ColorType . Theme , fill . BackgroundColor . Type ) ;
357+ Assert . Equal ( expectedOppositeColor , fill . ForegroundColor ) ;
358+ Assert . Equal ( color . StringValue , fill . BackgroundColor . ThemeColor . StringValue ) ;
359+ }
360+ Assert . Equal ( PatternValue . Solid , fill . PatternFill ) ;
361+ }
362+
363+ [ Theory ( DisplayName = "Test of the SetColor function, when using a system color object" ) ]
364+ [ InlineData ( SystemColor . Value . ActiveBorder , FillType . FillColor , true , "FF000000" ) ]
365+ [ InlineData ( SystemColor . Value . Background , FillType . PatternColor , false , "FF000000" ) ]
366+ [ InlineData ( SystemColor . Value . ButtonFace , FillType . FillColor , true , "FF000000" ) ]
367+ [ InlineData ( SystemColor . Value . Menu , FillType . PatternColor , false , "FF000000" ) ]
368+ [ InlineData ( SystemColor . Value . Window , FillType . FillColor , true , "FF000000" ) ]
369+ [ InlineData ( SystemColor . Value . CaptionText , FillType . PatternColor , false , "FF000000" ) ]
370+ public void SetColorTest5 ( SystemColor . Value systemValue , FillType fillType , bool expectedForegroundHasColor , string expectedOppositeColor )
371+ {
372+ Fill fill = new Fill ( ) ;
373+ SystemColor color = new SystemColor ( systemValue ) ;
374+ Assert . Equal ( Fill . DefaultColor , fill . ForegroundColor ) ;
375+ Assert . Equal ( Fill . DefaultColor , fill . BackgroundColor ) ;
376+ Assert . Equal ( PatternValue . None , fill . PatternFill ) ;
377+ fill . SetColor ( color , fillType ) ;
378+ if ( expectedForegroundHasColor )
379+ {
380+ Assert . Equal ( Color . ColorType . System , fill . ForegroundColor . Type ) ;
381+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
382+ Assert . Equal ( color . StringValue , fill . ForegroundColor . SystemColor . StringValue ) ;
383+ Assert . Equal ( expectedOppositeColor , fill . BackgroundColor ) ;
384+ }
385+ else
386+ {
387+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
388+ Assert . Equal ( Color . ColorType . System , fill . BackgroundColor . Type ) ;
389+ Assert . Equal ( expectedOppositeColor , fill . ForegroundColor ) ;
390+ Assert . Equal ( color . StringValue , fill . BackgroundColor . SystemColor . StringValue ) ;
391+ }
392+ Assert . Equal ( PatternValue . Solid , fill . PatternFill ) ;
393+ }
394+
395+ [ Theory ( DisplayName = "Test of the SetColor function, when using an auto color object" ) ]
396+ [ InlineData ( FillType . FillColor , true , "FF000000" ) ]
397+ [ InlineData ( FillType . PatternColor , false , "FF000000" ) ]
398+ public void SetColorTest6 ( FillType fillType , bool expectedForegroundHasColor , string expectedOppositeColor )
399+ {
400+ Fill fill = new Fill ( ) ;
401+ AutoColor color = new AutoColor ( ) ;
402+ Assert . Equal ( Fill . DefaultColor , fill . ForegroundColor ) ;
403+ Assert . Equal ( Fill . DefaultColor , fill . BackgroundColor ) ;
404+ Assert . Equal ( PatternValue . None , fill . PatternFill ) ;
405+ fill . SetColor ( color , fillType ) ;
406+ if ( expectedForegroundHasColor )
407+ {
408+ Assert . Equal ( Color . ColorType . Auto , fill . ForegroundColor . Type ) ;
409+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
410+ Assert . True ( fill . ForegroundColor . Auto ) ;
411+ Assert . False ( fill . BackgroundColor . Auto ) ;
412+ Assert . Equal ( expectedOppositeColor , fill . BackgroundColor ) ;
413+ }
414+ else
415+ {
416+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
417+ Assert . Equal ( Color . ColorType . Auto , fill . BackgroundColor . Type ) ;
418+ Assert . False ( fill . ForegroundColor . Auto ) ;
419+ Assert . True ( fill . BackgroundColor . Auto ) ;
420+ Assert . Equal ( expectedOppositeColor , fill . ForegroundColor ) ;
421+ }
422+ Assert . Equal ( PatternValue . Solid , fill . PatternFill ) ;
423+ }
424+
425+ [ Theory ( DisplayName = "Test of the SetColor function, when a compound color object was passed" ) ]
426+ [ InlineData ( FillType . FillColor , true , "FF000000" ) ]
427+ [ InlineData ( FillType . PatternColor , false , "FF000000" ) ]
428+ public void SetColorTest7 ( FillType fillType , bool expectedForegroundHasColor , string expectedOppositeColor )
429+ {
430+ Fill fill = new Fill ( ) ;
431+ Color color = Color . CreateRgb ( "FF112233" ) ;
432+ Assert . Equal ( Fill . DefaultColor , fill . ForegroundColor ) ;
433+ Assert . Equal ( Fill . DefaultColor , fill . BackgroundColor ) ;
434+ Assert . Equal ( PatternValue . None , fill . PatternFill ) ;
435+ fill . SetColor ( color , fillType ) ;
436+ if ( expectedForegroundHasColor )
437+ {
438+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
439+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
440+ Assert . Equal ( color . GetArgbValue ( ) , fill . ForegroundColor . GetArgbValue ( ) ) ;
441+ Assert . Equal ( expectedOppositeColor , fill . BackgroundColor ) ;
442+ }
443+ else
444+ {
445+ Assert . Equal ( Color . ColorType . Rgb , fill . ForegroundColor . Type ) ;
446+ Assert . Equal ( Color . ColorType . Rgb , fill . BackgroundColor . Type ) ;
447+ Assert . Equal ( expectedOppositeColor , fill . ForegroundColor ) ;
448+ Assert . Equal ( color . GetArgbValue ( ) , fill . BackgroundColor . GetArgbValue ( ) ) ;
449+ }
450+ Assert . Equal ( PatternValue . Solid , fill . PatternFill ) ;
451+ }
452+
453+
280454 [ Theory ( DisplayName = "Test of the ValidateColor function" ) ]
281455 [ InlineData ( "" , false , false , false ) ]
282456 [ InlineData ( null , false , false , false ) ]
0 commit comments