Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Created November 30, 2013 16:14
Show Gist options
  • Save beyond-code-github/7720973 to your computer and use it in GitHub Desktop.
Save beyond-code-github/7720973 to your computer and use it in GitHub Desktop.
ʃ.Route(ʅ => ʅ / "Hello" * Pipeline.Action<FirstComponent>() / (
ʅ / "World" * Pipeline.Action<SecondComponent>()
| ʅ / "Foobar" * Pipeline.Action<ThirdComponent>()));
public class FirstComponent
{
private readonly Func<IDictionary<string, object>, Task> next;
public FirstComponent(Func<IDictionary<string, object>, Task> next)
{
this.next = next;
}
public async Task Invoke(IDictionary<string, object> environment)
{
await environment.WriteResponse("before#1");
await this.next(environment);
await environment.WriteResponse("after#1");
}
}
public class SecondComponent
{
private readonly Func<IDictionary<string, object>, Task> next;
public SecondComponent(Func<IDictionary<string, object>, Task> next)
{
this.next = next;
}
public async Task Invoke(IDictionary<string, object> environment)
{
await environment.WriteResponse("before#2");
await this.next(environment);
await environment.WriteResponse("after#2");
}
}
public class When_building_a_pipeline_with_options_invoking_the_first : When_building_a_pipeline_with_options
{
private Because of = () => responseMessage = client.GetAsync("http://localhost/Hello/World").Result;
private It should_execute_the_final_function = () => responseMessage.Content.ReadAsStringAsync().Result.ShouldEqual("before#1before#2after#2after#1");
private It should_return_200 = () => responseMessage.StatusCode.ShouldEqual(HttpStatusCode.OK);
}
public class When_building_a_pipeline_with_options_invoking_the_second : When_building_a_pipeline_with_options
{
private Because of = () => responseMessage = client.GetAsync("http://localhost/Hello/Foobar").Result;
private It should_execute_the_final_function = () => responseMessage.Content.ReadAsStringAsync().Result.ShouldEqual("before#1before#3after#3after#1");
private It should_return_200 = () => responseMessage.StatusCode.ShouldEqual(HttpStatusCode.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment