public void TestGetStream() {
      ReportResponse response = new ReportResponse(webResponse);

      using (MemoryStream stream = new MemoryStream())
      using (StreamWriter writer = new StreamWriter(stream)) {
        writer.Write(FILE_CONTENTS);
        writer.Flush();
        stream.Position = 0;

        FileAssert.AreEqual(stream, response.Stream, "Streams do not match");
      }
    }
示例#2
0
 /// <summary>
 /// Gets the report download response asynchronously.
 /// </summary>
 public void GetResponseAsync()
 {
     asyncThread = new Thread(new ThreadStart(delegate() {
         try {
             ReportResponse response = GetResponse();
             if (onReady != null)
             {
                 onReady(response);
             }
         } catch (AdsReportsException e) {
             if (onFailed != null)
             {
                 onFailed(e);
             }
             else
             {
                 throw;
             }
         }
     }));
     asyncThread.Start();
 }
    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);
    }
 public void TestDownload() {
   ReportResponse response = new ReportResponse(webResponse);
   this.AssertContentsAreEqual(response.Download());
 }
 private void AssertSaveWasSuccessful(string fileName, ReportResponse response) {
   Assert.AreEqual(fileName, response.Path);
   using (StreamReader reader = new StreamReader(fileName)) {
     Assert.AreEqual(FILE_CONTENTS, reader.ReadToEnd(), "File contents do not match");
   }
 }
    public void TestSaveAsync() {
      Boolean success = false;
      ManualResetEvent waiter = new ManualResetEvent(false);
      ReportResponse response = new ReportResponse(webResponse);

      response.OnSaveSuccess = () => {
        success = true;
        waiter.Set();
      };

      response.OnFailed = e => waiter.Set();

      String fileName = Path.GetTempFileName();
      response.SaveAsync(fileName);
      waiter.WaitOne();

      Assert.IsTrue(success, "SaveAsync triggered OnFailed.");
      this.AssertSaveWasSuccessful(fileName, response);
    }
    public void TestSave() {
      ReportResponse response = new ReportResponse(webResponse);

      String fileName = Path.GetTempFileName();
      response.Save(fileName);

      this.AssertSaveWasSuccessful(fileName, response);
    }