Skip to content

Instantly share code, notes, and snippets.

@csainty
Forked from thecodejunkie/gist:4429702
Last active December 10, 2015 12:19
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 csainty/4433314 to your computer and use it in GitHub Desktop.
Save csainty/4433314 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Net;
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());
Assert.Equal("non async", result);
}
[Fact]
public async Task Should_work_async()
{
var module = new Class1();
var result = await module.routes["/stuff"].Invoke(new object());
Assert.Equal("async", result);
}
}
public class Class1 : Module
{
public Class1()
{
Get["/"] = x =>
{
return "non async";
};
Get["/stuff"] = Stuff;
}
public async Task<dynamic> Stuff(dynamic _)
{
await Task.Delay(100);
return "async";
}
}
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 Func<dynamic, dynamic> this[string path]
{
set { this.module.routes.Add(path, value); }
}
//public Func<dynamic, Task<dynamic>> this[string path]
//{
// set { this.module.routes.Add(path, value); }
//}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment