c# - How to test an async void method -
Please consider the code as shown below. By calling GetBrands, property brands will be assigned with appropriate data.
Public class brands view models: seeModelBase {Private IEnumerable & lt; Brand & gt; _brands; Public IEnumerable & lt; Brand & gt; Find Brand ({return _ Brands;} set {SetProperty (Ref _brands, value);}} public void Async GetBrands () {// ...... Brands = Wait _dataHelper.GetFavoriteBrands (); //. .....}} but if I think it's shown below, the test failed. how do I wait for async calls under GetBrands method? < pre> [TestMethod] public void AllBrandsTest () {BrandsViewModel viewModel = New BrandsViewModel (); viewModel.GetBrands (); Assert.IsTrue (viewModel.Brands.Any ());}
here The simple answer is: it in async not create null . Actually, never some async null is not created until it is fully event does not work as -handlr. things that async null are lost OK are the things that you want it for your test (And possibly for your actual code). async job method, and now you have complete (with expiration) / continuous There is the ability to wait to add a hint, and to check whether it exits with success or exception or not. This is a word change:
Public async Task GetBrands () {// ...... Brands = Wait _dataHelper.GetFavoriteBrands (); // ......} and then test:
[TestMethod] public async Task AllBrandsTest () {Brands Drisyamodl Modlmodel = new BrandsViewModel (); Var function = viewModel. Gatebrand (); Confirm. True (task.Wait (YOUR_TIMEOUT), "failed to load in time"); Claim it. ITRTU (see model no. Brand, "no brand"); }
Comments
Post a Comment