public override void CompareType(CompareParms parms)
        {
            if(parms.ParentObject1 == null || parms.ParentObject2 == null)
            {
                base.CompareType (parms);
                return;
            }

            PropertyInfo prop1 = null, prop2 = null;
            if(parms.Object1 != null)
                prop1 = parms.Object1.GetType ().GetProperty ("Id");
            if(parms.Object2 != null)
                prop2 = parms.Object2.GetType ().GetProperty ("Id");

            if (prop1 != null && prop2 != null &&
                (int)prop1.GetValue (parms.Object1, null) == (int)prop2.GetValue (parms.Object2, null)) {
                if (parms.ParentObject1 is IList)
                    base.CompareType (parms);
                return;
            }

            Difference difference = new Difference
            {
                ParentObject1 =  new WeakReference(parms.ParentObject1),
                ParentObject2 =  new WeakReference(parms.ParentObject2),
                PropertyName = parms.BreadCrumb,
                Object1Value = parms.Object1 == null ? String.Empty : HistoryMain.GetObjectTilte (parms.Object1),
                Object2Value = parms.Object2 == null ? String.Empty : HistoryMain.GetObjectTilte (parms.Object2),
                ChildPropertyName = "Id",
                Object1 = new WeakReference(parms.Object1),
                Object2 = new WeakReference(parms.Object2)
            };

            AddDifference(parms.Result, difference);
        }
        /// <summary>
        /// Compare all tables and all rows in all tables
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareDataset(object object1, object object2, string breadCrumb)
        {
            DataSet dataSet1 = object1 as DataSet;
            DataSet dataSet2 = object2 as DataSet;

            //This should never happen, null check happens one level up
            if (dataSet1 == null || dataSet2 == null)
                return;

            //There must be the same amount of tables in the dataset
            if (dataSet1.Tables.Count != dataSet2.Tables.Count)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = dataSet1.Tables.Count.ToString(CultureInfo.InvariantCulture),
                    Object2Value = dataSet2.Tables.Count.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Tables.Count"
                };
                Differences.Add(difference);

                if (Differences.Count >= MaxDifferences)
                    return;
            }

            for (int i = 0; i < Math.Min(dataSet1.Tables.Count,dataSet2.Tables.Count); i++)
            {
                string currentBreadCrumb = AddBreadCrumb(breadCrumb, "Tables", string.Empty, dataSet1.Tables[i].TableName);

                CompareDataTable(dataSet1.Tables[i], dataSet2.Tables[i], currentBreadCrumb);

                if (Differences.Count >= MaxDifferences)
                    return;
            }
        }
        /// <summary>
        /// Compare all rows in a data table
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareDataTable(object object1, object object2, string breadCrumb)
        {
            DataTable dataTable1 = object1 as DataTable;
            DataTable dataTable2 = object2 as DataTable;

            //This should never happen, null check happens one level up
            if (dataTable1 == null || dataTable2 == null)
                return;

            //Only compare specific table names
            if (ElementsToInclude.Count > 0 && !ElementsToInclude.Contains(dataTable1.TableName))
                return;

            //If we should ignore it, skip it
            if (ElementsToInclude.Count == 0 && ElementsToIgnore.Contains(dataTable1.TableName))
                return;

            //There must be the same amount of rows in the datatable
            if (dataTable1.Rows.Count != dataTable2.Rows.Count)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = dataTable1.Rows.Count.ToString(CultureInfo.InvariantCulture),
                    Object2Value = dataTable2.Rows.Count.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Rows.Count"
                };
                Differences.Add(difference);

                if (Differences.Count >= MaxDifferences)
                    return;
            }

            //There must be the same amount of columns in the datatable
            if (dataTable1.Columns.Count != dataTable2.Columns.Count)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = dataTable1.Columns.Count.ToString(CultureInfo.InvariantCulture),
                    Object2Value = dataTable2.Columns.Count.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Columns.Count"
                };
                Differences.Add(difference);

                if (Differences.Count >= MaxDifferences)
                    return;
            }

            for (int i = 0; i < Math.Min(dataTable1.Rows.Count,dataTable2.Rows.Count); i++)
            {
                string currentBreadCrumb = AddBreadCrumb(breadCrumb, "Rows", string.Empty, i);

                CompareDataRow(dataTable1.Rows[i], dataTable2.Rows[i], currentBreadCrumb);

                if (Differences.Count >= MaxDifferences)
                    return;
            }
        }
        /// <summary>
        /// Compare all columns in a data row
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareDataRow(object object1, object object2, string breadCrumb)
        {
            DataRow dataRow1 = object1 as DataRow;
            DataRow dataRow2 = object2 as DataRow;

            //This should never happen, null check happens one level up
            if (dataRow1 == null || dataRow2 == null)
                return;

            for (int i = 0; i < dataRow1.Table.Columns.Count; i++)
            {
                //Only compare specific column names
                if (ElementsToInclude.Count > 0 && !ElementsToInclude.Contains(dataRow1.Table.Columns[i].ColumnName))
                    continue;
                
                //If we should ignore it, skip it
                if (ElementsToInclude.Count == 0 && ElementsToIgnore.Contains(dataRow1.Table.Columns[i].ColumnName))
                    continue;

                //If we should ignore read only, skip it
                if (!CompareReadOnly && dataRow1.Table.Columns[i].ReadOnly)
                    continue;

                //Both are null
                if (dataRow1.IsNull(i) && dataRow2.IsNull(i))
                    continue;

                string currentBreadCrumb = AddBreadCrumb(breadCrumb, string.Empty, string.Empty, dataRow1.Table.Columns[i].ColumnName);

                //Check if one of them is null
                if (dataRow1.IsNull(i))
                {
                    Difference difference = new Difference
                    {
                        ExpectedName = ExpectedName,
                        ActualName = ActualName,
                        PropertyName = currentBreadCrumb,
                        Object1Value = "(null)",
                        Object2Value = NiceString(object2)
                    };
                    Differences.Add(difference);
                    return;
                }

                if (dataRow2.IsNull(i))
                {
                    Difference difference = new Difference
                    {
                        ExpectedName = ExpectedName,
                        ActualName = ActualName,
                        PropertyName = currentBreadCrumb,
                        Object1Value = NiceString(object1),
                        Object2Value = "(null)"
                    };
                    Differences.Add(difference);
                    return;
                }

                Compare(dataRow1[i], dataRow2[i], currentBreadCrumb);

                if (Differences.Count >= MaxDifferences)
                    return;
            }
        }
 public void ParentPropertyNameArrayTest()
 {
     Difference diff = new Difference();
     diff.PropertyName = ".Password[4]";
     Assert.AreEqual(".Password", diff.ParentPropertyName);
 }
Пример #6
0
        private bool ColumnCountsDifferent(CompareParms parms)
        {
            DataTable dataTable1 = parms.Object1 as DataTable;
            DataTable dataTable2 = parms.Object2 as DataTable;

            if (dataTable1.Columns.Count != dataTable2.Columns.Count)
            {
                Difference difference = new Difference
                {
                    ParentObject1 = new WeakReference(parms.ParentObject1),
                    ParentObject2 = new WeakReference(parms.ParentObject2),
                    PropertyName = parms.BreadCrumb,
                    Object1Value = dataTable1.Columns.Count.ToString(CultureInfo.InvariantCulture),
                    Object2Value = dataTable2.Columns.Count.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Columns.Count",
                    Object1 = new WeakReference(parms.Object1),
                    Object2 = new WeakReference(parms.Object2)
                };

                AddDifference(parms.Result, difference);

                if (parms.Result.ExceededDifferences)
                    return true;
            }
            return false;
        }
Пример #7
0
        private bool TableCountsDifferent(CompareParms parms, DataSet dataSet2, DataSet dataSet1)
        {
            if (dataSet1.Tables.Count != dataSet2.Tables.Count)
            {
                Difference difference = new Difference
                                            {
                                                ParentObject1 = new WeakReference(parms.ParentObject1),
                                                ParentObject2 = new WeakReference(parms.ParentObject2),
                                                PropertyName = parms.BreadCrumb,
                                                Object1Value = dataSet1.Tables.Count.ToString(CultureInfo.InvariantCulture),
                                                Object2Value = dataSet2.Tables.Count.ToString(CultureInfo.InvariantCulture),
                                                ChildPropertyName = "Tables.Count",
                                                Object1 = new WeakReference(parms.Object1),
                                                Object2 = new WeakReference(parms.Object2)
                                            };

                AddDifference(parms.Result, difference);

                if (parms.Result.ExceededDifferences)
                    return true;
            }
            return false;
        }
        /// <summary>
        /// Compare an enumeration
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareEnum(object object1, object object2, string breadCrumb)
        {
            if (object1.ToString() != object2.ToString())
            {
                string currentBreadCrumb = AddBreadCrumb(breadCrumb, object1.GetType().Name, string.Empty, -1);

                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = currentBreadCrumb,
                    Object1Value = object1.ToString(),
                    Object2Value = object2.ToString()
                };
                Differences.Add(difference);
            }
        }
        /// <summary>
        /// Compare a HashSet
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareHashSet(object object1, object object2, string breadCrumb)
        {
            try
            {
                _parents.Add(object1);
                _parents.Add(object2);

                Type t1 = object1.GetType();

                //Get count by reflection since we can't cast it to HashSet<>
                int hashSet1Count = (int) GetPropertyValue(t1, object1, "Count");
                int hashSet2Count = (int) GetPropertyValue(t1, object2, "Count");

                //Objects must be the same length
                if (hashSet1Count != hashSet2Count)
                {
                    Difference difference = new Difference
                    {
                        ExpectedName = ExpectedName,
                        ActualName = ActualName,
                        PropertyName = breadCrumb,
                        Object1Value = hashSet1Count.ToString(CultureInfo.InvariantCulture),
                        Object2Value = hashSet2Count.ToString(CultureInfo.InvariantCulture),
                        ChildPropertyName = "Count"
                    };
                    Differences.Add(difference);

                    if (Differences.Count >= MaxDifferences)
                        return;
                }

                //Get enumerators by reflection
                MethodInfo methodInfo = GetMethod(t1, "GetEnumerator");
                IEnumerator enumerator1 = (IEnumerator) methodInfo.Invoke(object1, null);
                IEnumerator enumerator2 = (IEnumerator) methodInfo.Invoke(object2, null);

                int count = 0;

                while (enumerator1.MoveNext() && enumerator2.MoveNext())
                {
                    string currentBreadCrumb = AddBreadCrumb(breadCrumb, string.Empty, string.Empty, count);

                    Compare(enumerator1.Current, enumerator2.Current, currentBreadCrumb);

                    if (Differences.Count >= MaxDifferences)
                        return;

                    count++;
                }
            }
            finally
            {
                _parents.Remove(object1);
                _parents.Remove(object2);
            }
        }
        /// <summary>
        /// Compare an array or something that implements IList
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareIList(object object1, object object2, string breadCrumb)
        {
            IList ilist1 = object1 as IList;
            IList ilist2 = object2 as IList;

            //This should never happen, null check happens one level up
            if (ilist1 == null || ilist2 == null)
                return;

            try
            {
                _parents.Add(object1);
                _parents.Add(object2);

                //Objects must be the same length
                if (ilist1.Count != ilist2.Count)
                {
                    Difference difference = new Difference
                    {
                        ExpectedName = ExpectedName,
                        ActualName = ActualName,
                        PropertyName = breadCrumb,
                        Object1Value = ilist1.Count.ToString(CultureInfo.InvariantCulture),
                        Object2Value = ilist2.Count.ToString(CultureInfo.InvariantCulture),
                        ChildPropertyName = "Count"
                    };
                    Differences.Add(difference);

                    if (Differences.Count >= MaxDifferences)
                        return;
                }

                IEnumerator enumerator1 = ilist1.GetEnumerator();
                IEnumerator enumerator2 = ilist2.GetEnumerator();
                int count = 0;

                while (enumerator1.MoveNext() && enumerator2.MoveNext())
                {
                    string currentBreadCrumb = AddBreadCrumb(breadCrumb, string.Empty, string.Empty, count);

                    Compare(enumerator1.Current, enumerator2.Current, currentBreadCrumb);

                    if (Differences.Count >= MaxDifferences)
                        return;

                    count++;
                }
            }
            finally
            {
                _parents.Remove(object1);
                _parents.Remove(object2);
            }
        }
        /// <summary>
        /// Compare an integer indexer
        /// </summary>
        /// <param name="info"></param>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareIndexer(PropertyInfo info, object object1, object object2, string breadCrumb)
        {
            string currentCrumb;
            int indexerCount1 = (int)info.ReflectedType.GetProperty("Count").GetGetMethod().Invoke(object1, new object[] { });
            int indexerCount2 = (int)info.ReflectedType.GetProperty("Count").GetGetMethod().Invoke(object2, new object[] { });

            //Indexers must be the same length
            if (indexerCount1 != indexerCount2)
            {
                currentCrumb = AddBreadCrumb(breadCrumb, info.Name, string.Empty, -1);
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = currentCrumb,
                    Object1Value = indexerCount1.ToString(CultureInfo.InvariantCulture),
                    Object2Value = indexerCount2.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Count"
                };
                Differences.Add(difference);

                if (Differences.Count >= MaxDifferences)
                    return;
            }

            // Run on indexer
            for (int i = 0; i < indexerCount1; i++)
            {
                currentCrumb = AddBreadCrumb(breadCrumb, info.Name, string.Empty, i);
                object objectValue1 = info.GetValue(object1, new object[] { i });
                object objectValue2 = info.GetValue(object2, new object[] { i });
                Compare(objectValue1, objectValue2, currentCrumb);

                if (Differences.Count >= MaxDifferences)
                    return;
            }
        }
