private static async Task TestDateLogUpdateActivitiesTest(ITranscriptStore transcriptStore)
        {
            var dateTimeStartOffset1 = new DateTimeOffset(DateTime.Now);
            var dateTimeStartOffset2 = new DateTimeOffset(DateTime.UtcNow);

            var         conversation = TestAdapter.CreateConversation(Guid.NewGuid().ToString("n"));
            TestAdapter adapter      = new TestAdapter(conversation)
                                       .Use(new TranscriptLoggerMiddleware(transcriptStore));
            Activity activityToUpdate = null;

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                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(100);

            // Perform some queries
            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id, null, dateTimeStartOffset1.DateTime);

            Assert.Equal(3, pagedResult.Items.Length);
            Assert.Equal("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.Equal("new response", pagedResult.Items[1].AsMessageActivity().Text);
            Assert.Equal("update", pagedResult.Items[2].AsMessageActivity().Text);

            // Perform some queries
            pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id, null, DateTimeOffset.MinValue);

            Assert.Equal(3, pagedResult.Items.Length);
            Assert.Equal("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.Equal("new response", pagedResult.Items[1].AsMessageActivity().Text);
            Assert.Equal("update", pagedResult.Items[2].AsMessageActivity().Text);

            // Perform some queries
            pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id, null, DateTimeOffset.MaxValue);

            Assert.Empty(pagedResult.Items);
        }
        private static async Task LogDeleteActivitesTest(ITranscriptStore transcriptStore)
        {
            var         conversation = TestAdapter.CreateConversation(Guid.NewGuid().ToString("n"));
            TestAdapter adapter      = new TestAdapter(conversation)
                                       .Use(new TranscriptLoggerMiddleware(transcriptStore));
            string activityId = null;

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                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(100);

            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id);

            Assert.Equal(3, pagedResult.Items.Length);
            Assert.Equal("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.NotNull(pagedResult.Items[1].AsMessageDeleteActivity());
            Assert.Equal(ActivityTypes.MessageDelete, pagedResult.Items[1].Type);
            Assert.Equal("deleteIt", pagedResult.Items[2].AsMessageActivity().Text);
        }
        public static async Task EnsureToLogActivitiesWithIdsTest(ITranscriptStore transcriptStore)
        {
            var conversation = TestAdapter.CreateConversation(Guid.NewGuid().ToString("n"));
            var adapter      = new AllowNullIdTestAdapter(conversation)
                               .Use(new TranscriptLoggerMiddleware(transcriptStore));

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                var activityWithId = new Activity
                {
                    Id        = "TestActivityWithId",
                    Text      = "I am an activity with an Id.",
                    Type      = ActivityTypes.Message,
                    RelatesTo = context.Activity.RelatesTo
                };
                var activityWithNullId = new Activity
                {
                    Id        = null,
                    Text      = "My Id is null.",
                    Type      = ActivityTypes.Message,
                    RelatesTo = context.Activity.RelatesTo
                };

                await context.SendActivityAsync(activityWithId);
                await context.SendActivityAsync(activityWithId);

                await context.SendActivityAsync(activityWithNullId);
            })
            .Send("inbound message to TestFlow")
            .AssertReply("I am an activity with an Id.")
            .Send("2nd inbound message to TestFlow")
            .AssertReply((activity) => Assert.AreEqual(activity.Id, "TestActivityWithId"))
            .Send("3rd inbound message to TestFlow")
            .AssertReply("My Id is null.")
            .StartTestAsync();

            await Task.Delay(100);

            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id);

            Assert.AreEqual(12, pagedResult.Items.Length);
            Assert.AreEqual("inbound message to TestFlow", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.IsNotNull(pagedResult.Items[1].AsMessageActivity());
            Assert.AreEqual("I am an activity with an Id.", pagedResult.Items[1].AsMessageActivity().Text);
            Assert.AreEqual("2nd inbound message to TestFlow", pagedResult.Items[4].AsMessageActivity().Text);
            Assert.AreEqual("TestActivityWithId", pagedResult.Items[5].Id);
            Assert.AreEqual("3rd inbound message to TestFlow", pagedResult.Items[8].AsMessageActivity().Text);
            Assert.AreEqual("My Id is null.", pagedResult.Items[11].AsMessageActivity().Text);
            Assert.IsTrue(pagedResult.Items[11].AsMessageActivity().Id.Contains("g_"));
            foreach (var activity in pagedResult.Items)
            {
                Assert.IsTrue(activity.Timestamp > default(DateTimeOffset));
            }
        }
        public async Task ElasticsearchTranscriptStore_RetrieveTranscriptsTest()
        {
            // Arrange
            var activity = new Activity();

            activity.ChannelId       = "TestChannelId";
            activity.Conversation    = new ConversationAccount();
            activity.Conversation.Id = "TestConversationId";
            activity.Timestamp       = DateTimeOffset.Now;

            for (int i = 0; i < 50; i++)
            {
                // Log activity.
                await transcriptStore.LogActivityAsync(activity);

                // Update timestamp.
                activity.Timestamp = DateTimeOffset.Now.AddSeconds(1);
            }

            // Act
            var result      = new List <IActivity>();
            var pagedResult = new PagedResult <IActivity>();

            do
            {
                pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(activity.ChannelId, activity.Conversation.Id, pagedResult.ContinuationToken);

                foreach (var item in pagedResult.Items)
                {
                    result.Add(item);
                }

                Assert.AreNotEqual(0, pagedResult.Items.Length);
            }while (pagedResult.ContinuationToken != null);

            // Assert
            Assert.AreNotEqual(0, result.Count);
        }
        private static async Task LogActivitiesTest(ITranscriptStore transcriptStore)
        {
            var         conversation = TestAdapter.CreateConversation(Guid.NewGuid().ToString("n"));
            TestAdapter adapter      = new TestAdapter(conversation)
                                       .Use(new TranscriptLoggerMiddleware(transcriptStore));

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

            await Task.Delay(100);

            var pagedResult = await transcriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id);

            Assert.Equal(6, pagedResult.Items.Length);
            Assert.Equal("foo", pagedResult.Items[0].AsMessageActivity().Text);
            Assert.NotNull(pagedResult.Items[1].AsTypingActivity());
            Assert.Equal("echo:foo", pagedResult.Items[2].AsMessageActivity().Text);
            Assert.Equal("bar", pagedResult.Items[3].AsMessageActivity().Text);
            Assert.NotNull(pagedResult.Items[4].AsTypingActivity());
            Assert.Equal("echo:bar", pagedResult.Items[5].AsMessageActivity().Text);
            foreach (var activity in pagedResult.Items)
            {
                Assert.True(!string.IsNullOrWhiteSpace(activity.Id));
                Assert.True(activity.Timestamp > default(DateTimeOffset));
            }
        }
