Example #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);
        }
        public void request_is_faulted_when_writer_throws_exception()
        {
            var requestCompletion        = new RequestCompletion();
            AggregateException exception = null;
            var waitHandle = new ManualResetEvent(false);

            requestCompletion.WhenCompleteDo(ex =>
            {
                exception = ex as AggregateException;
                waitHandle.Set();
            });
            var asyncCoordinator = new AsyncCoordinator(requestCompletion, Enumerable.Empty <IExceptionHandler>());

            theWriter.WriterThrows = true;

            var task = theChannelWriter.Write(theTopic);

            theChannel.Write(q => q.Write(e1));

            asyncCoordinator.Push(task);

            waitHandle.WaitOne(TimeSpan.FromSeconds(1));
            var exceptions = exception.Flatten().InnerExceptions;

            exceptions.Count.ShouldBe(1);
            exceptions[0].Message.ShouldBe(RecordingServerEventWriter.ExceptionMessage);
        }
Example #3
0
 public void Setup()
 {
     _completedCount    = 0;
     _exception         = null;
     _requestCompletion = new RequestCompletion();
     _requestCompletion.WhenCompleteDo(x =>
     {
         _exception = x;
         _completedCount++;
     });
 }
Example #4
0
        public void multiple_completion_subscribers_are_notified()
        {
            var completed = false;

            _requestCompletion.WhenCompleteDo(x =>
            {
                completed = true;
            });
            _requestCompletion.Start(() => { });
            completed.ShouldBeTrue();
            _completedCount.ShouldEqual(1);
        }
        public IAsyncResult BeginProcessRequest(System.Web.HttpContext context, AsyncCallback cb, object extraData)
        {
            var taskCompletionSource = new TaskCompletionSource<object>();
            var requestCompletion = new RequestCompletion();
            requestCompletion.WhenCompleteDo(ex =>
            {
                if (ex != null)
                {
                    taskCompletionSource.SetException(ex);
                }
                taskCompletionSource.SetResult(null);
                cb(taskCompletionSource.Task);
            });
            requestCompletion.Start(() => _invoker.Invoke(_arguments, _routeData, requestCompletion));

            return taskCompletionSource.Task;
        }
        public IAsyncResult BeginProcessRequest(System.Web.HttpContext context, AsyncCallback cb, object extraData)
        {
            var taskCompletionSource = new TaskCompletionSource <object>();
            var requestCompletion    = new RequestCompletion();

            requestCompletion.WhenCompleteDo(ex =>
            {
                if (ex != null)
                {
                    taskCompletionSource.SetException(ex);
                }
                taskCompletionSource.SetResult(null);
                cb(taskCompletionSource.Task);
            });
            requestCompletion.Start(() => _invoker.Invoke(_arguments, _routeData, requestCompletion));

            return(taskCompletionSource.Task);
        }
Example #7
0
        protected override void beforeEach()
        {
            var waitHandle = new ManualResetEvent(false);
            var completion = new RequestCompletion();

            completion.WhenCompleteDo(x => waitHandle.Set());
            Services.Container.Configure(x =>
            {
                x.For <IRequestCompletion>().Use(completion);
                x.For <IAsyncCoordinator>().Use <AsyncCoordinator>();
            });
            var task = Task.Factory.StartNew(() =>
            {
                throw new Exception("Failed!");
            });

            MockFor <IFubuRequest>().Expect(x => x.Get <Task>()).Return(task);

            ClassUnderTest.Invoke();
            waitHandle.WaitOne(TimeSpan.FromSeconds(1)).ShouldBeTrue();
        }
Example #8
0
        protected override void beforeEach()
        {
            var waitHandle = new ManualResetEvent(false);
            var completion = new RequestCompletion();

            completion.WhenCompleteDo(x => waitHandle.Set());
            Services.Container.Configure(x =>
            {
                x.For <IRequestCompletion>().Use(completion);
                x.For <IAsyncCoordinator>().Use <AsyncCoordinator>();
            });
            ClassUnderTest.Inner = MockFor <IActionBehavior>();
            expectedOutput       = new Output();
            var task = new Task <Output>(() => expectedOutput);

            task.RunSynchronously();

            MockFor <IFubuRequest>().Expect(x => x.Get <Task <Output> >()).Return(task);

            ClassUnderTest.Invoke();
            waitHandle.WaitOne(TimeSpan.FromSeconds(1)).ShouldBeTrue();
        }