public void Newlines_seperate_directives() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse(@"Load TestName Load TestTwo"); AssertLoadNames(loader, "TestName", "TestTwo"); }
public void Builder_should_call_and_return_single_app() { FnApp app = (env, fault, result) => { }; var builder = new Builder(); builder.Run(app); var app2 = builder.ToApp(); Assert.That(app2, Is.SameAs(app)); }
public void Run_directive_calls_app_factory() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse(@" Load TestName Run TestApp "); var app = builder.ToApp(); Assert.That(app, Is.SameAs(TestApp.Singleton)); }
public void Leading_and_trailing_newlines_ignored() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse(@" Load TestName Load TestTwo "); AssertLoadNames(loader, "TestName", "TestTwo"); }
void IHttpModule.Init(HttpApplication context) { var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; var lines = File.ReadLines(Path.Combine(applicationBase, "config.taco")); var builder = new Builder(); builder.ParseLines(lines); var app = builder.ToApp(); var standardError = Console.OpenStandardError(); //TODO: correct place for default output? context.AddOnBeginRequestAsync( (sender, e, callback, state) => { var httpApplication = (HttpApplication)sender; var httpContext = httpApplication.Context; var httpRequest = httpContext.Request; var httpResponse = httpContext.Response; var serverVariables = httpRequest.ServerVariables; httpResponse.Buffer = false; var env = serverVariables.AllKeys .ToDictionary(key => key, key => (object)serverVariables[key]); new Environment(env) { Version = new Version(1, 0), UrlScheme = httpRequest.Url.Scheme, Body = new RequestBody(httpRequest.GetBufferlessInputStream()), Errors = standardError, Multithread = true, Multiprocess = false, RunOnce = false, Session = new Session(httpContext.Session), Logger = (eventType, message, exception) => { }, //TODO: any default logger for this host? }; var scriptName = httpRequest.ApplicationPath; if (scriptName == "/") scriptName = ""; var pathInfo = httpRequest.Url.AbsolutePath; if (pathInfo == "") pathInfo = "/"; env["SCRIPT_NAME"] = scriptName; env["PATH_INFO"] = pathInfo.Substring(scriptName.Length); var task = Task.Factory.StartNew(_ => { app.InvokeAsync(env) .Then((status, headers, body) => { httpResponse.StatusCode = status; foreach (var header in Split(headers)) { httpResponse.AppendHeader(header.Key, header.Value); } var writer = new ResponseBody( httpResponse.ContentEncoding, httpResponse.OutputStream.Write, httpResponse.OutputStream.BeginWrite, httpResponse.OutputStream.EndWrite); body.ForEach(writer.Write).Then(httpResponse.End); }); }, state, TaskCreationOptions.PreferFairness); if (callback != null) task.Finally(() => callback(task)); return task; }, ar => ((Task)ar).Wait()); }
public void Run_with_an_enumerable_fnapp_argument_will_wrap_all_previous_run_calls() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse(@" Load TestName Use TestMiddleware Run TestApp Use TestMiddleware Run TestApp Run TestCascade "); var app = builder.ToApp(); IDictionary<string, object> env = new Dictionary<string, object>(); app(env, ex => { }, (a, b, c) => { }); Assert.That(env.ContainsKey("TestMiddleware"), Is.False, "the use are attached to the apps, not the cascade"); Assert.That(env["TestCascade.Count"], Is.EqualTo(2)); }
public void Use_with_more_text_provides_extra_argument() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse(@" Load TestName Use TestWithData Foo Run TestApp "); var app = builder.ToApp(); IDictionary<string, object> env = new Dictionary<string, object>(); app(env, ex => { }, (a, b, c) => { }); Assert.That(env.ContainsKey("TestWithData"), Is.True); Assert.That(env["TestWithData.Data"], Is.EqualTo("Foo")); }
public void Use_directive_calls_middleware_factory() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse(@" Load TestName Use TestMiddleware Run TestApp "); var app = builder.ToApp(); IDictionary<string, object> env = new Dictionary<string, object>(); app(env, ex => { }, (a, b, c) => { }); Assert.That(env["TestMiddleware"], Is.True); Assert.That(env["TestApp"], Is.True); }
public void Simple_format_may_be_parsed_to_load_assemblies() { var loader = new StubAssemblyLoader(); var builder = new Builder(loader); builder.Parse("Load TestName"); AssertLoadNames(loader, "TestName"); }