public async Task Status_TwoItemsOneDoesNotCallNext()
        {
            bool called1 = false;
            bool called2 = false;

            var one = new CallMeMiddlware(() =>
            {
                Assert.IsFalse(called2, "Second Middleware was called");
                called1 = true;
            });

            var two = new DoNotCallNextMiddleware(() =>
            {
                Assert.IsTrue(called1, "First Middleware was not called");
                called2 = true;
            });

            var m = new MiddlewareSet();

            m.Use(one);
            m.Use(two);

            bool didAllRun = false;
            await m.ReceiveActivityWithStatus(null, (ctx) =>
            {
                didAllRun = true;
                return(Task.CompletedTask);
            });

            Assert.IsTrue(called1);
            Assert.IsTrue(called2);

            // The 2nd middleware did not call next, so the "final" action should not have run.
            Assert.IsFalse(didAllRun);
        }
        public async Task TwoMiddlewareItemsInOrder()
        {
            bool called1 = false;
            bool called2 = false;

            CallMeMiddlware one = new CallMeMiddlware(() =>
            {
                Assert.IsFalse(called2, "Second Middleware was called");
                called1 = true;
            });

            CallMeMiddlware two = new CallMeMiddlware(() =>
            {
                Assert.IsTrue(called1, "First Middleware was not called");
                called2 = true;
            });

            MiddlewareSet m = new MiddlewareSet();

            m.Use(one);
            m.Use(two);

            await m.ReceiveActivity(null);

            Assert.IsTrue(called1);
            Assert.IsTrue(called2);
        }
Beispiel #3
0
        public async Task TwoMiddlewareItemsInOrder()
        {
            bool called1 = false;
            bool called2 = false;

            CallMeMiddlware one = new CallMeMiddlware(() =>
            {
                Assert.False(called2, "Second Middleware was called");
                called1 = true;
            });

            CallMeMiddlware two = new CallMeMiddlware(() =>
            {
                Assert.True(called1, "First Middleware was not called");
                called2 = true;
            });

            MiddlewareSet m = new MiddlewareSet();

            m.Use(one);
            m.Use(two);

            await m.ReceiveActivityWithStatusAsync(null, null, default(CancellationToken));

            Assert.True(called1);
            Assert.True(called2);
        }
        public async Task Status_OneMiddlewareRan()
        {
            bool called1 = false;

            CallMeMiddlware one = new CallMeMiddlware(() => { called1 = true; });

            Middleware.MiddlewareSet m = new Middleware.MiddlewareSet();
            m.Use(one);

            // The middlware in this pipeline calls next(), so the resulting
            // status should be TRUE.
            bool didAllRun = await m.ReceiveActivityWithStatus(null);

            Assert.IsTrue(called1);
            Assert.IsTrue(didAllRun);
        }
Beispiel #5
0
        public async Task Status_OneMiddlewareRan()
        {
            bool called1 = false;

            CallMeMiddlware one = new CallMeMiddlware(() => { called1 = true; });

            MiddlewareSet m = new MiddlewareSet();

            m.Use(one);

            // The middlware in this pipeline calls next(), so the delegate should be called
            bool didAllRun = false;
            await m.ReceiveActivityWithStatus(null, async (ctx) => didAllRun = true);

            Assert.IsTrue(called1);
            Assert.IsTrue(didAllRun);
        }
        public async Task Status_OneMiddlewareRan()
        {
            bool called1 = false;

            var one = new CallMeMiddlware(() => { called1 = true; });

            var m = new MiddlewareSet();

            m.Use(one);

            // The middlware in this pipeline calls next(), so the delegate should be called
            bool didAllRun = false;
            await m.ReceiveActivityWithStatusAsync(null, (ctx, cancellationToken) =>
            {
                didAllRun = true;
                return(Task.CompletedTask);
            },
                                                   default(CancellationToken));

            Assert.IsTrue(called1);
            Assert.IsTrue(didAllRun);
        }