This commit is contained in:
Dave Taniguchi 2018-11-19 20:55:11 -08:00
Родитель fe29fb1db6
Коммит 71a862ab37
24 изменённых файлов: 772 добавлений и 200 удалений

Просмотреть файл

@ -4,7 +4,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using System.Collections.Generic;
using System;
namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
{
@ -19,13 +20,25 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
Assert.IsNotNull(client);
}
[TestMethod]
public void TrackAvailabilityTest()
{
var telemetryClient = new TelemetryClient();
var client = new BotTelemetryClient(telemetryClient);
client.TrackAvailability("test", DateTimeOffset.Now, new TimeSpan(1000), "run location", true,
"message", new Dictionary<string, string>() { { "hello", "value" } }, new Dictionary<string, double>() { { "metric", 0.6 } });
}
[TestMethod]
public void TrackEventTest()
{
var telemetryClient = new TelemetryClient();
var client = new BotTelemetryClient(telemetryClient);
var eventTelemetry = new EventTelemetry();
client.TrackEvent(eventTelemetry);
client.TrackEvent("test", new Dictionary<string, string>() { { "hello", "value" } }, new Dictionary<string, double>() { { "metric", 0.6 } });
}
[TestMethod]
@ -33,8 +46,7 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
{
var telemetryClient = new TelemetryClient();
var client = new BotTelemetryClient(telemetryClient);
var telemetry = new DependencyTelemetry("my dependency", "my target", "foo", "data");
client.TrackDependency(telemetry);
client.TrackDependency("test", "target", "dependencyname", "data", DateTimeOffset.Now, new TimeSpan(10000), "result", false );
}
[TestMethod]
@ -42,8 +54,7 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
{
var telemetryClient = new TelemetryClient();
var client = new BotTelemetryClient(telemetryClient);
var telemetry = new ExceptionTelemetry();
client.TrackException(telemetry);
client.TrackException(new Exception(), new Dictionary<string, string>() { { "foo", "bar" } }, new Dictionary<string, double>() { { "metric", 0.6 } });
}
[TestMethod]
@ -51,8 +62,7 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
{
var telemetryClient = new TelemetryClient();
var client = new BotTelemetryClient(telemetryClient);
var telemetry = new TraceTelemetry();
client.TrackTrace(telemetry);
client.TrackTrace("hello", Severity.Critical, new Dictionary<string, string>() { { "foo", "bar" } });
}

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Dialogs;
@ -25,12 +26,13 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
var telemetryClient = new Mock<IBotTelemetryClient>();
var dialogState = convoState.CreateProperty<DialogState>("dialogState");
var dialogs = new DialogSet(dialogState);
dialogs.Add(new TelemetryWaterfallDialog("test", telemetryClient.Object, new WaterfallStep[]
dialogs.Add(new WaterfallDialog("test", new WaterfallStep[]
{
async (step, cancellationToken) => { await step.Context.SendActivityAsync("step1"); return Dialog.EndOfTurn; },
async (step, cancellationToken) => { await step.Context.SendActivityAsync("step2"); return Dialog.EndOfTurn; },
async (step, cancellationToken) => { await step.Context.SendActivityAsync("step3"); return Dialog.EndOfTurn; },
}));
})
{ Logger = telemetryClient.Object });
await new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
@ -48,7 +50,7 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
.Send("hello")
.AssertReply("step3")
.StartTestAsync();
telemetryClient.Verify(m => m.TrackWaterfallStep(It.IsAny<WaterfallStepContext>(), It.IsAny<String>()), Times.Exactly(3));
telemetryClient.Verify(m => m.TrackEvent(It.IsAny<string>(), It.IsAny<IDictionary<string,string>>(), It.IsAny<IDictionary<string, double>>()), Times.Exactly(3));
Console.WriteLine("Complete");
}
@ -63,12 +65,13 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
var dialogState = convoState.CreateProperty<DialogState>("dialogState");
var dialogs = new DialogSet(dialogState);
var telemetryClient = new Mock<IBotTelemetryClient>(); ;
var waterfallDialog = new TelemetryWaterfallDialog("test", telemetryClient.Object, new WaterfallStep[]
var waterfallDialog = new WaterfallDialog("test", new WaterfallStep[]
{
async (step, cancellationToken) => { await step.Context.SendActivityAsync("step1"); return Dialog.EndOfTurn; },
async (step, cancellationToken) => { await step.Context.SendActivityAsync("step2"); return Dialog.EndOfTurn; },
async (step, cancellationToken) => { await step.Context.SendActivityAsync("step3"); return Dialog.EndOfTurn; },
});
})
{ Logger = telemetryClient.Object };
dialogs.Add(waterfallDialog);
@ -88,23 +91,16 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Tests
.Send("hello")
.AssertReply("step3")
.StartTestAsync();
telemetryClient.Verify(m => m.TrackWaterfallStep(It.IsAny<WaterfallStepContext>(), It.IsAny<String>()), Times.Exactly(3));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public async Task WaterfallWithNullTelemetryClient()
{
var waterfall = new TelemetryWaterfallDialog("test", null);
telemetryClient.Verify(m => m.TrackEvent(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<IDictionary<string, double>>()), Times.Exactly(3));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public async Task WaterfallWithStepsNull()
public void WaterfallWithStepsNull()
{
var telemetryClient = new Mock<IBotTelemetryClient>();
var waterfall = new TelemetryWaterfallDialog("test", telemetryClient.Object);
var telemetryClient = new Mock<IBotTelemetryClient>();
var waterfall = new WaterfallDialog("test") { Logger = telemetryClient.Object };
waterfall.AddStep(null);
}

Просмотреть файл

@ -68,7 +68,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.Appli
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.ApplicationInsights.Core.Tests", "tests\integration\Microsoft.Bot.ApplicationInsights.Core.Tests\Microsoft.Bot.ApplicationInsights.Core.Tests.csproj", "{3F4A0DD8-4D47-4B9C-939A-3146E68C84F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Bot.Builder.ApplicationInsights.Tests", "Microsoft.Bot.Builder.ApplicationInsights.Tests\Microsoft.Bot.Builder.ApplicationInsights.Tests.csproj", "{FC304BC8-D719-4E97-8C6C-36BDC342F069}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.ApplicationInsights.Tests", "Microsoft.Bot.Builder.ApplicationInsights.Tests\Microsoft.Bot.Builder.ApplicationInsights.Tests.csproj", "{FC304BC8-D719-4E97-8C6C-36BDC342F069}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Bot.Builder.ApplicationInsights.WebApi", "libraries\integration\Microsoft.Bot.Builder.ApplicationInsights.WebApi\Microsoft.Bot.Builder.ApplicationInsights.WebApi.csproj", "{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -303,6 +305,14 @@ Global
{FC304BC8-D719-4E97-8C6C-36BDC342F069}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{FC304BC8-D719-4E97-8C6C-36BDC342F069}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC304BC8-D719-4E97-8C6C-36BDC342F069}.Release|Any CPU.Build.0 = Release|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug - NuGet Packages|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Debug - NuGet Packages|Any CPU.Build.0 = Debug - NuGet Packages|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -340,6 +350,7 @@ Global
{B609DB2C-5C1F-46D1-A0FA-A0FF9216899A} = {4269F3C3-6B42-419B-B64A-3E6DC0F1574A}
{3F4A0DD8-4D47-4B9C-939A-3146E68C84F7} = {0A0E26B0-7A46-4F1A-8BFE-9A763FDF6CF8}
{FC304BC8-D719-4E97-8C6C-36BDC342F069} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
{400BB78F-AFDC-4B1C-AD85-BE159B576FCE} = {276EBE79-A13A-46BD-A566-B01DC0477A9B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7173C9F3-A7F9-496E-9078-9156E35D6E16}

Просмотреть файл

@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.Bot.Builder.Dialogs;
namespace Microsoft.Bot.Builder.ApplicationInsights
{
@ -15,67 +16,151 @@ namespace Microsoft.Bot.Builder.ApplicationInsights
{
_telemetryClient = telemetryClient;
}
/// <summary>
/// Send information about external dependency call in the application. Create a
// separate Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry instance
// for each call to Microsoft.ApplicationInsights.TelemetryClient.TrackDependency(Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry)
/// Send information about availability of an application.
/// </summary>
/// <param name="telemetry">A </param>
public void TrackDependency(DependencyTelemetry telemetry)
/// <param name="name">Availability test name.</param>
/// <param name="timeStamp">The time when the availability was captured.</param>
/// <param name="duration">The time taken for the availability test to run.</param>
/// <param name="runLocation">Name of the location the availability test was run from.</param>
/// <param name="success">True if the availability test ran successfully.</param>
/// <param name="message">Error message on availability test run failure.</param>
/// <param name="properties">Named string values you can use to classify and search for this availability telemetry.</param>
/// <param name="metrics">Additional values associated with this availability telemetry.</param>
public void TrackAvailability(string name, DateTimeOffset timeStamp, TimeSpan duration, string runLocation, bool success, string message = null, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new AvailabilityTelemetry(name, timeStamp, duration, runLocation, success, message);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackAvailability(telemetry);
}
/// <summary>
/// Send information about an external dependency (outgoing call) in the application.
/// </summary>
/// <param name="dependencyTypeName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are SQL, Azure table, and HTTP.</param>
/// <param name="target">External dependency target.</param>
/// <param name="dependencyName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are stored procedure name and URL path template.</param>
/// <param name="data">Command initiated by this dependency call. Examples are SQL statement and HTTP
/// URL's with all query parameters.</param>
/// <param name="startTime">The time when the dependency was called.</param>
/// <param name="duration">The time taken by the external dependency to handle the call.</param>
/// <param name="resultCode">Result code of dependency call execution.</param>
/// <param name="success">True if the dependency call was handled successfully.</param>
public void TrackDependency(string dependencyTypeName, string target, string dependencyName, string data, DateTimeOffset startTime, TimeSpan duration, string resultCode, bool success)
{
var telemetry = new DependencyTelemetry
{
Type = dependencyTypeName,
Target = target,
Name = dependencyName,
Data = data,
Timestamp = startTime,
Duration = duration,
ResultCode = resultCode,
Success = success
};
_telemetryClient.TrackDependency(telemetry);
}
/// <summary>
/// Send an Microsoft.ApplicationInsights.DataContracts.EventTelemetry for display
// in Diagnostic Search and in the Analytics Portal.
/// Logs custom events with extensible named fields.
/// </summary>
/// <param name="telemetry">An event log item.</param>
public void TrackEvent(EventTelemetry telemetry)
/// <param name="eventName">A name for the event.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
/// <remarks>For Application Insights, this maps to <cref="https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/application-insights/app-insights-api-custom-events-metrics.md#trackevent".</remarks>
public void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new EventTelemetry(eventName);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackEvent(telemetry);
}
/// <summary>
/// Send an Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry for display
// in Diagnostic Search. Create a separate Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry
// instance for each call to Microsoft.ApplicationInsights.TelemetryClient.TrackException(Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry)
/// Logs a system exception.
/// </summary>
/// <param name="telemetry"></param>
public void TrackException(ExceptionTelemetry telemetry)
/// <param name="exception">The exception to log.</param>
/// <param name="properties">Named string values you can use to classify and search for this exception.</param>
/// <param name="metrics">Additional values associated with this exception.</param>
public void TrackException(Exception exception, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new ExceptionTelemetry(exception);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackException(telemetry);
}
/// <summary>
/// Send a trace message for display in Diagnostic Search. Create a separate Microsoft.ApplicationInsights.DataContracts.TraceTelemetry
// instance for each call to Microsoft.ApplicationInsights.TelemetryClient.TrackTrace(Microsoft.ApplicationInsights.DataContracts.TraceTelemetry).
//
/// Send a trace message
/// </summary>
/// <param name="telemetry">Message with optional properties.</param>
public void TrackTrace(TraceTelemetry telemetry)
/// <param name="message">Message to display.</param>
/// <param name="severityLevel">Trace severaity level <see cref="Severity"/></param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
public void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties)
{
_telemetryClient.TrackTrace(telemetry);
}
var telemetry = new TraceTelemetry(message)
{
SeverityLevel = (SeverityLevel)severityLevel
};
/// <summary>
/// Tracks single Waterfall step in Application Insights.
/// </summary>
/// <param name="waterfallStepContext">The WaterfallStepContext for this waterfall dialog.</param>
/// <param name="stepFriendlyName">The friendly name that is logged with the waterfall dialog id.</param>
public void TrackWaterfallStep(WaterfallStepContext waterfallStepContext, string stepFriendlyName)
{
_telemetryClient.TrackWaterfallStep(waterfallStepContext, stepFriendlyName);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackTrace(telemetry);
}
/// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary>
public void Flush()
{
_telemetryClient.Flush();
}
public void Flush() => _telemetryClient.Flush();
}
}

