public Task Invoke(IDictionary<string, object> environment) { var owinHttpContext = new OwinHttpContext(environment); var routeData = _routes.GetRouteData(owinHttpContext); if (routeData == null) { write404(environment); return Task.Factory.StartNew(() => { }); } new OwinRequestReader().Read(environment); var arguments = new OwinServiceArguments(routeData, environment); var invoker = routeData.RouteHandler.As<FubuRouteHandler>().Invoker; var taskCompletionSource = new TaskCompletionSource<object>(); var requestCompletion = new RequestCompletion(); requestCompletion.WhenCompleteDo(ex => { if (ex != null) { //This seems like OWIN should handle the .SetException(ex) with standard error screen formatting? write500(environment, ex); } taskCompletionSource.SetResult(null); }); arguments.With<IRequestCompletion>(requestCompletion); requestCompletion.SafeStart(() => invoker.Invoke(arguments, routeData.Values, requestCompletion)); return taskCompletionSource.Task; }
public void Setup() { _completedCount = 0; _exception = null; _requestCompletion = new RequestCompletion(); _requestCompletion.WhenCompleteDo(x => { _exception = x; _completedCount++; }); }