private async Task <object> DownloadContent(ReportResponse response) { var result = default(object); response.OnDownloadSuccess = new ReportResponse.OnDownloadSuccessCallback((bytes) => result = Encoding.UTF8.GetString(bytes)); response.OnFailed = new ReportResponse.OnFailedCallback((ex) => result = ex.Message); var task = Task.Run(async() => { while (result == null) { await Task.Delay(1000); } return(result); }); response.DownloadAsync(); return(await task); }
public void TestDownloadAsync() { Boolean success = false; ManualResetEvent waiter = new ManualResetEvent(false); ReportResponse response = new ReportResponse(webResponse); byte[] contents = null; response.OnDownloadSuccess = ret => { contents = ret; success = true; waiter.Set(); }; response.OnFailed = e => waiter.Set(); response.DownloadAsync(); waiter.WaitOne(); Assert.IsTrue(success, "DownloadAsync triggered OnFailed"); this.AssertContentsAreEqual(contents); }