Просмотреть файл

@ -1,59 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.Bot.Builder.Dialogs;
namespace Microsoft.Bot.Builder.ApplicationInsights
{
/// <summary>
/// Logging client for Bot Telemetry.
/// </summary>
public interface IBotTelemetryClient
{
/// <summary>
/// Send information about external dependency call in the application. Create a
// separate Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry instance
// for each call to Microsoft.ApplicationInsights.TelemetryClient.TrackDependency(Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry)
/// </summary>
/// <param name="telemetry">A </param>
void TrackDependency(DependencyTelemetry telemetry);
/// <summary>
/// Send an Microsoft.ApplicationInsights.DataContracts.EventTelemetry for display
// in Diagnostic Search and in the Analytics Portal.
/// </summary>
/// <param name="telemetry">An event log item.</param>
void TrackEvent(EventTelemetry telemetry);
/// <summary>
/// Send an Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry for display
// in Diagnostic Search. Create a separate Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry
// instance for each call to Microsoft.ApplicationInsights.TelemetryClient.TrackException(Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry)
/// </summary>
/// <param name="telemetry"></param>
void TrackException(ExceptionTelemetry telemetry);
/// <summary>
/// Send a trace message for display in Diagnostic Search. Create a separate Microsoft.ApplicationInsights.DataContracts.TraceTelemetry
// instance for each call to Microsoft.ApplicationInsights.TelemetryClient.TrackTrace(Microsoft.ApplicationInsights.DataContracts.TraceTelemetry).
//
/// </summary>
/// <param name="telemetry">Message with optional properties.</param>
void TrackTrace(TraceTelemetry telemetry);
/// <summary>
/// Tracks single Waterfall step in Application Insights.
/// </summary>
/// <param name="waterfallStepContext">The WaterfallStepContext for this waterfall dialog.</param>
/// <param name="stepFriendlyName">The friendly name that is logged with the waterfall dialog id.</param>
void TrackWaterfallStep(WaterfallStepContext waterfallStepContext, string stepFriendlyName = null);
/// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary>
void Flush();
}
}

