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

  • Home
  • SEARCH
  • 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 6694469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:06:19+00:00 2026-05-26T06:06:19+00:00

Quick Info: I’m using C# 4.0 and RhinoMocks (with AAA) I’ll explain with some

  • 0

Quick Info: I’m using C# 4.0 and RhinoMocks (with AAA)

I’ll explain with some code what I’m thinking about doing:

public class SampleData
{
    private List<Person> _persons = new List<Person>()
    {
         new Person { PersonID = 1, Name = "Jack"},
         new Person { PersonID = 2, Name = "John"}
    };

    public List<Person> Persons
    {
        get { return _persons; }
    }
}

So this is a class which mimics data in the DB. Now I want to use this data in my unit tests. In other words, instead of getting data out of the DB, I want to get them out of the datarepository.

I think I can achieve this by stubbing the Repository and by making it use the DataRepository instead:

UC1003_ConsultantsBeherenBL consultantsBeherenBL = new UC1003_ConsultantsBeherenBL();

consultantsBeherenBL = MockRepository.GeneratePartialMock<UC1003_ConsultantsBeherenBL>();
consultantsBeherenBL.Repository = MockRepository.GenerateMock<IRepository>();

This would cause my code to automaticly look for data in the DataRepository instead. So instead of stubbing a method and directly inserting a list (e.g. d => d.Find(Arg.Is.Anything)).IgnoreArguments().Return(a list which you just filled up)) I’d get “real” data back (the data which has been filtered from the DataRepository). This means I can test if my code can really find something, without having to insert test data in my DB (integration test).

How would I go about implementing such a thing? I’ve tried looking on the web for articles or questions, but I can’t seem to find a lot :/

Any help is appreciated.

EDIT: I’ve tried to SimpleInjector and StructureMap, but I’m stuck implementing one of them.

I’m currently using a repository on my entity framework, so my baseBL looks like this (note: all my other BL’s enherit from this one):

public class BaseBL
{
    private IRepository _repository;

    public IRepository Repository
    {
        get
        {
            if (_repository == null)
                _repository = new Repository(new DetacheringenEntities());
            return _repository;
        }
        set { _repository = value; }
    }

    public IEnumerable<T> GetAll<T>()
    {
    ... --> Generic methods

My Repository class:

public class Repository : BaseRepository, IRepository
{
    #region Base Implementation

    private bool _disposed;

    public Repository(DetacheringenEntities context)
    {
        this._context = context;
        this._contextReused = true;
    }

    #endregion

    #region IRepository Members

    public int Add<T>(T entity)
    ... --> implementations of generic methods

As far as I can make out, I now need to be able to say in my tests that instead of using the DetacheringenEntities, I need to use my DataRepository. I don’t understand how I switch out my entity framework with a data class, because that data class won’t fit in there.

Should I let my DataRepository enherit my IRepository class and make my own implementations?

public class SampleData : IRepository

But I can’t do things like this with my lists :/

    public IEnumerable<T> GetAll<T>()
    {
        return Repository.GetAll<T>();
    }

Big thanks again for help

EDIT: I realised that a unit test doesn’t need a data repository, so I’m just testing that logic in an integration test. This makes a data repository useless, since the code can be tested without a repository.
I’d like to thank everybody for their help though, thanks 🙂

  • 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-26T06:06:20+00:00Added an answer on May 26, 2026 at 6:06 am

    Use a Dependency injection framework to handle your dependencies. In your unit test you can swap the real implementation with a stubbed one.

    In StructureMap for example, you’ll say in your code. “All right, now give me the active instance of IDataRepository“, for your normal code this would point to an implementation to the real database. In your unittest you can then overwrite this by putting ObjectFactory.Inject(new FakeDataRepository()). The fake repo is then used by all your code, which makes it really easy to test a single unit of work.Í

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

Sidebar

Related Questions

a quick, simple question from me about for-loops. Situation I'm currently writing some high-performance
Quick question regarding CSS and the browser. I tried searching SO and found some
Take a look at this fiddle . Quick info: The div is 500px wide
I'm pulling some info from a database then putting it into a DIV and
Quick background info: of the three database tables that are relevant for this question,
I have a quick question about a preg_replace problem I have. I am just
Hi guys i have quick question, So i have uset UIViewController to push some
I have a quick Matlab question. In the code below, I am dividing two
i was in the process of doing a fun project gathering music info/playable links
I know about perlop. What I am looking for is a quick lookup like

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.