Skip to content

Commit

Permalink
Merge pull request #2 from microsoft/master
Browse files Browse the repository at this point in the history
latest upstream updates
  • Loading branch information
abiemann authored Jun 7, 2019
2 parents 63caa76 + d80b2aa commit ee4b105
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 263 deletions.
10 changes: 8 additions & 2 deletions docs/tutorials/csharp/skill.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ A Bot Framework Skill app (in C#) that greets a new user.
5. Install Bot Framework (CLI) tool dependencies. It's important to do this even if you have earlier versions as we make use of the latest capabilities:

```
npm install -g botdispatch ludown luis-apis qnamaker [email protected] botskills
npm install -g botdispatch ludown luis-apis qnamaker [email protected]
```

6. Install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest)
6. Install Botskills (CLI) tool:

```
npm install -g botskills
```

7. Install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest)

## Create your Skill

Expand Down
11 changes: 8 additions & 3 deletions docs/tutorials/csharp/virtualassistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ A Virtual Assistant app (in C#) that greets a new user.
5. Download and install the Bot Framework (CLI) tool dependencies. It's important to do this even if you have earlier versions as the Virtual Assistant makes use of the latest capabilities:

```
npm install -g botdispatch ludown luis-apis qnamaker [email protected] botskills
npm install -g botdispatch ludown luis-apis qnamaker [email protected]
```
6. Install Botskills (CLI) tool:

```
npm install -g botskills
```

6. Download and install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest).
7. Download and install the [Bot Framework Emulator](https://aka.ms/botframework-emulator).
7. Download and install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest).
8. Download and install the [Bot Framework Emulator](https://aka.ms/botframework-emulator).

## Create your assistant

Expand Down
12 changes: 9 additions & 3 deletions docs/tutorials/typescript/skill.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,22 @@ A Bot Framework Skill app (in TypeScript) that greets a new user.
3. Install Bot Framework (CLI) tool dependencies. It's important to do this even if you have earlier versions as we make use of the latest capabilities:

```
npm install -g botdispatch [email protected] luis-apis qnamaker [email protected] botskills
npm install -g botdispatch [email protected] luis-apis qnamaker [email protected]
```

4. Install [Yeoman](http://yeoman.io)
4. Install Botskills (CLI) tool:

```
npm install -g botskills
```

5. Install [Yeoman](http://yeoman.io)

```
npm install -g yo
```

5. Install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest).
6. Install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest).

## Create your Skill

Expand Down
12 changes: 9 additions & 3 deletions docs/tutorials/typescript/virtualassistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ A Virtual Assistant app (in TypeScript) that greets a new user.
3. Download and install Bot Framework (CLI) tool dependencies. It's important to do this even if you have earlier versions because the Virtual Assistant makes use of the latest capabilities:

```shell
npm install -g botdispatch ludown luis-apis qnamaker [email protected] botskills
npm install -g botdispatch ludown luis-apis qnamaker [email protected]
```

4. Install [Yeoman](http://yeoman.io)
4. Install Botskills (CLI) tool:

```
npm install -g botskills
```

5. Install [Yeoman](http://yeoman.io)

```shell
npm install -g yo
```

5. Install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest).
6. Install the [Azure Command Line Tools (CLI)](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest).

## Create your assistant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@
<Content Include="manifestTemplate.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\skillBeginEvent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\skillBeginEventWithOneParam.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\skillBeginEventWithTwoParams.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Protocol;
using Microsoft.Bot.Schema;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Skills.Tests.Mocks
{
public class MockSkillTransport : ISkillTransport
{
private string _activityForwarded = string.Empty;
private Activity _activityForwarded;

public Task CancelRemoteDialogsAsync(ITurnContext turnContext)
{
Expand All @@ -22,19 +19,19 @@ public void Disconnect()

public Task<bool> ForwardToSkillAsync(ITurnContext dialogContext, Activity activity, Action<Activity> tokenRequestHandler = null)
{
_activityForwarded = JsonConvert.SerializeObject(activity, SerializationSettings.BotSchemaSerializationSettings);
_activityForwarded = activity;

return Task.FromResult(true);
}

public bool CheckIfSkillInvoked()
{
return !string.IsNullOrWhiteSpace(_activityForwarded);
return _activityForwarded != null;
}

public void VerifyActivityForwardedCorrectly(Func<string, bool> assertion)
public void VerifyActivityForwardedCorrectly(Action<Activity> assertion)
{
Assert.IsTrue(assertion(_activityForwarded));
assertion(_activityForwarded);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Adapters;
Expand All @@ -9,6 +8,7 @@
using Microsoft.Bot.Builder.Skills.Tests.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;

namespace Microsoft.Bot.Builder.Skills.Tests
{
Expand Down Expand Up @@ -68,108 +68,84 @@ public void AddSkills()
}

/// <summary>
/// Ensure the SkillBegin event activity is sent to the Skill when starting a skill conversation.
/// Ensure the activity received on the skill side includes the slots that were configured in the manifest.
/// </summary>
/// <returns>Task.</returns>
[TestMethod]
public async Task SkilllBeginEventTest()
public async Task SkillInvocationWithSlotsTest()
{
string eventToMatch = await File.ReadAllTextAsync(@".\TestData\skillBeginEvent.json");

var sp = Services.BuildServiceProvider();
var adapter = sp.GetService<TestAdapter>();

await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskill"), "testSkill/testAction", null)
.Send("hello")
.StartTestAsync();

_mockSkillTransport.VerifyActivityForwardedCorrectly(activity => ValidateActivity(activity, eventToMatch));
}

/// <summary>
/// Ensure the skillBegin event is sent and includes the slots that were configured in the manifest
/// and present in State.
/// </summary>
/// <returns>Task.</returns>
[TestMethod]
public async Task SkilllBeginEventWithSlotsTest()
{
string eventToMatch = await File.ReadAllTextAsync(@".\TestData\skillBeginEventWithOneParam.json");

var sp = Services.BuildServiceProvider();
var adapter = sp.GetService<TestAdapter>();

// Data to add to the UserState managed SkillContext made available for slot filling
// within SkillDialog
Dictionary<string, object> slots = new Dictionary<string, object>();
slots.Add("param1", "TEST");
var slots = new SkillContext();
dynamic entity = new { key1 = "TEST1", key2 = "TEST2" };
slots.Add("param1", JObject.FromObject(entity));

await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithslots"), "testSkill/testActionWithSlots", slots)
await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithslots"), "testSkill/testActionWithSlots", slots)
.Send("hello")
.StartTestAsync();

_mockSkillTransport.VerifyActivityForwardedCorrectly(activity => ValidateActivity(activity, eventToMatch));
_mockSkillTransport.VerifyActivityForwardedCorrectly(activity =>
{
var semanticAction = activity.SemanticAction;
Assert.AreEqual(semanticAction.Entities["param1"].Properties["key1"], "TEST1");
Assert.AreEqual(semanticAction.Entities["param1"].Properties["key2"], "TEST2");
});
}

/// <summary>
/// Ensure the skillBegin event is sent and includes the slots that were configured in the manifest
/// This test has extra data in the SkillContext "memory" which should not be sent across
/// and present in State.
/// Ensure the activity received on the skill side includes the slots that were configured in the manifest
/// This test has extra data in the SkillContext "memory" which should not be sent across.
/// </summary>
/// <returns>Task.</returns>
[TestMethod]
public async Task SkilllBeginEventWithSlotsTestExtraItems()
public async Task SkillInvocationWithSlotsTestExtraItems()
{
string eventToMatch = await File.ReadAllTextAsync(@".\TestData\skillBeginEventWithOneParam.json");

var sp = Services.BuildServiceProvider();
var adapter = sp.GetService<TestAdapter>();

// Data to add to the UserState managed SkillContext made available for slot filling
// within SkillDialog
Dictionary<string, object> slots = new Dictionary<string, object>();
slots.Add("param1", "TEST");
slots.Add("param2", "TEST");
slots.Add("param3", "TEST");
slots.Add("param4", "TEST");
var slots = new SkillContext();
dynamic entity = new { key1 = "TEST1", key2 = "TEST2" };
slots.Add("param1", JObject.FromObject(entity));

await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithslots"), "testSkill/testActionWithSlots", slots)
await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithslots"), "testSkill/testActionWithSlots", slots)
.Send("hello")
.StartTestAsync();

_mockSkillTransport.VerifyActivityForwardedCorrectly(activity => ValidateActivity(activity, eventToMatch));
_mockSkillTransport.VerifyActivityForwardedCorrectly(activity =>
{
var semanticAction = activity.SemanticAction;
Assert.AreEqual(semanticAction.Entities["param1"].Properties["key1"], "TEST1");
Assert.AreEqual(semanticAction.Entities["param1"].Properties["key2"], "TEST2");
});
}

/// <summary>
/// Ensure the skillBegin event is sent and includes the slots that were configured in the manifest
/// and present in State. This doesn't pass an action so "global" slot filling is used
/// </summary>
/// <returns>Task.</returns>
[TestMethod]
public async Task SkilllBeginEventNoActionPassed()
/// <summary>
/// Ensure the activity received on the skill side includes the slots that were configured in the manifest
/// This doesn't pass an action so "global" slot filling is used.
/// </summary>
/// <returns>Task.</returns>
[TestMethod]
public async Task SkillInvocationNoActionPassed()
{
string eventToMatch = await File.ReadAllTextAsync(@".\TestData\skillBeginEventWithTwoParams.json");

var sp = Services.BuildServiceProvider();
var adapter = sp.GetService<TestAdapter>();

// Data to add to the UserState managed SkillContext made available for slot filling
// within SkillDialog
Dictionary<string, object> slots = new Dictionary<string, object>();
slots.Add("param1", "TEST");
slots.Add("param2", "TEST2");
var slots = new SkillContext();
dynamic entity = new { key1 = "TEST1", key2 = "TEST2" };
slots.Add("param1", JObject.FromObject(entity));

// Not passing action to test the "global" slot filling behaviour
await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithmultipleactionsandslots"), null, slots)
.Send("hello")
.StartTestAsync();

_mockSkillTransport.VerifyActivityForwardedCorrectly(activity => ValidateActivity(activity, eventToMatch));
}

private bool ValidateActivity(string activitySent, string activityToMatch)
{
return string.Equals(activitySent, activityToMatch);
_mockSkillTransport.VerifyActivityForwardedCorrectly(activity =>
{
var semanticAction = activity.SemanticAction;
Assert.AreEqual(semanticAction.Entities["param1"].Properties["key1"], "TEST1");
Assert.AreEqual(semanticAction.Entities["param1"].Properties["key2"], "TEST2");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Bot.Builder.Solutions.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;

namespace Microsoft.Bot.Builder.Skills.Tests
{
Expand Down Expand Up @@ -47,7 +48,7 @@ public override void Initialize()
Services.AddSingleton<ISkillTransport, SkillWebSocketTransport>();
}

public TestFlow GetTestFlow(SkillManifest skillManifest, string actionId, Dictionary<string, object> slots)
public TestFlow GetTestFlow(SkillManifest skillManifest, string actionId, Dictionary<string, JObject> slots)
{
var sp = Services.BuildServiceProvider();
var adapter = sp.GetService<TestAdapter>();
Expand Down
Loading

0 comments on commit ee4b105

Please sign in to comment.