Windows ストア アプリを作成していますが、グリッド (XAML コントロール) を作成するメソッドをテストする際にスレッドの問題があります。NUnit と MSTest を使用してテストしようとしました。
テスト方法は次のとおりです。
[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))