Example #6
0
        public async Task _BadArgs()
        {
            try
            {
                await store.LogActivityAsync(null);

                Assert.Fail("LogActivity Should have thrown on null ");
            }
            catch (ArgumentNullException) { }
            catch { Assert.Fail("LogActivity Should have thrown ArgumentNull exception on null "); }

            try
            {
                await store.GetTranscriptActivitiesAsync(null, null);

                Assert.Fail("GetConversationActivities Should have thrown on null");
            }
            catch (ArgumentNullException) { }
            catch { Assert.Fail("DeleteConversation Should have thrown ArgumentNull "); }

            try
            {
                await store.GetTranscriptActivitiesAsync("asdfds", null);

                Assert.Fail("GetConversationActivities Should have thrown on null");
            }
            catch (ArgumentNullException) { }
            catch { Assert.Fail("DeleteConversation Should have thrown ArgumentNull "); }

            try
            {
                await store.ListTranscriptsAsync(null);

                Assert.Fail("ListConversations Should have thrown on null");
            }
            catch (ArgumentNullException) { }
            catch { Assert.Fail("ListConversations Should have thrown ArgumentNull "); }

            try
            {
                await store.DeleteTranscriptAsync(null, null);

                Assert.Fail("DeleteConversation Should have thrown on null channelId");
            }
            catch (ArgumentNullException) { }
            catch { Assert.Fail("DeleteConversation Should have thrown ArgumentNull on channelId"); }

            try
            {
                await store.DeleteTranscriptAsync("test", null);

                Assert.Fail("DeleteConversation Should have thrown on null conversationId");
            }
            catch (ArgumentNullException) { }
            catch { Assert.Fail("DeleteConversation Should have thrown ArgumentNull on conversationId"); }
        }