This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public async Task TestLocationSearchHasResult() | |
{ | |
var testVm = new GeocodeViewModel { SearchText = "Springerstraat Amersfoort Netherlands" }; | |
await Deployment.Current.Dispatcher.InvokeTaskAsync(() => testVm.SearchLocation()); | |
Assert.IsTrue(testVm.MapLocations.Any()); | |
} | |
public static class DispatcherExtensions | |
{ | |
public static Task<T> InvokeTaskAsync<T>(this Dispatcher dispatcher, Func<Task<T>> func) | |
{ | |
var tcs = new TaskCompletionSource<T>(); | |
dispatcher.BeginInvoke(new Action(async () =>{ | |
try | |
{ | |
var result = await func(); | |
tcs.SetResult(result); | |
} | |
catch (Exception e) | |
{ | |
tcs.SetException(e); | |
} | |
})); | |
return tcs.Task; | |
} | |
public static Task<T> InvokeAsync<T>(this Dispatcher dispatcher, Func<T> func) | |
{ | |
var tcs = new TaskCompletionSource<T>(); | |
dispatcher.BeginInvoke(new Action(()=>{ | |
try | |
{ | |
var result = func(); | |
tcs.SetResult(result); | |
} | |
catch (Exception e) | |
{ | |
tcs.SetException(e); | |
} | |
})); | |
return tcs.Task; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment