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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:53:00+00:00 2026-06-12T21:53:00+00:00

I started to use moq but from my understanding I always have to mock

  • 0

I started to use moq but from my understanding I always have to mock up all the methods that could be called even if I really do not care about them.

Sometimes it takes so long to mockup stuff you forget what you want to do. So I been looking at auto mocking but I am not sure what one I should use.

AutoFixture as an auto-mocking container

Automocking

I don’t get how to use the first one at all. I sort of get the second one but never really tried it.

I am not sure if one is better than the other. The only thing I know is I am using AutoFixtures already what is a dependency of the first one.

So maybe in the long run it makes sense to go with the first one but like I said I can’t find any basic tutorials on how to use it.

Edit

I am trying to follow “Nikos Baxevanis” examples but I am running into errors.

Failure: System.ArgumentException : A matching constructor for the given arguments was not found on the mocked type.
  ----> System.MissingMethodException : Constructor on type 'DatabaseProxyded46c36c8524889972231ef23659a72' not found.


var fixture = new Fixture().Customize(new AutoMoqCustomization());
        var fooMock = fixture.Freeze<Mock<IFoo>>();
       // fooMock.Setup(x => x.GetAccounts(It.IsAny<IUnitOfWork>()));
        var sut = fixture.CreateAnonymous<AdminService>();

        sut.Apply();
        fooMock.VerifyAll();

I think it is because of my petapoco unitOfWork property

PetaPoco.Database Db { get; }

Not sure if I got to mock this up somehow or what.

  • 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-06-12T21:53:01+00:00Added an answer on June 12, 2026 at 9:53 pm

    While I have never used moq-contrib Automocking, I could probably provide some information on using AutoFixture as an auto-mocking container.

    Currently there is support for Moq, Rhino Mocks, FakeItEasy, and NSubstitute. Just install the appropriate extension AutoMoq, AutoRhinoMocks, AutoFakeItEasy, and AutoNSubstitute.

    Once you have installed one of the extensions for Auto Mocking the extra call is:

    var fixture = new Fixture()
        .Customize(new AutoMoqCustomization());
    

    (or if you are using Rhino Mocks)

    var fixture = new Fixture()
         .Customize(new AutoRhinoMockCustomization());
    

    (or if you are using FakeItEasy)

    var fixture = new Fixture()
         .Customize(new AutoFakeItEasyCustomization());
    

    (or if you are using NSubstitute)

    var fixture = new Fixture()
         .Customize(new AutoNSubstituteCustomization());
    

    Example 1

    public class MyController : IController
    {
        public MyController(IFoo foo)
        {
        }
    }
    
    public interface IFoo
    {
    }
    

    Here is how to use AutoFixture to create instances of MyController class:

    var fixture = new Fixture()
        .Customize(new AutoMoqCustomization());
    
    var sut = fixture.CreateAnonymous<MyController>();
    

    Now, if you inspect the sut variable you will see the the IFoo is a mocked instance (having a type name similar to Castle.Proxies.IFooProxy).

    Example 2

    This examples extends the previous one.

    You can instruct AutoFixture to use your own, pre-configured, mocked instance:

    var fooMock = fixture.Freeze<Mock<IFoo>>();
    // At this point you may setup expectation(s) on the fooMock.
    
    var sut = fixture.CreateAnonymous<MyController>();
    // This instance now uses the already created fooMock.
    // Verify any expectation(s).
    

    That’s basically it – but it can go further!

    Below are the previous examples using AutoFixture decleratively with the xUnit.net extension.

    Example 1

    [Theory, AutoMoqData]
    public void TestMethod(MyController sut)
    {
        // Start using the sut instance directly.
    }
    

    Example 2

    [Theory, AutoMoqData]
    public void TestMethod([Frozen]Mock<IFoo> fooMock, MyController sut)
    {
       // At this point you may setup expectation(s) on the fooMock.
       // The sut instance now uses the already created fooMock.
       // Verify any expectation(s).
    }
    

    You may find more information on this blog post which contains links to everything related around AutoFixture, xUnit.net, and Auto Mocking.

    Hope that helps.

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

Sidebar

Related Questions

I started to use vim recently, but I miss the character/line selection methods from
I have started to use the simplexml function that seems to work out better
I've started to use GeckoFX but I got a major issue with javascript:void(0) that
I started to use the CommandLine Parser Library for a tool that will have
I have started to use Flying Saucer for creating PDF from JSF files and
I started to use Lex for my homework. In my Lex file, I always
I started to use Borland's Turbo C++ a few days ago. I actually have
recently I started to use XNA with MonoMac. I have problem with classes. I
I have started to use MSpec for BDD, and since long ago I use
I have started using moq for mocking. Can someone explain me the concept of

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.