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 6127383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:30:03+00:00 2026-05-23T16:30:03+00:00

I have a custom attribute that is just used to mark a member (no

  • 0

I have a custom attribute that is just used to mark a member (no constructor, no properties):

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class MyCustomAttribute : Attribute { }

How would I unit test this? And, to clarify… I know the ‘what’, but not the ‘how’

I assume there is a way to unit test it to ensure the proper AttributeUsage is in place? So how could I do this? Every time I create a mock class and try to add the attribute to the wrong thing it won’t let me compile, so how can I create a bad mock class to test?

  • 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-23T16:30:03+00:00Added an answer on May 23, 2026 at 4:30 pm

    You would not create a mock class to test this. Instead, you would simply test the attribute class itself to see if it has the proper AttributeUsageAttribute attribute properties. whew, what a mouthful

    [TestMethod]
    public void Is_Attribute_Multiple_False()
    {
        var attributes = (IList<AttributeUsageAttribute>)typeof(MyCustomAttribute).GetCustomAttributes(typeof(AttributeUsageAttribute), false);
        Assert.AreEqual(1, attributes.Count);
    
        var attribute = attributes[0];
        Assert.IsFalse(attribute.AllowMultiple);
    }
    
    // Etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom attribute defined like so: [AttributeUsage(AttributeTargets.Field)] public class EnumDisplayAttribute : Attribute {
How do i select elements that have my custom data attribute data-validate with jQuery
Has everyone ever programatically created a custom attribute? (At the moment I've just used
I have a property on my view model that is a custom class with
Suppose I have a simple XHTML document that uses a custom namespace for attributes:
I have a custom attribute which can be assigned to a class, [FooAttribute] .
I have a custom attribute and I need to have the name of the
I have a custom validation attribute derived from action filter attribute. Currently the attribute
I have a custom authorize attribute on my controllers and it is not being
Should I need to have explicit custom ID attribute as PK for each of

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.