【发布时间】:2016-10-13 17:45:00
【问题描述】:
我一直在阅读 MSDN 上的 Actions 和 Lambda 表达式,但我仍然缺少一些东西。我有以下公开课。
public class ExitChecker
{
public Action EnvironmentExitAction { get; set; }
public ExitChecker(string[] args)
{
if (string.Compare(args[0], "-help", true) == 0)
{
EnvironmentExitAction = () => Environment.Exit(0);
}
}
}
我有以下测试类。
[TestFixture]
public class AVSRunnerConsoleAppTests
{
[Test]
public void TestConsoleAppWithHelpArg()
{
string[] args = new string[1] { "-help" };
ExitChecker exitchecker = new ExitChecker(args);
bool exitZeroOccured = false;
exitchecker.EnvironmentExitAction = () => exitZeroOccured = true;
Assert.That(exitZeroOccured, Is.True);
}
}
我试图在没有实际调用 Environment.Exit 的情况下测试 Environment.Exit。一切似乎都可以编译和运行,但我似乎无法将 Lambda 表达式中的 exitZeroOccured 更改为 true。有人可以指出我正确的方向吗?
【问题讨论】:
标签: c# testing lambda nunit action