问题描述
我有以下代码片段:
[Test]
public void ValidCancel_ReturnsSuccess()
{
// TODO:重写此操作以真正检查取消
bool取消;
var message =
new MessageHubCancellableGenericMessage< string>(this," Test",()=> cancel = true);
Assert.IsNotNull(message.Sender);
Assert.IsNotNull(message.Content);
}
// TODO: Rewrite this action to really check the cancel bool cancel; var message = new MessageHubCancellableGenericMessage<string>(this, "Test", () => cancel = true ); Assert.IsNotNull(message.Sender); Assert.IsNotNull(message.Content);}
我正在传递 动作  ; as
我在设置变量的参数 cancel as true ,
但是我需要检查值是否更改为 true ( Assert.IsTrue(cancel) ),
但是当我这样做时,值为 false 。是否可以检查变量的变化 取消?
I'm passing an Action as an argument where I'm setting the variable cancel as true, but I need to check if the value was changed to true (an Assert.IsTrue(cancel)), but when I do that the value is false. Is it possible to check the change of the variable cancel?
推荐答案
您要进行单元测试的程序类型是什么?Wpf,Winform或其他。您的问题与单元测试更相关,我会将该线程移至
Visual Studio单元测试论坛,以获得合适的支持。
What type of program you want to unit test? Wpf, Winform or others. And your question is more related to unit test, I will move the thread toVisual Studio Unit Testing forum for suitable support.
如果您在使用c#时遇到语法或代码错误,请随时与我们联系。我们会尽力为您提供解决方案。
If you have some grammar or code errors in using c#, please feel free to contact us. We will try our best to give you a solution.
最好的问候,
Neil Hu
这篇关于在Action中检查值已更改(单元测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!