我想测试一个使用数据字段值呈现文本块的应用程序。渲染完成后,我想获得实际宽度和实际高度。一切正常。当我尝试测试该应用程序时,问题首先出现。我无法从测试项目调用调度程序。
以下是代码。
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。所以,请帮助我。
Thanks
您可能想看看http://www.codeproject.com/KB/WPF/UnitTestDispatcherTimer.aspx http://www.codeproject.com/KB/WPF/UnitTestDispatcherTimer.aspx它涉及一个DispatcherTimer
在 WPF 和 NUnit 中,它们又使用Dispatcher
.
Edit
从链接中尝试在测试之前执行此操作:
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, testMethod);
// Start the worker thread's message pump
Dispatcher.Run(); // This will block until the dispatcher is shutdown
并在测试后停止。
Dispatcher disp = Dispatcher.CurrentDispatcher;
// Kill the worker thread's Dispatcher so that the
// message pump is shut down and the thread can die.
disp.BeginInvokeShutdown(DispatcherPriority.Normal);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)