Skip to content

Commit 7159ae9

Browse files
committed
Added Enumeration Tests for AreDeeplyEqual()
1 parent 84a2fef commit 7159ae9

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

test/MyTested.AspNetCore.Mvc.Abstractions.Test/UtilitiesTests/ReflectionTests.cs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MyTested.AspNetCore.Mvc.Test.UtilitiesTests
1+
using MyTested.AspNetCore.Mvc.Test.Setups.Common;
2+
3+
namespace MyTested.AspNetCore.Mvc.Test.UtilitiesTests
24
{
35
using System;
46
using System.Collections.Generic;
@@ -449,6 +451,24 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithPrimitiveAndStructTypes()
449451
Assert.False(Reflection.AreDeeplyEqual(new DateTime(2015, 10, 19), new DateTime(2015, 10, 20)));
450452
}
451453

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+
452472
[Fact]
453473
public void AreDeeplyEqualsShouldWorkCorrectlyWithNormalObjects()
454474
{
@@ -463,6 +483,10 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNormalObjects()
463483
Assert.True(Reflection.AreDeeplyEqual(new EqualsModel { Integer = 1, String = "test" }, new EqualsModel { Integer = 1, String = "another" }));
464484
Assert.True(Reflection.AreDeeplyEqual(new EqualityOperatorModel { Integer = 1, String = "test" }, new EqualityOperatorModel { Integer = 1, String = "another" }));
465485
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));
466490
Assert.False(Reflection.AreDeeplyEqual(DateTime.Now, "test"));
467491
Assert.False(Reflection.AreDeeplyEqual("test", DateTime.Now));
468492
Assert.False(Reflection.AreDeeplyEqual(true, new object()));
@@ -488,12 +512,14 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
488512
{
489513
Integer = 1,
490514
String = "test1",
515+
Enum = CustomEnum.ConstantWithCustomValue,
491516
Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } }
492517
},
493518
new NestedModel
494519
{
495520
Integer = 1,
496521
String = "test1",
522+
Enum = CustomEnum.ConstantWithCustomValue,
497523
Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } }
498524
}));
499525

@@ -502,12 +528,14 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
502528
{
503529
Integer = 1,
504530
String = "test",
531+
Enum = CustomEnum.ConstantWithCustomValue,
505532
Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } }
506533
},
507534
new NestedModel
508535
{
509536
Integer = 1,
510537
String = "test",
538+
Enum = CustomEnum.ConstantWithCustomValue,
511539
Nested = new NestedModel { Integer = 2, String = "test1", Nested = new NestedModel { Integer = 3, String = "test3" } }
512540
}));
513541

@@ -516,12 +544,14 @@ public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
516544
{
517545
Integer = 1,
518546
String = "test1",
547+
Enum = CustomEnum.ConstantWithCustomValue,
519548
Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test2" } }
520549
},
521550
new NestedModel
522551
{
523552
Integer = 1,
524553
String = "test1",
554+
Enum = CustomEnum.ConstantWithCustomValue,
525555
Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } }
526556
}));
527557
}
@@ -535,27 +565,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
535565
new NestedModel
536566
{
537567
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" } }
539569
},
540570
new NestedModel
541571
{
542572
Integer = 1,
543573
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" } }
545575
}
546576
},
547577
new List<NestedModel>
548578
{
549579
new NestedModel
550580
{
551581
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" } }
553583
},
554584
new NestedModel
555585
{
556586
Integer = 1,
557587
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" } }
559589
}
560590
}));
561591

@@ -565,23 +595,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
565595
{
566596
Integer = 1,
567597
String = "test1",
598+
Enum = CustomEnum.ConstantWithCustomValue,
568599
Nested =
569600
new NestedModel
570601
{
571602
Integer = 2,
572603
String = "test2",
604+
Enum = CustomEnum.ConstantWithCustomValue,
573605
Nested = new NestedModel { Integer = 3, String = "test3" }
574606
}
575607
},
576608
new NestedModel
577609
{
578610
Integer = 1,
579611
String = "test1",
612+
Enum = CustomEnum.ConstantWithCustomValue,
580613
Nested =
581614
new NestedModel
582615
{
583616
Integer = 2,
584617
String = "test2",
618+
Enum = CustomEnum.ConstantWithCustomValue,
585619
Nested = new NestedModel { Integer = 3, String = "test3" }
586620
}
587621
}
@@ -593,23 +627,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
593627
{
594628
Integer = 1,
595629
String = "test1",
630+
Enum = CustomEnum.ConstantWithCustomValue,
596631
Nested =
597632
new NestedModel
598633
{
599634
Integer = 2,
600635
String = "test2",
636+
Enum = CustomEnum.ConstantWithCustomValue,
601637
Nested = new NestedModel { Integer = 3, String = "test3" }
602638
}
603639
},
604640
new NestedModel
605641
{
606642
Integer = 1,
607643
String = "test1",
644+
Enum = CustomEnum.ConstantWithCustomValue,
608645
Nested =
609646
new NestedModel
610647
{
611648
Integer = 2,
612649
String = "test2",
650+
Enum = CustomEnum.ConstantWithCustomValue,
613651
Nested = new NestedModel { Integer = 3, String = "test3" }
614652
}
615653
}
@@ -894,27 +932,27 @@ public void AreDeeplyEqualShouldWorkCorrectlyWithDictionaries()
894932

895933
var firstDictionaryWithObject = new Dictionary<string, NestedModel>
896934
{
897-
{ "Key", new NestedModel { Integer = 1, String = "Text" } },
935+
{ "Key", new NestedModel { Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue} },
898936
{ "AnotherKey", new NestedModel { Integer = 2, String = "AnotherText" } }
899937
};
900938

901939
var secondDictionaryWithObject = new Dictionary<string, NestedModel>
902940
{
903-
{ "Key", new NestedModel { Integer = 1, String = "Text" } },
941+
{ "Key", new NestedModel { Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue } },
904942
{ "AnotherKey", new NestedModel { Integer = 2, String = "AnotherText" } }
905943
};
906944

907945
Assert.True(Reflection.AreDeeplyEqual(firstDictionaryWithObject, secondDictionaryWithObject));
908946

909947
firstDictionaryWithObject = new Dictionary<string, NestedModel>
910948
{
911-
{ "Key", new NestedModel { Integer = 1, String = "Text" } },
949+
{ "Key", new NestedModel { Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue } },
912950
{ "AnotherKey", new NestedModel { Integer = 2, String = "Text" } }
913951
};
914952

915953
secondDictionaryWithObject = new Dictionary<string, NestedModel>
916954
{
917-
{ "Key", new NestedModel { Integer = 1, String = "Text" } },
955+
{ "Key", new NestedModel { Integer = 1, String = "Text", } },
918956
{ "AnotherKey", new NestedModel { Integer = 2, String = "AnotherText" } }
919957
};
920958

0 commit comments

Comments
 (0)