Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[4.4] Fixes test projects (#1083)
Browse files Browse the repository at this point in the history
* updated va template tests

* updated todo skill tests

* updates to poi

* email skill tests

* removed mbbs nuget reference

* automotive skill tests

* poi skill tests

* updated skill lib tests

* started calendar skill tests

* fixed timezone tests

* commented 4 calendar skill tests that broke state

* fixed merge conflicts

* removed assistant and assistant.tests projects
  • Loading branch information
lauren-mills committed Apr 10, 2019
1 parent 5ea2629 commit 19f8a77
Show file tree
Hide file tree
Showing 285 changed files with 1,295 additions and 23,911 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ public async Task DeserializeValidManifestFile()
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.34-preview" />
<Compile Remove="Utterances\**" />
<EmbeddedResource Remove="Utterances\**" />
<None Remove="Utterances\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="InvokeSkillTests.cs" />
<Compile Remove="SkillTestBase.cs" />
</ItemGroup>

<ItemGroup>
<None Remove="calendarSkill.json" />
</ItemGroup>

<ItemGroup>
<Content Include="calendarSkill.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\microsoft.bot.builder.solutions\microsoft.bot.builder.solutions\Microsoft.Bot.Builder.Solutions.csproj" />
<ProjectReference Include="..\Microsoft.Bot.Builder.Skills\Microsoft.Bot.Builder.Skills.csproj" />
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<ItemGroup>
<Folder Include="Utterances\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,55 +1,29 @@
using Autofac;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Configuration;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Builder.Solutions.Proactive;
using Microsoft.Bot.Builder.Solutions.TaskExtensions;
using Microsoft.Bot.Builder.Solutions.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;
using Microsoft.Bot.Builder.Solutions.Testing;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;

namespace Microsoft.Bot.Builder.Solutions.Tests.Skills
{
[TestClass]
public class SkillTestBase : BotTestBase
{
public DialogSet Dialogs { get; set; }

public UserState UserState { get; set; }

public ConversationState ConversationState { get; set; }

public ProactiveState ProactiveState { get; set; }

public IStatePropertyAccessor<DialogState> DialogState { get; set; }
public IServiceCollection Services { get; set; }

public IBotTelemetryClient TelemetryClient { get; set; }

public IBackgroundTaskQueue BackgroundTaskQueue { get; set; }

public EndpointService EndpointService { get; set; }

public ConversationReference ConversationReference { get; set; }
public DialogSet Dialogs { get; set; }

[TestInitialize]
public new void Initialize()
{
var builder = new ContainerBuilder();

ConversationState = new ConversationState(new MemoryStorage());
DialogState = ConversationState.CreateProperty<DialogState>(nameof(DialogState));
UserState = new UserState(new MemoryStorage());
ProactiveState = new ProactiveState(new MemoryStorage());
TelemetryClient = new NullBotTelemetryClient();
BackgroundTaskQueue = new BackgroundTaskQueue();
EndpointService = new EndpointService();

builder.RegisterInstance(new BotStateSet(UserState, ConversationState));
Container = builder.Build();

Dialogs = new DialogSet(DialogState);

Services = new ServiceCollection();
}

/// <summary>
Expand All @@ -60,8 +34,8 @@ public class SkillTestBase : BotTestBase
/// <returns></returns>
public TestFlow GetTestFlow(SkillDefinition skillDefinition, string locale = null)
{
var adapter = new TestAdapter(sendTraceActivity: false)
.Use(new AutoSaveStateMiddleware(ConversationState));
var sp = Services.BuildServiceProvider();
var adapter = sp.GetService<TestAdapter>();

var testFlow = new TestFlow(adapter, async (context, cancellationToken) =>
{
Expand All @@ -80,10 +54,5 @@ public TestFlow GetTestFlow(SkillDefinition skillDefinition, string locale = nul

return testFlow;
}

public override IBot BuildBot()
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ private Task<bool> AuthPromptValidator(PromptValidatorContext<TokenResponse> pro
{
return Task.FromResult(true);
}
else if (promptContext.Context.Activity.AsEventActivity().Name == "tokens/response")
{
promptContext.Recognized.Value = promptContext.Context.Activity.AsEventActivity().Value as TokenResponse;
return Task.FromResult(true);
}
else
{
return Task.FromResult(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BotSettingsBase
public List<OAuthConnection> OAuthConnections { get; set; }

/// <summary>
/// Gets of sets the CosmosDB Configuration for the bot.
/// Gets or sets the CosmosDB Configuration for the bot.
/// </summary>
public CosmosDbStorageOptions CosmosDb { get; set; }

Expand All @@ -54,12 +54,12 @@ public class BotSettingsBase
/// <summary>
/// Gets or sets the dictionary of cognitive model configurations by locale for the bot.
/// </summary>
public Dictionary<string, CognitiveModelConfiguration> CognitiveModels { get; set; }
public Dictionary<string, CognitiveModelConfiguration> CognitiveModels { get; set; } = new Dictionary<string, CognitiveModelConfiguration>();

/// <summary>
/// Gets or sets the Properties dictionary.
/// </summary>
public Dictionary<string, string> Properties { get; set; }
public Dictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Class representing configuration for an Azure Blob Storage service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="1.0.3" />
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.1" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.ContentModerator" Version="1.0.0" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;

namespace Microsoft.Bot.Builder.Solutions
{
Expand All @@ -9,6 +9,6 @@ public class CognitiveModelSet

public Dictionary<string, IRecognizer> LuisServices { get; set; } = new Dictionary<string, IRecognizer>();

public Dictionary<string, QnAMaker> QnAServices { get; set; } = new Dictionary<string, QnAMaker>();
public Dictionary<string, ITelemetryQnAMaker> QnAServices { get; set; } = new Dictionary<string, ITelemetryQnAMaker>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="1.0.3" />
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.1" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.ContentModerator" Version="1.0.0" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,18 @@

using System.Collections.Specialized;
using System.Text.RegularExpressions;
using Autofac;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Solutions.Shared.Responses;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Bot.Builder.Solutions.Testing
{
public abstract class BotTestBase
{
private static readonly Regex ResponseTokensRegex = new Regex(@"\{(\w+)\}", RegexOptions.Compiled);

public IContainer Container { get; set; }

public IConfigurationRoot Configuration { get; set; }

public ResponseManager ResponseManager { get; set; }

public abstract IBot BuildBot();

public virtual void Initialize()
{
this.Configuration = new BuildConfig().Configuration;

var builder = new ContainerBuilder();
builder.RegisterInstance<IConfiguration>(this.Configuration);

this.Container = builder.Build();
}

protected TestFlow TestFlow(IMiddleware intentRecognizerMiddleware)
{
var storage = new MemoryStorage();
var convState = new ConversationState(storage);
var userState = new UserState(storage);
var adapter = new TestAdapter()
.Use(new AutoSaveStateMiddleware(userState, convState))
.Use(new ConsoleOutputMiddleware());

if (intentRecognizerMiddleware != null)
{
adapter.Use(intentRecognizerMiddleware);
}

var testFlow = new TestFlow(adapter, async (context, token) =>
{
var bot = this.BuildBot();
await bot.OnTurnAsync(context, token);
});

return testFlow;
}

protected TestFlow TestEventFlow()
{
return this.TestFlow((IMiddleware)null);
}

protected string[] ParseReplies(string templateId, string[] tokens)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Solutions.Middleware;

namespace Microsoft.Bot.Builder.Solutions.Testing
{
public class DefaultTestAdapter : TestAdapter
{
public DefaultTestAdapter(BotStateSet botStateSet)
: base(sendTraceActivity: false)
{
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
}
}
}
Loading

0 comments on commit 19f8a77

Please sign in to comment.