Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 681443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:29:03+00:00 2026-05-14T01:29:03+00:00

I created an extension method called HasContentPermission on the System.Security.Principal.IIdentity : namespace System.Security.Principal {

  • 0

I created an extension method called HasContentPermission on the System.Security.Principal.IIdentity:

namespace System.Security.Principal
{
    public static class IdentityExtensions
    {
        public static bool HasContentPermission
            (this IIdentity identity, 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:29:03+00:00Added an answer on May 14, 2026 at 1:29 am

    Make sure you’ve:

    1. made the class static
    2. made the class accessible to the calling code
    3. included this before the type to extend
    4. built the project containing the extension
    5. added a reference to the project in your unit test project
    6. added a using myns; to any source file that uses the extension method if your extension method is contained inside a different namespace

    Note that you’ve also got (I assume) a typo in your example in that the method isn’t in a class.

    Finally, I would avoid putting methods into the official .NET namespaces. It can only be confusing to anyone coming after you who might think that the method is an officially supported method when in reality it is your own and contained within your project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an extension method called AddGZip which looks like the following: public
I've created an Html extension method in Helper class, but I can not get
I've created an extension method for SqlCommand that allows some additional work before executing
When I try to create an extension method for the File class, I get
I'm having trouble getting the C# compiler to call an extension method I created,
I've created an Extension of GenericHandler called SOAPHeaderHandler. I placed log4j statements in the
At a previous organization, we implemented an extension method that created a shorthand for
I created an extension function called startsWith in my general js. It goes like
I am trying to create an extension method for the generic delegate Action<T> to
I wonder if it's possible to create an extension method which has functionality &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.