7
我一直在创建一个Windows应用商店应用程序,但我有线程问题测试创建一个网格(这是一个XAML控件)的方法。 我试过使用NUnit和MSTest进行测试。单元测试Windows 8商店应用程序用户界面(Xaml控件)
的测试方法是:
[TestMethod]
public void CreateThumbnail_EmptyLayout_ReturnsEmptyGrid()
{
Layout l = new Layout();
ThumbnailCreator creator = new ThumbnailCreator();
Grid grid = creator.CreateThumbnail(l, 192, 120);
int count = grid.Children.Count;
Assert.AreEqual(count, 0);
}
而creator.CreateThumbnail(这引发错误的方法):
public Grid CreateThumbnail(Layout l, double totalWidth, double totalHeight)
{
Grid newGrid = new Grid();
newGrid.Width = totalWidth;
newGrid.Height = totalHeight;
SolidColorBrush backGroundBrush = new SolidColorBrush(BackgroundColor);
newGrid.Background = backGroundBrush;
newGrid.Tag = l;
return newGrid;
}
当运行该测试它引发此错误:
System.Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
非常感谢。 它适用于MS Test。在NUnit中它不起作用。 –