Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Forked from thecodejunkie/gist:4429702
Last active December 10, 2015 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeGinnivan/4433991 to your computer and use it in GitHub Desktop.
Save JakeGinnivan/4433991 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
public class Fixture
{
[Fact]
public void Should_FactMethodName()
{
var module = new Class1();
var result = module.routes["/"].Invoke(new object());
var i = 10;
}
}
public class Class1 : Module
{
public Class1()
{
Get["/"].Route(x =>
{
return "non async";
});
Get["/stuff"].Route(async x =>
{
var client = new HttpClient();
var result = await client.GetAsync("http://www.nancyfx.org");
var content = await result.Content.ReadAsStringAsync();
return content;
});
}
}
public class Module
{
public readonly IDictionary<string, Func<dynamic, dynamic>> routes = new Dictionary<string, Func<dynamic, dynamic>>();
public Builder Get
{
get { return new Builder(this); }
}
public class Builder
{
private readonly Module module;
public Builder(Module module)
{
this.module = module;
}
public void Route(Func<dynamic, dynamic> route)
{
this.module.routes.Add(path, value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment