예제 #1
0
        /// <summary>
        /// Set the configuration for the comparison
        /// </summary>
        /// <param name="config"></param>
        public ComparisonResult(ComparisonConfig config)
        {
            Config = config;
            Differences = new List<Difference>();

            #if !PORTABLE
                Watch = new Stopwatch();
            #endif
        }
예제 #2
0
 public void Clone()
 {
     var pFiller = new Filler<Constraint>();
     var test = pFiller.Create();
     var clone = test.Clone();
     var config = new ComparisonConfig();
     config.MembersToIgnore.Add("Table"); //table should never be cloned
     var compareLogic = new CompareLogic(config);
     var result = compareLogic.Compare(test, clone);
     Assert.True(result.AreEqual, result.DifferencesString);
 }
        /// <summary>
        /// Returns true if the property or field should be excluded
        /// </summary>
        /// <param name="config"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public static bool ShouldExcludeMember(ComparisonConfig config, MemberInfo info)
        {
            //Only compare specific field names
            if (config.MembersToInclude.Count > 0 && !config.MembersToInclude.Contains(info.Name))
                return true;

            //If we should ignore it, skip it
            if (config.MembersToIgnore.Count > 0 && config.MembersToIgnore.Contains(info.Name))
                return true;

            if (IgnoredByAttribute(config, info))
                return true;

            return false;
        }
예제 #4
0
        /// <summary>
        /// Get a list of the fields within a type
        /// </summary>
        /// <param name="config"> </param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IEnumerable<FieldInfo> GetFieldInfo(ComparisonConfig config, Type type)
        {
            lock (_fieldCache)
            {
                if (config.Caching && _fieldCache.ContainsKey(type))
                    return _fieldCache[type];

                FieldInfo[] currentFields;

#if !PORTABLE
                if (config.ComparePrivateFields && !config.CompareStaticFields)
                {
                    List<FieldInfo> list = new List<FieldInfo>();
                    Type t = type;
                    do
                    {
                        list.AddRange(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
                        t = t.BaseType;
                    } while (t != null);
                    currentFields = list.ToArray();
                }
                else if (config.ComparePrivateFields && config.CompareStaticFields)
                {
                    List<FieldInfo> list = new List<FieldInfo>();
                    Type t = type;
                    do
                    {
                        list.AddRange(
                            t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic |
                                        BindingFlags.Static));
                        t = t.BaseType;
                    } while (t != null);
                    currentFields = list.ToArray();
                }
                else
#endif
                    currentFields = type.GetFields(); //Default is public instance and static

                if (config.Caching)
                    _fieldCache.Add(type, currentFields);

                return currentFields;
            }
        }
예제 #5
0
        public static bool HasTheSameDataAs(this DataSet left, DataSet right)
        {
            var config = new ComparisonConfig();
            config.CustomComparers.Add(new NDbUnitDataSetComparer(RootComparerFactory.GetRootComparer()));
            config.CustomComparers.Add(new NDbUnitDataTableComparer(RootComparerFactory.GetRootComparer()));
            config.CustomComparers.Add(new NDbUnitDataRowCollectionComparer(RootComparerFactory.GetRootComparer()));

            config.MaxDifferences = MAX_DIFFERENCES_BEFORE_ABORT;

            var comparer = new CompareLogic(config);

            var result = comparer.Compare(left, right);

            if (!result.AreEqual)
            {
                Log(result.DifferencesString);
            }

            return result.AreEqual;
        }
        private static ComparisonResult CompareObjects(Object expectedObj, Object actualObj, String[] ignoredMembers = null)
        {

            ComparisonConfig cfg = new ComparisonConfig()
            {
                IgnoreObjectTypes = true,
                IgnoreCollectionOrder = true,
                IgnoreUnknownObjectTypes = true,
                ComparePrivateFields = false,
                ComparePrivateProperties = false,
                MembersToIgnore = new List<string>() { "_entityWrapper" },
                CompareChildren = false,
                MaxStructDepth = 1,
                MaxDifferences = 20,
                TreatStringEmptyAndNullTheSame = true

            };
            if (ignoredMembers != null)
            {
                cfg.MembersToIgnore.AddRange(ignoredMembers);
            }
            //also add not mapped attributes
            if (actualObj.PropertiesWithAttribute<NotMappedAttribute>().Length > 0)
            {
                cfg.MembersToIgnore.AddRange(actualObj.PropertiesWithAttribute<NotMappedAttribute>());
            }

            //check on null objects
            CompareLogic cpl = new CompareLogic(cfg);


            var result = cpl.Compare(expectedObj, actualObj);


            return result;
        }
        /// <summary>
        /// Check if the class type should be excluded based on the configuration
        /// </summary>
        /// <param name="config"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public static bool ShouldExcludeClassType(ComparisonConfig config, Type t1, Type t2)
        {
            //Only include specific class types
            if (config.ClassTypesToInclude.Count > 0 
                && (!config.ClassTypesToInclude.Contains(t1) 
                    || !config.ClassTypesToInclude.Contains(t2)))
            {
                return true;
            }

            //Ignore specific class types
            if (config.ClassTypesToIgnore.Count > 0
                && (config.ClassTypesToIgnore.Contains(t1)
                    || config.ClassTypesToIgnore.Contains(t2)))
            {
                return true;
            }

            //The class is ignored by an attribute
            if (IgnoredByAttribute(config, t1.GetTypeInfo()))
                return true;

            return false;
        }
