Please consider the code as shown below. By calling GetBrands, property Brands will be assigned with proper data.
public class BrandsViewModel : ViewModelBase { private IEnumerable<Brand> _brands; public IEnumerable<Brand> Brands { get { return _brands; } set { SetProperty(ref _brands, value); } } public async void GetBrands() { // ...... Brands = await _dataHelper.GetFavoriteBrands(); // ...... } } But if I test it as shown below, the test failed. How do I wait for the async call inside method GetBrands?
[TestMethod] public void AllBrandsTest() { BrandsViewModel viewModel = new BrandsViewModel(); viewModel.GetBrands(); Assert.IsTrue(viewModel.Brands.Any()); }
async voidexcept for event handlers.