public static void AreEqual(IDataItem expected, IDataItem actual)
        {
            var expectedNames = expected.GetFieldNames();

            Assert.IsNotNull(expectedNames, Resources.NullExpectedFieldNames);

            var actualNames = actual.GetFieldNames();

            Assert.IsNotNull(actualNames, Resources.NullActualFieldNames);

            CollectionAssert.AreEquivalent(expectedNames.ToArray(), actualNames.ToArray(), Resources.InvalidFieldNames);

            foreach (var fieldName in expectedNames)
            {
                var expectedValue = expected.GetValue(fieldName);
                var actualValue   = actual.GetValue(fieldName);

                if (expectedValue is IDataItem)
                {
                    Assert.IsTrue(actualValue is IDataItem, Resources.InvalidDataItemFieldValue);
                    AreEqual((IDataItem)expectedValue, (IDataItem)actualValue);
                }
                else
                {
                    if (expectedValue != null && expectedValue.GetType().IsValueType)
                    {
                        // Try change type to expected for value types to workaround DocumentDB deserialization issue (Int32 are becoming Int64)
                        try { actualValue = Convert.ChangeType(actualValue, expectedValue.GetType(), CultureInfo.InvariantCulture); } catch { }
                    }
                    Assert.AreEqual(expectedValue, actualValue, Resources.InvalidFieldValue);
                }
            }
        }
예제 #2
0
        protected static void VerifyDataItem(IReadOnlyDictionary <string, object> expected, IDataItem actual)
        {
            var actualColumns = actual.GetFieldNames().ToList();

            foreach (var key in expected.Keys)
            {
                Assert.IsTrue(actualColumns.Contains(key), TestResources.PropertyMissingFormat, key);
                Assert.AreEqual(expected[key], actual.GetValue(key), TestResources.InvalidPropertyValueFormat, key);
            }
        }
        protected static void VerifyDataItem(IReadOnlyDictionary<string, object> expected, IDataItem actual)
        {
            var actualColumns = actual.GetFieldNames().ToList();

            foreach (var key in expected.Keys)
            {
                Assert.IsTrue(actualColumns.Contains(key), TestResources.PropertyMissingFormat, key);
                Assert.AreEqual(expected[key], actual.GetValue(key), TestResources.InvalidPropertyValueFormat, key);
            }
        }
        private static int GetDataItemHash(IDataItem dataItem)
        {
            var result = 0;

            foreach (var fieldName in dataItem.GetFieldNames())
            {
                var value = dataItem.GetValue(fieldName);
                if (value == null)
                    continue;

                result ^= fieldName.GetHashCode() ^ (
                    value is IDataItem
                        ? GetDataItemHash((IDataItem)value)
                        : GetValueHashCode(value));
            }

            return result;
        }
예제 #5
0
        private static int GetDataItemHash(IDataItem dataItem)
        {
            var result = 0;

            foreach (var fieldName in dataItem.GetFieldNames())
            {
                var value = dataItem.GetValue(fieldName);
                if (value == null)
                {
                    continue;
                }

                result ^= fieldName.GetHashCode() ^ (
                    value is IDataItem
                        ? GetDataItemHash((IDataItem)value)
                        : GetValueHashCode(value));
            }

            return(result);
        }
예제 #6
0
        public static void AreEqual(IDataItem expected, IDataItem actual)
        {
            var expectedNames = expected.GetFieldNames();

            Assert.IsNotNull(expectedNames, Resources.NullExpectedFieldNames);

            var actualNames = actual.GetFieldNames();

            Assert.IsNotNull(actualNames, Resources.NullActualFieldNames);

            CollectionAssert.AreEquivalent(expectedNames.ToArray(), actualNames.ToArray(), Resources.InvalidFieldNames);

            foreach (var fieldName in expectedNames)
            {
                var expectedValue = expected.GetValue(fieldName);
                var actualValue   = actual.GetValue(fieldName);

                CheckItem(expectedValue, actualValue);
            }
        }
예제 #7
0
 public IEnumerable <string> GetFieldNames()
 {
     return(dataItem.GetFieldNames());
 }