Exemplo n.º 1
0
 public void eventSourceIsInEnvironmentDict()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     var response = testServerGet(app.noEvents, request);
     Assert.IsTrue(response.IsSuccessStatusCode);
     Assert.AreEqual(app.responseBody, response.Content.ReadAsStringAsync().Result);
 }
Exemplo n.º 2
0
 public void normalResponseBodyIsReturnedThroughMiddleware()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     var response = testServerGet(app.noEvents, request);
     Assert.IsTrue(response.IsSuccessStatusCode);
     Assert.AreEqual(app.responseBody, response.Content.ReadAsStringAsync().Result);
 }
Exemplo n.º 3
0
 public void headersAreSetIfStreamIsWritten()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     var response = testServerGet(app.openStreamAndWrite, request, true);
     Assert.IsTrue(response.IsSuccessStatusCode);
     var ct = response.Content.Headers.ContentType.ToString();
     Assert.AreEqual("text/event-stream", ct);
 }
Exemplo n.º 4
0
 public void writeAfterReturnWorks()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     using (var server = TestServer.Create(app.openStreamReturnAndWrite)) {
         var client = server.HttpClient;
         var response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result;
         Assert.IsTrue(response.IsSuccessStatusCode);
         using (var events = response.Content.ReadAsStreamAsync().Result) {
             using (var reader = new StreamReader(events)) {
                 var line = reader.ReadLine();
                 Assert.AreEqual(app.responseBody, line);
             }
         }
     }
 }
Exemplo n.º 5
0
 public void onCloseGetsCalledOnceWhenServerClosesAfterReturn()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     var response = testServerGet(app.openStreamAndWrite, request, true);
     app.stream.Close();
     Assert.AreEqual(1, app.onCloseCalledCount);
 }
Exemplo n.º 6
0
 public void onCloseGetsCalledOnceWhenServerClosesImmediately()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     var response = testServerGet(app.openClose, request, true);
     Assert.AreEqual(1, app.onCloseCalledCount);
 }
Exemplo n.º 7
0
 public void onCloseGetsCalledOnceClientDisconnects()
 {
     var app = new EventTestApp();
     var request = new HttpRequestMessage(HttpMethod.Get, "http://xyz.com/");
     using (var server = TestServer.Create(app.openStream)) {
         var client = server.HttpClient;
         var writeDelay = app.writeDelayMilliseconds;
         client.Timeout = new TimeSpan(0, 0, 0, 0, writeDelay/2);
         var response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
             .ContinueWith(_ => Assert.AreEqual(1, app.onCloseCalledCount));
     }
 }