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 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 DifferentTypeCompareWithMissingPropertyTest()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objTwo.Name = "This is object two.";
            //
            // The comparsion for the 'TestObj2' against the 'TestObj1' should fail since
            // 'TestObj2' has more properties than 'TestObj1'. There is no corresponding
            // property in 'TestObj1' to compare against for those properties.
            //
            var result = objTwo.IsEqualTo(objOne);

            Assert.IsFalse(result, "Comparsion of two duck type different objects 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 CopyDifferentTypeFail()
        {
            var objOne = new TestObj1();
            var objTwo = new TestObj2();

            objTwo.BoolNullableValue      = false;
            objTwo.BoolValue              = true;
            objTwo.CountEnumNullableValue = CountEnum.three;
            objTwo.CountEnumValue         = CountEnum.two;
            objTwo.IntNullableValue       = null;
            objTwo.IntValue    = 42;
            objTwo.StringValue = "Values from objTwo.";
            objTwo.Name        = "This is obj two";
            objTwo.FloatValue  = 42F;

            Assert.ThrowsException <DataObjectExtension.DataObjectExtensionException>(() => { objTwo.CopyTo(objOne); }, "The copy operation should fail with a 'DataObjectExtensionException' because the target object is missing some properties.");
        }
        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.");
        }