Пример #1
0
        public async Task Status_TwoItemsOneDoesNotCallNext()
        {
            bool called1 = false;
            bool called2 = false;

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

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

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

            bool didAllRun = false;
            await m.ReceiveActivityWithStatus(null, async (ctx) => didAllRun = true);

            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 Status_RunAtEndEmptyPipeline()
        {
            Middleware.MiddlewareSet m = new Middleware.MiddlewareSet();

            // This middlware pipeline has no entries. This should result in
            // the status being TRUE.
            bool didAllRun = await m.ReceiveActivityWithStatus(null);

            Assert.IsTrue(didAllRun);
        }
        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);
        }
Пример #4
0
        public async Task Status_OneEntryThatDoesNotCallNext()
        {
            bool called1 = false;

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

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

            // The middlware in this pipeline DOES NOT call next(), so this must not be called
            bool didAllRun = false;
            await m.ReceiveActivityWithStatus(null, async (ctx) => didAllRun = true);

            Assert.IsTrue(called1);

            // Our "Final" action MUST NOT have been called, as the Middlware Pipeline
            // didn't complete.
            Assert.IsFalse(didAllRun);
        }