Exemple #1
0
        public async Task AllowInterceptionOfDeliveryOnSend()
        {
            bool responsesSent = false;

            void ValidateResponses(Activity[] activities)
            {
                responsesSent = true;
                Assert.Fail("Should not be called. Interceptor did not work");
            }

            SimpleAdapter a = new SimpleAdapter(ValidateResponses);
            TurnContext   c = new TurnContext(a, new Activity());

            int count = 0;

            c.OnSendActivities(async(context, activities, next) =>
            {
                Assert.IsNotNull(activities, "Null Array passed in");
                count = activities.Count();
                // Do not call next.
                return(null);
            });

            await c.SendActivity(TestMessage.Message());

            Assert.IsTrue(count == 1);
            Assert.IsFalse(responsesSent, "Responses made it to the adapter.");
        }
Exemple #2
0
        public async Task InterceptAndMutateOnSend()
        {
            bool foundIt = false;

            void ValidateResponses(Activity[] activities)
            {
                Assert.IsNotNull(activities);
                Assert.IsTrue(activities.Length == 1);
                Assert.IsTrue(activities[0].Id == "changed");
                foundIt = true;
            }

            SimpleAdapter a = new SimpleAdapter(ValidateResponses);
            TurnContext   c = new TurnContext(a, new Activity());

            c.OnSendActivities(async(context, activities, next) =>
            {
                Assert.IsNotNull(activities, "Null Array passed in");
                Assert.IsTrue(activities.Count() == 1);
                Assert.IsTrue(activities[0].Id == "1234", "Unknown Id Passed In");
                activities[0].Id = "changed";
                return(await next());
            });

            await c.SendActivity(TestMessage.Message());

            // Intercepted the message, changed it, and sent it on to the Adapter
            Assert.IsTrue(foundIt);
        }
Exemple #3
0
        public async Task SendActivity()
        {
            // Arrange
            var activity = new Activity();
            // Act
            await _target.SendActivity(activity);

            // Assert
            A.CallTo(() => _adapter.SendActivity(activity)).MustHaveHappened();
        }
Exemple #4
0
        public async Task TraceActivitiesDoNoSetResponded()
        {
            SimpleAdapter a = new SimpleAdapter();
            TurnContext   c = new TurnContext(a, new Activity());

            Assert.IsFalse(c.Responded);

            // Send a Trace Activity, and make sure responded is NOT set.
            ITraceActivity trace = Activity.CreateTraceActivity("trace");
            await c.SendActivity(trace);

            Assert.IsFalse(c.Responded);

            // Just to sanity check everything, send a Message and verify the
            // responded flag IS set.
            IMessageActivity msg = TestMessage.Message().AsMessageActivity();
            await c.SendActivity(msg);

            Assert.IsTrue(c.Responded);
        }
Exemple #5
0
        public async Task SendAndSetResponded()
        {
            SimpleAdapter a = new SimpleAdapter();
            TurnContext   c = new TurnContext(a, new Activity());

            Assert.IsFalse(c.Responded);
            var response = await c.SendActivity(TestMessage.Message("testtest"));

            Assert.IsTrue(c.Responded);
            Assert.IsTrue(response.Id == "testtest");
        }
Exemple #6
0
        public async Task SendAndSetRespondedUsingIMessageActivity()
        {
            SimpleAdapter a = new SimpleAdapter();
            TurnContext   c = new TurnContext(a, new Activity());

            Assert.IsFalse(c.Responded);

            IMessageActivity msg = TestMessage.Message().AsMessageActivity();
            await c.SendActivity(msg);

            Assert.IsTrue(c.Responded);
        }
Exemple #7
0
        public async Task SendOneActivityToAdapter()
        {
            bool foundActivity = false;

            void ValidateResponses(Activity[] activities)
            {
                Assert.IsTrue(activities.Count() == 1, "Incorrect Count");
                Assert.IsTrue(activities[0].Id == "1234");
                foundActivity = true;
            }

            SimpleAdapter a = new SimpleAdapter(ValidateResponses);
            TurnContext   c = new TurnContext(a, new Activity());
            await c.SendActivity(TestMessage.Message());

            Assert.IsTrue(foundActivity);
        }
Exemple #8
0
        public async Task CallOnSendBeforeDelivery()
        {
            SimpleAdapter a = new SimpleAdapter();
            TurnContext   c = new TurnContext(a, new Activity());

            int count = 0;

            c.OnSendActivities(async(context, activities, next) =>
            {
                Assert.IsNotNull(activities, "Null Array passed in");
                count = activities.Count();
                return(await next());
            });

            await c.SendActivity(TestMessage.Message());

            Assert.IsTrue(count == 1);
        }
Exemple #9
0
        public async Task PassResourceResponsesThrough()
        {
            void ValidateResponses(Activity[] activities)
            {
                // no need to do anything.
            }

            SimpleAdapter a = new SimpleAdapter(ValidateResponses);
            TurnContext   c = new TurnContext(a, new Activity());

            string activityId = Guid.NewGuid().ToString();
            var    activity   = TestMessage.Message();

            activity.Id = activityId;

            var resourceResponse = await c.SendActivity(activity);

            Assert.IsTrue(resourceResponse.Id == activityId, "Incorrect response Id returned");
        }
Exemple #10
0
        public async Task ThrowExceptionInOnSend()
        {
            SimpleAdapter a = new SimpleAdapter();
            TurnContext   c = new TurnContext(a, new Activity());

            c.OnSendActivities(async(context, activities, next) =>
            {
                throw new Exception("test");
            });

            try
            {
                await c.SendActivity(TestMessage.Message());

                Assert.Fail("Should not get here");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message == "test");
            }
        }