我不熟悉FakeItEasy和一般的嘲弄。我创建了一个Visual Studio 2010 c#类库项目。我添加了对NUnit DLL和FakeItEasy DLL的引用。我为两者都添加了"using"语句,然后尝试了一些文档示例。我的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FakeItEasy.Core;
// ...
using NUnit.Framework;
namespace TestLib
{
[TestFixture]
public class Tester
{
[Test]
public void SomeTest()
{
ISomething mockThing = A.Fake<ISomething>();
/*
...
*/
}
}
}
我得到错误"类型或命名空间名称' issomething '找不到"和"名称'A'在当前上下文中不存在"。
我错过了什么?
事实证明,创建模拟中引用的接口是必要的。它们不是自动生成的。
但是可以指定要实现的其他接口:
var foo = A.Fake<IFoo>(x => x.Implements(typeof(IComparable)).Implements(typeof(IFormattable)));