Esempio n. 1
0
        public async Task InterceptAndMutateOnDelete()
        {
            bool adapterCalled = false;

            void ValidateDelete(ConversationReference r)
            {
                Assert.IsTrue(r.ActivityId == "mutated");
                adapterCalled = true;
            }

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

            c.OnDeleteActivity(async(context, convRef, next) =>
            {
                Assert.IsNotNull(convRef, "Null activity passed in");
                Assert.IsTrue(convRef.ActivityId == "1234", "Incorrect Activity Id");
                convRef.ActivityId = "mutated";
                await next();
            });

            await c.DeleteActivity("1234");

            Assert.IsTrue(adapterCalled); // Adapter was called + valided the change
        }
Esempio n. 2
0
        public async Task InterceptOnDelete()
        {
            bool adapterCalled = false;

            void ValidateDelete(ConversationReference r)
            {
                adapterCalled = true;
                Assert.True(false); // Should not be called
            }

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

            bool wasCalled = false;

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

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

            await c.DeleteActivityAsync("1234");

            Assert.True(wasCalled);      // Interceptor was called
            Assert.False(adapterCalled); // Adapter was not
        }
Esempio n. 3
0
        public async Task InterceptOnDelete()
        {
            bool adapterCalled = false;

            void ValidateDelete(ConversationReference r)
            {
                adapterCalled = true;
                Assert.Fail("Should not be called.");
            }

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

            bool wasCalled = false;

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

            await c.DeleteActivity("1234");

            Assert.IsTrue(wasCalled);      // Interceptor was called
            Assert.IsFalse(adapterCalled); // Adapter was not
        }
Esempio n. 4
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));
        }