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