Пример #12
0
        private bool TypesDifferent(CompareParms parms, Type t1, Type t2)
        {
            //Objects must be the same type and not be null
            if (!parms.Config.IgnoreObjectTypes
                && parms.Object1 != null 
                && parms.Object2 != null 
                && t1 != t2)
            {
                Difference difference = new Difference
                {
                    ParentObject1 = new WeakReference(parms.ParentObject1),
                    ParentObject2 = new WeakReference(parms.ParentObject2),
                    PropertyName = parms.BreadCrumb,
                    Object1Value = t1.FullName,
                    Object2Value = t2.FullName,
                    ChildPropertyName = "GetType()",
                    MessagePrefix = "Different Types",
                    Object1 = new WeakReference(parms.Object1),
                    Object2 = new WeakReference(parms.Object2)
                };

                AddDifference(parms.Result, difference);
                return true;
            }

            return false;
        }
Пример #13
0
        /// <summary>
        /// Compare a dictionary
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareIDictionary(object object1, object object2, string breadCrumb)
        {
            IDictionary iDict1 = object1 as IDictionary;
            IDictionary iDict2 = object2 as IDictionary;

            //This should never happen, null check happens one level up
            if (iDict1 == null || iDict2 == null)
                return;

            try
            {
                AddParent(object1.GetHashCode());
                AddParent(object2.GetHashCode());

                //Objects must be the same length
                if (iDict1.Count != iDict2.Count)
                {
                    Difference difference = new Difference
                    {
                        ExpectedName = ExpectedName,
                        ActualName = ActualName,
                        PropertyName = breadCrumb,
                        Object1Value = iDict1.Count.ToString(CultureInfo.InvariantCulture),
                        Object2Value = iDict2.Count.ToString(CultureInfo.InvariantCulture),
                        ChildPropertyName = "Count"
                    };
                    Differences.Add(difference);

                    if (Differences.Count >= MaxDifferences)
                        return;
                }

                IDictionaryEnumerator enumerator1 = iDict1.GetEnumerator();
                IDictionaryEnumerator enumerator2 = iDict2.GetEnumerator();

                while (enumerator1.MoveNext() && enumerator2.MoveNext())
                {
                    string currentBreadCrumb = AddBreadCrumb(breadCrumb, "Key", string.Empty, -1);

                    Compare(enumerator1.Key, enumerator2.Key, currentBreadCrumb);

                    if (Differences.Count >= MaxDifferences)
                        return;

                    currentBreadCrumb = AddBreadCrumb(breadCrumb, "Value", string.Empty, -1);

                    Compare(enumerator1.Value, enumerator2.Value, currentBreadCrumb);

                    if (Differences.Count >= MaxDifferences)
                        return;
                }
            }
            finally
            {
                RemoveParent(object1.GetHashCode());
                RemoveParent(object2.GetHashCode());
            }
        }
 public void ParentPropertyNameChildTest()
 {
     Difference diff = new Difference();
     diff.PropertyName = ".Customer.FirstName";
     Assert.AreEqual(".Customer", diff.ParentPropertyName);
 }
 /// <summary>
 /// Compare a timespan struct
 /// </summary>
 /// <param name="object1"></param>
 /// <param name="object2"></param>
 /// <param name="breadCrumb"></param>
 private void CompareTimespan(object object1, object object2, string breadCrumb)
 {
     if (((TimeSpan)object1).Ticks != ((TimeSpan)object2).Ticks)
     {
         Difference difference = new Difference
         {
             ExpectedName = ExpectedName,
             ActualName = ActualName,
             PropertyName = breadCrumb,
             Object1Value = ((TimeSpan)object1).Ticks.ToString(CultureInfo.InvariantCulture),
             Object2Value = ((TimeSpan)object1).Ticks.ToString(CultureInfo.InvariantCulture),
             ChildPropertyName = "Ticks"
         };
         Differences.Add(difference);
     }
 }
 /// <summary>
 /// Compare a pointer struct
 /// </summary>
 /// <param name="object1"></param>
 /// <param name="object2"></param>
 /// <param name="breadCrumb"></param>
 private void ComparePointer(object object1, object object2, string breadCrumb)
 {
     if ((object1 is IntPtr && object2 is IntPtr && ((IntPtr)object1) != ((IntPtr)object2)) 
         || (object1 is UIntPtr && object2 is UIntPtr && ((UIntPtr)object1) != ((UIntPtr)object2)))
     {
         Difference difference = new Difference
         {
             ExpectedName = ExpectedName,
             ActualName = ActualName,
             PropertyName = breadCrumb
         };
         Differences.Add(difference);
     }
 }
        /// <summary>
        /// Compare two objects
        /// </summary>
        /// <param name="object1">The first object to compare</param>
        /// <param name="object2">The second object to compare</param>
        /// <param name="breadCrumb">Where we are in the object hiearchy</param>
        private void Compare(object object1, object object2, string breadCrumb)
        {
            //If both null return true
            if (object1 == null && object2 == null)
                return;

            //Check if one of them is null
            if (object1 == null)
            {
                Difference difference = new Difference
                    {
                        ExpectedName = ExpectedName,
                        ActualName = ActualName,
                        PropertyName = breadCrumb,
                        Object1Value = "(null)",
                        Object2Value = NiceString(object2)
                    };
                Differences.Add(difference);
                return;
            }

            if (object2 == null)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = NiceString(object1),
                    Object2Value = "(null)"
                };
                Differences.Add(difference);
                return;
            }

            Type t1 = object1.GetType();
            Type t2 = object2.GetType();

            //Objects must be the same type
            if (t1 != t2 && !IgnoreObjectTypes)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = t1.FullName,
                    Object2Value = t2.FullName,
                    ChildPropertyName = "GetType()",
                    MessagePrefix = "Different Types"
                };
                Differences.Add(difference);

                return;
            }

            if (IsUseCustomTypeComparer(t1))
            {
                CompareWithCustomComparer(object1, object2, breadCrumb);
            }
            else if (IsTypeOfType(t1))
            {
                CompareType(object1, object2, breadCrumb);
            }
            else if (IsIPEndPoint(t1))
            {
                CompareIpEndPoint(object1, object2, breadCrumb);
            }
