public async Task ShouldNotLogContinueConversation()
        {
            var transcriptStore = new MemoryTranscriptStore();
            var sut             = new TranscriptLoggerMiddleware(transcriptStore);

            var conversationId = Guid.NewGuid().ToString();
            var adapter        = new TestAdapter(TestAdapter.CreateConversation(conversationId))
                                 .Use(sut);

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                await context.SendActivityAsync("bar", cancellationToken: cancellationToken);
            })
            .Send("foo")
            .AssertReply(async activity =>
            {
                Assert.Equal("bar", ((Activity)activity).Text);
                var activities = await transcriptStore.GetTranscriptActivitiesAsync(activity.ChannelId, conversationId);
                Assert.Equal(2, activities.Items.Length);
            })
            .Send(new Activity(ActivityTypes.Event)
            {
                Name = ActivityEventNames.ContinueConversation
            })
            .AssertReply(async activity =>
            {
                // Ensure the event hasn't been added to the transcript.
                var activities = await transcriptStore.GetTranscriptActivitiesAsync(activity.ChannelId, conversationId);
                Assert.DoesNotContain(activities.Items, a => ((Activity)a).Type == ActivityTypes.Event && ((Activity)a).Name == ActivityEventNames.ContinueConversation);
                Assert.Equal(3, activities.Items.Length);
            })
            .StartTestAsync();
        }
