public static AppDelegate App() { return (env, result, fault) => { var request = new Request(env); var response = new Response(result); if (request.Path == "/") { response.Status = "200 OK"; response.ContentType = "text/html"; response.Start(() => { response.Write("<h1>Sample.App</h1>"); response.Write("<p><a href='{0}/wilson/'>Wilson</a></p>", request.PathBase); response.Write("<p><a href='{0}/wilsonasync/'>Wilson (async)</a></p>", request.PathBase); response.Write("<p><a href='{0}/nancy/'>Nancy</a></p>", request.PathBase); response.Write("<p><a href='{0}/fileupload'>File Upload</a></p>", request.PathBase); response.End(); }); } else { NotFound.Call(env, result, fault); } }; }
private static async Task<Response> ExecuteCore(IEdgePage page, Request request, ITrace tracer) { Response resp = new Response(200); resp.Start(); await page.Run(request, resp); resp.End(); return resp; }
private ResultParameters HandleException(Exception ex) { // Run the adapters ErrorSummary details = null; foreach (IExceptionAnalyzer analyzer in Analyzers) { details = analyzer.Analyze(ex); if (details != null) { break; } } if (details == null) { details = GenerateNoProcessorsError(ex); } // Generate the HTML ErrorPageBuilder builder = new ErrorPageBuilder(details); Response resp = new Response(details.StatusCode); resp.Start(); resp.ReasonPhrase = details.ReasonPhrase; resp.ContentType = "text/html"; StringBuilder sb = new StringBuilder(); using (StringWriter w = new StringWriter(sb)) { builder.Write(w); } resp.Write(sb.ToString()); resp.End(); return resp.GetResultAsync().Result; //Good idea? Probably not... }
public async Task ReturnsResultOfCallingExecutorIfAllPhasesSucceed() { // Arrange var app = CreateEdgeApp(); var appDel = app.Start(); var testFile = app.TestFileSystem.AddTestFile("Bar.cshtml", "Flarg"); Type compiled = typeof(EdgeApplicationFacts); Mock<IEdgePage> page = new Mock<IEdgePage>(); Response resp = new Response(418) { ReasonPhrase = "I'm a teapot" }; resp.Start(); app.MockCompilationManager .Setup(c => c.Compile(testFile, It.IsAny<ITrace>())) .Returns(Task.FromResult(CompilationResult.Successful(null, compiled, Enumerable.Empty<CompilationMessage>()))); app.MockActivator .Setup(a => a.ActivatePage(compiled, It.IsAny<ITrace>())) .Returns(ActivationResult.Successful(page.Object)); app.MockExecutor .Setup(e => e.Execute(page.Object, It.IsAny<Request>(), It.IsAny<ITrace>())) .Returns(Task.FromResult(resp)); // Act var result = await appDel(TestData.CreateCallParams(path: "/Bar")); // Assert Assert.Equal(418, result.Status); Assert.Equal("I'm a teapot", result.Properties["owin.ReasonPhrase"]); }