Просмотреть файл

@ -4,6 +4,11 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.1" />
</ItemGroup>

Просмотреть файл

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Linq;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.Bot.Builder.Dialogs;
namespace Microsoft.Bot.Builder.ApplicationInsights
{
public static class TelemetryTrackWaterfallStepExtension
{
/// <summary>
/// Tracks single Waterfall step in Application Insights.
/// </summary>
/// <typeparam name="TResult">The type of the return value of the method that this delegate encapsulates.</typeparam>
/// <param name="telemetryClient">The <seealso cref="TelemetryClient"/>.</param>
/// <param name="waterfallStepContext">Encapsulates a method that has no parameters and returns a value of the type specified by the TResult parameter.</param>
public static void TrackWaterfallStep(this TelemetryClient telemetryClient, WaterfallStepContext waterfallStepContext, string stepFriendlyName)
{
if (waterfallStepContext == null)
{
throw new ArgumentNullException(nameof(waterfallStepContext));
}
if (string.IsNullOrWhiteSpace(stepFriendlyName))
{
stepFriendlyName = waterfallStepContext.Stack[waterfallStepContext.Index].Id;
}
var eventName = waterfallStepContext.Stack.Last().Id + stepFriendlyName;
var evt = new EventTelemetry(eventName);
// Log the event into Application Insights
telemetryClient.TrackEvent(evt);
}
}
}

