Reputation: 433
I created an extension method for System.Type and I would like to unit test that method. Is this possible? Thanks!
public static bool GetFoo(this Type self)
{
if (self == null)
{
throw new ArgumentNullException("this")
}
...
}
Upvotes: 0
Views: 108
Reputation: 4542
Just extending with other ways:
this.GetType().GetFoo();//inside some class.
typeof(SomeType).GetFoo();
Since it throws an ArgumentNullException you can wrap it inside a proper try-catch block
Upvotes: 0
Reputation: 6082
MS VS Unit Test
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void TestFoo()
{
Type t = null;
t.GetFoo();
}
Upvotes: 3
Reputation: 117230
You can do this too:
ExtensionClass.GetFoo(null)
Edit: Just noted this is the same as Jason Evans's now deleted answer...
Upvotes: 1