更新时间:2023-11-20 15:43:04
您的控件相关代码需要在 UI 线程上运行.试试:
Your controls related code needs to be run on a UI thread. Try:
[TestMethod]
async public Task CreateThumbnail_EmptyLayout_ReturnsEmptyGrid()
{
int count = 0;
await ExecuteOnUIThread(() =>
{
Layout l = new Layout();
ThumbnailCreator creator = new ThumbnailCreator();
Grid grid = creator.CreateThumbnail(l, 192, 120);
count = grid.Children.Count;
});
Assert.AreEqual(count, 0);
}
public static IAsyncAction ExecuteOnUIThread(Windows.UI.Core.DispatchedHandler action)
{
return Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, action);
}
以上内容应该适用于 MS Test.我不知道 NUnit.
The above should work on MS Test. I don't know about NUnit.