Просмотреть файл

@ -1,35 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.Bot.Builder.Dialogs;
namespace Microsoft.Bot.Builder.ApplicationInsights
{
public class TelemetryWaterfallDialog : WaterfallDialog
{
private readonly IBotTelemetryClient _telemetryClient;
public TelemetryWaterfallDialog(string dialogId, IBotTelemetryClient telemetryClient, IEnumerable<WaterfallStep> steps = null)
: base(dialogId, steps)
{
if (telemetryClient == null)
{
throw new ArgumentNullException(nameof(telemetryClient));
}
_telemetryClient = telemetryClient;
}
protected override async Task<DialogTurnResult> OnStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
_telemetryClient.TrackWaterfallStep(stepContext, null);
return await base.OnStepAsync(stepContext, cancellationToken);
}
}
}

Просмотреть файл

@ -26,6 +26,12 @@ namespace Microsoft.Bot.Builder.Dialogs
public string Id { get; }
/// <summary>
/// Gets or sets the telemetry client for logging events.
/// </summary>
/// <value>The Telemetry Client logger.</value>
public IBotTelemetryClient Logger { get; set; } = new NullBotTelemetryClient();
/// <summary>
/// Method called when a new dialog has been pushed onto the stack and is being activated.
/// </summary>

Просмотреть файл

