public void NullArguments_ArgumentNullException()
        {
            var builder = new AppBuilder();
            var noMiddleware = new AppBuilder().Build<AppFunc>();
            var noOptions = new MapWhenOptions();
            Assert.Throws<ArgumentNullException>(() => builder.MapWhen(null, UseNotImplemented));
            Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, (Action<IAppBuilder>)null));
            Assert.Throws<ArgumentNullException>(() => new MapWhenMiddleware(null, noOptions));
            Assert.Throws<ArgumentNullException>(() => new MapWhenMiddleware(noMiddleware, null));

            Assert.Throws<ArgumentNullException>(() => builder.MapWhenAsync(null, UseNotImplemented));
            Assert.Throws<ArgumentNullException>(() => builder.MapWhenAsync(NotImplementedPredicateAsync, (Action<IAppBuilder>)null));
            Assert.Throws<ArgumentNullException>(() => new MapWhenMiddleware(null, noOptions));
            Assert.Throws<ArgumentNullException>(() => new MapWhenMiddleware(noMiddleware, null));
        }
        public void PredicateAsyncFalseAction_PassThrough()
        {
            IOwinContext context = new OwinContext();
            IAppBuilder builder = new AppBuilder();
            builder.MapWhenAsync(FalsePredicateAsync, UseNotImplemented);
            builder.Run(Success);
            var app = builder.Build<OwinMiddleware>();
            app.Invoke(context).Wait();

            Assert.Equal(200, context.Response.StatusCode);
        }
        public void ChainedPredicatesAsync_Success()
        {
            IAppBuilder builder = new AppBuilder();
            builder.MapWhenAsync(TruePredicateAsync, map1 =>
            {
                map1.MapWhenAsync((PredicateAsync)FalsePredicateAsync, UseNotImplemented);
                map1.MapWhenAsync((PredicateAsync)TruePredicateAsync, map2 => map2.MapWhenAsync((PredicateAsync)TruePredicateAsync, UseSuccess));
                map1.Run(NotImplemented);
            });
            var app = builder.Build<OwinMiddleware>();

            IOwinContext context = new OwinContext();
            app.Invoke(context).Wait();
            Assert.Equal(200, context.Response.StatusCode);
        }
        public void PredicateAsyncTrueAction_BranchTaken()
        {
            IOwinContext context = new OwinContext();
            IAppBuilder builder = new AppBuilder();
            builder.MapWhenAsync(TruePredicateAsync, UseSuccess);
            var app = builder.Build<OwinMiddleware>();
            app.Invoke(context).Wait();

            Assert.Equal(200, context.Response.StatusCode);
        }