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

Address final stylecop warnings in Skills/Solutions nuget #1147

Merged
merged 8 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/csharp/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<CodeAnalysisRuleSet>$(SolutionDir)BotBuilder-DotNet.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008" PrivateAssets="all" />
</ItemGroup>
Expand Down Expand Up @@ -52,7 +56,7 @@
Suppress a warning about upcoming deprecation of PackageLicenseUrl. When embedding licenses are supported,
replace PackageLicenseUrl with PackageLicenseExpression.
-->
<NoWarn>$(NoWarn);NU5125</NoWarn>
<NoWarn>$(NoWarn);NU5125,NU1701</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration) == 'Debug'">
<!-- For debug builds, we don't generate documentation. Supress the StyleCop rule that warns about this. -->
Expand Down
2 changes: 1 addition & 1 deletion lib/csharp/NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Microsoft AI MyGet Feed" value="https://botbuilder.myget.org/F/aitemplates/api/v3/index.json" />
<add key="Bot Builder MyGet Feed" value="https://botbuilder.myget.org/F/botbuilder-declarative/api/v3/index.json" />
<add key="Bot Builder Experimental MyGet Feed" value="https://botbuilder.myget.org/F/experimental/api/v3/index.json" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace Microsoft.Bot.Builder.Skills.Tests.Mocks
{
public class DummyMicrosoftAppCredentialsEx : MicrosoftAppCredentialsEx
{
public DummyMicrosoftAppCredentialsEx(string appId, string password, string scope) : base(appId, password, scope)
public DummyMicrosoftAppCredentialsEx(string appId, string password, string scope)
: base(appId, password, scope)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public void AddSkillManifest()
"testSkill/testAction");

// Add the SkillDialog to the available dialogs passing the initialized FakeSkill
Dialogs.Add(new SkillDialogTest(_skillManifest, new DummyMicrosoftAppCredentialsEx(null, null, null), _mockTelemetryClient, _mockHttp, UserState));
Dialogs.Add(new SkillDialogTest(_skillManifest, new DummyMicrosoftAppCredentialsEx(Guid.NewGuid().ToString(), "PASSWORD", "SCOPE"), _mockTelemetryClient, _mockHttp, UserState));
}

/// <summary>
/// Create a SkillDialog and send a mesage triggering a HTTP call to the remote skill which the mock intercepts.
/// This ensures the SkillDialog is handling the SkillManifest correctly and sending the HttpRequest to the skill
/// This ensures the SkillDialog is handling the SkillManifest correctly and sending the HttpRequest to the skill.
/// </summary>
/// <returns>Task.</returns>
[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void AddSkills()
// the SkillDialog to know which action is invoked and identify the slots as appropriate.
foreach (var skill in _skillManifests)
{
Dialogs.Add(new SkillDialogTest(skill, new DummyMicrosoftAppCredentialsEx(null, null, null), _mockTelemetryClient, _mockHttp, UserState));
Dialogs.Add(new SkillDialogTest(skill, new DummyMicrosoftAppCredentialsEx(Guid.NewGuid().ToString(), "PASSWORD", "SCOPE"), _mockTelemetryClient, _mockHttp, UserState));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public async Task SkillMiddlewareNullSlotData()
TestAdapter adapter = new TestAdapter()
.Use(new SkillMiddleware(_userState, _conversationState, _dialogStateAccessor));

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
var testFlow = new TestFlow(adapter, async (context, cancellationToken) =>
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
});

Expand All @@ -145,7 +147,9 @@ public async Task SkillMiddlewareNullEventName()
TestAdapter adapter = new TestAdapter()
.Use(new SkillMiddleware(_userState, _conversationState, _dialogStateAccessor));

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
var testFlow = new TestFlow(adapter, async (context, cancellationToken) =>
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
});

Expand All @@ -162,7 +166,7 @@ private async Task ValidateSkillContextData(ITurnContext context, Dictionary<str
$"SkillContext didn't contain the expected data after Skill middleware processing: {CreateCollectionMismatchMessage(skillContext, skillTestDataToValidate)} ");
}