@ -152,6 +152,20 @@ namespace Microsoft.Bot.Builder.Dialogs
// Pop active dialog off the stack
if (Stack.Any())
{
// Log WaterfallConvert event.
var dialogId = Stack.ElementAt(0).Id;
var dialog = Dialogs.Find(dialogId);
var dialogType = dialog.GetType();
if (dialogType == typeof(WaterfallDialog) || dialogType.IsSubclassOf(typeof(WaterfallDialog)))
{
var properties = new Dictionary<string, string>()
{
{ "DialogId", dialogId },
{ "DialogType", dialog.GetType().Name },
};
dialog.Logger.TrackEvent("WaterfallConvert", properties);
}
Stack.RemoveAt(0);
}

Просмотреть файл

@ -105,6 +105,14 @@ namespace Microsoft.Bot.Builder.Dialogs
protected virtual async Task<DialogTurnResult> OnStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// Log Waterfall Step event. Each event has a distinct name to hook up
// to the Application Insights funnel.
var eventName = $"{Id}.Step{stepContext.Index + 1}of{_steps.Count}";
var properties = new Dictionary<string, string>()
{
{ "DialogId", Id.ToString() },
};
Logger.TrackEvent(eventName, properties);
return await _steps[stepContext.Index](stepContext, cancellationToken).ConfigureAwait(false);
}
@ -135,5 +143,20 @@ namespace Microsoft.Bot.Builder.Dialogs
return await dc.EndDialogAsync(result).ConfigureAwait(false);
}
}
public override Task EndDialogAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default(CancellationToken))
{
if (reason == DialogReason.CancelCalled)
{
var properties = new Dictionary<string, string>()
{
{ "DialogId", Id.ToString() },
};
Logger.TrackEvent("WaterfallCancel", properties);
}
// No-op by default
return Task.CompletedTask;
}
}
}

Просмотреть файл

