2
0

DictionaryAssert.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  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. {
  11. return;
  12. }
  13. if (expected == null)
  14. {
  15. throw new AssertFailedException("Expected dictionary to be null, but was not null.");
  16. }
  17. if (actual == null)
  18. {
  19. throw new AssertFailedException("Expected dictionary not to be null, but was null.");
  20. }
  21. if (expected.Count != actual.Count)
  22. {
  23. throw new AssertFailedException(string.Format("Expected dictionary to contain {0} entries, but was {1}.",
  24. expected.Count, actual.Count));
  25. }
  26. foreach (var expectedEntry in expected)
  27. {
  28. if (!actual.TryGetValue(expectedEntry.Key, out var actualValue))
  29. {
  30. throw new AssertFailedException(string.Format("Dictionary contains no entry with key '{0}'.", expectedEntry.Key));
  31. }
  32. if (!Equals(expectedEntry.Value, actualValue))
  33. {
  34. throw new AssertFailedException(string.Format("Value for key '{0}' does not match.", expectedEntry.Key));
  35. }
  36. }
  37. }
  38. }
  39. }