Why is my Extension Method not showing up in my test class?
- by Robert Harvey
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?