#if !SILVERLIGHT
            else if (IsDataset(t1))
            {
                CompareDataset(object1, object2, breadCrumb);
            }
            else if (IsDataTable(t1))
            {
                CompareDataTable(object1, object2, breadCrumb);
            }
            else if (IsDataRow(t1))
            {
                CompareDataRow(object1, object2, breadCrumb);
            }
#endif
            else if (IsIList(t1)) //This will do arrays, multi-dimensional arrays and generic lists
            {
                CompareIList(object1, object2, breadCrumb);
            }
            else if (IsHashSet(t1))
            {
                CompareHashSet(object1,object2,breadCrumb);
            }
            else if (IsIDictionary(t1))
            {
                CompareIDictionary(object1, object2, breadCrumb);
            }
            else if (IsEnum(t1))
            {
                CompareEnum(object1, object2, breadCrumb);
            }
            else if (IsPointer(t1))
            {
                ComparePointer(object1, object2, breadCrumb);
            }
            else if (IsUri(t1))
            {
                CompareUri(object1, object2, breadCrumb);
            }
            else if (IsSimpleType(t1))
            {
                CompareSimpleType(object1, object2, breadCrumb);
            }
            else if (IsClass(t1))
            {
                CompareClass(object1, object2, breadCrumb);
            }
            else if (IsTimespan(t1))
            {
                CompareTimespan(object1, object2, breadCrumb);
            }
            else if (IsStruct(t1))
            {
                CompareStruct(object1, object2, breadCrumb);
            }
            else
            {
                throw new NotSupportedException("Cannot compare object of type " + t1.Name);
            }

        }
        /// <summary>
        /// Compare a simple type
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareSimpleType(object object1, object object2, string breadCrumb)
        {
            //This should never happen, null check happens one level up
            if (object2 == null || object1 == null)
                return;

            IComparable valOne = object1 as IComparable;

            if (valOne == null) 
                throw new Exception("Expected value does not implement IComparable");

            if (valOne.CompareTo(object2) != 0)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = object1.ToString(),
                    Object2Value = object2.ToString()
                };
                Differences.Add(difference);
            }
        }
        private void CompareIpEndPoint(object object1, object object2, string breadCrumb)
        {
            IPEndPoint ipEndPoint1 = object1 as IPEndPoint;
            IPEndPoint ipEndPoint2 = object2 as IPEndPoint;

            //Null check happens above
            if (ipEndPoint1 == null || ipEndPoint2 == null)
                return;

            if (ipEndPoint1.Port != ipEndPoint2.Port)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = ipEndPoint1.Port.ToString(CultureInfo.InvariantCulture),
                    Object2Value = ipEndPoint2.Port.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Port"
                };
                Differences.Add(difference);
            }

            if (Differences.Count >= MaxDifferences)
                return;

            if (ipEndPoint1.Address.ToString() != ipEndPoint2.Address.ToString())
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = ipEndPoint1.Address.ToString(),
                    Object2Value = ipEndPoint2.Address.ToString(),
                    ChildPropertyName = "Address"
                };
                Differences.Add(difference);
            }
        }
