示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
             }
         }
     }
 }
示例#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);
 }
示例#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);
 }
示例#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));
     }
 }