我在 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()
是位于 Ninject.ResolutionExtensions
类中的扩展方法。添加 using Ninject;
解决了这个问题。没有一个示例显示您需要使用哪些 namespace ,这令人沮丧。
关于c# - 为什么 MoqMockingKernel 中缺少 Get 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23964850/