Код: Выделить всё
private async void DoStuff(long idToLookUp)
{
IOrder order = await orderService.LookUpIdAsync(idToLookUp);
// Close the search
IsSearchShowing = false;
}
//Other stuff in case you want to see it
public DelegateCommand DoLookupCommand{ get; set; }
ViewModel()
{
DoLookupCommand= new DelegateCommand(DoStuff);
}
Код: Выделить всё
[TestMethod]
public void TestDoStuff()
{
//+ Arrange
myViewModel.IsSearchShowing = true;
// container is my Unity container and it setup in the init method.
container.Resolve().Returns(orderService);
orderService = Substitute.For();
orderService.LookUpIdAsync(Arg.Any())
.Returns(new Task(() => null));
//+ Act
myViewModel.DoLookupCommand.Execute(0);
//+ Assert
myViewModel.IsSearchShowing.Should().BeFalse();
}
Я перехожу на Async/Await с помощью BackgroundWorker. С фоновым работником это работало правильно, потому что я мог дождаться завершения работы BackgroundWorker.
Но, похоже, нет способа дождаться асинхронного метода void. .
Как я могу протестировать этот метод?
Подробнее здесь: https://stackoverflow.com/questions/142 ... it-testing
Мобильная версия