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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:04:42+00:00 2026-05-21T00:04:42+00:00

So, I’ve been searching around on the internet for a bit, trying to see

  • 0

So, I’ve been searching around on the internet for a bit, trying to see if someone has already invented the wheel here. What I want to do is write an integration test that will parse the current project, find all references to a certain method, find it’s arguments, and then check the database for that argument. For example:

public interface IContentProvider
{
     ContentItem GetContentFor(string descriptor);
}

public class ContentProvider : IContentProvider
{
    public virtual ContentItem GetContentFor(string descriptor)
    {
        // Fetches Content from Database for descriptor and returns in
    }
}

Any other class will get an IContentProvider injected into their constructor using IOC, such that they could write something like:

contentProvider.GetContentFor("SomeDescriptor");
contentProvider.GetContentFor("SomeOtherDescriptor");

Basically, the unit test finds all these references, find the set of text [“SomeDescriptor”, “SomeOtherDescriptor”], and then I can check the database to make sure I have rows defined for those descriptors. Furthermore, the descriptors are hard coded.

I could make an enum value for all descriptors, but the enum would have thousands of possible options, and that seems like kinda a hack.

Now, this link on SO: How I can get all reference with Reflection + C# basically says it’s impossible without some very advanced IL parsing. To clarify; I don’t need Reflector or anything – it’s just to be an automated test I can run so that if any other developers on my team check in code that calls for this content without creating the DB record, the test will fail.

Is this possible? If so, does anyone have a resource to look at or sample code to modify?

EDIT: Alternatively, perhaps a different method of doing this VS trying to find all references? The end result is I want a test to fail when the record doesnt exist.

  • 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-21T00:04:43+00:00Added an answer on May 21, 2026 at 12:04 am

    This will be very difficult: your program may compute the value of the descriptor, which will mean your test is able to know which value are possible without executing said code.

    I would suggest to change the way you program here, by using an enum type, or coding using the type safe enum pattern. This way, each and every use of a GetContentFor will be safe: the argument is part of the enum, and the languages type checker performs the check.

    Your test can then easily iterate on the different enum fields, and check they are all declared in your database, very easily.

    Adding a new content key requires editing the enum, but this is a small inconvenient you can live with, as it help a log ensuring all calls are safe.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have been unable to fix a problem with Java Unicode and encoding. The

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.