private string CreateCollectionMismatchMessage (SkillContext context, Dictionary<string, object> test)
private string CreateCollectionMismatchMessage(SkillContext context, Dictionary<string, object> test)
{
var contextData = string.Join(",", context.Select(x => x.Key + "=" + x.Value));
var testData = string.Join(",", test.Select(x => x.Key + "=" + x.Value));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Bot.Builder.Skills.Models.Manifest;
using System;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Bot.Builder.Skills.Models.Manifest;

namespace Microsoft.Bot.Builder.Skills.Tests.Utilities
{
Expand All @@ -14,18 +13,18 @@ public static SkillManifest CreateSkill(string id, string name, string endpoint,
Name = name,
Id = id,
Endpoint = new Uri(endpoint),
Actions = new List<Models.Manifest.Action>()
Actions = new List<Models.Manifest.Action>(),
};

var action = new Models.Manifest.Action
{
Id = actionId,
Definition = new ActionDefinition()
Definition = new ActionDefinition(),
};

// Provide slots if we have them
if (slots != null)
{
{
action.Definition.Slots = slots;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<PackageReference Include="Microsoft.Bot.Builder" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Protocol.WebSockets" Version="1.0.0-55610" />
<PackageReference Include="Microsoft.Bot.Protocol" Version="1.0.0-55897" />
<PackageReference Include="Microsoft.Bot.Protocol.WebSockets" Version="1.0.0-55897" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008" PrivateAssets="all" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Skills.Models.Manifest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Skills.Models.Manifest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
Expand All @@ -25,7 +26,6 @@ public class SkillDialog : ComponentDialog

private SkillManifest _skillManifest;
private ISkillTransport _skillTransport;
private Models.Manifest.Action _action;

private Queue<Activity> _queuedResponses = new Queue<Activity>();
private object _lockObject = new object();
Expand All @@ -48,8 +48,8 @@ public SkillDialog(SkillManifest skillManifest, MicrosoftAppCredentialsEx micros
_telemetryClient = telemetryClient ?? throw new ArgumentNullException();
_userState = userState;
_skillTransport = new SkillWebSocketTransport(_skillManifest, _microsoftAppCredentialsEx);
//_skillTransport = new SkillHttpTransport(_skillManifest, _microsoftAppCredentialsEx);

// _skillTransport = new SkillHttpTransport(_skillManifest, _microsoftAppCredentialsEx);
if (authDialog != null)
{
_authDialog = authDialog;
Expand Down Expand Up @@ -87,38 +87,39 @@ public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstan
var accessor = _userState.CreateProperty<SkillContext>(nameof(SkillContext));
var skillContext = await accessor.GetAsync(innerDc.Context, () => new SkillContext());

// var actionName = options as string;
// if (actionName == null)
// {
// throw new ArgumentException("SkillDialog requires an Action in order to be able to identify which Action within a skill to invoke.");
// }
// else
// {
// // Find the Action within the selected Skill for slot filling evaluation
// _action = _skillManifest.Actions.Single(a => a.Id == actionName);
// if (_action != null)
// {
// // If the action doesn't define any Slots or SkillContext is empty then we skip slot evaluation
// if (_action.Definition.Slots != null && skillContext.Count > 0)
// {
// foreach (Slot slot in _action.Definition.Slots)
// {
// // For each slot we check to see if there is an exact match, if so we pass this slot across to the skill
// if (skillContext.TryGetValue(slot.Name, out object slotValue))
// {
// slots.Add(slot.Name, slotValue);
// // Send trace to emulator
// dialogContext.Context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"-->Matched the {slot.Name} slot within SkillContext and passing to the {actionName} action.")).GetAwaiter().GetResult();
// }
// }
// }
// }
// else
// {
// // Loosening checks for current Dispatch evaluation, TODO - Review
// // throw new ArgumentException($"Passed Action ({actionName}) could not be found within the {_skillManifest.Id} skill manifest action definition.");
// }
// }
var actionName = options as string;
if (actionName == null)
{
throw new ArgumentException("SkillDialog requires an Action in order to be able to identify which Action within a skill to invoke.");
}
else
{
// Find the Action within the selected Skill for slot filling evaluation
var action = _skillManifest.Actions.SingleOrDefault(a => a.Id == actionName);
if (action != null)
{
// If the action doesn't define any Slots or SkillContext is empty then we skip slot evaluation
if (action.Definition.Slots != null && skillContext.Count > 0)
{
foreach (Slot slot in action.Definition.Slots)
{
// For each slot we check to see if there is an exact match, if so we pass this slot across to the skill
if (skillContext.TryGetValue(slot.Name, out object slotValue))
{
slots.Add(slot.Name, slotValue);

// Send trace to emulator
innerDc.Context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"-->Matched the {slot.Name} slot within SkillContext and passing to the {actionName} action.")).GetAwaiter().GetResult();
}
}
}
}
else
{
// Loosening checks for current Dispatch evaluation, TODO - Review
// throw new ArgumentException($"Passed Action ({actionName}) could not be found within the {_skillManifest.Id} skill manifest action definition.");
}
}

await innerDc.Context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"-->Handing off to the {_skillManifest.Name} skill."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task<InvokeResponse> ProcessActivityAsync(Activity activity, BotCal
return response;
}

public async Task SendRemoteTokenRequestEvent(ITurnContext turnContext, CancellationToken cancellationToken)
public async Task SendRemoteTokenRequestEventAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
// We trigger a Token Request from the Parent Bot by sending a "TokenRequest" event back and then waiting for a "TokenResponse"
var response = turnContext.Activity.CreateReply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public class SkillHttpTransport : ISkillTransport
private readonly SkillManifest _skillManifest;
private readonly MicrosoftAppCredentialsEx _microsoftAppCredentialsEx;

// Protected to enable mocking
protected HttpClient HttpClient { get => _httpClient; set => _httpClient = value; }

public SkillHttpTransport(SkillManifest skillManifest, MicrosoftAppCredentialsEx microsoftAppCredentialsEx)
{
_skillManifest = skillManifest ?? throw new ArgumentNullException(nameof(skillManifest));
_microsoftAppCredentialsEx = microsoftAppCredentialsEx ?? throw new ArgumentNullException(nameof(microsoftAppCredentialsEx));
}

// Protected to enable mocking
protected HttpClient HttpClient { get => _httpClient; set => _httpClient = value; }

public async Task CancelRemoteDialogsAsync(ITurnContext turnContext)
{
var cancelRemoteDialogEvent = turnContext.Activity.CreateReply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public override async Task DeleteActivityAsync(ITurnContext turnContext, Convers
await SendRequestAsync(request, cancellationToken);
}

public async Task SendRemoteTokenRequestEvent(ITurnContext turnContext, CancellationToken cancellationToken)
public async Task SendRemoteTokenRequestEventAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
// We trigger a Token Request from the Parent Bot by sending a "TokenRequest" event back and then waiting for a "TokenResponse"
var response = turnContext.Activity.CreateReply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ private string EnsureWebSocketUrl(string url)

var httpPrefix = "http://";
var httpsPrefix = "https://";
#pragma warning disable SA1305 // Field names should not use Hungarian notation
var wsPrefix = "ws://";
#pragma warning restore SA1305 // Field names should not use Hungarian notation
var wssPrefix = "wss://";

if (url.StartsWith(httpPrefix))
Expand Down
Loading