简体   繁体   English

在单元测试中设置 AutoResetEvent.WaitOne() 的方法

[英]A way to set AutoResetEvent.WaitOne() in a unit test

I am writing a unit test for some code that another developer wrote.我正在为另一个开发人员编写的某些代码编写单元测试。 At one point the developer used a bool statement for WaitOne().有一次,开发人员对 WaitOne() 使用了 bool 语句。 He set up the defaults to be false, is there way to set WaitOne() to be true for the unit test?他将默认值设置为 false,有没有办法在单元测试中将 WaitOne() 设置为 true? From what I have read about WaitOne it has to do with threads and I am just trying to write a simple unit test first to make sure what was written works?从我对 WaitOne 的了解来看,它与线程有关,我只是想先编写一个简单的单元测试以确保编写的内容有效? Does anyone know of a way in the unit test I can set WaitOne to true?有谁知道在单元测试中我可以将 WaitOne 设置为 true 的方法吗? I looked at the documentation at http://msdn.microsoft.com/en-us/library/cc190477.aspx .我查看了http://msdn.microsoft.com/en-us/library/cc190477.aspx上的文档。 It mentioned that when it receives a signal it will be true.它提到当它接收到一个信号时它会是真的。 Can and how would I use the unit test to send the signal我可以以及如何使用单元测试来发送信号

The docs are vague about this issue.文档对这个问题含糊不清。 WaitOne returns true if it returns due to the WaitHandle being signaled as opposed to being in a timeout situation.如果WaitOne由于WaitHandle被通知而不是处于超时情况而返回,则返回true。

I have confirmed this with Reflector.我已经通过 Reflector 确认了这一点。 See http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx and method InternalWaitOne .请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx和方法InternalWaitOne

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM