How does the Silverlight testing framework's EnqueueConditional work?
So let's say I have a test that looks something like
[TestMethod]
[Asynchronous]
public void MyTest() {
MyObject m = new MyObject();
m.DoAsyncStuff();
EnqueueConditional(() => m.TaskComplete);
开发者_如何学编程 EnqueueCallback(() => Assert.IsTrue(m.ValidState));
EnqueueTestComplete();
}
How does EnqueueConditional
work? Assume MyObject
has no property change notifiers or anything. I'm assuming EnqueueConditional
polls the variable periodically? But I'm not sure.
That's precisely what it does. It polls the m.TaskComplete
variable multiple times a second (I'm not sure how many). It's a hack, and you wouldn't want it in production code, but it works for a testing framework, and it sure as heck simplifies a lot of other code.
For example, in production code, you'd probably want to make MyObject implement INotifyPropertyChanged, and then use Reactive Extensions to subscribe to the INPC notifications. But that would be a lot of extra work for the sort of simple conditionals that are everywhere in testing code, and I think that Jeff Wilcox made the right call in how he implemented this, however hacky it might be.
精彩评论