我需要为我们的应用程序运行集成/回归测试套件,并且应用程序应该在一天中的不同时间表现不同。我无法更改系统时间,因为其他应用程序依赖它我想为此模拟 DateTime.Now。但是,当我将模拟放在 main 方法中时,抛出了异常。当我在同一应用程序的 nunit 测试中使用模拟时,它工作正常。typemock 只能在单元测试的上下文中使用吗?无论如何我可以在启用模拟的情况下运行解决方案吗?我也通过 TMockRunner.exe 运行了解决方案,但遇到了同样的问题。
谢谢!
当我使用 Travis 提到的 @Travis Illig 的方法运行时,我看到了这个错误,包装器的代码是:
class Program
{
static void Main(string[] args)
{
ExpectationsSetup();
ConsoleApplication2.Program.Main(args);
}
public static void ExpectationsSetup()
{
Isolate.WhenCalled(() => DateTime.Now).WillReturn(new DateTime(2010, 1, 2));
}
}
I see the following error:
Unhandled Exception: TypeMock.TypeMockException:
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake an unsupported mscorlib type? See supported types
here: http://www.typemock.com/mscorlib-types
at gt.a(c0 A_0, Boolean A_1)
at bg.a(Boolean A_0)
at dt.b(Boolean A_0)
at i2.b(Boolean A_0)
at i2.a(Object A_0, Boolean A_1, Func`1 A_2, Action A_3, Action A_4, Action A
_5, Boolean A_6)
at i2.b(Object A_0)
at TypeMock.ArrangeActAssert.ExpectationEngine`1.a(TResult A_0)
at ConsoleApplication2Mock.Program.ExpectationsSetup() in C:\Users\shvenkat\D
ocuments\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication2Mock
\Program.cs:line 22
at ConsoleApplication2Mock.Program.Main(String[] args) in C:\Users\shvenkat\D
ocuments\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication2Mock
\Program.cs:line 14
任何帮助将不胜感激谢谢!