Implementing mocking objects with Moq when constructor has parameters

Viewed 86652

I have read this answer by Ragzitsu for the same question. I am still confused how to implement things though. Can somebody give me an example of an implementation.

I have the following classes:

class Fizz : IFizz
{
}

class Buzz : IBuzz
{

}

class Bar : IBar
{

}

class Foo : IFoo
{
    public Foo(IBar bar, IFizz fizz, IBuzz buzz)
    {
        //initialize etc.
    }

    //public methods
}

What is the practical way to get around the constructor here? I want to do something like

var foo = new Mock<IFoo>();

In other words how would the code look after the advice

The best thing to do would be right click on your class and choose Extract interface.

7 Answers
Related