tags:

views:

28

answers:

1

I have a class that takes in a db factory.

public class ArticleManager
{
     private IDAOFactor _factory;

     public ArticleManager(IDAOFactory factory)
      {
            this._factory = factory;
       }

}

Using moq, how do I create an instance of ArticleManager?

I tried:

var mockFactory = new Mock<IDAOFactory>();
ArticleManager am = new ArticleManager(mockFactory);

But that isn't compiling.

+1  A: 

mockFactory is a proxy class for moq. To expose the ArticleManager object instance within the mock, you'd use mockFactory.Object like so:

var mockFactory = new Mock<IDAOFactory>();
ArticleManager am = new ArticleManager(mockFactory.Object);
zulkamal