6
6
using Microsoft . AspNetCore . Authorization ;
7
7
using Microsoft . AspNetCore . Mvc ;
8
8
using Microsoft . Extensions . DependencyInjection ;
9
+ using Setups . Common ;
9
10
using Setups . Controllers ;
10
11
using Setups . Models ;
11
12
using Setups . Services ;
@@ -449,6 +450,24 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithPrimitiveAndStructTypes()
449
450
Assert . False ( Reflection . AreDeeplyEqual ( new DateTime ( 2015 , 10 , 19 ) , new DateTime ( 2015 , 10 , 20 ) ) ) ;
450
451
}
451
452
453
+ [ Fact ]
454
+ public void AreDeeplyEqualShouldWorkCorrectlyWithEnumerations ( )
455
+ {
456
+ // Enum with default values.
457
+ Assert . True ( Reflection . AreDeeplyEqual ( DateTimeKind . Unspecified , DateTimeKind . Unspecified ) ) ;
458
+ Assert . False ( Reflection . AreDeeplyEqual ( DateTimeKind . Local , DateTimeKind . Utc ) ) ;
459
+
460
+ //Enum with overridden values.
461
+ Assert . True ( Reflection . AreDeeplyEqual ( AttributeTargets . Delegate , AttributeTargets . Delegate ) ) ;
462
+ Assert . False ( Reflection . AreDeeplyEqual ( AttributeTargets . Assembly , AttributeTargets . All ) ) ;
463
+ Assert . False ( Reflection . AreDeeplyEqual ( AttributeTargets . Assembly , AttributeTargets . Module ) ) ;
464
+
465
+ //Enum with default and overriden values.
466
+ Assert . True ( Reflection . AreDeeplyEqual ( CustomEnum . DefaultConstant , CustomEnum . DefaultConstant ) ) ;
467
+ Assert . False ( Reflection . AreDeeplyEqual ( CustomEnum . DefaultConstant , CustomEnum . ConstantWithCustomValue ) ) ;
468
+ Assert . False ( Reflection . AreDeeplyEqual ( CustomEnum . DefaultConstant , CustomEnum . CombinedConstant ) ) ;
469
+ }
470
+
452
471
[ Fact ]
453
472
public void AreDeeplyEqualsShouldWorkCorrectlyWithNormalObjects ( )
454
473
{
@@ -463,6 +482,10 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNormalObjects()
463
482
Assert . True ( Reflection . AreDeeplyEqual ( new EqualsModel { Integer = 1 , String = "test" } , new EqualsModel { Integer = 1 , String = "another" } ) ) ;
464
483
Assert . True ( Reflection . AreDeeplyEqual ( new EqualityOperatorModel { Integer = 1 , String = "test" } , new EqualityOperatorModel { Integer = 1 , String = "another" } ) ) ;
465
484
Assert . False ( Reflection . AreDeeplyEqual ( new object ( ) , "test" ) ) ;
485
+ Assert . False ( Reflection . AreDeeplyEqual ( new object ( ) , AttributeTargets . All ) ) ;
486
+ Assert . False ( Reflection . AreDeeplyEqual ( AttributeTargets . All , new object ( ) ) ) ;
487
+ Assert . True ( Reflection . AreDeeplyEqual ( AttributeTargets . All , ( object ) AttributeTargets . All ) ) ;
488
+ Assert . True ( Reflection . AreDeeplyEqual ( ( object ) AttributeTargets . All , AttributeTargets . All ) ) ;
466
489
Assert . False ( Reflection . AreDeeplyEqual ( DateTime . Now , "test" ) ) ;
467
490
Assert . False ( Reflection . AreDeeplyEqual ( "test" , DateTime . Now ) ) ;
468
491
Assert . False ( Reflection . AreDeeplyEqual ( true , new object ( ) ) ) ;
@@ -488,12 +511,14 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
488
511
{
489
512
Integer = 1 ,
490
513
String = "test1" ,
514
+ Enum = CustomEnum . ConstantWithCustomValue ,
491
515
Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
492
516
} ,
493
517
new NestedModel
494
518
{
495
519
Integer = 1 ,
496
520
String = "test1" ,
521
+ Enum = CustomEnum . ConstantWithCustomValue ,
497
522
Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
498
523
} ) ) ;
499
524
@@ -502,12 +527,14 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
502
527
{
503
528
Integer = 1 ,
504
529
String = "test" ,
530
+ Enum = CustomEnum . ConstantWithCustomValue ,
505
531
Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
506
532
} ,
507
533
new NestedModel
508
534
{
509
535
Integer = 1 ,
510
536
String = "test" ,
537
+ Enum = CustomEnum . ConstantWithCustomValue ,
511
538
Nested = new NestedModel { Integer = 2 , String = "test1" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
512
539
} ) ) ;
513
540
@@ -516,12 +543,14 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
516
543
{
517
544
Integer = 1 ,
518
545
String = "test1" ,
546
+ Enum = CustomEnum . ConstantWithCustomValue ,
519
547
Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test2" } }
520
548
} ,
521
549
new NestedModel
522
550
{
523
551
Integer = 1 ,
524
552
String = "test1" ,
553
+ Enum = CustomEnum . ConstantWithCustomValue ,
525
554
Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
526
555
} ) ) ;
527
556
}
@@ -535,27 +564,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
535
564
new NestedModel
536
565
{
537
566
Integer = 1 , String = "test1" ,
538
- Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
567
+ Nested = new NestedModel { Integer = 2 , String = "test2" , Enum = CustomEnum . CombinedConstant , Nested = new NestedModel { Integer = 3 , String = "test3" } }
539
568
} ,
540
569
new NestedModel
541
570
{
542
571
Integer = 1 ,
543
572
String = "test1" ,
544
- Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
573
+ Nested = new NestedModel { Integer = 2 , String = "test2" , Enum = CustomEnum . CombinedConstant , Nested = new NestedModel { Integer = 3 , String = "test3" } }
545
574
}
546
575
} ,
547
576
new List < NestedModel >
548
577
{
549
578
new NestedModel
550
579
{
551
580
Integer = 1 , String = "test1" ,
552
- Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
581
+ Nested = new NestedModel { Integer = 2 , String = "test2" , Enum = CustomEnum . CombinedConstant , Nested = new NestedModel { Integer = 3 , String = "test3" } }
553
582
} ,
554
583
new NestedModel
555
584
{
556
585
Integer = 1 ,
557
586
String = "test1" ,
558
- Nested = new NestedModel { Integer = 2 , String = "test2" , Nested = new NestedModel { Integer = 3 , String = "test3" } }
587
+ Nested = new NestedModel { Integer = 2 , String = "test2" , Enum = CustomEnum . CombinedConstant , Nested = new NestedModel { Integer = 3 , String = "test3" } }
559
588
}
560
589
} ) ) ;
561
590
@@ -565,23 +594,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
565
594
{
566
595
Integer = 1 ,
567
596
String = "test1" ,
597
+ Enum = CustomEnum . ConstantWithCustomValue ,
568
598
Nested =
569
599
new NestedModel
570
600
{
571
601
Integer = 2 ,
572
602
String = "test2" ,
603
+ Enum = CustomEnum . ConstantWithCustomValue ,
573
604
Nested = new NestedModel { Integer = 3 , String = "test3" }
574
605
}
575
606
} ,
576
607
new NestedModel
577
608
{
578
609
Integer = 1 ,
579
610
String = "test1" ,
611
+ Enum = CustomEnum . ConstantWithCustomValue ,
580
612
Nested =
581
613
new NestedModel
582
614
{
583
615
Integer = 2 ,
584
616
String = "test2" ,
617
+ Enum = CustomEnum . ConstantWithCustomValue ,
585
618
Nested = new NestedModel { Integer = 3 , String = "test3" }
586
619
}
587
620
}
@@ -593,23 +626,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
593
626
{
594
627
Integer = 1 ,
595
628
String = "test1" ,
629
+ Enum = CustomEnum . ConstantWithCustomValue ,
596
630
Nested =
597
631
new NestedModel
598
632
{
599
633
Integer = 2 ,
600
634
String = "test2" ,
635
+ Enum = CustomEnum . ConstantWithCustomValue ,
601
636
Nested = new NestedModel { Integer = 3 , String = "test3" }
602
637
}
603
638
} ,
604
639
new NestedModel
605
640
{
606
641
Integer = 1 ,
607
642
String = "test1" ,
643
+ Enum = CustomEnum . ConstantWithCustomValue ,
608
644
Nested =
609
645
new NestedModel
610
646
{
611
647
Integer = 2 ,
612
648
String = "test2" ,
649
+ Enum = CustomEnum . ConstantWithCustomValue ,
613
650
Nested = new NestedModel { Integer = 3 , String = "test3" }
614
651
}
615
652
}
@@ -894,27 +931,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithDictionaries()
894
931
895
932
var firstDictionaryWithObject = new Dictionary < string , NestedModel >
896
933
{
897
- { "Key" , new NestedModel { Integer = 1 , String = "Text" } } ,
934
+ { "Key" , new NestedModel { Integer = 1 , String = "Text" , Enum = CustomEnum . ConstantWithCustomValue } } ,
898
935
{ "AnotherKey" , new NestedModel { Integer = 2 , String = "AnotherText" } }
899
936
} ;
900
937
901
938
var secondDictionaryWithObject = new Dictionary < string , NestedModel >
902
939
{
903
- { "Key" , new NestedModel { Integer = 1 , String = "Text" } } ,
940
+ { "Key" , new NestedModel { Integer = 1 , String = "Text" , Enum = CustomEnum . ConstantWithCustomValue } } ,
904
941
{ "AnotherKey" , new NestedModel { Integer = 2 , String = "AnotherText" } }
905
942
} ;
906
943
907
944
Assert . True ( Reflection . AreDeeplyEqual ( firstDictionaryWithObject , secondDictionaryWithObject ) ) ;
908
945
909
946
firstDictionaryWithObject = new Dictionary < string , NestedModel >
910
947
{
911
- { "Key" , new NestedModel { Integer = 1 , String = "Text" } } ,
948
+ { "Key" , new NestedModel { Integer = 1 , String = "Text" , Enum = CustomEnum . ConstantWithCustomValue } } ,
912
949
{ "AnotherKey" , new NestedModel { Integer = 2 , String = "Text" } }
913
950
} ;
914
951
915
952
secondDictionaryWithObject = new Dictionary < string , NestedModel >
916
953
{
917
- { "Key" , new NestedModel { Integer = 1 , String = "Text" } } ,
954
+ { "Key" , new NestedModel { Integer = 1 , String = "Text" , } } ,
918
955
{ "AnotherKey" , new NestedModel { Integer = 2 , String = "AnotherText" } }
919
956
} ;
920
957
0 commit comments