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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:44:45+00:00 2026-05-10T14:44:45+00:00

I have been making a little toy web application in C# along the lines

  • 0

I have been making a little toy web application in C# along the lines of Rob Connery’s Asp.net MVC storefront.

I find that I have a repository interface, call it IFooRepository, with methods, say

IQueryable<Foo> GetFoo(); void PersistFoo(Foo foo); 

And I have three implementations of this: ISqlFooRepository, IFileFooRepostory, and IMockFooRepository.

I also have some test cases. What I would like to do, and haven’t worked out how to do yet, is to run the same test cases against each of these three implementations, and have a green tick for each test pass on each interface type.

e.g.

[TestMethod] Public void GetFoo_NotNull_Test() {    IFooRepository repository = GetRepository();    var results = repository. GetFoo();    Assert.IsNotNull(results); } 

I want this test method to be run three times, with some variation in the environment that allows it to get three different kinds of repository. At present I have three cut-and-pasted test classes that differ only in the implementation of the private helper method IFooRepository GetRepository(); Obviously, this is smelly.

However, I cannot just remove duplication by consolidating the cut and pasted methods, since they need to be present, public and marked as test for the test to run.

I am using the Microsoft testing framework, and would prefer to stay with it if I can. But a suggestion of how to do this in, say, MBUnit would also be of some interest.

  • 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. 2026-05-10T14:44:46+00:00Added an answer on May 10, 2026 at 2:44 pm

    Create an abstract class that contains concrete versions of the tests and an abstract GetRepository method which returns IFooRepository. Create three classes that derive from the abstract class, each of which implements GetRepository in a way that returns the appropriate IFooRepository implementation. Add all three classes to your test suite, and you’re ready to go.

    To be able to selectively run the tests for some providers and not others, consider using the MbUnit ‘[FixtureCategory]’ attribute to categorise your tests – suggested categories are ‘quick’ ‘slow’ ‘db’ ‘important’ and ‘unimportant’ (The last two are jokes – honest!)

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

Sidebar

Related Questions

I am making an MVC 3 web application in asp.net. It is supposed to
We have an ASP.Net Web Application that is running in an IIS Web-Garden--which is
For some time i have been making more or less little games. One level
I've been studying and making little games for a while, and I have decided
I have a PHP web application where I've made a little module system, that
I'm pretty new to web development. Lately I have been making a site using
I have been making a little program that needs to read a list of
I have been making some research in the domain of servers for a website
I have been using the Rails console a fair bit lately and its making
I am making a game that needs a crosshair. I have been playing with

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.