Exemple #1
0
        public void UseMiddleware_T_NonServiceProvider()
        {
            var builder = new TestPipelineBuilder(null);

            Should.NotThrow(() => builder.UseMiddleware <TestPipelineContext, ManyParametersMiddleware>());
            var context = new TestPipelineContext();

            Should.Throw <InvalidOperationException>(() => builder.Build()(context));
        }
Exemple #2
0
        public void UseMiddleware_T_Exception3()
        {
            var descriptors     = new ServiceCollection();
            var serviceProvider = descriptors.BuildServiceProvider();
            var builder         = new TestPipelineBuilder(serviceProvider);

            builder.ApplicationServices.ShouldBe(serviceProvider);
            Should.NotThrow(() => builder.UseMiddleware <TestPipelineContext, NotTaskMiddleware>());
            var context = new TestPipelineContext();

            Should.Throw <InvalidOperationException>(() => builder.Build()(context));
        }
Exemple #3
0
        public void UseMiddleware_T_Exception5()
        {
            var descriptors     = new ServiceCollection();
            var serviceProvider = descriptors.BuildServiceProvider();
            var builder         = new TestPipelineBuilder(serviceProvider);

            builder.ApplicationServices.ShouldBe(serviceProvider);
            Should.NotThrow(() => builder.UseMiddleware <TestPipelineContext, ByRefParametersMiddleware>());
            var context = new TestPipelineContext();

            Should.Throw <NotSupportedException>(() => builder.Build()(context));
        }
Exemple #4
0
        public void UseMiddleware_ManyParameters()
        {
            var descriptors     = new ServiceCollection();
            var serviceProvider = descriptors.BuildServiceProvider();
            var builder         = new TestPipelineBuilder(serviceProvider);

            builder.ApplicationServices.ShouldBe(serviceProvider);
            Should.NotThrow(() => builder.UseMiddleware <TestPipelineContext, ManyParametersMiddleware>());
            var context = new TestPipelineContext();

            context.PipelineInvoked.ShouldBeFalse();
            Should.NotThrow(() => builder.Build()(context));
            context.PipelineInvoked.ShouldBeTrue();
        }
Exemple #5
0
        public void Use_Build()
        {
            var descriptors     = new ServiceCollection();
            var serviceProvider = descriptors.BuildServiceProvider();
            var builder         = new TestPipelineBuilder(serviceProvider);

            builder.ApplicationServices.ShouldBe(serviceProvider);
            Should.Throw <ArgumentNullException>(() => builder.Use(null));
            Should.NotThrow(() => builder.Use(next => context => { context.PipelineInvoked = true; return(next(context)); }));
            var context = new TestPipelineContext();

            context.PipelineInvoked.ShouldBeFalse();
            Should.NotThrow(() => builder.Build()(context));
            context.PipelineInvoked.ShouldBeTrue();
        }
Exemple #6
0
        public void UseMiddleware()
        {
            var descriptors     = new ServiceCollection();
            var serviceProvider = descriptors.BuildServiceProvider();
            var builder         = new TestPipelineBuilder(serviceProvider);

            builder.ApplicationServices.ShouldBe(serviceProvider);
            Should.Throw <ArgumentNullException>(() => builder.UseMiddleware(null));
            Should.NotThrow(() => builder.UseMiddleware(typeof(FuncResultMiddleware)));
            Should.NotThrow(() => builder.UseMiddleware(typeof(TestMiddleware)));
            var context = new TestPipelineContext();

            context.PipelineInvoked.ShouldBeFalse();
            Should.NotThrow(() => builder.Build()(context));
            context.PipelineInvoked.ShouldBeTrue();
        }