/// <summary>
        /// There are some async oddities within TranscriptLoggerMiddleware that make it difficult to set a short delay when running this tests that ensures
        /// the TestFlow completes while also logging transcripts. Some tests will not pass without longer delays, but this method minimizes the delay required.
        /// </summary>
        /// <param name="conversation">ConversationReference to pass to GetTranscriptActivitiesAsync() that contains ChannelId and Conversation.Id.</param>
        /// <param name="expectedLength">Expected length of pagedResult array.</param>
        /// <param name="maxTimeout">Maximum time to wait to retrieve pagedResult.</param>
        /// <returns>PagedResult.</returns>
        private async Task <PagedResult <IActivity> > GetPagedResultAsync(ConversationReference conversation, int expectedLength, int maxTimeout = 10000)
        {
            PagedResult <IActivity> pagedResult = null;

            for (var timeout = 0; timeout < maxTimeout; timeout += 500)
            {
                await Task.Delay(500);

                try
                {
                    pagedResult = await TranscriptStore.GetTranscriptActivitiesAsync(conversation.ChannelId, conversation.Conversation.Id);

                    if (pagedResult.Items.Length >= expectedLength)
                    {
                        break;
                    }
                }
                catch (KeyNotFoundException)
                {
                }
                catch (NullReferenceException)
                {
                }
            }

            if (pagedResult == null)
            {
                throw new TimeoutException("Unable to retrieve pagedResult in time");
            }

            return(pagedResult);
        }
        public async Task ActivityAddPagedResultTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var cleanChanel = Guid.NewGuid().ToString();

                var loggedPagedResult = new PagedResult <IActivity>();
                var activities        = new List <IActivity>();

                for (var i = 0; i < ConversationIds.Length; i++)
                {
                    var a = CreateActivity(0, i, ConversationIds);
                    a.ChannelId = cleanChanel;

                    await TranscriptStore.LogActivityAsync(a);

                    activities.Add(a);
                }

                loggedPagedResult = TranscriptStore.GetTranscriptActivitiesAsync(cleanChanel, ConversationIds[0]).Result;
                var ct = loggedPagedResult.ContinuationToken;
                Assert.Equal(20, loggedPagedResult.Items.Length);
                Assert.NotNull(ct);
                Assert.True(loggedPagedResult.ContinuationToken.Length > 0);
                loggedPagedResult = TranscriptStore.GetTranscriptActivitiesAsync(cleanChanel, ConversationIds[0], ct).Result;
                ct = loggedPagedResult.ContinuationToken;
                Assert.Equal(10, loggedPagedResult.Items.Length);
                Assert.Null(ct);
            }
        }
Пример #3
0
        public async Task TestDateLogUpdateActivities()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                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(5000);

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

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

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

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

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

                Assert.AreEqual(0, pagedResult.Items.Length);
            }
        }
        public async Task ActivityEmptyTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                foreach (var convoId in ConversationSpecialIds)
                {
                    var activities = await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, convoId);

                    Assert.Empty(activities.Items);
                }
            }
        }
        public async Task TranscriptRemoveSpecialCharsTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                for (var i = 0; i < ConversationSpecialIds.Length; i++)
                {
                    var a = CreateActivity(i, i, ConversationSpecialIds);
                    await TranscriptStore.DeleteTranscriptAsync(a.ChannelId, a.Conversation.Id);

                    var loggedActivities =
                        await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, ConversationSpecialIds[i]);

                    Assert.Empty(loggedActivities.Items);
                }
            }
        }
Пример #6
0
        public async Task LogActivities()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                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(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();

                await Task.Delay(1000);

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

                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(DateTimeOffset));
                }
            }
        }
        public async Task ActivityAddTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var loggedActivities = new IActivity[5];
                var activities       = new List <IActivity>();
                for (var i = 0; i < 5; i++)
                {
                    var a = CreateActivity(i, i, ConversationIds);
                    await TranscriptStore.LogActivityAsync(a);

                    activities.Add(a);
                    loggedActivities[i] = TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[i]).Result.Items[0];
                }

                Assert.Equal(5, loggedActivities.Length);
            }
        }
Пример #8
0
        public async Task TranscriptRemoveTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                for (var i = 0; i < 5; i++)
                {
                    var a = CreateActivity(i, i, ConversationIds);
                    await TranscriptStore.LogActivityAsync(a);

                    await TranscriptStore.DeleteTranscriptAsync(a.ChannelId, a.Conversation.Id);

                    var loggedActivities =
                        await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[i]);

                    Assert.AreEqual(0, loggedActivities.Items.Length);
                }
            }
        }
Пример #9
0
        public async Task TranscriptRemovePagedTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var loggedActivities = new PagedResult <IActivity>();
                int i;
                for (i = 0; i < ConversationSpecialIds.Length; i++)
                {
                    var a = CreateActivity(i, i, ConversationIds);
                    await TranscriptStore.DeleteTranscriptAsync(a.ChannelId, a.Conversation.Id);
                }

                loggedActivities =
                    await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[i]);

                Assert.AreEqual(0, loggedActivities.Items.Length);
            }
        }
Пример #10
0
        public async Task LogDeleteActivities()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                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(1000);

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

                Assert.AreEqual(3, pagedResult.Items.Length);
                Assert.AreEqual("foo", pagedResult.Items[0].AsMessageActivity().Text);
                Assert.IsNotNull(pagedResult.Items[1].AsMessageDeleteActivity());
                Assert.AreEqual(ActivityTypes.MessageDelete, pagedResult.Items[1].Type);
                Assert.AreEqual("deleteIt", pagedResult.Items[2].AsMessageActivity().Text);
            }
        }