我想測試一個呈現帶有數據字段值的文本塊的應用程序。一旦渲染完成,我想獲得實際寬度和實際高度。一切正常。當我嘗試測試應用程序時,問題首先出現。我無法從測試項目調用調度程序。如何在Nunit中調用WPF調度程序?
以下是驗證碼。
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。所以,請幫助我。
感謝
準確地說,我在找什麼。謝謝史蒂文太棒了:) – 2010-06-10 07:04:08