@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
namespace Microsoft.Bot.Builder
{
/// <summary>
/// Logging client for Bot Telemetry.
/// </summary>
public interface IBotTelemetryClient
{
/// <summary>
/// Send information about availability of an application.
/// </summary>
/// <param name="name">Availability test name.</param>
/// <param name="timeStamp">The time when the availability was captured.</param>
/// <param name="duration">The time taken for the availability test to run.</param>
/// <param name="runLocation">Name of the location the availability test was run from.</param>
/// <param name="success">True if the availability test ran successfully.</param>
/// <param name="message">Error message on availability test run failure.</param>
/// <param name="properties">Named string values you can use to classify and search for this availability telemetry.</param>
/// <param name="metrics">Additional values associated with this availability telemetry.</param>
void TrackAvailability(string name, DateTimeOffset timeStamp, TimeSpan duration, string runLocation, bool success, string message = null, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Send information about an external dependency (outgoing call) in the application.
/// </summary>
/// <param name="dependencyTypeName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are SQL, Azure table, and HTTP.</param>
/// <param name="target">External dependency target.</param>
/// <param name="dependencyName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are stored procedure name and URL path template.</param>
/// <param name="data">Command initiated by this dependency call. Examples are SQL statement and HTTP
/// URL's with all query parameters.</param>
/// <param name="startTime">The time when the dependency was called.</param>
/// <param name="duration">The time taken by the external dependency to handle the call.</param>
/// <param name="resultCode">Result code of dependency call execution.</param>
/// <param name="success">True if the dependency call was handled successfully.</param>
void TrackDependency(string dependencyTypeName, string target, string dependencyName, string data, DateTimeOffset startTime, TimeSpan duration, string resultCode, bool success);
/// <summary>
/// Logs custom events with extensible named fields.
/// </summary>
/// <param name="eventName">A name for the event.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Logs a system exception.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="properties">Named string values you can use to classify and search for this exception.</param>
/// <param name="metrics">Additional values associated with this exception.</param>
void TrackException(Exception exception, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Send a trace message.
/// </summary>
/// <param name="message">Message to display.</param>
/// <param name="severityLevel">Trace severaity level <see cref="Severity"/>.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties);
/// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary>
void Flush();
}
}

Просмотреть файл

@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
namespace Microsoft.Bot.Builder
{
public class NullBotTelemetryClient : IBotTelemetryClient
{
public static IBotTelemetryClient Instance { get; } = new NullBotTelemetryClient();
public void Flush()
{
}
public void TrackAvailability(string name, DateTimeOffset timeStamp, TimeSpan duration, string runLocation, bool success, string message = null, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public void TrackDependency(string dependencyTypeName, string target, string dependencyName, string data, DateTimeOffset startTime, TimeSpan duration, string resultCode, bool success)
{
}
public void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public void TrackException(Exception exception, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties)
{
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Bot.Builder
{
/// <summary>
/// This enumeration is used by TrackTrace to identify severity level.
/// </summary>
public enum Severity
{
/// <summary>
/// Verbose severity level.
/// </summary>
Verbose = 0,
/// <summary>
/// Information severity level.
/// </summary>
Information = 1,
/// <summary>
/// Warning severity level.
/// </summary>
Warning = 2,
/// <summary>
/// Error severity level.
/// </summary>
Error = 3,
/// <summary>
/// Critical severity level.
/// </summary>
Critical = 4,
}
}

Просмотреть файл

@ -38,10 +38,10 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Core
// Enables Bot Telemetry to save user/session id's as the bot user id and session
services.AddMemoryCache();
services.TryAddTransient<TelemetrySaveBodyASPMiddleware>();
services.TryAddSingleton<ITelemetryInitializer>(new OperationCorrelationTelemetryInitializer());
services.TryAddSingleton<ITelemetryInitializer, TelemetryBotIdInitializer>();
services.TryAddSingleton<IBotTelemetryClient, BotTelemetryClient>();
services.AddTransient<TelemetrySaveBodyASPMiddleware>();
services.AddSingleton<ITelemetryInitializer>(new OperationCorrelationTelemetryInitializer());
services.AddSingleton<ITelemetryInitializer, TelemetryBotIdInitializer>();
services.AddSingleton<IBotTelemetryClient, BotTelemetryClient>();
return services;
}
}

Просмотреть файл

@ -44,6 +44,9 @@ namespace Microsoft.Bot.Builder.ApplicationInsights.Core
// Set the session id on the Application Insights telemetry item.
telemetry.Context.Session.Id = conversationId;
// Set the activity id
telemetry.Context.GlobalProperties.Add("activity_id", (string)body["id"]);
}
}
}

Просмотреть файл

@ -0,0 +1,113 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version Condition=" '$(PackageVersion)' == '' ">4.0.0-local</Version>
<Version Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</Version>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">4.0.0-local</PackageVersion>
<PackageVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</PackageVersion>
<Configurations>Debug;Release;Documentation;Debug - NuGet Packages;</Configurations>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>..\..\..\build\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<PackageId>Microsoft.Bot.Builder.ApplicationInsights.WebApi</PackageId>
<Description>This library integrates the Microsoft Bot Builder SDK with Application Insights WebAPI.</Description>
<Summary>This library provides integration between the Microsoft Bot Builder SDK and Application Insights.</Summary>
</PropertyGroup>
<PropertyGroup>
<Company>Microsoft</Company>
<Authors>microsoft,BotFramework,nugetbotbuilder</Authors>
<Product>Microsoft Bot Builder SDK</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Microsoft/botbuilder-dotnet</PackageProjectUrl>
<PackageIconUrl>http://docs.botframework.com/images/bot_icon.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/Microsoft/BotBuilder/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/Microsoft/botbuilder-dotnet</RepositoryUrl>
<LicenseUrl>https://github.com/Microsoft/BotBuilder-dotnet/blob/master/LICENSE</LicenseUrl>
<RepositoryType />
<PackageTags>bots;ai;botframework;botbuilder</PackageTags>
<NeutralLanguage />
<AssemblyName>Microsoft.Bot.Builder.ApplicationInsights.WebApi</AssemblyName>
<RootNamespace>Microsoft.Bot.Builder.ApplicationInsights.WebApi</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Documentation|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\net461\Microsoft.Bot.Builder.ApplicationInsights.WebApi.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\net461\Microsoft.Bot.Builder.ApplicationInsights.WebApi.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>Microsoft.Bot.Builder.ApplicationInsights.WebApi.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNet.WebApi" Version="5.2.4" />
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(PackageVersion)' == '' " Version="4.0.0-local" />
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(PackageVersion)' != '' " Version="$(PackageVersion)" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Configuration" />
<Reference Include="System.Web" />
<Reference Include="Microsoft.AI.Agent.Intercept, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.4.0\lib\net45\Microsoft.AI.Agent.Intercept.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AI.DependencyCollector, Version=2.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.DependencyCollector.2.8.1\lib\net45\Microsoft.AI.DependencyCollector.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AI.PerfCounterCollector, Version=2.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.PerfCounterCollector.2.8.1\lib\net45\Microsoft.AI.PerfCounterCollector.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AI.ServerTelemetryChannel, Version=2.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.8.1\lib\net45\Microsoft.AI.ServerTelemetryChannel.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AI.Web, Version=2.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.Web.2.8.1\lib\net45\Microsoft.AI.Web.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AI.WindowsServer, Version=2.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.WindowsServer.2.8.1\lib\net45\Microsoft.AI.WindowsServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationInsights, Version=2.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.ApplicationInsights.2.8.1\lib\net46\Microsoft.ApplicationInsights.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.TelemetryCorrelation, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.4\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"/>
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for StyleCop.Analyzers" Description="Code analysis rules for StyleCop.Analyzers.csproj." ToolsVersion="14.0">
<Rules AnalyzerId="AsyncUsageAnalyzers" RuleNamespace="AsyncUsageAnalyzers">
<Rule Id="UseConfigureAwait" Action="Warning" />
<Rule Id="AvoidAsyncVoid" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
<Rule Id="IDE0003" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1101" Action="None" />
<!-- local calls prefixed with this -->
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1305" Action="Warning" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1412" Action="Warning" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1609" Action="Warning" />
<Rule Id="SA1633" Action="None" />
</Rules>
</RuleSet>

Просмотреть файл

@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.IO;
using System.Text;
using System.Web;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Microsoft.Bot.Builder.ApplicationInsights.WebApi
{
/// <summary>
/// Initializer that sets the user ID based on Bot data.
/// </summary>
public class TelemetryBotIdInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
var httpContext = HttpContext.Current;
var request = httpContext?.Request;
if (request != null && request.HttpMethod == "POST")
{
JObject body = null;
// Retrieve Http Body and pull appropriate ID's.
try
{
using (var reader = new StreamReader(request.InputStream, Encoding.UTF8, true, 1024, true))
{
// Set cache options.
var bodyAsString = reader.ReadToEnd();
body = JObject.Parse(bodyAsString);
}
}
catch (JsonReaderException)
{
// Request not json.
return;
}
finally
{
// rewind for next middleware.
request.InputStream.Position = 0;
}
var userId = (string)body["from"]?["id"];
var channelId = (string)body["channelId"];
var conversationId = (string)body["conversation"]?["id"];
// Set the user id on the Application Insights telemetry item.
telemetry.Context.User.Id = channelId + userId;
// Set the session id on the Application Insights telemetry item.
telemetry.Context.Session.Id = conversationId;
}
}
}
}

