DictionaryAssert.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System.Collections.Generic;
  3. namespace Renci.SshNet.Tests.Common
  4. {
  5. public static class DictionaryAssert
  6. {
  7. public static void AreEqual<TKey, TValue>(IDictionary<TKey, TValue> expected, IDictionary<TKey, TValue> actual)
  8. {
  9. if (ReferenceEquals(expected, actual))
  10. return;
  11. if (expected == null)
  12. throw new AssertFailedException("Expected dictionary to be null, but was not null.");
  13. if (actual == null)
  14. throw new AssertFailedException("Expected dictionary not to be null, but was null.");
  15. if (expected.Count != actual.Count)
  16. throw new AssertFailedException(string.Format("Expected dictionary to contain {0} entries, but was {1}.",
  17. expected.Count, actual.Count));
  18. foreach (var expectedEntry in expected)
  19. {
  20. TValue actualValue;
  21. if (!actual.TryGetValue(expectedEntry.Key, out actualValue))
  22. {
  23. throw new AssertFailedException(string.Format("Dictionary contains no entry with key '{0}'.", expectedEntry.Key));
  24. }
  25. if (!Equals(expectedEntry.Value, actualValue))
  26. {
  27. throw new AssertFailedException(string.Format("Value for key '{0}' does not match.", expectedEntry.Key));
  28. }
  29. }
  30. }
  31. }
  32. }