Пример #1
0
        public async Task NestedSet_AllIsRun()
        {
            bool   innerOnSendCalled    = false;
            bool   innerOnReceiveCalled = false;
            bool   innerOnCreatedCalled = false;
            string replyMessage         = Guid.NewGuid().ToString();

            MiddlewareSet inner = new MiddlewareSet();

            inner.Use(new AnonymousSendActivityMiddleware(async(context, activities, next) =>
            {
                Assert.IsTrue(activities.Count == 1, "incorrect activity count");
                Assert.IsTrue(activities[0].AsMessageActivity().Text == replyMessage, "unexpected message");

                innerOnSendCalled = true;
                await next();
            }));

            inner.Use(new AnonymousReceiveMiddleware(async(context, next) =>
            {
                context.Responses.Add(MessageFactory.Text(replyMessage));
                innerOnReceiveCalled = true;
                await next();
            }));

            inner.Use(new AnonymousContextCreatedMiddleware(async(context, next) =>
            {
                innerOnCreatedCalled = true;
                await next();
            }));

            Middleware.MiddlewareSet outer = new Middleware.MiddlewareSet();
            outer.Use(inner);

            IBotContext c = TestUtilities.CreateEmptyContext();
            await outer.ContextCreated(c);

            await outer.ReceiveActivity(c);

            await outer.SendActivity(c, c.Responses);

            Assert.IsTrue(innerOnReceiveCalled, "Inner Middleware Receive Activity was not called.");
            Assert.IsTrue(innerOnCreatedCalled, "Inner Middleware Create Context was not called.");
            Assert.IsTrue(innerOnSendCalled, "Inner Middleware SendActivity was not called.");
        }