Пример #1
0
        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);
        }
Пример #2
0
 public void safe_start_errors_should_be_handled()
 {
     _requestCompletion.SafeStart(() => { throw new InvalidOperationException(); });
     _exception.ShouldNotBeNull();
     _exception.ShouldBeOfType <InvalidOperationException>();
 }