예제 #8
0
 /// <summary>
 /// Pass in the configuration
 /// </summary>
 /// <param name="config"></param>
 public CompareLogic(ComparisonConfig config)
 {
     Config = config;
 }
        /// <summary>
        /// Check if any type has attributes that should be bypassed
        /// </summary>
        /// <returns></returns>
        public static bool IgnoredByAttribute(ComparisonConfig config, MemberInfo info)
        {
            var attributes = info.GetCustomAttributes(true);

            return attributes.Any(a => config.AttributesToIgnore.Contains(a.GetType()));
        }
예제 #10
0
 /// <summary>
 /// Get the value of a property
 /// </summary>
 /// <param name="config"> </param>
 /// <param name="type"></param>
 /// <param name="objectValue"></param>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 public static object GetPropertyValue(ComparisonConfig config, Type type, object objectValue, string propertyName)
 {
     lock (_propertyCache)
         return(GetPropertyInfo(config, type).First(o => o.Name == propertyName).GetValue(objectValue, null));
 }
예제 #11
0
        private bool RowsHaveSameData(DataRow left, DataRow right)
        {
            //this instance of the comparer is intentionally independent from the main one
            // (i.e., it does not report its DIFFERENCEs, etc. up the chain) b/c at this level we only
            // care about a single match in a vacuum so the 'reporting' back up the chain would be meaningless noise
            var config = new ComparisonConfig { IgnoreCollectionOrder = true, CompareChildren = false };
            var comparer = new CompareLogic(config);

            var result = comparer.Compare(left, right);

            return result.AreEqual;
        }
예제 #12
0
        /// <summary>
        /// Check if any type has attributes that should be bypassed
        /// </summary>
        /// <returns></returns>
        public static bool IgnoredByAttribute(ComparisonConfig config, MemberInfo info)
        {
            var attributes = info.GetCustomAttributes(true);

            return(attributes.Any(a => config.AttributesToIgnore.Contains(a.GetType())));
        }
예제 #13
0
 /// <summary>
 /// Set up defaults for the comparison
 /// </summary>
 public CompareLogic()
 {
     Config = new ComparisonConfig();
 }
예제 #14
0
        public void CompareInterfaceMembers()
        {
            ComparisonConfig config = new ComparisonConfig();
            config.InterfaceMembers.Add(typeof(IName));

            _compare = new CompareLogic(config);

            Person person1 = new Person();
            person1.Name = "Greg";
            person1.DateCreated = DateTime.Now;

            Person person2 = new Person();
            person2.Name = "Greg";
            person2.DateCreated = DateTime.Now.AddDays(-1);

            var result = _compare.Compare(person1, person2);
            Assert.IsTrue(result.AreEqual, result.DifferencesString);

        }
예제 #15
0
        /// <summary>
        /// Set up defaults for the comparison
        /// </summary>
        /// <param name="useAppConfigSettings">If true, use settings from the app.config</param>
        public CompareLogic(bool useAppConfigSettings)
        {
            Config = new ComparisonConfig();

            if (useAppConfigSettings)
                SetupWithAppConfigSettings();
        }
 public ComparisonResultWrapper(ComparisonConfig config) : base(config)
 {
 }
예제 #17
0
 /// <summary>
 /// Set up defaults for the comparison
 /// </summary>
 public CompareLogic()
 {
     Config = new ComparisonConfig();
 }
예제 #18
0
 /// <summary>
 /// Pass in the configuration
 /// </summary>
 /// <param name="config"></param>
 public CompareLogic(ComparisonConfig config)
 {
     Config = config;
 }
예제 #19
0
파일: Deeply.cs 프로젝트: rslijp/sharptiles
 public IsDeeplyEqualConstraint With(ComparisonConfig comparisonConfig)
 {
     _comparisonConfig = comparisonConfig;
     return this;
 }