Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace NUnit.Framework {
  5. public static class ShouldHavePropertiesExtension {
  6.  
  7. /// <summary>For checking lots of properties on an object</summary>
  8. /// <remarks>
  9. /// Lets you say:
  10. /// <code>
  11. /// foo.ShouldHaveProperties(new {
  12. /// Id = "This",
  13. /// Foo = 15.89,
  14. /// Hi = "Something"
  15. /// });
  16. /// </code>
  17. ///
  18. /// Instead of having to say:
  19. /// <code>
  20. /// foo.Id.ShouldEqual("This");
  21. /// foo.Foo.ShouldEqual(15.89);
  22. /// foo.Hi.ShouldEqual("Something");
  23. /// </code>
  24. /// </remarks>
  25. public static void ShouldHaveProperties(this object o, object anonymousObjectOfAttributes) {
  26. var type = o.GetType();
  27. foreach (var propertyItem in anonymousObjectOfAttributes.ToDictionary()) {
  28. var property = type.GetProperty(propertyItem.Key);
  29. var expected = propertyItem.Value;
  30. var actual = property.GetValue(o, new object[] {});
  31. actual.ShouldEqual(expected);
  32. }
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment