Exemplo n.º 1
0
        public async Task InterceptAndMutateOnUpdate()
        {
            bool adapterCalled = false;

            void ValidateUpdate(Activity activity)
            {
                Assert.IsTrue(activity.Id == "mutated");
                adapterCalled = true;
            }

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

            c.OnUpdateActivity(async(context, activity, next) =>
            {
                Assert.IsNotNull(activity, "Null activity passed in");
                Assert.IsTrue(activity.Id == "1234");
                activity.Id = "mutated";
                return(await next());
            });

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

            Assert.IsTrue(adapterCalled); // Adapter was not
        }
Exemplo n.º 2
0
        public async Task InterceptOnUpdate()
        {
            bool adapterCalled = false;

            void ValidateUpdate(Activity activity)
            {
                adapterCalled = true;
                Assert.Fail("Should not be called.");
            }

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

            bool wasCalled = false;

            c.OnUpdateActivity(async(context, activity, next) =>
            {
                Assert.IsNotNull(activity, "Null activity passed in");
                wasCalled = true;
                // Do Not Call Next
                return(null);
            });

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

            Assert.IsTrue(wasCalled);      // Interceptor was called
            Assert.IsFalse(adapterCalled); // Adapter was not
        }
Exemplo n.º 3
0
        public async Task InterceptOnUpdate()
        {
            bool adapterCalled = false;

            void ValidateUpdate(Activity activity)
            {
                adapterCalled = true;
                Assert.True(false); // Should not be called
            }

            var a = new SimpleAdapter(ValidateUpdate);
            var c = new TurnContext(a, new Activity());

            bool wasCalled = false;

            c.OnUpdateActivity((context, activity, next) =>
            {
                Assert.NotNull(activity); // Null activity passed in
                wasCalled = true;

                // Do Not Call Next
                return(Task.FromResult <ResourceResponse>(null));
            });

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

            Assert.True(wasCalled);      // Interceptor was called
            Assert.False(adapterCalled); // Adapter was not
        }
Exemplo n.º 4
0
        public async Task CallOnUpdateBeforeDelivery()
        {
            bool foundActivity = false;

            void ValidateUpdate(Activity activity)
            {
                Assert.IsNotNull(activity);
                Assert.IsTrue(activity.Id == "1234");
                foundActivity = true;
            }

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

            bool wasCalled = false;

            c.OnUpdateActivity(async(context, activity, next) =>
            {
                Assert.IsNotNull(activity, "Null activity passed in");
                wasCalled = true;
                return(await next());
            });
            await c.UpdateActivity(TestMessage.Message());

            Assert.IsTrue(wasCalled);
            Assert.IsTrue(foundActivity);
        }
Exemplo n.º 5
0
        public void TestTurnContextClone()
        {
            var c1 = new TurnContext(new SimpleAdapter(), new Activity()
            {
                Text = "one"
            });

            c1.TurnState.Add("x", "test");
            c1.OnSendActivities((context, activities, next) => next());
            c1.OnDeleteActivity((context, activity, next) => next());
            c1.OnUpdateActivity((context, activity, next) => next());
            var c2 = new TurnContext(c1, new Activity()
            {
                Text = "two"
            });

            Assert.Equal("one", c1.Activity.Text);
            Assert.Equal("two", c2.Activity.Text);
            Assert.Equal(c1.Adapter, c2.Adapter);
            Assert.Equal(c1.TurnState, c2.TurnState);

            var binding       = BindingFlags.Instance | BindingFlags.NonPublic;
            var onSendField   = typeof(TurnContext).GetField("_onSendActivities", binding);
            var onDeleteField = typeof(TurnContext).GetField("_onDeleteActivity", binding);
            var onUpdateField = typeof(TurnContext).GetField("_onUpdateActivity", binding);

            Assert.Equal(onSendField.GetValue(c1), onSendField.GetValue(c2));
            Assert.Equal(onDeleteField.GetValue(c1), onDeleteField.GetValue(c2));
            Assert.Equal(onUpdateField.GetValue(c1), onUpdateField.GetValue(c2));
        }