【问题标题】:Why is the Get method missing from MoqMockingKernel?为什么 MoqMockingKernel 中缺少 Get 方法?
【发布时间】:2014-05-30 23:36:04
【问题描述】:

我在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()

【问题讨论】:

    标签: c# ninject moq


    【解决方案1】:

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

    【讨论】:

    • 谢谢。 .Net 代码示例受到“猜测扩展方法放入哪个随机命名空间”的困扰。
    • 非常感谢,帮我节省了几分钟 :)
    猜你喜欢
    • 1970-01-01
    • 2022-10-02
    • 2022-01-14
    • 1970-01-01
    • 2015-11-14
    • 2020-10-26
    • 2012-08-12
    • 2019-04-29
    • 2020-11-02
    相关资源
    最近更新 更多