示例#1
0
        /// <summary>
        /// Compares the objects in one dictionary with another.
        /// </summary>
        /// <param name="dictionary1">
        /// The dictionary that is compared with dictionary2.</param>
        /// <param name="dictionary2">
        /// The dictionary that is compared with dictionary1.</param>
        /// <param name="equalityFunc">An optional <c>Func</c>
        /// to test for dictionary item equality.
        /// If <c>null</c>, <c>object.Equals</c> is used.</param>
        /// <returns><c>true</c> if the collections
        /// have the same set of keys and values.</returns>
        public static bool IsEqualDictionary(
            this IDictionary dictionary1,
            IDictionary dictionary2,
            Func <object, object, bool> equalityFunc = null)
        {
            AssertArg.IsNotNull(dictionary1, nameof(dictionary1));

            return(CollectionComparer.AreEqualDictionaries(
                       dictionary1, dictionary2, equalityFunc));
        }
示例#2
0
        public void AreEqualDictionariesShouldReturnTrueIfEqual()
        {
            var dictionary1 = CreateDummyDictionary();
            var dictionary2 = CreateDummyDictionary();

            bool areEqual = CollectionComparer.AreEqualDictionaries(
                dictionary1, dictionary2);

            Assert.IsTrue(areEqual);
        }
示例#3
0
        public void AreEqualDictionariesShouldReturnFalseIfContainsMoreElements()
        {
            var dictionary1 = CreateDummyDictionary();
            var dictionary2 = CreateDummyDictionary();

            dictionary2.Add("Foo2", new object());

            bool areEqual = CollectionComparer.AreEqualDictionaries(
                dictionary1, dictionary2);

            Assert.IsFalse(areEqual);
        }
示例#4
0
        public void AreEqualDictionariesShouldReturnFalseIfValueDifferent()
        {
            var dictionary1 = CreateDummyDictionary();
            var dictionary2 = CreateDummyDictionary();
            var firstKey    = dictionary1.First().Key;

            dictionary1[firstKey] = new object();

            bool areEqual = CollectionComparer.AreEqualDictionaries(
                dictionary1, dictionary2);

            Assert.IsFalse(areEqual);
        }