Пример #20
0
        /// <summary>
        /// Compare two datatables
        /// </summary>
        public override void CompareType(CompareParms parms)
        {
            DataTable dataTable1 = parms.Object1 as DataTable;
            DataTable dataTable2 = parms.Object2 as DataTable;

            //This should never happen, null check happens one level up
            if (dataTable1 == null || dataTable2 == null)
                return;

            //Only compare specific table names
            if (parms.Config.MembersToInclude.Count > 0 && !parms.Config.MembersToInclude.Contains(dataTable1.TableName))
                return;

            //If we should ignore it, skip it
            if (parms.Config.MembersToInclude.Count == 0 && parms.Config.MembersToIgnore.Contains(dataTable1.TableName))
                return;

            //There must be the same amount of rows in the datatable
            if (dataTable1.Rows.Count != dataTable2.Rows.Count)
            {
                Difference difference = new Difference
                {
                    ParentObject1 = new WeakReference(parms.ParentObject1),
                    ParentObject2 = new WeakReference(parms.ParentObject2),
                    PropertyName = parms.BreadCrumb,
                    Object1Value = dataTable1.Rows.Count.ToString(CultureInfo.InvariantCulture),
                    Object2Value = dataTable2.Rows.Count.ToString(CultureInfo.InvariantCulture),
                    ChildPropertyName = "Rows.Count",
                    Object1 = new WeakReference(parms.Object1),
                    Object2 = new WeakReference(parms.Object2)
                };

                AddDifference(parms.Result, difference);

                if (parms.Result.ExceededDifferences)
                    return;
            }

            if (ColumnCountsDifferent(parms)) return;

            CompareRowCollections(parms);
        }
        /// <summary>
        /// Compare an object of type URI
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareUri(object object1, object object2, string breadCrumb)
        {
            Uri uri1 = object1 as Uri;
            Uri uri2 = object2 as Uri;

            //This should never happen, null check happens one level up
            if (uri1 == null || uri2 == null)
                return;

            if (uri1.OriginalString != uri2.OriginalString)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = NiceString(uri1.OriginalString),
                    Object2Value = NiceString(uri2.OriginalString),
                    ChildPropertyName = "OriginalString"
                };
                Differences.Add(difference);
            }
        }
