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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:35:40+00:00 2026-05-26T16:35:40+00:00

Environment In my solution I have three projects, they are: Web (Asp.net MVC4) Model

  • 0

Environment

In my solution I have three projects, they are:

  1. Web (Asp.net MVC4)
  2. Model (Class library)
  3. Test (Test project)

In Model project have:

Couple = Class

IRepository = Interface-based repository

ICoupleRepository = Interface Repository couple

Implementation repository = CoupleRepository couple

In Test project have:

Fake/CoupleRepository = Fake implementation of Repository couple (inside the folder Fake).
CoupleTest couple class = Test

Behavior

By adding a couple under, need to modify some properties and also add a couple object also add other objects to the database.

I put this logic into the CoupleRepository (not fake) repository in Add method, I set these properties, add the object couple and two other objects.

public class CoupleRepository : ICoupleRepository
{
    public void Add(Couple couple)
    {
        couple.Bride.Gender = Gender.Female;
        couple.Groom.Gender = Gender.Male;
        db.Couples.Add(couple);

        db.Users.Add(new User{ CoupleID = couple.Bride.ID });
        db.Users.Add(new User{ CoupleID = couple.Groom.ID });
        db.SaveChanges();

    }
}

Question

In my test class, CoupleTest, need to test the addition of these users as well, and the modification of the properties.

Create a fake repository for my forehead it will not help me, really need to test code that is in default CoupleRepository.

What is the tip you give me?

Where Mocks and Stubs come in all this?

Where would this logic to save a couple?

I have to test repositories? Perhaps the ideal would be to test the controllers?

Many questions, I know =)


I’m new to TDD and do not know if I’m going in the right direction.

Test the default repository would not be ideal, since it accesses the database.

  • 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-26T16:35:41+00:00Added an answer on May 26, 2026 at 4:35 pm

    Main issue here is that you mix different layers. Repository is a intermediate level between Business Logic and storage. If your case, repository performs actions which are the part of Business logic. That’s why you’re forced to mimic that in your tests.

    In general your entity should be fully constructed prior to saving. Repository should only save it (probably, invoking Validate method, if you need that).

    This code:

    couple.Bride.Gender = Gender.Female;
    couple.Groom.Gender = Gender.Male;
    

    should be moved to Couple business logic (constructor, for example).

    From the more global point of view, with TDD you make mocks around the functionality you want to test. With your current approach you’ll probably have something like IView -> Couple class -> IRepository chain. That means that by mocking those interfaces, you intend to test Couple class (or business logic work in general).

    To test the repository, you need a structure like Couple class -> CoupleRepository -> IDatabaseDriver sequence. By mocking IDatabaseDriver you’ll be able to verify SqlCommands or Queries generated by real implementation of CoupleRepository.

    In that case you’ll write tests like (very simplistic sample):

    var driver = new  MockDatabaseDriver();
    var repo = CoupleRepository(MockDatabaseDriver);
    repo.Add(new Couple());
    Assert.AreEquals("Insert into COUPLES values ('bride', groom')", driver.SqlQueryText);
    

    Here MockDatabaseDriver doesn’t execute queries, just indicates actions performed by repository.

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

Sidebar

Related Questions

I have a solution-file with ASP.NET Web Sites. When I build the solution with
I have a solution with about 10 projects with read-only config. They are web
I have a complex web project template where files can be divided into three
In my current .Net 4.0 solution, I have one project containing a lot of
Environment: Windows 2003 Server (32 bit); IIS6, ASP.NET 2.0 (3.5); 4Gb Ram; 1 Worker
Environment: Team Foundation Server 2005 Visual Studio 2008 I have a reasonably large project
Environment: C# projects, Visual studio 2008, C#, .Net 3.5, MSBuild Objective: Run my own
With VS 2008 I always used Web Deployment Projects to build to three different
I need help in setting up the development environment for .Net based projects. I
I have a solution that uses NServicebus which contains at least 3 projects that

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.