/// <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)); }
public void AreEqualDictionariesShouldReturnTrueIfEqual() { var dictionary1 = CreateDummyDictionary(); var dictionary2 = CreateDummyDictionary(); bool areEqual = CollectionComparer.AreEqualDictionaries( dictionary1, dictionary2); Assert.IsTrue(areEqual); }
public void AreEqualDictionariesShouldReturnFalseIfContainsMoreElements() { var dictionary1 = CreateDummyDictionary(); var dictionary2 = CreateDummyDictionary(); dictionary2.Add("Foo2", new object()); bool areEqual = CollectionComparer.AreEqualDictionaries( dictionary1, dictionary2); Assert.IsFalse(areEqual); }
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); }