Why is my Extension Method not showing up in my test class?
Posted
by Robert Harvey
on Stack Overflow
See other posts from Stack Overflow
or by Robert Harvey
Published on 2010-03-26T17:12:59Z
Indexed on
2010/03/26
17:23 UTC
Read the original article
Hit count: 297
I created an extension method called HasContentPermission
on the System.Security.Principal.IIdentity
interface:
namespace System.Security.Principal
{
public static bool HasContentPermission
(this IIdentity itentity, int contentID)
{
// I do stuff here
return result;
}
}
And I call it like this:
bool hasPermission = User.Identity.HasPermission(contentID);
Works like a charm. Now I want to unit test it. To do that, all I really need to do is call the extension method directly, so:
using System.Security.Principal;
namespace MyUnitTests
{
[TestMethod]
public void HasContentPermission_PermissionRecordExists_ReturnsTrue()
{
IIdentity identity;
bool result = identity.HasContentPermission(...
But HasContentPermission
won't intellisense. I tried creating a stub class that inherits from IIdentity
, but that didn't work either. Why?
Or am I going about this the wrong way?
© Stack Overflow or respective owner