为什么MoqMockingKernel中缺少Get方法?

时间:2014-05-30 23:36:04

标签: c# ninject moq

我在example from the wiki之后使用MoqMockingKernel,但缺少Get()方法。我的简化代码:

using Moq;
using Ninject.MockingKernel.Moq;

namespace Store.Web.Tests.Controllers
{
    [TestClass]
    public class PeopleControllerTests
    {
        private MoqMockingKernel _mockingKernel;        

        [TestInitialize]
        public void SetUp()
        {
            _mockingKernel = new MoqMockingKernel();            
        }

        [TestMethod]
        public void AddAnotherPersonAddsAnotherPerson()
        {
            // There is no Get method on _mockingKernel
            var peopleController = _mockingKernel.Get<PeopleController>();                      
        }
    }
}

我在这里做错了什么?它有GetHashCode()GetMock()GetModules()GetType(),但没有Get()

1 个答案:

答案 0 :(得分:7)

终于明白了。 Get()是一种存在于Ninject.ResolutionExtensions类中的扩展方法。添加using Ninject;解决了这个问题。这些示例都没有显示您需要使用哪些名称空间令人沮丧。

相关问题