开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