public void AreDeeplyEqualShouldWorkCorrectlyWithSameReferences() { var firstObject = new NestedModel { Integer = 1, String = "Text" }; var secondObject = new NestedModel { Integer = 1, String = "Text", Nested = firstObject }; firstObject.Nested = secondObject; Assert.True(Reflection.AreDeeplyEqual(firstObject, secondObject)); }
/// <inheritdoc /> public IAndDistributedCacheTestBuilder ContainingEntryWithValue(byte[] value) { var hasValue = this.distributedCacheDictionary .Values .Any(v => Reflection.AreDeeplyEqual(v, value)); if (!hasValue) { this.ThrowNewDataProviderAssertionException( DistributedCacheName, "to have an entry with the given value", "such was not found"); } return(this); }
public static void ValidateValue <TDictionaryKey, TValue>( string name, IDictionary <TDictionaryKey, object> dictionary, TValue value, Action <string, string, string> failedValidationAction) { var sameEntry = dictionary.Values.FirstOrDefault(entry => Reflection.AreDeeplyEqual(value, entry)); if (sameEntry == null) { failedValidationAction( name, "to have entry with the provided value", "none was found"); } }
public void AreDeeplyEqualShouldWorkCorrectlyWithEnumerations() { // Enum with default values. Assert.True(Reflection.AreDeeplyEqual(DateTimeKind.Unspecified, DateTimeKind.Unspecified)); Assert.False(Reflection.AreDeeplyEqual(DateTimeKind.Local, DateTimeKind.Utc)); //Enum with overridden values. Assert.True(Reflection.AreDeeplyEqual(AttributeTargets.Delegate, AttributeTargets.Delegate)); Assert.False(Reflection.AreDeeplyEqual(AttributeTargets.Assembly, AttributeTargets.All)); Assert.False(Reflection.AreDeeplyEqual(AttributeTargets.Assembly, AttributeTargets.Module)); //Enum with default and overriden values. Assert.True(Reflection.AreDeeplyEqual(CustomEnum.DefaultConstant, CustomEnum.DefaultConstant)); Assert.False(Reflection.AreDeeplyEqual(CustomEnum.DefaultConstant, CustomEnum.ConstantWithCustomValue)); Assert.False(Reflection.AreDeeplyEqual(CustomEnum.DefaultConstant, CustomEnum.CombinedConstant)); }
public void AreDeeplyEqualShouldWorkCorrectlyWithPrimitiveAndStructTypes() { Assert.IsTrue(Reflection.AreDeeplyEqual(1, 1)); Assert.IsTrue(Reflection.AreDeeplyEqual(null, null)); Assert.IsTrue(Reflection.AreDeeplyEqual("test", "test")); Assert.IsTrue(Reflection.AreDeeplyEqual('a', 'a')); Assert.IsTrue(Reflection.AreDeeplyEqual(1.1, 1.1)); Assert.IsTrue(Reflection.AreDeeplyEqual(1.1m, 1.1m)); Assert.IsTrue(Reflection.AreDeeplyEqual(true, true)); Assert.IsTrue(Reflection.AreDeeplyEqual(new DateTime(2015, 10, 19), new DateTime(2015, 10, 19))); Assert.IsFalse(Reflection.AreDeeplyEqual(1, 0)); Assert.IsFalse(Reflection.AreDeeplyEqual(1, null)); Assert.IsFalse(Reflection.AreDeeplyEqual("test1", "test2")); Assert.IsFalse(Reflection.AreDeeplyEqual('a', 'b')); Assert.IsFalse(Reflection.AreDeeplyEqual(1.1, 1.2)); Assert.IsFalse(Reflection.AreDeeplyEqual(1.1m, 1.2m)); Assert.IsFalse(Reflection.AreDeeplyEqual(true, false)); Assert.IsFalse(Reflection.AreDeeplyEqual(1, "1")); Assert.IsFalse(Reflection.AreDeeplyEqual(new DateTime(2015, 10, 19), new DateTime(2015, 10, 20))); }
public void AreDeeplyEqualShouldWorkCorrectlyWithCollections() { Assert.True(Reflection.AreDeeplyEqual( new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } }, new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } })); var listOfNestedModels = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } }; var arrayOfNestedModels = new[] { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } }; Assert.True(Reflection.AreDeeplyEqual(listOfNestedModels, arrayOfNestedModels)); Assert.True(Reflection.AreDeeplyEqual( new NestedCollection { Integer = 1, String = "test", Nested = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } } }, new NestedCollection { Integer = 1, String = "test", Nested = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } } })); Assert.True(Reflection.AreDeeplyEqual( new NestedCollection { Integer = 1, String = "test", Nested = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } } }, new NestedCollection { Integer = 1, String = "test", Nested = new[] { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } } })); Assert.False(Reflection.AreDeeplyEqual( new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } }, new List <NestedModel> { new NestedModel { Integer = 1, String = "test2", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } })); listOfNestedModels = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } }; arrayOfNestedModels = new[] { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 4, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } }; Assert.False(Reflection.AreDeeplyEqual(listOfNestedModels, arrayOfNestedModels)); Assert.False(Reflection.AreDeeplyEqual( new NestedCollection { Integer = 1, String = "test", Nested = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } } }, new NestedCollection { Integer = 1, String = "test", Nested = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 5, String = "test3" } } } } })); Assert.False(Reflection.AreDeeplyEqual( new NestedCollection { Integer = 1, String = "test", Nested = new List <NestedModel> { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } } } }, new NestedCollection { Integer = 1, String = "test", Nested = new[] { new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test3", Nested = new NestedModel { Integer = 3, String = "test3" } } } } })); Assert.True(Reflection.AreDeeplyEqual(new List <int> { 1, 2, 3 }, new[] { 1, 2, 3 })); Assert.False(Reflection.AreDeeplyEqual(new List <int> { 1, 2, 3, 4 }, new[] { 1, 2, 3 })); Assert.False(Reflection.AreDeeplyEqual(new List <int>(), new object())); Assert.False(Reflection.AreDeeplyEqual(new object(), new List <int>())); }
public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects() { Assert.True(Reflection.AreDeeplyEqual( new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } })); Assert.False(Reflection.AreDeeplyEqual( new NestedModel { Integer = 1, String = "test", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } }, new NestedModel { Integer = 1, String = "test", Nested = new NestedModel { Integer = 2, String = "test1", Nested = new NestedModel { Integer = 3, String = "test3" } } })); Assert.False(Reflection.AreDeeplyEqual( new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test2" } } }, new NestedModel { Integer = 1, String = "test1", Nested = new NestedModel { Integer = 2, String = "test2", Nested = new NestedModel { Integer = 3, String = "test3" } } })); }
public void AreDeeplyEqualsShouldWorkCorrectlyWithNormalObjects() { Assert.True(Reflection.AreDeeplyEqual(new object(), new object())); Assert.True(Reflection.AreDeeplyEqual((object)5, (object)5)); Assert.True(Reflection.AreDeeplyEqual((object)5, 5)); Assert.True(Reflection.AreDeeplyEqual(new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } }, new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } })); Assert.True(Reflection.AreDeeplyEqual(new RequestModel { Integer = 1 }, new RequestModel { Integer = 1 })); Assert.True(Reflection.AreDeeplyEqual(new RequestModel { Integer = 1, NonRequiredString = "test" }, new RequestModel { Integer = 1, NonRequiredString = "test" })); Assert.True(Reflection.AreDeeplyEqual(new GenericComparableModel { Integer = 1, String = "test" }, new GenericComparableModel { Integer = 1, String = "another" })); Assert.True(Reflection.AreDeeplyEqual(new ComparableModel { Integer = 1, String = "test" }, new ComparableModel { Integer = 1, String = "another" })); Assert.True(Reflection.AreDeeplyEqual(new EqualsModel { Integer = 1, String = "test" }, new EqualsModel { Integer = 1, String = "another" })); Assert.True(Reflection.AreDeeplyEqual(new EqualityOperatorModel { Integer = 1, String = "test" }, new EqualityOperatorModel { Integer = 1, String = "another" })); Assert.False(Reflection.AreDeeplyEqual(new object(), "test")); Assert.False(Reflection.AreDeeplyEqual(DateTime.Now, "test")); Assert.False(Reflection.AreDeeplyEqual("test", DateTime.Now)); Assert.False(Reflection.AreDeeplyEqual(true, new object())); Assert.False(Reflection.AreDeeplyEqual("test", new object())); Assert.False(Reflection.AreDeeplyEqual(new object(), true)); Assert.False(Reflection.AreDeeplyEqual(new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } }, new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 4 } })); Assert.False(Reflection.AreDeeplyEqual(new RequestModel { Integer = 2 }, new RequestModel { Integer = 1 })); Assert.False(Reflection.AreDeeplyEqual(new object(), new RequestModel { Integer = 1 })); Assert.False(Reflection.AreDeeplyEqual(new RequestModel { Integer = 2 }, new object())); Assert.False(Reflection.AreDeeplyEqual(new RequestModel { Integer = 2, NonRequiredString = "test" }, new RequestModel { Integer = 1 })); Assert.False(Reflection.AreDeeplyEqual(new GenericComparableModel { Integer = 1, String = "test" }, new GenericComparableModel { Integer = 2, String = "test" })); Assert.False(Reflection.AreDeeplyEqual(new ComparableModel { Integer = 1, String = "test" }, new ComparableModel { Integer = 2, String = "test" })); Assert.False(Reflection.AreDeeplyEqual(new EqualsModel { Integer = 1, String = "test" }, new EqualsModel { Integer = 2, String = "test" })); Assert.False(Reflection.AreDeeplyEqual(new EqualityOperatorModel { Integer = 1, String = "test" }, new EqualityOperatorModel { Integer = 2, String = "test" })); Assert.False(Reflection.AreDeeplyEqual(new ComparableModel { Integer = 1, String = "test" }, new RequestModel())); }
public void AreDeeplyEqualShouldWorkCorrectlyWithDictionaries() { var firstDictionary = new Dictionary <string, string> { { "Key", "Value" }, { "AnotherKey", "AnotherValue" }, }; var secondDictionary = new Dictionary <string, string> { { "Key", "Value" }, { "AnotherKey", "AnotherValue" }, }; Assert.True(Reflection.AreDeeplyEqual(firstDictionary, secondDictionary)); firstDictionary = new Dictionary <string, string> { { "Key", "Value" }, { "AnotherKey", "Value" }, }; secondDictionary = new Dictionary <string, string> { { "Key", "Value" }, { "AnotherKey", "AnotherValue" }, }; Assert.False(Reflection.AreDeeplyEqual(firstDictionary, secondDictionary)); var firstDictionaryWithObject = new Dictionary <string, NestedModel> { { "Key", new NestedModel { Integer = 1, String = "Text" } }, { "AnotherKey", new NestedModel { Integer = 2, String = "AnotherText" } } }; var secondDictionaryWithObject = new Dictionary <string, NestedModel> { { "Key", new NestedModel { Integer = 1, String = "Text" } }, { "AnotherKey", new NestedModel { Integer = 2, String = "AnotherText" } } }; Assert.True(Reflection.AreDeeplyEqual(firstDictionaryWithObject, secondDictionaryWithObject)); firstDictionaryWithObject = new Dictionary <string, NestedModel> { { "Key", new NestedModel { Integer = 1, String = "Text" } }, { "AnotherKey", new NestedModel { Integer = 2, String = "Text" } } }; secondDictionaryWithObject = new Dictionary <string, NestedModel> { { "Key", new NestedModel { Integer = 1, String = "Text" } }, { "AnotherKey", new NestedModel { Integer = 2, String = "AnotherText" } } }; Assert.False(Reflection.AreDeeplyEqual(firstDictionaryWithObject, secondDictionaryWithObject)); }