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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:07:01+00:00 2026-05-13T06:07:01+00:00

Currently I’m reading a book (Pro ASP.Net Framework). In this book, the author suggests

  • 0

Currently I’m reading a book (Pro ASP.Net Framework).

In this book, the author suggests to use a Moq framework to help to do TDD.

[Test]
public void List_Presents_Correct_Page_Of_Products()
{
    IProductsRepository repository = MockProductsRepository(
        new Product { Name = "P1" }, new Product { Name = "P2" },
        new Product { Name = "P3" }, new Product { Name = "P4" },
        new Product { Name = "P5" }
    );

    ProductsController controller = new ProductsController(repository);
    ...
}


static IProductsRepository MockProductsRepository(params Product[] prods)
{
    // Generate an implementor of IProductsRepository at runtime using Moq
    var mockProductsRepos = new Moq.Mock<IProductsRepository>();
    mockProductsRepos.Setup(x => x.Products).Returns(prods.AsQueryable());
    return mockProductsRepos.Object;
}

In the model layer, we’ve define a FakeRepository, and a SqlRepository.

The fact is I don’t see the advantage of using this moq framework. Why don’t we only use our FakeRepository ? Or clear our FakeRepository and add fake product on it ?

At first, I thought that the moq framework was there to generate fake data so you don’t have to if you have for example 100 fake objects to generate.

What I miss ?

  • 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-13T06:07:02+00:00Added an answer on May 13, 2026 at 6:07 am

    Some advantages of mock frameworks over hand-rolled mocks:

    • The mock behavior is closer to the test code because it is in the test code. This makes tests easier to understand without having to look at other code.
    • You don’t need to create yet another mock class (or worse: add logic to an existing one) just because you want slightly different behavior.
    • You end up writing less boilerplate because you only need to setup the methods you want to mock, while with hand-rolled ones you have to implement the whole interface.

    Some disadvantages:

    • You have to learn a framework, while anyone can write mocks by hand.
    • It is yet another dependency you add to your project.

    (This is what I can think of right now. Feel free to edit and add more.)

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

Sidebar

Related Questions

Currently ASP.NET MVC's OutputCache attribute has a huge downfall. If you want to cache
Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Currently we use jQuery to add RIA goodness to our apps, but recently we
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently I'm prototyping search with Lucene.Net-2.0-004 on a web application. It's working very well,
Currently I am debugging the signing of an Android app. And this would be
Currently, I use an abstract factory to allow the specification of a custom class
I want use html5's new tag to play a wav file (currently only supported
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.

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.