2009-12-18 90 views
0

我有一個需要在db工廠的類。幫助使用Moq

public class ArticleManager 
{ 
    private IDAOFactor _factory; 

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

} 

使用moq,如何創建ArticleManager的實例?

我想:

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

但不是編譯。

+0

IDAOFactory在VAR mockFactory作爲接口decalred,但我沒有看到它的任何地方聲明(除非你忽略它)。 – 2009-12-18 01:29:32

回答

1

mockFactory是moq的代理類。爲了模擬中暴露ArticleManager對象實例,你會使用mockFactory.Object像這樣:

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