/// <summary>
        /// Runs a deep equality test between two objects, using the properties common to both sides
        /// of the comparison to match on.
        /// </summary>
        /// <param name="objSource">Source object to perform comparison against</param>
        /// <param name="objCompare">Comparison object to compare</param>
        /// <param name="ignorePropertiesByName">Optional params array of properties to ignore by name</param>
        /// <returns>True if relevant properties are found and match; false otherwise. If no common properties are found, returns false; caveat: performing this comparison on two vanilla Object() instances will return true.</returns>
        public static bool DeepIntersectionEquals(this object objSource, object objCompare,
                                                  params string[] ignorePropertiesByName)
        {
            var tester = new DeepEqualityTester(
                objSource,
                objCompare,
                ignorePropertiesByName
                )
            {
                OnlyTestIntersectingProperties = true
            };

            return(tester.AreDeepEqual());
        }
        /// <summary>
        /// Runs a deep equality test between two objects,
        /// ignoring reference differences wherever possible
        /// and logging failures with the provided action. Properties
        /// can be explided by name with the ignorePropertiesByName params
        /// </summary>
        /// <param name="objSource"></param>
        /// <param name="objCompare"></param>
        /// <param name="failureLogAction"></param>
        /// <param name="ignorePropertiesByName"></param>
        /// <returns></returns>
        public static bool DeepEquals(this object objSource,
                                      object objCompare,
                                      Action <string> failureLogAction,
                                      params string[] ignorePropertiesByName)
        {
            var tester = new DeepEqualityTester(
                objSource, objCompare, ignorePropertiesByName)
            {
                RecordErrors = true
            };
            var result = tester.AreDeepEqual();

            tester.Errors.ForEach(failureLogAction);
            return(result);
        }
Exemple #3
0
        private static bool PerformShapeEqualityTesting(
            object left,
            object right,
            bool allowMissingProperties,
            params string[] ignorePropsByName
            )
        {
            var tester = new DeepEqualityTester(left, right, ignorePropsByName)
            {
                OnlyCompareShape        = true,
                IncludeFields           = true,
                FailOnMissingProperties = !allowMissingProperties
            };

            return(tester.AreDeepEqual());
        }
Exemple #4
0
        /// <summary>
        /// Runs a deep equality test between two objects, using the properties on objSource (and children) as
        /// the set of properties to match on
        /// </summary>
        /// <param name="objSource">Source object to perform comparison against</param>
        /// <param name="objCompare">Comparison object to compare</param>
        /// <param name="ignorePropertiesByName">Optional params array of properties to ignore by name</param>
        /// <returns>True if relevant properties are found and match; false otherwise</returns>
        public static bool DeepSubEquals(
            this object objSource,
            object objCompare,
            params string[] ignorePropertiesByName)
        {
            var tester = new DeepEqualityTester(
                objSource,
                objCompare,
                ignorePropertiesByName
                )
            {
                FailOnMissingProperties = false
            };

            return(tester.AreDeepEqual());
        }
Exemple #5
0
        /// <summary>
        /// Runs a deep equality test between two objects, glossing over reference
        /// differences between class-types and comparing only primitive types. Use
        /// this when you'd like to essentially test whether the data in one object
        /// hierachy matches that of another
        /// </summary>
        /// <param name="objSource">Object which is the source of truth</param>
        /// <param name="objCompare">Object to compare with</param>
        /// <param name="comparison">Method for comparison</param>
        /// <param name="ignorePropertiesByName">Params array of properties to ignore by name</param>
        /// <returns></returns>
        public static bool DeepEquals(
            this object objSource,
            object objCompare,
            ObjectComparisons comparison,
            params string[] ignorePropertiesByName
            )
        {
            var tester = new DeepEqualityTester(
                objSource,
                objCompare,
                ignorePropertiesByName
                )
            {
                IncludeFields = comparison == ObjectComparisons.PropertiesAndFields
            };

            return(tester.AreDeepEqual());
        }