From 5b61dc0b3acf696ca9d70edf2617ef1725bf42c9 Mon Sep 17 00:00:00 2001 From: virtual-josh Date: Fri, 26 Jun 2020 16:34:47 -0700 Subject: [PATCH 1/4] porting tests to xunit --- .../ActivityFactoryTests.cs | 553 +++++++++--------- .../LGGeneratorTests.cs | 137 +++-- ...er.Dialogs.Adaptive.Templates.Tests.csproj | 5 + .../Startup.cs | 8 +- 4 files changed, 353 insertions(+), 350 deletions(-) diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs index e50813eb2c..73d52045a7 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs @@ -5,24 +5,23 @@ using Microsoft.Bot.Builder.Dialogs.Declarative.Resources; using Microsoft.Bot.Builder.LanguageGeneration; using Microsoft.Bot.Schema; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; +using Xunit; namespace Microsoft.Bot.Builder.Dialogs.Tests { - [TestClass] public class ActivityFactoryTests { - [TestMethod] + [Fact] public void TestInlineActivityFactory() { var lgResult = GetNormalStructureLGFile().EvaluateText("text").ToString(); var activity = ActivityFactory.FromObject(lgResult); - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual("text", activity.Text); - Assert.AreEqual("text", activity.Speak); - Assert.IsNull(activity.InputHint); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal("text", activity.Text); + Assert.Equal("text", activity.Speak); + Assert.Null(activity.InputHint); var data = new JObject(); data["title"] = "titleContent"; @@ -32,17 +31,17 @@ public void TestInlineActivityFactory() AssertCardActionActivity(activity); } - [TestMethod] + [Fact] public void TestNotSupportStructuredType() { // fallback to text activity var lgResult = GetNormalStructureLGFile().Evaluate("notSupport"); var activity = ActivityFactory.FromObject(lgResult); - Assert.AreEqual(0, activity.Attachments.Count); - Assert.AreEqual("{\"lgType\":\"Acti\",\"key\":\"value\"}", activity.Text.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace(" ", string.Empty)); + Assert.Equal(0, activity.Attachments.Count); + Assert.Equal("{\"lgType\":\"Acti\",\"key\":\"value\"}", activity.Text.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace(" ", string.Empty)); } - [TestMethod] + [Fact] public void TestHerocardWithCardAction() { dynamic data = new JObject(); @@ -53,7 +52,7 @@ public void TestHerocardWithCardAction() AssertCardActionActivity(activity); } - [TestMethod] + [Fact] public void TestAdaptivecardActivity() { dynamic data = new JObject(); @@ -63,7 +62,7 @@ public void TestAdaptivecardActivity() AssertAdaptiveCardActivity(activity); } - [TestMethod] + [Fact] public void TestExternalAdaptiveCardActivity() { dynamic data = new JObject(); @@ -73,7 +72,7 @@ public void TestExternalAdaptiveCardActivity() AssertAdaptiveCardActivity(activity); } - [TestMethod] + [Fact] public void TestMultiExternalAdaptiveCardActivity() { dynamic data = new JObject(); @@ -83,7 +82,7 @@ public void TestMultiExternalAdaptiveCardActivity() AssertMultiAdaptiveCardActivity(activity); } - [TestMethod] + [Fact] public void TestAdaptivecardActivityWithAttachmentStructure() { dynamic data = new JObject(); @@ -93,7 +92,7 @@ public void TestAdaptivecardActivityWithAttachmentStructure() AssertAdaptiveCardActivity(activity); } - [TestMethod] + [Fact] public void TestExternalHeroCardActivity() { dynamic data = new JObject(); @@ -105,7 +104,7 @@ public void TestExternalHeroCardActivity() AssertActivityWithHeroCardAttachment(activity); } - [TestMethod] + [Fact] public void TestEventActivity() { dynamic data = new JObject(); @@ -115,7 +114,7 @@ public void TestEventActivity() AssertEventActivity(activity); } - [TestMethod] + [Fact] public void TestHandoffActivity() { dynamic data = new JObject(); @@ -125,7 +124,7 @@ public void TestHandoffActivity() AssertHandoffActivity(activity); } - [TestMethod] + [Fact] public void TestActivityWithHeroCardAttachment() { dynamic data = new JObject(); @@ -136,7 +135,7 @@ public void TestActivityWithHeroCardAttachment() AssertActivityWithHeroCardAttachment(activity); } - [TestMethod] + [Fact] public void TestHerocardAttachment() { dynamic data = new JObject(); @@ -148,7 +147,7 @@ public void TestHerocardAttachment() AssertActivityWithHeroCardAttachment(activity); } - [TestMethod] + [Fact] public void TestHerocardActivityWithAttachmentStructure() { dynamic data = new JObject(); @@ -159,7 +158,7 @@ public void TestHerocardActivityWithAttachmentStructure() AssertActivityWithMultiAttachments(activity); } - [TestMethod] + [Fact] public void TestActivityWithSuggestionActions() { dynamic data = new JObject(); @@ -170,7 +169,7 @@ public void TestActivityWithSuggestionActions() AssertActivityWithSuggestionActions(activity); } - [TestMethod] + [Fact] public void TestMessageActivityAll() { dynamic data = new JObject(); @@ -181,7 +180,7 @@ public void TestMessageActivityAll() AssertMessageActivityAll(activity); } - [TestMethod] + [Fact] public void TestActivityWithMultiStructuredSuggestionActions() { dynamic data = new JObject(); @@ -191,7 +190,7 @@ public void TestActivityWithMultiStructuredSuggestionActions() AssertActivityWithMultiStructuredSuggestionActions(activity); } - [TestMethod] + [Fact] public void TestActivityWithMultiStringSuggestionActions() { dynamic data = new JObject(); @@ -201,7 +200,7 @@ public void TestActivityWithMultiStringSuggestionActions() AssertActivityWithMultiStringSuggestionActions(activity); } - [TestMethod] + [Fact] public void TestHeroCardTemplate() { dynamic data = new JObject(); @@ -211,7 +210,7 @@ public void TestHeroCardTemplate() AssertHeroCardActivity(activity); } - [TestMethod] + [Fact] public void TestThumbnailCardTemplate() { dynamic data = new JObject(); @@ -221,7 +220,7 @@ public void TestThumbnailCardTemplate() AssertThumbnailCardActivity(activity); } - [TestMethod] + [Fact] public void TestAudioCardTemplate() { dynamic data = new JObject(); @@ -231,7 +230,7 @@ public void TestAudioCardTemplate() AssertAudioCardActivity(activity); } - [TestMethod] + [Fact] public void TestVideoCardTemplate() { dynamic data = new JObject(); @@ -241,7 +240,7 @@ public void TestVideoCardTemplate() AssertVideoCardActivity(activity); } - [TestMethod] + [Fact] public void TestSigninCardTemplate() { dynamic data = new JObject(); @@ -252,7 +251,7 @@ public void TestSigninCardTemplate() AssertSigninCardActivity(activity); } - [TestMethod] + [Fact] public void TestOAuthCardTemplate() { dynamic data = new JObject(); @@ -264,7 +263,7 @@ public void TestOAuthCardTemplate() AssertOAuthCardActivity(activity); } - [TestMethod] + [Fact] public void TestReceiptCardTemplate() { var data = new JObject @@ -289,7 +288,7 @@ public void TestReceiptCardTemplate() AssertReceiptCardActivity(activity); } - [TestMethod] + [Fact] public void TestSuggestedActionsReference() { dynamic data = new JObject(); @@ -299,37 +298,37 @@ public void TestSuggestedActionsReference() AssertSuggestedActionsReferenceActivity(activity); } - [TestMethod] + [Fact] public void CheckOutPutNotFromStructuredLG() { var diagnostics = ActivityFactory.CheckLGResult("Not a valid json"); - Assert.AreEqual(diagnostics.Count, 1); - Assert.AreEqual("[WARNING]LG output is not a json object, and will fallback to string format.", diagnostics[0]); + Assert.Equal(diagnostics.Count, 1); + Assert.Equal("[WARNING]LG output is not a json object, and will fallback to string format.", diagnostics[0]); } - [TestMethod] + [Fact] public void CheckStructuredLGDiagnostics() { var lgResult = GetDiagnosticStructureLGFile().Evaluate("ErrorStructuredType", null); var diagnostics = ActivityFactory.CheckLGResult(lgResult); - Assert.AreEqual(diagnostics.Count, 1); - Assert.AreEqual("[WARNING]Type 'mystruct' is not supported currently.", diagnostics[0]); + Assert.Equal(diagnostics.Count, 1); + Assert.Equal("[WARNING]Type 'mystruct' is not supported currently.", diagnostics[0]); lgResult = GetDiagnosticStructureLGFile().Evaluate("ErrorActivityType", null); diagnostics = ActivityFactory.CheckLGResult(lgResult); - Assert.AreEqual(2, diagnostics.Count); - Assert.AreEqual("[ERROR]'xxx' is not a valid activity type.", diagnostics[0]); - Assert.AreEqual("[WARNING]'invalidproperty' not support in Activity.", diagnostics[1]); + Assert.Equal(2, diagnostics.Count); + Assert.Equal("[ERROR]'xxx' is not a valid activity type.", diagnostics[0]); + Assert.Equal("[WARNING]'invalidproperty' not support in Activity.", diagnostics[1]); lgResult = GetDiagnosticStructureLGFile().Evaluate("ErrorMessage", null); diagnostics = ActivityFactory.CheckLGResult(lgResult); - Assert.AreEqual(diagnostics.Count, 5); - Assert.AreEqual("[WARNING]'attachment,suggestedaction' not support in Activity.", diagnostics[0]); - Assert.AreEqual("[WARNING]'mystruct' is not card action type.", diagnostics[1]); - Assert.AreEqual("[ERROR]'yyy' is not a valid card action type.", diagnostics[2]); - Assert.AreEqual("[ERROR]'notsure' is not a boolean value.", diagnostics[3]); - Assert.AreEqual("[WARNING]'mystruct' is not an attachment type.", diagnostics[4]); + Assert.Equal(diagnostics.Count, 5); + Assert.Equal("[WARNING]'attachment,suggestedaction' not support in Activity.", diagnostics[0]); + Assert.Equal("[WARNING]'mystruct' is not card action type.", diagnostics[1]); + Assert.Equal("[ERROR]'yyy' is not a valid card action type.", diagnostics[2]); + Assert.Equal("[ERROR]'notsure' is not a boolean value.", diagnostics[3]); + Assert.Equal("[WARNING]'mystruct' is not an attachment type.", diagnostics[4]); } private static string GetProjectFolder() @@ -339,346 +338,346 @@ private static string GetProjectFolder() private void AssertSuggestedActionsReferenceActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual("textContent", activity.Text, "should have right text"); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal("textContent", activity.Text); - Assert.AreEqual(5, activity.SuggestedActions.Actions.Count, "should have 5 actions in suggestedAction"); - Assert.AreEqual("Add todo", activity.SuggestedActions.Actions[0].Value); - Assert.AreEqual("View Todo", activity.SuggestedActions.Actions[1].Value); - Assert.AreEqual("Remove Todo", activity.SuggestedActions.Actions[2].Value); - Assert.AreEqual("Cancel", activity.SuggestedActions.Actions[3].Value); - Assert.AreEqual("Help", activity.SuggestedActions.Actions[4].Value); + Assert.Equal(5, activity.SuggestedActions.Actions.Count); + Assert.Equal("Add todo", activity.SuggestedActions.Actions[0].Value); + Assert.Equal("View Todo", activity.SuggestedActions.Actions[1].Value); + Assert.Equal("Remove Todo", activity.SuggestedActions.Actions[2].Value); + Assert.Equal("Cancel", activity.SuggestedActions.Actions[3].Value); + Assert.Equal("Help", activity.SuggestedActions.Actions[4].Value); } private void AssertMessageActivityAll(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual("textContent", activity.Text); - Assert.AreEqual("textContent", activity.Speak); - Assert.AreEqual("accepting", activity.InputHint); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal("textContent", activity.Text); + Assert.Equal("textContent", activity.Speak); + Assert.Equal("accepting", activity.InputHint); var semanticAction = activity.SemanticAction; - Assert.AreEqual("actionId", semanticAction.Id); - Assert.AreEqual(1, semanticAction.Entities.Count); - Assert.AreEqual(true, semanticAction.Entities.ContainsKey("key1")); - Assert.AreEqual("entityType", semanticAction.Entities["key1"].Type); - - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(AttachmentLayoutTypes.List, activity.AttachmentLayout); - Assert.AreEqual(HeroCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal("actionId", semanticAction.Id); + Assert.Equal(1, semanticAction.Entities.Count); + Assert.Equal(true, semanticAction.Entities.ContainsKey("key1")); + Assert.Equal("entityType", semanticAction.Entities["key1"].Type); + + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(AttachmentLayoutTypes.List, activity.AttachmentLayout); + Assert.Equal(HeroCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have herocard"); + Assert.NotNull(card); var tap = card.Tap; - Assert.AreEqual("taptitle", tap.Title, "tap title should be set"); - Assert.AreEqual("tapvalue", tap.Value, "tap value should be set"); - Assert.AreEqual("imBack", tap.Type, "tap type should be set"); - Assert.AreEqual("textContent", card.Text, "card text should be set"); - Assert.AreEqual(1, card.Buttons.Count, "card buttons should be set"); - Assert.AreEqual($"imBack", card.Buttons[0].Type, "card buttons should be set"); - Assert.AreEqual($"titleContent", card.Buttons[0].Title, "card buttons should be set"); - Assert.AreEqual($"textContent", card.Buttons[0].Value, "card buttons should be set"); - Assert.AreEqual(2, activity.SuggestedActions.Actions.Count); - Assert.AreEqual("firstItem", activity.SuggestedActions.Actions[0].Title); - Assert.AreEqual("firstItem", activity.SuggestedActions.Actions[0].Value); - Assert.AreEqual("titleContent", activity.SuggestedActions.Actions[1].Title); - Assert.AreEqual("textContent", activity.SuggestedActions.Actions[1].Value); + Assert.Equal("taptitle", tap.Title); + Assert.Equal("tapvalue", tap.Value); + Assert.Equal("imBack", tap.Type); + Assert.Equal("textContent", card.Text); + Assert.Equal(1, card.Buttons.Count); + Assert.Equal($"imBack", card.Buttons[0].Type); + Assert.Equal($"titleContent", card.Buttons[0].Title); + Assert.Equal($"textContent", card.Buttons[0].Value); + Assert.Equal(2, activity.SuggestedActions.Actions.Count); + Assert.Equal("firstItem", activity.SuggestedActions.Actions[0].Title); + Assert.Equal("firstItem", activity.SuggestedActions.Actions[0].Value); + Assert.Equal("titleContent", activity.SuggestedActions.Actions[1].Title); + Assert.Equal("textContent", activity.SuggestedActions.Actions[1].Value); } private void AssertActivityWithSuggestionActions(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual("textContent", activity.Text); - Assert.AreEqual(2, activity.SuggestedActions.Actions.Count); - Assert.AreEqual("firstItem", activity.SuggestedActions.Actions[0].Title); - Assert.AreEqual("firstItem", activity.SuggestedActions.Actions[0].Value); - Assert.AreEqual("titleContent", activity.SuggestedActions.Actions[1].Title); - Assert.AreEqual("textContent", activity.SuggestedActions.Actions[1].Value); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal("textContent", activity.Text); + Assert.Equal(2, activity.SuggestedActions.Actions.Count); + Assert.Equal("firstItem", activity.SuggestedActions.Actions[0].Title); + Assert.Equal("firstItem", activity.SuggestedActions.Actions[0].Value); + Assert.Equal("titleContent", activity.SuggestedActions.Actions[1].Title); + Assert.Equal("textContent", activity.SuggestedActions.Actions[1].Value); } private void AssertActivityWithMultiAttachments(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(2, activity.Attachments.Count); - Assert.AreEqual(ThumbnailCard.ContentType, activity.Attachments[1].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(2, activity.Attachments.Count); + Assert.Equal(ThumbnailCard.ContentType, activity.Attachments[1].ContentType); var card = ((JObject)activity.Attachments[1].Content).ToObject(); - Assert.IsNotNull(card, "should have herocard"); - Assert.AreEqual("Cheese gromit!", card.Title, "card title should be set"); - Assert.AreEqual("type", card.Subtitle, "card subtitle should be data bound "); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[0].Url, "image should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[1].Url, "image should be set"); - Assert.AreEqual(3, card.Buttons.Count, "card buttons should be set"); + Assert.NotNull(card); + Assert.Equal("Cheese gromit!", card.Title); + Assert.Equal("type", card.Subtitle); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[0].Url); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[1].Url); + Assert.Equal(3, card.Buttons.Count); for (int i = 0; i <= 2; i++) { - Assert.AreEqual($"Option {i + 1}", card.Buttons[i].Title, "card buttons should be set"); + Assert.Equal($"Option {i + 1}", card.Buttons[i].Title); } } private void AssertActivityWithHeroCardAttachment(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(HeroCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(HeroCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); var tap = card.Tap; - Assert.AreEqual("taptitle", tap.Title, "tap title should be set"); - Assert.AreEqual("tapvalue", tap.Value, "tap value should be set"); - Assert.AreEqual("imBack", tap.Type, "tap type should be set"); - Assert.IsNotNull(card, "should have herocard"); - Assert.AreEqual("titleContent", card.Title, "card title should be set"); - Assert.AreEqual("textContent", card.Text, "card text should be set"); - Assert.AreEqual(1, card.Buttons.Count, "card buttons should be set"); - Assert.AreEqual($"imBack", card.Buttons[0].Type, "card buttons should be set"); - Assert.AreEqual($"titleContent", card.Buttons[0].Title, "card buttons should be set"); - Assert.AreEqual($"textContent", card.Buttons[0].Value, "card buttons should be set"); + Assert.Equal("taptitle", tap.Title); + Assert.Equal("tapvalue", tap.Value); + Assert.Equal("imBack", tap.Type); + Assert.NotNull(card); + Assert.Equal("titleContent", card.Title); + Assert.Equal("textContent", card.Text); + Assert.Equal(1, card.Buttons.Count); + Assert.Equal($"imBack", card.Buttons[0].Type); + Assert.Equal($"titleContent", card.Buttons[0].Title); + Assert.Equal($"textContent", card.Buttons[0].Value); } private void AssertHandoffActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Handoff, activity.Type); - Assert.AreEqual("textContent", activity.Name, "card name should be set"); - Assert.AreEqual("textContent", activity.Value, "card value should be set"); + Assert.Equal(ActivityTypes.Handoff, activity.Type); + Assert.Equal("textContent", activity.Name); + Assert.Equal("textContent", activity.Value); } private void AssertEventActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Event, activity.Type); - Assert.AreEqual("textContent", activity.Name, "card name should be set"); - Assert.AreEqual("textContent", activity.Value, "card value should be set"); + Assert.Equal(ActivityTypes.Event, activity.Type); + Assert.Equal("textContent", activity.Name); + Assert.Equal("textContent", activity.Value); } private void AssertAdaptiveCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual("application/vnd.microsoft.card.adaptive", activity.Attachments[0].ContentType); - Assert.AreEqual("test", (string)((dynamic)activity.Attachments[0].Content).body[0].text); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal("application/vnd.microsoft.card.adaptive", activity.Attachments[0].ContentType); + Assert.Equal("test", (string)((dynamic)activity.Attachments[0].Content).body[0].text); } private void AssertMultiAdaptiveCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(3, activity.Attachments.Count); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(3, activity.Attachments.Count); for (int i = 0; i < 3; ++i) { - Assert.AreEqual("application/vnd.microsoft.card.adaptive", activity.Attachments[i].ContentType); - Assert.AreEqual($"test{i}", (string)((dynamic)activity.Attachments[i].Content).body[0].text); + Assert.Equal("application/vnd.microsoft.card.adaptive", activity.Attachments[i].ContentType); + Assert.Equal($"test{i}", (string)((dynamic)activity.Attachments[i].Content).body[0].text); } } private void AssertCardActionActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(HeroCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(HeroCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have herocard"); - Assert.AreEqual("titleContent", card.Title, "card title should be set"); - Assert.AreEqual("textContent", card.Text, "card text should be set"); - Assert.AreEqual(1, card.Buttons.Count, "card buttons should be set"); - Assert.AreEqual($"imBack", card.Buttons[0].Type, "card buttons should be set"); - Assert.AreEqual($"titleContent", card.Buttons[0].Title, "card buttons should be set"); - Assert.AreEqual($"textContent", card.Buttons[0].Value, "card buttons should be set"); + Assert.NotNull(card); + Assert.Equal("titleContent", card.Title); + Assert.Equal("textContent", card.Text); + Assert.Equal(1, card.Buttons.Count); + Assert.Equal($"imBack", card.Buttons[0].Type); + Assert.Equal($"titleContent", card.Buttons[0].Title); + Assert.Equal($"textContent", card.Buttons[0].Value); } private void AssertThumbnailCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(ThumbnailCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(ThumbnailCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have herocard"); - Assert.AreEqual("Cheese gromit!", card.Title, "card title should be set"); - Assert.AreEqual("thumbnailcard", card.Subtitle, "card subtitle should be data bound "); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[0].Url, "image should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[1].Url, "image should be set"); - Assert.AreEqual(3, card.Buttons.Count, "card buttons should be set"); + Assert.NotNull(card); + Assert.Equal("Cheese gromit!", card.Title); + Assert.Equal("thumbnailcard", card.Subtitle); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[0].Url); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[1].Url); + Assert.Equal(3, card.Buttons.Count); for (int i = 0; i <= 2; i++) { - Assert.AreEqual($"Option {i + 1}", card.Buttons[i].Title, "card buttons should be set"); + Assert.Equal($"Option {i + 1}", card.Buttons[i].Title); } } private void AssertHeroCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(HeroCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(HeroCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have herocard"); - Assert.AreEqual("Cheese gromit!", card.Title, "card title should be set"); - Assert.AreEqual("herocard", card.Subtitle, "card subtitle should be data bound "); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[0].Url, "image should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[1].Url, "image should be set"); - Assert.AreEqual(3, card.Buttons.Count, "card buttons should be set"); + Assert.NotNull(card); + Assert.Equal("Cheese gromit!", card.Title); + Assert.Equal("herocard", card.Subtitle); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[0].Url); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Images[1].Url); + Assert.Equal(3, card.Buttons.Count); for (int i = 0; i <= 2; i++) { - Assert.AreEqual($"Option {i + 1}", card.Buttons[i].Title, "card buttons should be set"); + Assert.Equal($"Option {i + 1}", card.Buttons[i].Title); } } private void AssertAudioCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(AudioCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(AudioCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have audiocard"); - Assert.AreEqual("Cheese gromit!", card.Title, "card title should be set"); - Assert.AreEqual("audiocard", card.Subtitle, "card subtitle should be data bound "); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Image.Url, "image should be set"); - Assert.AreEqual("https://contoso.com/media/AllegrofromDuetinCMajor.mp3", card.Media[0].Url); - Assert.AreEqual(false, card.Shareable); - Assert.AreEqual(true, card.Autoloop); - Assert.AreEqual(true, card.Autostart); - Assert.AreEqual("16:9", card.Aspect); - Assert.AreEqual(3, card.Buttons.Count, "card buttons should be set"); + Assert.NotNull(card); + Assert.Equal("Cheese gromit!", card.Title); + Assert.Equal("audiocard", card.Subtitle); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Image.Url); + Assert.Equal("https://contoso.com/media/AllegrofromDuetinCMajor.mp3", card.Media[0].Url); + Assert.Equal(false, card.Shareable); + Assert.Equal(true, card.Autoloop); + Assert.Equal(true, card.Autostart); + Assert.Equal("16:9", card.Aspect); + Assert.Equal(3, card.Buttons.Count); for (int i = 0; i <= 2; i++) { - Assert.AreEqual($"Option {i + 1}", card.Buttons[i].Title, "card buttons should be set"); + Assert.Equal($"Option {i + 1}", card.Buttons[i].Title); } } private void AssertVideoCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(VideoCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(VideoCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have videocard"); - Assert.AreEqual("Cheese gromit!", card.Title, "card title should be set"); - Assert.AreEqual("videocard", card.Subtitle, "card subtitle should be data bound "); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Image.Url, "image should be set"); - Assert.AreEqual("https://youtu.be/530FEFogfBQ", card.Media[0].Url); - Assert.AreEqual(false, card.Shareable); - Assert.AreEqual(true, card.Autoloop); - Assert.AreEqual(true, card.Autostart); - Assert.AreEqual("16:9", card.Aspect); - Assert.AreEqual(3, card.Buttons.Count, "card buttons should be set"); + Assert.NotNull(card); + Assert.Equal("Cheese gromit!", card.Title); + Assert.Equal("videocard", card.Subtitle); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal("https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg", card.Image.Url); + Assert.Equal("https://youtu.be/530FEFogfBQ", card.Media[0].Url); + Assert.Equal(false, card.Shareable); + Assert.Equal(true, card.Autoloop); + Assert.Equal(true, card.Autostart); + Assert.Equal("16:9", card.Aspect); + Assert.Equal(3, card.Buttons.Count); for (int i = 0; i <= 2; i++) { - Assert.AreEqual($"Option {i + 1}", card.Buttons[i].Title, "card buttons should be set"); + Assert.Equal($"Option {i + 1}", card.Buttons[i].Title); } } private void AssertSigninCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(SigninCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(SigninCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have signincard"); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual(1, card.Buttons.Count, "card buttons should be set"); - Assert.AreEqual($"Sign in", card.Buttons[0].Title); - Assert.AreEqual(ActionTypes.Signin, card.Buttons[0].Type); - Assert.AreEqual($"https://login.microsoftonline.com/", card.Buttons[0].Value); + Assert.NotNull(card); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal(1, card.Buttons.Count); + Assert.Equal($"Sign in", card.Buttons[0].Title); + Assert.Equal(ActionTypes.Signin, card.Buttons[0].Type); + Assert.Equal($"https://login.microsoftonline.com/", card.Buttons[0].Value); } private void AssertOAuthCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.IsTrue(string.IsNullOrEmpty(activity.Text)); - Assert.IsTrue(string.IsNullOrEmpty(activity.Speak)); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(OAuthCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.True(string.IsNullOrEmpty(activity.Text)); + Assert.True(string.IsNullOrEmpty(activity.Speak)); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(OAuthCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have signincard"); - Assert.AreEqual("This is some text describing the card, it's cool because it's cool", card.Text, "card text should be set"); - Assert.AreEqual("MyConnection", card.ConnectionName); - Assert.AreEqual(1, card.Buttons.Count, "card buttons should be set"); - Assert.AreEqual($"Sign in", card.Buttons[0].Title); - Assert.AreEqual(ActionTypes.Signin, card.Buttons[0].Type); - Assert.AreEqual($"https://login.microsoftonline.com/", card.Buttons[0].Value); + Assert.NotNull(card); + Assert.Equal("This is some text describing the card, it's cool because it's cool", card.Text); + Assert.Equal("MyConnection", card.ConnectionName); + Assert.Equal(1, card.Buttons.Count); + Assert.Equal($"Sign in", card.Buttons[0].Title); + Assert.Equal(ActionTypes.Signin, card.Buttons[0].Type); + Assert.Equal($"https://login.microsoftonline.com/", card.Buttons[0].Value); } private void AssertActivityWithMultiStructuredSuggestionActions(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual("textContent", activity.Text); - Assert.AreEqual(3, activity.SuggestedActions.Actions.Count); - Assert.AreEqual("first suggestion", activity.SuggestedActions.Actions[0].Value); - Assert.AreEqual("first suggestion", activity.SuggestedActions.Actions[0].Title); - Assert.AreEqual("first suggestion", activity.SuggestedActions.Actions[0].Text); - Assert.AreEqual("second suggestion", activity.SuggestedActions.Actions[1].Value); - Assert.AreEqual("second suggestion", activity.SuggestedActions.Actions[1].Title); - Assert.AreEqual("second suggestion", activity.SuggestedActions.Actions[1].Text); - Assert.AreEqual("third suggestion", activity.SuggestedActions.Actions[2].Value); - Assert.AreEqual("third suggestion", activity.SuggestedActions.Actions[2].Title); - Assert.AreEqual("third suggestion", activity.SuggestedActions.Actions[2].Text); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal("textContent", activity.Text); + Assert.Equal(3, activity.SuggestedActions.Actions.Count); + Assert.Equal("first suggestion", activity.SuggestedActions.Actions[0].Value); + Assert.Equal("first suggestion", activity.SuggestedActions.Actions[0].Title); + Assert.Equal("first suggestion", activity.SuggestedActions.Actions[0].Text); + Assert.Equal("second suggestion", activity.SuggestedActions.Actions[1].Value); + Assert.Equal("second suggestion", activity.SuggestedActions.Actions[1].Title); + Assert.Equal("second suggestion", activity.SuggestedActions.Actions[1].Text); + Assert.Equal("third suggestion", activity.SuggestedActions.Actions[2].Value); + Assert.Equal("third suggestion", activity.SuggestedActions.Actions[2].Title); + Assert.Equal("third suggestion", activity.SuggestedActions.Actions[2].Text); } private void AssertActivityWithMultiStringSuggestionActions(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual("textContent", activity.Text); - Assert.AreEqual(3, activity.SuggestedActions.Actions.Count); - Assert.AreEqual("first suggestion", activity.SuggestedActions.Actions[0].Value); - Assert.AreEqual("first suggestion", activity.SuggestedActions.Actions[0].Title); - Assert.AreEqual("second suggestion", activity.SuggestedActions.Actions[1].Value); - Assert.AreEqual("second suggestion", activity.SuggestedActions.Actions[1].Title); - Assert.AreEqual("third suggestion", activity.SuggestedActions.Actions[2].Value); - Assert.AreEqual("third suggestion", activity.SuggestedActions.Actions[2].Title); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal("textContent", activity.Text); + Assert.Equal(3, activity.SuggestedActions.Actions.Count); + Assert.Equal("first suggestion", activity.SuggestedActions.Actions[0].Value); + Assert.Equal("first suggestion", activity.SuggestedActions.Actions[0].Title); + Assert.Equal("second suggestion", activity.SuggestedActions.Actions[1].Value); + Assert.Equal("second suggestion", activity.SuggestedActions.Actions[1].Title); + Assert.Equal("third suggestion", activity.SuggestedActions.Actions[2].Value); + Assert.Equal("third suggestion", activity.SuggestedActions.Actions[2].Title); } private void AssertReceiptCardActivity(Activity activity) { - Assert.AreEqual(ActivityTypes.Message, activity.Type); - Assert.AreEqual(1, activity.Attachments.Count); - Assert.AreEqual(ReceiptCard.ContentType, activity.Attachments[0].ContentType); + Assert.Equal(ActivityTypes.Message, activity.Type); + Assert.Equal(1, activity.Attachments.Count); + Assert.Equal(ReceiptCard.ContentType, activity.Attachments[0].ContentType); var card = ((JObject)activity.Attachments[0].Content).ToObject(); - Assert.IsNotNull(card, "should have ReceiptCard"); - Assert.AreEqual("John Doe", card.Title); - Assert.AreEqual("$ 7.50", card.Tax); - Assert.AreEqual("$ 90.95", card.Total); + Assert.NotNull(card); + Assert.Equal("John Doe", card.Title); + Assert.Equal("$ 7.50", card.Tax); + Assert.Equal("$ 90.95", card.Total); var buttons = card.Buttons; - Assert.AreEqual(1, buttons.Count, "should have a button"); - Assert.AreEqual(ActionTypes.OpenUrl, buttons[0].Type); - Assert.AreEqual("More information", buttons[0].Title); - Assert.AreEqual("https://account.windowsazure.com/content/6.10.1.38-.8225.160809-1618/aux-pre/images/offer-icon-freetrial.png", buttons[0].Image); - Assert.AreEqual("https://azure.microsoft.com/en-us/pricing/", buttons[0].Value); + Assert.Equal(1, buttons.Count); + Assert.Equal(ActionTypes.OpenUrl, buttons[0].Type); + Assert.Equal("More information", buttons[0].Title); + Assert.Equal("https://account.windowsazure.com/content/6.10.1.38-.8225.160809-1618/aux-pre/images/offer-icon-freetrial.png", buttons[0].Image); + Assert.Equal("https://azure.microsoft.com/en-us/pricing/", buttons[0].Value); var facts = card.Facts; - Assert.AreEqual(2, facts.Count, "should have 2 facts"); - Assert.AreEqual("Order Number", facts[0].Key); - Assert.AreEqual("1234", facts[0].Value); - Assert.AreEqual("Payment Method", facts[1].Key); - Assert.AreEqual("VISA 5555-****", facts[1].Value); + Assert.Equal(2, facts.Count); + Assert.Equal("Order Number", facts[0].Key); + Assert.Equal("1234", facts[0].Value); + Assert.Equal("Payment Method", facts[1].Key); + Assert.Equal("VISA 5555-****", facts[1].Value); var items = card.Items; - Assert.AreEqual(2, items.Count, "should have 2 items"); - Assert.AreEqual("Data Transfer", items[0].Title); - Assert.AreEqual("https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png", items[0].Image.Url); - Assert.AreEqual("$ 38.45", items[0].Price); - Assert.AreEqual("368", items[0].Quantity); - Assert.AreEqual("App Service", items[1].Title); - Assert.AreEqual("https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png", items[1].Image.Url); - Assert.AreEqual("$ 45.00", items[1].Price); - Assert.AreEqual("720", items[1].Quantity); + Assert.Equal(2, items.Count); + Assert.Equal("Data Transfer", items[0].Title); + Assert.Equal("https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png", items[0].Image.Url); + Assert.Equal("$ 38.45", items[0].Price); + Assert.Equal("368", items[0].Quantity); + Assert.Equal("App Service", items[1].Title); + Assert.Equal("https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png", items[1].Image.Url); + Assert.Equal("$ 45.00", items[1].Price); + Assert.Equal("720", items[1].Quantity); } private Templates GetNormalStructureLGFile() diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs index 68ca87a2f6..24e5f5c423 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs @@ -3,6 +3,7 @@ #pragma warning disable SA1402 using System; using System.Collections.Generic; +using System.Reflection; using System.Threading; using System.Threading.Tasks; using Microsoft.Bot.Builder.Adapters; @@ -15,25 +16,23 @@ using Microsoft.Bot.Builder.Dialogs.Declarative; using Microsoft.Bot.Builder.Dialogs.Declarative.Resources; using Microsoft.Bot.Schema; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; namespace Microsoft.Bot.Builder.AI.LanguageGeneration.Tests { - [TestClass] public class LGGeneratorTests { - public TestContext TestContext { get; set; } + //public TestContext TestContext { get; set; } - [TestMethod] - [ExpectedException(typeof(Exception))] + [Fact] public async Task TestNotFoundTemplate() { var context = GetDialogContext(string.Empty); var lg = new TemplateEngineLanguageGenerator(); - await lg.GenerateAsync(context, "${tesdfdfsst()}", null); + await Assert.ThrowsAsync(() => lg.GenerateAsync(context, "${tesdfdfsst()}", null)); } - [TestMethod] + [Fact] public async Task TestMultiLangImport() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -44,35 +43,35 @@ public async Task TestMultiLangImport() var resource = resourceExplorer.GetResource("a.en-US.lg") as FileResource; var generator = new TemplateEngineLanguageGenerator(resource.FullName, lgResourceGroup); var result = await generator.GenerateAsync(GetDialogContext(), "${templatea()}", null); - Assert.AreEqual("from a.en-us.lg", result); + Assert.Equal("from a.en-us.lg", result); // import b.en-us.lg result = await generator.GenerateAsync(GetDialogContext(), "${templateb()}", null); - Assert.AreEqual("from b.en-us.lg", result); + Assert.Equal("from b.en-us.lg", result); // fallback to c.en.lg result = await generator.GenerateAsync(GetDialogContext(), "${templatec()}", null); - Assert.AreEqual("from c.en.lg", result); + Assert.Equal("from c.en.lg", result); // there is no 'greeting' template in b.en-us.lg, no more fallback to b.lg - var ex = await Assert.ThrowsExceptionAsync(async () => await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null)); - Assert.IsTrue(ex.Message.Contains("greeting does not have an evaluator")); + var ex = await Assert.ThrowsAsync(async () => await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null)); + Assert.True(ex.Message.Contains("greeting does not have an evaluator")); resource = resourceExplorer.GetResource("a.lg") as FileResource; generator = new TemplateEngineLanguageGenerator(resource.FullName, lgResourceGroup); result = await generator.GenerateAsync(GetDialogContext(), "${templatea()}", null); - Assert.AreEqual("from a.lg", result); + Assert.Equal("from a.lg", result); result = await generator.GenerateAsync(GetDialogContext(), "${templateb()}", null); - Assert.AreEqual("from b.lg", result); + Assert.Equal("from b.lg", result); // ignore the "en" in c.en.lg, just load c.lg result = await generator.GenerateAsync(GetDialogContext(), "${templatec()}", null); - Assert.AreEqual("from c.lg", result); + Assert.Equal("from c.lg", result); result = await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null); - Assert.AreEqual("hi", result); + Assert.Equal("hi", result); } public class TestMultiLanguageDialog : Dialog @@ -83,64 +82,64 @@ public override async Task BeginDialogAsync(DialogContext dial // en-us locale dialogContext.Context.Activity.Locale = "en-us"; - Assert.IsNotNull(lg, "ILanguageGenerator should not be null"); - Assert.IsNotNull(dialogContext.Services.Get(), "ResourceExplorer should not be null"); + Assert.NotNull(lg); + Assert.NotNull(dialogContext.Services.Get()); var result = await lg.GenerateAsync(dialogContext, "${templatea()}", null); - Assert.AreEqual("from a.en-us.lg", result); + Assert.Equal("from a.en-us.lg", result); // import b.en-us.lg result = await lg.GenerateAsync(dialogContext, "${templateb()}", null); - Assert.AreEqual("from b.en-us.lg", result); + Assert.Equal("from b.en-us.lg", result); // fallback to c.en.lg result = await lg.GenerateAsync(dialogContext, "${templatec()}", null); - Assert.AreEqual("from c.en.lg", result); + Assert.Equal("from c.en.lg", result); // there is no 'greeting' template in b.en-us.lg, fallback to a.lg to find it. result = await lg.GenerateAsync(dialogContext, "${greeting()}", null); - Assert.AreEqual("hi", result); + Assert.Equal("hi", result); //en locale dialogContext.Context.Activity.Locale = "en"; - Assert.IsNotNull(lg, "ILanguageGenerator should not be null"); - Assert.IsNotNull(dialogContext.Services.Get(), "ResourceExplorer should not be null"); + Assert.NotNull(lg); + Assert.NotNull(dialogContext.Services.Get()); result = await lg.GenerateAsync(dialogContext, "${templatea()}", null); - Assert.AreEqual("from a.lg", result); + Assert.Equal("from a.lg", result); // import b.en-us.lg result = await lg.GenerateAsync(dialogContext, "${templateb()}", null); - Assert.AreEqual("from b.lg", result); + Assert.Equal("from b.lg", result); // c.en.lg is ignore in b.lg result = await lg.GenerateAsync(dialogContext, "${templatec()}", null); - Assert.AreEqual("from c.lg", result); + Assert.Equal("from c.lg", result); // there is no 'greeting' template in b.en-us.lg, fallback to a.lg to find it. result = await lg.GenerateAsync(dialogContext, "${greeting()}", null); - Assert.AreEqual("hi", result); + Assert.Equal("hi", result); // empty locale dialogContext.Context.Activity.Locale = string.Empty; result = await lg.GenerateAsync(dialogContext, "${templatea()}", null); - Assert.AreEqual("from a.lg", result); + Assert.Equal("from a.lg", result); result = await lg.GenerateAsync(dialogContext, "${templateb()}", null); - Assert.AreEqual("from b.lg", result); + Assert.Equal("from b.lg", result); // ignore the "en" in c.en.lg, just load c.lg result = await lg.GenerateAsync(dialogContext, "${templatec()}", null); - Assert.AreEqual("from c.lg", result); + Assert.Equal("from c.lg", result); result = await lg.GenerateAsync(dialogContext, "${greeting()}", null); - Assert.AreEqual("hi", result); + Assert.Equal("hi", result); return await dialogContext.EndDialogAsync(); } } - [TestMethod] + [Fact] public async Task TestMultiLanguageE2E() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -159,7 +158,7 @@ await CreateFlow(async (turnContext, cancellationToken) => .StartTestAsync(); } - [TestMethod] + [Fact] public async Task TestMultiLanguageGenerator() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -174,39 +173,39 @@ public async Task TestMultiLanguageGenerator() lg.LanguageGenerators["fr"] = new TemplateEngineLanguageGenerator(resourceExplorer.GetResource("test.fr.lg").ReadTextAsync().Result, "test.fr.lg", multilanguageresources); // test targeted in each language - Assert.AreEqual("english-us", await lg.GenerateAsync(GetDialogContext(locale: "en-us"), "${test()}", null)); - Assert.AreEqual("english-gb", await lg.GenerateAsync(GetDialogContext(locale: "en-gb"), "${test()}", null)); - Assert.AreEqual("english", await lg.GenerateAsync(GetDialogContext(locale: "en"), "${test()}", null)); - Assert.AreEqual("default", await lg.GenerateAsync(GetDialogContext(locale: string.Empty), "${test()}", null)); - Assert.AreEqual("default", await lg.GenerateAsync(GetDialogContext(locale: "foo"), "${test()}", null)); + Assert.Equal("english-us", await lg.GenerateAsync(GetDialogContext(locale: "en-us"), "${test()}", null)); + Assert.Equal("english-gb", await lg.GenerateAsync(GetDialogContext(locale: "en-gb"), "${test()}", null)); + Assert.Equal("english", await lg.GenerateAsync(GetDialogContext(locale: "en"), "${test()}", null)); + Assert.Equal("default", await lg.GenerateAsync(GetDialogContext(locale: string.Empty), "${test()}", null)); + Assert.Equal("default", await lg.GenerateAsync(GetDialogContext(locale: "foo"), "${test()}", null)); // test fallback for en-us -> en -> default - //Assert.AreEqual("default2", await lg.Generate(GetTurnContext(locale: "en-us"), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext(locale: "en-gb"), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext(locale: "en"), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext(locale: string.Empty), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext(locale: "foo"), "${test2()}", null)); + //Assert.Equal("default2", await lg.Generate(GetTurnContext(locale: "en-us"), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext(locale: "en-gb"), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext(locale: "en"), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext(locale: string.Empty), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext(locale: "foo"), "${test2()}", null)); } - [TestMethod] + [Fact] public async Task TestResourceMultiLanguageGenerator() { var lg = new ResourceMultiLanguageGenerator("test.lg"); // test targeted in each language - Assert.AreEqual("english-us", await lg.GenerateAsync(GetDialogContext("en-us", lg), "${test()}", null)); - Assert.AreEqual("english-us", await lg.GenerateAsync(GetDialogContext("en-us", lg), "${test()}", new { country = "us" })); - Assert.AreEqual("english-gb", await lg.GenerateAsync(GetDialogContext("en-gb", lg), "${test()}", null)); - Assert.AreEqual("english", await lg.GenerateAsync(GetDialogContext("en", lg), "${test()}", null)); - Assert.AreEqual("default", await lg.GenerateAsync(GetDialogContext(string.Empty, lg), "${test()}", null)); - Assert.AreEqual("default", await lg.GenerateAsync(GetDialogContext("foo", lg), "${test()}", null)); + Assert.Equal("english-us", await lg.GenerateAsync(GetDialogContext("en-us", lg), "${test()}", null)); + Assert.Equal("english-us", await lg.GenerateAsync(GetDialogContext("en-us", lg), "${test()}", new { country = "us" })); + Assert.Equal("english-gb", await lg.GenerateAsync(GetDialogContext("en-gb", lg), "${test()}", null)); + Assert.Equal("english", await lg.GenerateAsync(GetDialogContext("en", lg), "${test()}", null)); + Assert.Equal("default", await lg.GenerateAsync(GetDialogContext(string.Empty, lg), "${test()}", null)); + Assert.Equal("default", await lg.GenerateAsync(GetDialogContext("foo", lg), "${test()}", null)); // test fallback for en-us -> en -> default - //Assert.AreEqual("default2", await lg.Generate(GetTurnContext("en-us", lg), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext("en-gb", lg), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext("en", lg), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext(string.Empty, lg), "${test2()}", null)); - Assert.AreEqual("default2", await lg.GenerateAsync(GetDialogContext("foo", lg), "${test2()}", null)); + //Assert.Equal("default2", await lg.Generate(GetTurnContext("en-us", lg), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext("en-gb", lg), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext("en", lg), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext(string.Empty, lg), "${test2()}", null)); + Assert.Equal("default2", await lg.GenerateAsync(GetDialogContext("foo", lg), "${test2()}", null)); } public class TestLanguageGeneratorMiddlewareDialog : Dialog @@ -214,15 +213,15 @@ public class TestLanguageGeneratorMiddlewareDialog : Dialog public async override Task BeginDialogAsync(DialogContext dialogContext, object options = null, CancellationToken cancellationToken = default) { var lg = dialogContext.Services.Get(); - Assert.IsNotNull(lg, "ILanguageGenerator should not be null"); - Assert.IsNotNull(dialogContext.Services.Get(), "ResourceExplorer should not be null"); + Assert.NotNull(lg); + Assert.NotNull(dialogContext.Services.Get()); var text = await lg.GenerateAsync(dialogContext, "${test()}", null); - Assert.AreEqual("english-us", text, "template should be there"); + Assert.Equal("english-us", text); return await dialogContext.EndDialogAsync(); } } - [TestMethod] + [Fact] public async Task TestLanguageGeneratorMiddleware() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -252,7 +251,7 @@ public AssertLGDialog() public async override Task BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) { var generator = (ResourceMultiLanguageGenerator)dc.Services.Get(); - Assert.AreEqual(ResourceId, generator.ResourceId); + Assert.Equal(ResourceId, generator.ResourceId); await dc.Context.SendActivityAsync($"BeginDialog {Id}:{generator.ResourceId}"); return new DialogTurnResult(DialogTurnStatus.Waiting); } @@ -260,13 +259,13 @@ public async override Task BeginDialogAsync(DialogContext dc, public async override Task ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default) { var generator = (ResourceMultiLanguageGenerator)dc.Services.Get(); - Assert.AreEqual(ResourceId, generator.ResourceId); + Assert.Equal(ResourceId, generator.ResourceId); await dc.Context.SendActivityAsync($"ContinueDialog {Id}:{generator.ResourceId}"); return await dc.EndDialogAsync(); } } - [TestMethod] + [Fact] public async Task TestLGScopedAccess() { var dialog = new AdaptiveDialog() @@ -333,7 +332,7 @@ await CreateFlow(async (turnContext, cancellationToken) => .StartTestAsync(); } - [TestMethod] + [Fact] public async Task TestDialogInjectionDeclarative() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -373,7 +372,7 @@ public async override Task BeginDialogAsync(DialogContext dial } } - [TestMethod] + [Fact] public async Task TestLGInjection() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -392,7 +391,7 @@ await CreateFlow(async (turnContext, cancellationToken) => .StartTestAsync(); } - [TestMethod] + [Fact] public async Task TestDateTimeFunctions() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -431,7 +430,7 @@ await CreateFlow(async (turnContext, cancellationToken) => .StartTestAsync(); } - [TestMethod] + [Fact] public async Task TestNoResourceExplorerLanguageGeneration() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); @@ -485,7 +484,7 @@ private TestFlow CreateFlow(BotCallbackHandler handler) var convoState = new ConversationState(storage); var userState = new UserState(storage); - var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName)); + var adapter = new TestAdapter(TestAdapter.CreateConversation(MethodBase.GetCurrentMethod().ToString())); adapter .UseStorage(storage) .UseBotState(userState, convoState) @@ -500,7 +499,7 @@ private TestFlow CreateNoResourceExplorerFlow(BotCallbackHandler handler) var convoState = new ConversationState(storage); var userState = new UserState(storage); - var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName)); + var adapter = new TestAdapter(TestAdapter.CreateConversation(MethodBase.GetCurrentMethod().ToString())); adapter .UseStorage(storage) .UseBotState(userState, convoState) diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj index b1b832ba3e..3e9cc02ba0 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj @@ -19,6 +19,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs index 405072fe32..cd23e65646 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs @@ -2,15 +2,15 @@ using Microsoft.Bot.Builder.Dialogs.Adaptive; using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing; using Microsoft.Bot.Builder.Dialogs.Declarative; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; namespace Microsoft.Bot.Builder { - [TestClass] + //[TestClass] public class Startup { - [AssemblyInitialize] - public static void Initialize(TestContext testContext) + //[AssemblyInitialize] + public static void Initialize() //TestContext testContext) { ComponentRegistration.Add(new DeclarativeComponentRegistration()); ComponentRegistration.Add(new AdaptiveComponentRegistration()); From caeaaf1d418c030848970ef782fe88d01f3a8664 Mon Sep 17 00:00:00 2001 From: virtual-josh Date: Fri, 26 Jun 2020 16:45:41 -0700 Subject: [PATCH 2/4] removing unused file --- .../LGGeneratorTests.cs | 15 +++++++++++++ .../Startup.cs | 21 ------------------- 2 files changed, 15 insertions(+), 21 deletions(-) delete mode 100644 tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs index 24e5f5c423..4dba3f7461 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs @@ -12,6 +12,7 @@ using Microsoft.Bot.Builder.Dialogs.Adaptive.Actions; using Microsoft.Bot.Builder.Dialogs.Adaptive.Conditions; using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators; +using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing; using Microsoft.Bot.Builder.Dialogs.Debugging; using Microsoft.Bot.Builder.Dialogs.Declarative; using Microsoft.Bot.Builder.Dialogs.Declarative.Resources; @@ -335,6 +336,8 @@ await CreateFlow(async (turnContext, cancellationToken) => [Fact] public async Task TestDialogInjectionDeclarative() { + Initialize(); + var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); DialogManager dm = new DialogManager() .UseResourceExplorer(resourceExplorer) @@ -375,6 +378,8 @@ public async override Task BeginDialogAsync(DialogContext dial [Fact] public async Task TestLGInjection() { + Initialize(); + var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); DialogManager dm = new DialogManager() .UseResourceExplorer(resourceExplorer) @@ -394,6 +399,8 @@ await CreateFlow(async (turnContext, cancellationToken) => [Fact] public async Task TestDateTimeFunctions() { + Initialize(); + var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); DialogManager dm = new DialogManager() .UseResourceExplorer(resourceExplorer) @@ -450,6 +457,14 @@ await CreateNoResourceExplorerFlow(async (context, cancellationToken) => .StartTestAsync(); } + internal static void Initialize() + { + ComponentRegistration.Add(new DeclarativeComponentRegistration()); + ComponentRegistration.Add(new AdaptiveComponentRegistration()); + ComponentRegistration.Add(new AdaptiveTestingComponentRegistration()); + ComponentRegistration.Add(new LanguageGenerationComponentRegistration()); + } + private static string GetProjectFolder() { return AppContext.BaseDirectory.Substring(0, AppContext.BaseDirectory.IndexOf("bin")); diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs deleted file mode 100644 index cd23e65646..0000000000 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Startup.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Bot.Builder.Dialogs; -using Microsoft.Bot.Builder.Dialogs.Adaptive; -using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing; -using Microsoft.Bot.Builder.Dialogs.Declarative; -using Xunit; - -namespace Microsoft.Bot.Builder -{ - //[TestClass] - public class Startup - { - //[AssemblyInitialize] - public static void Initialize() //TestContext testContext) - { - ComponentRegistration.Add(new DeclarativeComponentRegistration()); - ComponentRegistration.Add(new AdaptiveComponentRegistration()); - ComponentRegistration.Add(new AdaptiveTestingComponentRegistration()); - ComponentRegistration.Add(new LanguageGenerationComponentRegistration()); - } - } -} From cc9329563f71bf56a1e3c1a243524838e8c316b4 Mon Sep 17 00:00:00 2001 From: virtual-josh Date: Fri, 26 Jun 2020 16:46:25 -0700 Subject: [PATCH 3/4] removing MS Test --- ...icrosoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj index 3e9cc02ba0..bda0546a52 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests.csproj @@ -17,8 +17,6 @@ - - all From af8dc4b333e1cdf6eeee84b1753a3dadec90b5c5 Mon Sep 17 00:00:00 2001 From: virtual-josh Date: Tue, 30 Jun 2020 10:32:01 -0700 Subject: [PATCH 4/4] registering components once per test suite --- .../ActivityFactoryTests.cs | 11 ++++++++++ .../LGGeneratorTests.cs | 22 ++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs index 73d52045a7..0e45d237ff 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/ActivityFactoryTests.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; using System.IO; +using Microsoft.Bot.Builder.Dialogs.Adaptive; using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators; +using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing; +using Microsoft.Bot.Builder.Dialogs.Declarative; using Microsoft.Bot.Builder.Dialogs.Declarative.Resources; using Microsoft.Bot.Builder.LanguageGeneration; using Microsoft.Bot.Schema; @@ -12,6 +15,14 @@ namespace Microsoft.Bot.Builder.Dialogs.Tests { public class ActivityFactoryTests { + public ActivityFactoryTests() + { + ComponentRegistration.Add(new DeclarativeComponentRegistration()); + ComponentRegistration.Add(new AdaptiveComponentRegistration()); + ComponentRegistration.Add(new AdaptiveTestingComponentRegistration()); + ComponentRegistration.Add(new LanguageGenerationComponentRegistration()); + } + [Fact] public void TestInlineActivityFactory() { diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs index 4dba3f7461..e1d96993c6 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests/LGGeneratorTests.cs @@ -23,7 +23,13 @@ namespace Microsoft.Bot.Builder.AI.LanguageGeneration.Tests { public class LGGeneratorTests { - //public TestContext TestContext { get; set; } + public LGGeneratorTests() + { + ComponentRegistration.Add(new DeclarativeComponentRegistration()); + ComponentRegistration.Add(new AdaptiveComponentRegistration()); + ComponentRegistration.Add(new AdaptiveTestingComponentRegistration()); + ComponentRegistration.Add(new LanguageGenerationComponentRegistration()); + } [Fact] public async Task TestNotFoundTemplate() @@ -336,8 +342,6 @@ await CreateFlow(async (turnContext, cancellationToken) => [Fact] public async Task TestDialogInjectionDeclarative() { - Initialize(); - var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); DialogManager dm = new DialogManager() .UseResourceExplorer(resourceExplorer) @@ -378,8 +382,6 @@ public async override Task BeginDialogAsync(DialogContext dial [Fact] public async Task TestLGInjection() { - Initialize(); - var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); DialogManager dm = new DialogManager() .UseResourceExplorer(resourceExplorer) @@ -399,8 +401,6 @@ await CreateFlow(async (turnContext, cancellationToken) => [Fact] public async Task TestDateTimeFunctions() { - Initialize(); - var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); DialogManager dm = new DialogManager() .UseResourceExplorer(resourceExplorer) @@ -457,14 +457,6 @@ await CreateNoResourceExplorerFlow(async (context, cancellationToken) => .StartTestAsync(); } - internal static void Initialize() - { - ComponentRegistration.Add(new DeclarativeComponentRegistration()); - ComponentRegistration.Add(new AdaptiveComponentRegistration()); - ComponentRegistration.Add(new AdaptiveTestingComponentRegistration()); - ComponentRegistration.Add(new LanguageGenerationComponentRegistration()); - } - private static string GetProjectFolder() { return AppContext.BaseDirectory.Substring(0, AppContext.BaseDirectory.IndexOf("bin"));