public void DifferentTypeCompareDefaultTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();
            var result = objOne.IsEqualTo(objTwo);

            Assert.IsTrue(result, "Comparsion of two duck type identical objects should pass.");
        }
        public void SameTypeCompareDiffStringTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj1();

            objTwo.StringValue = "42";
            var result = objOne.IsEqualTo(objTwo);

            Assert.IsFalse(result, "Comparsion of two objects of the same type with different values should fail.");
        }
        public void DifferentTypeWithInvalidMappingTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objOne.StringValue = "String from obj one";
            objTwo.Name        = "String from obj one";
            List <Map> mapList = new List <Map>();

            mapList.Add(new Map("StringValue", "NameX"));
            var result = objOne.IsEqualTo(objTwo, mapList);

            Assert.IsFalse(result, "Comparsion of two duck type different objects with an invalid mapping should fail.");
        }
        public void DifferentTypeCompareWithUnrelatedPropertyTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            //
            // There is no 'Name' property in the first object. For that reason there
            // is no comparsion on the 'Name' property between the first and the second
            // object.
            //
            objTwo.Name = "This is object two.";
            var result = objOne.IsEqualTo(objTwo);

            Assert.IsTrue(result, "Comparsion of two duck type identical objects should pass.");
        }
        public void DifferentTypeWithIncludeSelectionTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objOne.IntValue    = 42;
            objTwo.IntValue    = 41;
            objOne.StringValue = "42";
            objTwo.StringValue = "42";
            //
            // Include the 'StringValue' property into comparsion.
            //
            var result = objOne.IsEqualTo(objTwo, null, null, (first) => { return(first.Name == "StringValue"); });

            Assert.IsTrue(result, "Comparsion of two objects with matching included values should pass.");
        }
        public void DifferentTypeWithMappingAndConversionTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objOne.IntValue   = 42;
            objTwo.FloatValue = (float)42;
            List <Map> mapList = new List <Map>();

            //
            // Mapping the 'IntValue' property of 'TestObj1' to the 'FloatValue' of 'TestObj2'.
            // 'TestObj1' doesn't have a 'FloatValue' property.
            //
            mapList.Add(new Map("IntValue", "FloatValue", (object source) => { return((float)((int)source)); }));
            var result = objOne.IsEqualTo(objTwo, mapList);

            Assert.IsTrue(result, "Comparsion of two duck type different objects with a valid mapping should pass.");
        }
        public void DifferentTypeWithExcludeSelectionAndMappingTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objOne.IntValue    = 42;
            objTwo.StringValue = "42";
            List <Map> mapList = new List <Map>();

            //
            // Mapping the 'IntValue' from the first object to the 'StringValue' of the second object.
            //
            mapList.Add(new Map("IntValue", "StringValue", (object source) => { return(((int)source).ToString()); }));
            //
            // Excluding the 'StringValue' from the first object from comparsion since that comparsion
            // would fail because of the mapping.
            //
            var result = objOne.IsEqualTo(objTwo, mapList, (first) => { return(first.Name == "StringValue"); });

            Assert.IsTrue(result, "Comparsion of two duck type different objects with a valid mapping should pass.");
        }
        public void CopyDifferentTypeTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            byte[] objOneHash;
            byte[] objTwoHash;
            objOne.BoolNullableValue      = false;
            objOne.BoolValue              = true;
            objOne.CountEnumNullableValue = CountEnum.three;
            objOne.CountEnumValue         = CountEnum.two;
            objOne.IntNullableValue       = null;
            objOne.IntValue    = 42;
            objOne.StringValue = "Values from objOne.";
            objOneHash         = objOne.CreateHash();
            objOne.CopyTo(objTwo);
            objTwoHash = objTwo.CreateHash();

            var result = objOne.IsEqualTo(objTwo);

            Assert.IsFalse(objOneHash.SequenceEqual(objTwoHash), "Since both objects are of different types the hash values should not be equal.");
            Assert.IsTrue(result, "Both objects should be considered equal after the copy operation when calling 'objOne.IsEqualTo(objTwo)'.");
        }
        public void DifferentTypeWithIncludeAndExcludeSelectionTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objOne.IntValue          = 42;
            objOne.StringValue       = "42";
            objOne.BoolValue         = true;
            objOne.BoolNullableValue = null;

            objTwo.IntValue          = 41;
            objTwo.StringValue       = "41";
            objTwo.BoolNullableValue = true;
            objTwo.BoolValue         = true;

            //
            // Exclude the 'IntValue' property from comparsion.
            // Include the 'IntValue' and 'BoolValue' into comparison.
            //

            var result = objOne.IsEqualTo(objTwo, null, (first) => { return(first.Name == "IntValue"); }, (first) => { return((first.Name == "IntValue") || (first.Name == "BoolValue")); });

            Assert.IsTrue(result, "Comparsion of two objects with matching result set values should pass.");
        }