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); }
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); }
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); }
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); } } } }
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); }
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); }
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)); } }