Esempio n. 2
0
        public async Task Transcript_TestDateLogUpdateActivities()
        {
            var dateTimeStartOffset1 = new DateTimeOffset(DateTime.Now);
            var dateTimeStartOffset2 = new DateTimeOffset(DateTime.UtcNow);


            var         transcriptStore = new MemoryTranscriptStore();
            TestAdapter adapter         = new TestAdapter()
                                          .Use(new TranscriptLoggerMiddleware(transcriptStore));
            string   conversationId   = null;
            Activity activityToUpdate = null;

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                conversationId = context.Activity.Conversation.Id;
                if (context.Activity.Text == "update")
                {
                    activityToUpdate.Text = "new response";
                    await context.UpdateActivityAsync(activityToUpdate);
                }
                else
                {
                    var activity = context.Activity.CreateReply("response");

                    var response = await context.SendActivityAsync(activity);
                    activity.Id  = response.Id;

                    // clone the activity, so we can use it to do an update
                    activityToUpdate = JsonConvert.DeserializeObject <Activity>(JsonConvert.SerializeObject(activity));
                }
            })
            .Send("foo")
            .Send("update")
            .AssertReply("new response")
            .StartTestAsync();
            await Task.Delay(500);

            // Perform some queries
            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync("test", conversationId, null, dateTimeStartOffset1.DateTime);

            Assert.AreEqual(4, pagedResult.Items.Length);
            Assert.AreEqual("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.AreEqual("response", pagedResult.Items[1].AsMessageActivity().Text);
            Assert.AreEqual("new response", pagedResult.Items[2].AsMessageUpdateActivity().Text);
            Assert.AreEqual("update", pagedResult.Items[3].AsMessageActivity().Text);
            Assert.AreEqual(pagedResult.Items[1].Id, pagedResult.Items[2].Id);
            // Perform some queries
            pagedResult = await transcriptStore.GetTranscriptActivitiesAsync("test", conversationId, null, DateTimeOffset.MinValue);

            Assert.AreEqual(4, pagedResult.Items.Length);
            Assert.AreEqual("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.AreEqual("response", pagedResult.Items[1].AsMessageActivity().Text);
            Assert.AreEqual("new response", pagedResult.Items[2].AsMessageUpdateActivity().Text);
            Assert.AreEqual("update", pagedResult.Items[3].AsMessageActivity().Text);
            Assert.AreEqual(pagedResult.Items[1].Id, pagedResult.Items[2].Id);
            // Perform some queries
            pagedResult = await transcriptStore.GetTranscriptActivitiesAsync("test", conversationId, null, DateTimeOffset.MaxValue);

            Assert.AreEqual(0, pagedResult.Items.Length);
        }
Esempio n. 3
0
        public async Task Transcript_LogActivities()
        {
            var         transcriptStore = new MemoryTranscriptStore();
            TestAdapter adapter         = new TestAdapter()
                                          .Use(new TranscriptLoggerMiddleware(transcriptStore));
            string conversationId = null;

            await new TestFlow(adapter, async(context) =>
            {
                conversationId     = context.Activity.Conversation.Id;
                var typingActivity = new Activity
                {
                    Type      = ActivityTypes.Typing,
                    RelatesTo = context.Activity.RelatesTo
                };
                await context.SendActivityAsync(typingActivity);
                await Task.Delay(500);
                await context.SendActivityAsync("echo:" + context.Activity.Text);
            })
            .Send("foo")
            .AssertReply((activity) => Assert.AreEqual(activity.Type, ActivityTypes.Typing))
            .AssertReply("echo:foo")
            .Send("bar")
            .AssertReply((activity) => Assert.AreEqual(activity.Type, ActivityTypes.Typing))
            .AssertReply("echo:bar")
            .StartTestAsync();

            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync("test", conversationId);

            Assert.AreEqual(6, pagedResult.Items.Length);
            Assert.AreEqual("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.IsNotNull(pagedResult.Items[1].AsTypingActivity());
            Assert.AreEqual("echo:foo", pagedResult.Items[2].AsMessageActivity().Text);
            Assert.AreEqual("bar", pagedResult.Items[3].AsMessageActivity().Text);
            Assert.IsNotNull(pagedResult.Items[4].AsTypingActivity());
            Assert.AreEqual("echo:bar", pagedResult.Items[5].AsMessageActivity().Text);
            foreach (var activity in pagedResult.Items)
            {
                Assert.IsTrue(!String.IsNullOrWhiteSpace(activity.Id));
                Assert.IsTrue(activity.Timestamp > default(DateTime));
            }
        }
Esempio n. 4
0
        public async Task Transcript_LogDeleteActivities()
        {
            var         transcriptStore = new MemoryTranscriptStore();
            TestAdapter adapter         = new TestAdapter()
                                          .Use(new TranscriptLoggerMiddleware(transcriptStore));
            string conversationId = null;
            string activityId     = null;

            await new TestFlow(adapter, async(context) =>
            {
                conversationId = context.Activity.Conversation.Id;
                if (context.Activity.Text == "deleteIt")
                {
                    await context.DeleteActivityAsync(activityId);
                }
                else
                {
                    var activity = context.Activity.CreateReply("response");
                    var response = await context.SendActivityAsync(activity);
                    activityId   = response.Id;
                }
            })
            .Send("foo")
            .AssertReply("response")
            .Send("deleteIt")
            .StartTestAsync();
            await Task.Delay(500);

            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync("test", conversationId);

            Assert.AreEqual(4, pagedResult.Items.Length);
            Assert.AreEqual("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.AreEqual("response", pagedResult.Items[1].AsMessageActivity().Text);
            Assert.AreEqual("deleteIt", pagedResult.Items[2].AsMessageActivity().Text);
            Assert.AreEqual(ActivityTypes.MessageDelete, pagedResult.Items[3].Type);
            Assert.AreEqual(pagedResult.Items[1].Id, pagedResult.Items[3].Id);
        }
Esempio n. 5
0
        public async Task QnaMaker_TraceActivity()
        {
            // Mock Qna
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Post, GetRequestUrl())
            .Respond("application/json", GetResponse("QnaMaker_ReturnsAnswer.json"));
            var qna = GetQnAMaker(mockHttp,
                                  new QnAMakerEndpoint
            {
                KnowledgeBaseId = _knowlegeBaseId,
                EndpointKey     = _endpointKey,
                Host            = _hostname
            },
                                  new QnAMakerOptions
            {
                Top = 1
            });

            // Invoke flow which uses mock
            var         transcriptStore = new MemoryTranscriptStore();
            TestAdapter adapter         = new TestAdapter()
                                          .Use(new TranscriptLoggerMiddleware(transcriptStore));
            string conversationId = null;

            await new TestFlow(adapter, async(context, ct) =>
            {
                // Simulate Qna Lookup
                if (context?.Activity?.Text.CompareTo("how do I clean the stove?") == 0)
                {
                    var results = await qna.GetAnswersAsync(context);
                    Assert.IsNotNull(results);
                    Assert.AreEqual(results.Length, 1, "should get one result");
                    StringAssert.StartsWith(results[0].Answer, "BaseCamp: You can use a damp rag to clean around the Power Pack");
                }

                conversationId     = context.Activity.Conversation.Id;
                var typingActivity = new Activity
                {
                    Type      = ActivityTypes.Typing,
                    RelatesTo = context.Activity.RelatesTo
                };
                await context.SendActivityAsync(typingActivity);
                await Task.Delay(500);
                await context.SendActivityAsync("echo:" + context.Activity.Text);
            })
            .Send("how do I clean the stove?")
            .AssertReply((activity) => Assert.AreEqual(activity.Type, ActivityTypes.Typing))
            .AssertReply("echo:how do I clean the stove?")
            .Send("bar")
            .AssertReply((activity) => Assert.AreEqual(activity.Type, ActivityTypes.Typing))
            .AssertReply("echo:bar")
            .StartTestAsync();

            // Validate Trace Activity created
            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync("test", conversationId);

            Assert.AreEqual(7, pagedResult.Items.Length);
            Assert.AreEqual("how do I clean the stove?", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.IsTrue(pagedResult.Items[1].Type.CompareTo(ActivityTypes.Trace) == 0);
            QnAMakerTraceInfo traceInfo = ((JObject)((ITraceActivity)pagedResult.Items[1]).Value).ToObject <QnAMakerTraceInfo>();

            Assert.IsNotNull(traceInfo);
            Assert.IsNotNull(pagedResult.Items[2].AsTypingActivity());
            Assert.AreEqual("echo:how do I clean the stove?", pagedResult.Items[3].AsMessageActivity().Text);
            Assert.AreEqual("bar", pagedResult.Items[4].AsMessageActivity().Text);
            Assert.IsNotNull(pagedResult.Items[5].AsTypingActivity());
            Assert.AreEqual("echo:bar", pagedResult.Items[6].AsMessageActivity().Text);
            foreach (var activity in pagedResult.Items)
            {
                Assert.IsTrue(!string.IsNullOrWhiteSpace(activity.Id));
                Assert.IsTrue(activity.Timestamp > default(DateTimeOffset));
            }
        }