Exemplo n.º 1
0
        public void AddItemToStartOfPipeline_adds_to_the_end_of_the_pipeline()
        {
            Func <NancyContext, Response> item1 = (r) => { return(null); };
            Func <NancyContext, Response> item2 = (r) => { return(new Response()); };

            pipeline.AddItemToEndOfPipeline(item2);

            pipeline.AddItemToStartOfPipeline(item1);

            Assert.Equal(2, pipeline.PipelineItems.Count());
            Assert.Same(item1, pipeline.PipelineItems.First());
        }
Exemplo n.º 2
0
        private static BeforePipeline FakeOwinEnvironment()
        {
            var pipeline = new BeforePipeline();

            pipeline.AddItemToStartOfPipeline(
                context =>
            {
                context.Items.Add("OWIN_REQUEST_ENVIRONMENT", new Dictionary <string, object>());
                return(context.Response);
            });

            return(pipeline);
        }
        public async Task Should_be_able_to_throw_exception_from_async_pipeline_item()
        {
            // Given
            Func <NancyContext, CancellationToken, Task <Response> > pipeLineItem = (ctx, token) =>
            {
                throw new Exception("aaarg");
            };

            // When
            pipeline.AddItemToStartOfPipeline(pipeLineItem);

            // Then
            await AssertAsync.Throws <Exception>(async() => await pipeline.Invoke(CreateContext(), new CancellationToken()));
        }
        public void Should_be_able_to_throw_exception_from_async_pipeline_item()
        {
            // Given
            Func <NancyContext, CancellationToken, Task <Response> > pipeLineItem = (ctx, token) => new Task <Response>(() =>
            {
                Thread.Sleep(1000);
                throw new Exception("aaarg");
            });

            // When
            pipeline.AddItemToStartOfPipeline(pipeLineItem);

            // Then
            Assert.Throws <AggregateException>(() => pipeline.Invoke(CreateContext(), new CancellationToken()).Result);
        }
Exemplo n.º 5
0
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
        {
            BeforePipeline bp = new BeforePipeline();

            // Since we are including the API in the Parking.UI package (because of server constraints)
            // we need to remove the prefix folder so the routes are taken correctly.
            bp.AddItemToStartOfPipeline(ctx => {
                ctx.Request.Url.Path = ctx.Request.Url.Path.Replace("/api", "");
                return(ctx.Response);
            });

            pipelines.BeforeRequest += bp;

            // Register gzip compression
            pipelines.RegisterCompressionCheck();

            base.ApplicationStartup(container, pipelines);
        }
Exemplo n.º 6
0
        private static BeforePipeline FakeOwinEnvironment()
        {
            var pipeline = new BeforePipeline();

            pipeline.AddItemToStartOfPipeline(
                context =>
                    {
                        context.Items.Add("OWIN_REQUEST_ENVIRONMENT", new Dictionary<string, object>());
                        return context.Response;
                    });

            return pipeline;
        }