Created
February 6, 2011 05:40
-
-
Save beccasaurus/813165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
namespace NUnit.Framework { | |
public static class ShouldHavePropertiesExtension { | |
/// <summary>For checking lots of properties on an object</summary> | |
/// <remarks> | |
/// Lets you say: | |
/// <code> | |
/// foo.ShouldHaveProperties(new { | |
/// Id = "This", | |
/// Foo = 15.89, | |
/// Hi = "Something" | |
/// }); | |
/// </code> | |
/// | |
/// Instead of having to say: | |
/// <code> | |
/// foo.Id.ShouldEqual("This"); | |
/// foo.Foo.ShouldEqual(15.89); | |
/// foo.Hi.ShouldEqual("Something"); | |
/// </code> | |
/// </remarks> | |
public static void ShouldHaveProperties(this object o, object anonymousObjectOfAttributes) { | |
var type = o.GetType(); | |
foreach (var propertyItem in anonymousObjectOfAttributes.ToDictionary()) { | |
var property = type.GetProperty(propertyItem.Key); | |
var expected = propertyItem.Value; | |
var actual = property.GetValue(o, new object[] {}); | |
actual.ShouldEqual(expected); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment