Example #1
0
        public async Task TestBlobStorageChanges()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                // Arrange
                var storage = GetStorage();

                // Act
                await storage.WriteAsync(new Dictionary <string, object> {
                    { "a", "1.0" }, { "b", "2.0" }
                });

                await storage.WriteAsync(new Dictionary <string, object> {
                    { "c", "3.0" }
                });

                await storage.DeleteAsync(new[] { "b" });

                await storage.WriteAsync(new Dictionary <string, object> {
                    { "a", "1.1" }
                });

                var result = await storage.ReadAsync(new[] { "a", "b", "c", "d", "e" });

                // Assert
                Assert.Equal(2, result.Count);
                Assert.Equal("1.1", result["a"]);
                Assert.Equal("3.0", result["c"]);
            }
        }
Example #2
0
 public async void ListTranscriptsAsyncWithEmptyChannelIdShouldFail()
 {
     if (StorageEmulatorHelper.CheckEmulator())
     {
         await Assert.ThrowsAsync <ArgumentNullException>(() => TranscriptStore.ListTranscriptsAsync(string.Empty));
     }
 }
        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);
            }
        }
        public async Task LogMissingUpdateActivity()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var conversation = TestAdapter.CreateConversation(Guid.NewGuid().ToString("n"));
                var adapter      = new TestAdapter(conversation)
                                   .Use(new TranscriptLoggerMiddleware(TranscriptStore));
                string fooId = string.Empty;
                await new TestFlow(adapter, async(context, cancellationToken) =>
                {
                    fooId = context.Activity.Id;
                    var updateActivity  = JsonConvert.DeserializeObject <Activity>(JsonConvert.SerializeObject(context.Activity));
                    updateActivity.Text = "updated response";
                    var response        = await context.UpdateActivityAsync(updateActivity);
                })
                .Send("foo")
                .StartTestAsync();

                await Task.Delay(3000);

                var pagedResult = await GetPagedResultAsync(conversation, 2);

                Assert.Equal(2, pagedResult.Items.Length);
                Assert.Equal(fooId, pagedResult.Items[0].AsMessageActivity().Id);
                Assert.Equal("foo", pagedResult.Items[0].AsMessageActivity().Text);
                Assert.StartsWith("g_", pagedResult.Items[1].AsMessageActivity().Id);
                Assert.Equal("updated response", pagedResult.Items[1].AsMessageActivity().Text);
            }
        }
Example #5
0
        private async Task TestConversationStateBlobStorage_Method(IStorage blobs)
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                // Arrange
                var conversationState = new ConversationState(blobs);
                var propAccessor      = conversationState.CreateProperty <Prop>("prop");
                var adapter           = new TestStorageAdapter();
                var activity          = new Activity
                {
                    ChannelId    = "123",
                    Conversation = new ConversationAccount {
                        Id = "abc"
                    },
                };

                // Act
                var turnContext1 = new TurnContext(adapter, activity);
                var propValue1   = await propAccessor.GetAsync(turnContext1, () => new Prop());

                propValue1.X = "hello";
                propValue1.Y = "world";
                await conversationState.SaveChangesAsync(turnContext1, force : true);

                var turnContext2 = new TurnContext(adapter, activity);
                var propValue2   = await propAccessor.GetAsync(turnContext2);

                // Assert
                Assert.Equal("hello", propValue2.X);
                Assert.Equal("world", propValue2.Y);
            }
        }
Example #6
0
        public async Task TestBlobStorageWriteDeleteRead()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                // Arrange
                var storage = GetStorage();

                var changes = new Dictionary <string, object>
                {
                    { "x", "hello" },
                    { "y", "world" },
                };

                // Act
                await storage.WriteAsync(changes);

                await storage.DeleteAsync(new[] { "x" });

                var result = await storage.ReadAsync(new[] { "x", "y" });

                // Assert
                Assert.Equal(1, result.Count);
                Assert.Equal("world", result["y"]);
            }
        }
Example #7
0
 public async Task StatePersistsThroughMultiTurn_TypeNameHandlingNone()
 {
     if (StorageEmulatorHelper.CheckEmulator())
     {
         await StatePersistsThroughMultiTurn(GetStorage(true));
     }
 }
Example #8
0
 public async Task TestConversationStateBlobStorage_TypeNameHandlingNone()
 {
     if (StorageEmulatorHelper.CheckEmulator())
     {
         await TestConversationStateBlobStorage_Method(GetStorage(true));
     }
 }
        public async Task UpdateActivityOverwriteDoesNotThrowTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var conversationId = "UpdateActivityOverwriteDoesNotThrowTest";

                var activity = CreateActivity(99, conversationId);
                activity.ChannelData = new
                {
                    value = "original"
                };

                await TranscriptStore.LogActivityAsync(activity);

                var loggedActivities = await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, conversationId);

                Assert.Equal("100", loggedActivities.Items[0].Id);
                Assert.Equal("original", (loggedActivities.Items[0].ChannelData as JToken)["value"]);

                activity.Type        = ActivityTypes.MessageUpdate;
                activity.ChannelData = new
                {
                    value = "overwritten"
                };

                await TranscriptStore.LogActivityAsync(activity);

                loggedActivities = await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, conversationId);

                Assert.Single(loggedActivities.Items);
                Assert.Equal("overwritten", (loggedActivities.Items[0].ChannelData as JToken)["value"]);
            }
        }
        public async Task LogDeleteActivities()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var conversation = TestAdapter.CreateConversation(Guid.NewGuid().ToString("n"));
                var 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();

                var pagedResult = await GetPagedResultAsync(conversation, 3);

                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 async Task TestDateLogUpdateActivities()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();

                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 void Dispose()
 {
     if (StorageEmulatorHelper.CheckEmulator())
     {
         await new BlobContainerClient(ConnectionString, ContainerName)
         .DeleteIfExistsAsync().ConfigureAwait(false);
     }
 }
        public async Task TranscriptsEmptyTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var unusedChannelId = Guid.NewGuid().ToString();
                var transcripts     = await TranscriptStore.ListTranscriptsAsync(unusedChannelId);

                Assert.Empty(transcripts.Items);
            }
        }
Example #14
0
 public async Task DisposeAsync()
 {
     if (StorageEmulatorHelper.CheckEmulator())
     {
         await CloudStorageAccount.Parse(ConnectionString)
         .CreateCloudBlobClient()
         .GetContainerReference(ContainerName)
         .DeleteIfExistsAsync().ConfigureAwait(false);
     }
 }
Example #15
0
        public async Task TestBlobStorageWriteWithNullChangesShouldFail()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                // Arrange
                var storage = GetStorage();

                // Assert
                await Assert.ThrowsAsync <ArgumentNullException>(() => storage.WriteAsync(null));
            }
        }
        public async Task TranscriptListTestWithoutContinuationToken()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var a = CreateActivity(0, 0, ConversationIds);
                await TranscriptStore.LogActivityAsync(a);

                var result = await TranscriptStore.ListTranscriptsAsync(a.ChannelId);

                Assert.Single(result.Items);
            }
        }
        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 TranscriptsEmptyTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();

                var unusedChannelId = Guid.NewGuid().ToString();
                var transcripts     = await TranscriptStore.ListTranscriptsAsync(unusedChannelId);

                Assert.AreEqual(transcripts.Items.Length, 0);
            }
        }
        public async Task NullBlobTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();
                AzureBlobTranscriptStore store = null;

                await Assert.ThrowsExceptionAsync <NullReferenceException>(async() =>
                                                                           await store.LogActivityAsync(CreateActivity(0, 0, ConversationIds)));

                await Assert.ThrowsExceptionAsync <NullReferenceException>(async() =>
                                                                           await store.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[0]));
            }
        }
        public async Task ActivityEmptyTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();

                foreach (var convoId in ConversationSpecialIds)
                {
                    var activities = await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, convoId);

                    Assert.AreEqual(activities.Items.Length, 0);
                }
            }
        }
        public BlobsStorageTests(ITestOutputHelper testOutputHelper)
        {
            var helper = (TestOutputHelper)testOutputHelper;

            var test = (ITest)helper.GetType().GetField("test", BindingFlags.NonPublic | BindingFlags.Instance)
                       .GetValue(helper);

            _testName = test.TestCase.TestMethod.Method.Name;

            if (StorageEmulatorHelper.CheckEmulator())
            {
                new BlobContainerClient(ConnectionString, ContainerName)
                .DeleteIfExistsAsync().ConfigureAwait(false);
            }
        }
Example #22
0
        public async Task TestBlobStorageWriteWithEmptyKeyChangesShouldFail()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                // Arrange
                var storage = GetStorage();

                var changes = new Dictionary <string, object>
                {
                    { string.Empty, "hello" },
                };

                // Act
                await Assert.ThrowsAsync <ArgumentNullException>(() => storage.WriteAsync(changes));
            }
        }
        public async Task NullParameterTests()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var store = TranscriptStore;

                await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                 await store.LogActivityAsync(null));

                await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                 await store.GetTranscriptActivitiesAsync(null, ConversationIds[0]));

                await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                 await store.GetTranscriptActivitiesAsync(ChannelId, null));
            }
        }
        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);
                }
            }
        }
        public async Task LogActivities()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();

                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 void BlobStorageParamTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                Assert.Throws <ArgumentNullException>(() =>
                                                      new BlobsStorage(null, ContainerName));

                Assert.Throws <ArgumentNullException>(() =>
                                                      new BlobsStorage(ConnectionString, null));

                Assert.Throws <ArgumentNullException>(() =>
                                                      new BlobsStorage(string.Empty, ContainerName));

                Assert.Throws <ArgumentNullException>(() =>
                                                      new BlobsStorage(ConnectionString, string.Empty));
            }
        }
        public async Task GenericActivityOverwriteThrowsTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                var conversationId = "GenericActivityOverwriteThrowsTest";

                var activity = CreateActivity(99, conversationId);

                await TranscriptStore.LogActivityAsync(activity);

                var loggedActivities = await TranscriptStore.GetTranscriptActivitiesAsync(ChannelId, conversationId);

                Assert.Equal("100", loggedActivities.Items[0].Id);

                await Assert.ThrowsAsync <RequestFailedException>(async() => await TranscriptStore.LogActivityAsync(activity));
            }
        }
Example #28
0
        public AzureBlobStorageTests(ITestOutputHelper testOutputHelper)
        {
            var helper = (TestOutputHelper)testOutputHelper;

            var test = (ITest)helper.GetType().GetField("test", BindingFlags.NonPublic | BindingFlags.Instance)
                       .GetValue(helper);

            _testName = test.TestCase.TestMethod.Method.Name;

            if (StorageEmulatorHelper.CheckEmulator())
            {
                CloudStorageAccount.Parse(ConnectionString)
                .CreateCloudBlobClient()
                .GetContainerReference(ContainerName)
                .DeleteIfExistsAsync().ConfigureAwait(false);
            }
        }
        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);
            }
        }
        public async Task TranscriptRemoveTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();

                for (var i = 0; i < 5; i++)
                {
                    var a = CreateActivity(i, i, ConversationIds);
                    await TranscriptStore.DeleteTranscriptAsync(a.ChannelId, a.Conversation.Id);

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

                    Assert.AreEqual(0, loggedActivities.Items.Length);
                }
            }
        }