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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:36:58+00:00 2026-05-23T13:36:58+00:00

We’re currently following the DI model using Autofac as an IoC container. We’ve recently

  • 0

We’re currently following the DI model using Autofac as an IoC container.

We’ve recently started looking into mocking frameworks like MOQ and Rhino Mocks. However, we can’t seem to justify their usage over just creating Mock implementation classes for each of our interfaces.

Why do this:

var mock = new Mock<IFoo>();
mock.Setup(foo => foo.DoSomething("ping")).Returns(true);

Instead of this:

class FooMock : IFoo {
  bool DoSomething(string input) {
    return input == "ping";
  }
}
mock = new FooMock();

The latter is more verbose, but seems more flexible and appropriate for complex mocks.

  • 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-23T13:36:59+00:00Added an answer on May 23, 2026 at 1:36 pm

    What you have shown in your example is more of a fake/stub than a true mock and it is true that if you only want pre-canned behaviour from a dependent object then often a fake can be a better choice than using a mocking framework.

    There is a canonical article by Martin Fowler discussing the fact the Mocks aren’t Stubs and I’ve lifted the following paragraph from it:

    The key difference here is how we
    verify that the order did the right
    thing in its interaction with the
    warehouse. With state verification we
    do this by asserts against the
    warehouse’s state. Mocks use behavior
    verification, where we instead check
    to see if the order made the correct
    calls on the warehouse.

    Essentially with mocks you are usually intending to check how your method under test acts upon the dependencies – your mock has expectations and you verify those expectations after the method has run.

    You could of course still write your own case by case mocks but using a framework will save you a lot of time, give more readable tests and save on errors in the tests.

    That is particulaly true as the expectations you have grow more complex, imagine having a method to test which calls a particular dependant class a variable number of times with varying values depending on input parameters – this would be complex to write a mock for yourself, but trivial using a good mocking framework.

    To demonstrate with some code, imagine this PrintOrders method (excuse the silly example):

    public void PrintForeignOrders(List<Orders> orders)
    {
        foreach(var order in orders)
        {
            if (order.IsForeign)
            {
                printer.PrintOrder(order.Number, order.Name);
            }
        }
    }
    

    You would probably want to test at least:

    • When the list is empty nothing is printed
    • When there is a foreign order it is printed
    • When there are two orders both are printed (with the right number and name)

    With a good mocking framework setting up those tests against the injected printer object is just a matter of a few keystrokes.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.