public void Requests_ParallelRequests() { var expectedResponse = "Hello World"; var app = new App(); app.AddStaticStringView("/", (c) => expectedResponse); Action InnerTest = () => { var clientThreads = new Thread[10]; for (int i = 0; i < 10; i++) { clientThreads[i] = new Thread(() => { var client = new WebClient(); var actualResponse = client.DownloadString(TestUtils.AppPrefix); Assert.AreEqual(expectedResponse, actualResponse); }); } for (int i = 0; i < 10; i++) clientThreads[i].Start(); for (int i = 0; i < 10; i++) clientThreads[i].Join(); }; // First, test without async request processing app.EnableAsyncProcessing = false; TestUtils.AppTest(app, InnerTest); app.EnableAsyncProcessing = true; TestUtils.AppTest(app, InnerTest); }
public void Requests_SimpleRequest() { var expectedResponse = "Hello World"; var app = new App(); app.AddStaticStringView("/", (c) => expectedResponse); TestUtils.AppTest(app, () => { var client = new WebClient(); var actualResponse = client.DownloadString(TestUtils.AppPrefix); Assert.AreEqual(expectedResponse, actualResponse); }); }
public void UrlPatterns_ConstUrls() { // Generate many random strings and make sure they work correctly with the app.AddUrl view. var urls = new Dictionary<string, int>(); var app = new App(); for (int i = 0; i < 100; i++) { var randomString = TestUtils.GenerateRandomURL(100); if (!urls.ContainsKey(randomString)) { int response = i; urls[randomString] = response; app.AddStaticStringView(randomString, (c) => response.ToString()); } } TestUtils.AppTest(app, () => { var client = new WebClient(); foreach (var url in urls.Keys) { var expectedResult = urls[url].ToString(); string result = null; try { result = client.DownloadString(TestUtils.AppPrefix + url); } catch(WebException webException) { throw new WebException($"Failure on URL '{TestUtils.AppPrefix + url}': {webException.Message}", webException); } Assert.AreEqual(expectedResult, result); } }); }