Пример #22
0
        public override void CompareType(CompareParms parms)
        {
            var dataRowCollection1 = parms.Object1 as DataRowCollection;
            var dataRowCollection2 = parms.Object2 as DataRowCollection;

            if (null == dataRowCollection1 || null == dataRowCollection2)
                return;

            for (int i = 0; i < Math.Min(dataRowCollection1.Count, dataRowCollection2.Count); i++)
            {
                if (!CollectionContainsMatchingRow(dataRowCollection1[i], dataRowCollection2.Cast<DataRow>()))
                {
                    Difference difference = new Difference
                    {
                        ParentObject1 = new WeakReference(parms.ParentObject1),
                        ParentObject2 = new WeakReference(parms.ParentObject2),
                        PropertyName = parms.BreadCrumb,
                        Object1Value = string.Format("Row Contents: [{0}]", PrettifyRowValues(dataRowCollection1[i])),
                        Object2Value = "[No Matching Row Found in Second DataRowCollection]",
                        ChildPropertyName = string.Format("[{0}]", i),
                        Object1 = new WeakReference(dataRowCollection1[i]),
                        Object2 = new WeakReference(dataRowCollection2[i])
                    };

                    AddDifference(parms.Result, difference);

                    if (parms.Result.ExceededDifferences)
                        return;
                }
            }
        }
        /// <summary>
        /// Compare an object of type Type (Runtime type)
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="object2"></param>
        /// <param name="breadCrumb"></param>
        private void CompareType(object object1, object object2, string breadCrumb)
        {
            Type t1 = (Type)object1;
            Type t2 = (Type)object2;

            if (t1.FullName != t2.FullName)
            {
                Difference difference = new Difference
                {
                    ExpectedName = ExpectedName,
                    ActualName = ActualName,
                    PropertyName = breadCrumb,
                    Object1Value = t1.FullName,
                    Object2Value = t2.FullName,
                    ChildPropertyName = "FullName"
                };
                Differences.Add(difference);
            }
        }