如何调用WPF调度员在NUnit的? [英] How to invoke WPF Dispatcher in Nunit?
问题描述
我要测试这使得与数据字段值的文本块的应用程序。我想获得的实际宽度和实际高度,一旦呈现完成。一切工作正常。问题就来了第一次,当我试图测试应用程序。我无法从调用测试项目调度。
I want to test an application which renders a text block with a data field value. I would like to get the actual width and actual height, once the rendering completes. Everything works fine. The problem came first, when I tried to test the application. I'm unable to invoke the dispatcher from the test project.
以下是代码。
this.Loaded += (s, e) =>
{
TextBlock textBlock1 = new TextBlock();
//// Text block value is assigned from data base field.
textBlock1.Text = strValueFromDataBaseField;
//// Setting the wrap behavior.
textBlock1.TextWrapping = TextWrapping.WrapWithOverflow;
//// Adding the text block to the layout canvas.
this.layoutCanvas.Children.Add(textBlock1);
this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
(Action)(() =>
{
//// After rendering the text block with the data base field value. Measuring the actual width and height.
this.TextBlockActualWidth = textBlock1.ActualWidth;
this.TextBlockActualHeight = textBlock1.ActualHeight;
//// Other calculations based on the actual widht and actual height.
}
));
};
我刚刚使用NUnit的开始。所以,请帮助我。
I've just started using the NUnit. So, please help me.
感谢
推荐答案
我的天堂 t一起使用NUnit的编写前的单元测试,但是这是在VS单元测试的常见问题。有什么可以最终发生的是每个测试使用不同的调度和WPF要求使用同样的调度。为了解决这个问题,创建一个静态类缓存调度,然后通过它调用了一切。
I haven't used nUnit to write unit tests before, but this is a common problem with VS unit tests. What can end up happening is that each test uses a different dispatcher and WPF requires you to use the same dispatcher. To get around this, create a static class to cache the Dispatcher and then invoke everything through it.
这篇关于如何调用WPF调度员在NUnit的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!