Просмотреть файл

@ -117,7 +117,7 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.Core
}
/// <summary>
/// Adds the <see cref="BotFrameworkAdapter"/> as the <see cref="IAdapterIntegration"/> which will be used by the integration layer
/// Adds the <see cref="BotFrameworkAdapter"/> as the <see cref="IAdapterIntegration"/> which will be used by the integration layer
/// for processing bot requests.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
@ -126,7 +126,7 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.Core
/// <remarks>
/// The <see cref="BotFrameworkAdapter"/> will be registered as a <see cref="ServiceLifetime.Singleton">singleton</see>.
///
/// NOTE: Calling any of the <c>AddBot</c> overloads those will attempt to implicitly register this for you if there is no
/// NOTE: Calling any of the <c>AddBot</c> overloads those will attempt to implicitly register this for you if there is no
/// explicit <see cref="IAdapterIntegration"/> already registered in the <paramref name="services"/> collection.
/// </remarks>
/// <seealso cref="overloads:AddBot" />

Просмотреть файл

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.props" Condition="Exists('..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.props')" />
<Import Project="..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.props" Condition="Exists('..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{873BCC1F-ED12-424E-93FA-D76F4BA022C2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Bot.ApplicationInsights.WebApi.Tests</RootNamespace>
<AssemblyName>Microsoft.Bot.ApplicationInsights.WebApi.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug - NuGet Packages|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.CodeCoverage.15.9.0\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.10.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.10.0\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.6\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.Owin, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.Owin.5.2.6\lib\net45\System.Web.Http.Owin.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.WebHost, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.6\lib\net45\System.Web.Http.WebHost.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ServiceResolutionTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.props'))" />
<Error Condition="!Exists('..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.targets'))" />
<Error Condition="!Exists('..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.props'))" />
<Error Condition="!Exists('..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.targets'))" />
<Error Condition="!Exists('..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.targets" Condition="Exists('..\..\..\packages\Microsoft.CodeCoverage.15.9.0\build\netstandard1.0\Microsoft.CodeCoverage.targets')" />
<Import Project="..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.targets" Condition="Exists('..\..\..\packages\Microsoft.NET.Test.Sdk.15.9.0\build\net45\Microsoft.Net.Test.Sdk.targets')" />
<Import Project="..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>

Просмотреть файл

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.Bot.ApplicationInsights.WebApi.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.Bot.ApplicationInsights.WebApi.Tests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("873bcc1f-ed12-424e-93fa-d76f4ba022c2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Linq;
using Moq;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Bot.Builder.ApplicationInsights.Core;
using Microsoft.Bot.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.TestHost;
using System.Net.Http;
using System.IO;
namespace Microsoft.Bot.ApplicationInsights.WebApi.Tests
{
[TestClass]
[TestCategory("ApplicationInsights")]
public class ServiceResolutionTests
{
public ServiceResolutionTests()
{
// Arrange
//_server = new TestServer(new WebHostBuilder()
//.UseStartup<Startup>());
//_client = _server.CreateClient();
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void AppSettings_NoAppSettings()
{
var server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
}
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.3.1" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi" version="5.2.6" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.6" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.6" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.6" targetFramework="net461" />
<package id="Microsoft.CodeCoverage" version="15.9.0" targetFramework="net461" />
<package id="Microsoft.NET.Test.Sdk" version="15.9.0" targetFramework="net461" />
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net461" />
<package id="Moq" version="4.10.0" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
<package id="Owin" version="1.0" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>