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

[4.4] Fixes test projects #1083

Merged
merged 14 commits into from
Apr 10, 2019
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using NewsSkill.Responses.Main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using NewsSkill.Responses.Main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Solutions.Dialogs;
using Microsoft.Bot.Builder.Solutions.Skills;
using Microsoft.Bot.Schema;
using NewsSkill.Models;
using NewsSkill.Responses.Main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Solutions.Skills;
using NewsSkill.Models;
using NewsSkill.Responses.Main;
using NewsSkill.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.34-preview" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.3.1" />
Expand All @@ -28,6 +27,7 @@

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

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Solutions;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;

namespace NewsSkill.Services
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Shared.Responses;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using RestaurantBooking.Responses.Shared;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Shared.Responses;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using RestaurantBooking.Responses.Shared;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Bot.Builder.Dialogs.Choices;
using Microsoft.Bot.Builder.Solutions.Extensions;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Shared.Responses;
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
using RestaurantBooking.Content;
using RestaurantBooking.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Solutions.Dialogs;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Shared.Responses;
using Microsoft.Bot.Schema;
using RestaurantBooking.Models;
using RestaurantBooking.Responses.Main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using Luis;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Builder.Solutions.Shared.Responses;
using Microsoft.Bot.Builder.Solutions.Shared.Telemetry;
using Microsoft.Bot.Schema;
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
using Microsoft.Recognizers.Text.DateTime;
Expand Down
Loading