Merge
This commit is contained in:
Коммит
241881db3f
|
@ -61,8 +61,6 @@
|
|||
rt.Context.InstrumentationKey = svcs.GetService<TelemetryClient>().Context.InstrumentationKey;
|
||||
return rt;
|
||||
});
|
||||
|
||||
//services.AddScoped<RouteContext>
|
||||
}
|
||||
|
||||
public static HtmlString ApplicationInsightsJavaScriptSnippet(this IHtmlHelper helper, string instrumentationKey)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
namespace Microsoft.ApplicationInsights.AspNet.Tests.Helpers
|
||||
{
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using System;
|
||||
|
||||
public static class HttpContextAccessorHelper
|
||||
{
|
||||
public static HttpContextAccessor CreateHttpContextAccessor(RequestTelemetry requestTelemetry = null, ActionContext actionContext = null)
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var request = new DefaultHttpContext().Request;
|
||||
request.Method = "GET";
|
||||
request.Path = new PathString("/Test");
|
||||
var contextAccessor = new HttpContextAccessor() { HttpContext = request.HttpContext };
|
||||
|
||||
services.AddInstance<IHttpContextAccessor>(contextAccessor);
|
||||
|
||||
if (actionContext != null)
|
||||
{
|
||||
var si = new ScopedInstance<ActionContext>();
|
||||
si.Value = actionContext;
|
||||
services.AddInstance<IScopedInstance<ActionContext>>(si);
|
||||
}
|
||||
|
||||
if (requestTelemetry != null)
|
||||
{
|
||||
services.AddInstance<RequestTelemetry>(requestTelemetry);
|
||||
}
|
||||
|
||||
IServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
contextAccessor.HttpContext.RequestServices = serviceProvider;
|
||||
|
||||
return contextAccessor;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
namespace Microsoft.ApplicationInsights.AspNet.Tests.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TestServiceProvider : IServiceProvider
|
||||
{
|
||||
private IList<object> knownInstances;
|
||||
|
||||
public TestServiceProvider(IList<object> knownInstances = null)
|
||||
{
|
||||
this.knownInstances = knownInstances;
|
||||
}
|
||||
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
if (this.knownInstances != null)
|
||||
{
|
||||
foreach (object instance in this.knownInstances)
|
||||
{
|
||||
var instanceType = instance.GetType();
|
||||
|
||||
if (instanceType == serviceType)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
foreach (var interfaceType in instanceType.GetTypeInfo().ImplementedInterfaces)
|
||||
{
|
||||
if (interfaceType == serviceType)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,12 +41,11 @@
|
|||
[Fact]
|
||||
public void InitializeSetsIPFromStandardHeader()
|
||||
{
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
ac.HttpContext.Request.Headers.Add("X-Forwarded-For", new string[] { "127.0.0.3" });
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers.Add("X-Forwarded-For", new string[] { "127.0.0.3" });
|
||||
|
||||
var initializer = new ClientIpHeaderTelemetryInitializer(ac);
|
||||
var initializer = new ClientIpHeaderTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
@ -56,11 +55,11 @@
|
|||
[Fact]
|
||||
public void InitializeSetsIPFromCustomHeader()
|
||||
{
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
ac.HttpContext.Request.Headers.Add("HEADER", new string[] { "127.0.0.3;127.0.0.4" });
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new ClientIpHeaderTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers.Add("HEADER", new string[] { "127.0.0.3;127.0.0.4" });
|
||||
|
||||
var initializer = new ClientIpHeaderTelemetryInitializer(contextAccessor);
|
||||
initializer.HeaderNames.Add("HEADER");
|
||||
initializer.HeaderValueSeparators = ",;";
|
||||
|
||||
|
@ -74,10 +73,11 @@
|
|||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
requestTelemetry.Context.Location.Ip = "127.0.0.4";
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers.Add("X-Forwarded-For", new string[] { "127.0.0.3" });
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new ClientIpHeaderTelemetryInitializer(ac);
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers.Add("X-Forwarded-For", new string[] { "127.0.0.3" });
|
||||
|
||||
var initializer = new ClientIpHeaderTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
{
|
||||
var telemetry = new EventTelemetry();
|
||||
telemetry.Context.Operation.Id = "123";
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { new RequestTelemetry() });
|
||||
var initializer = new OperationIdTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor();
|
||||
|
||||
var initializer = new OperationIdTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
|
@ -57,9 +57,9 @@
|
|||
{
|
||||
var telemetry = new EventTelemetry();
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new OperationIdTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
|
||||
var initializer = new OperationIdTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
using Microsoft.ApplicationInsights.AspNet.Tests.Helpers;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
public class OperationNameTelemetryInitializerTests
|
||||
|
@ -41,12 +42,12 @@
|
|||
[Fact]
|
||||
public void InitializeDoesNotOverrideOperationNameProvidedInline()
|
||||
{
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
telemetry.Context.Operation.Name = "Name";
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { new RequestTelemetry() });
|
||||
var initializer = new OperationNameTelemetryInitializer(ac);
|
||||
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("Name", telemetry.Context.Operation.Name);
|
||||
|
@ -55,14 +56,11 @@
|
|||
[Fact]
|
||||
public void InitializeSetsTelemetryOperationNameToMethodAndPath()
|
||||
{
|
||||
var telemetry = new EventTelemetry();
|
||||
var request = new DefaultHttpContext().Request;
|
||||
request.Method = "GET";
|
||||
request.Path = new Microsoft.AspNet.Http.PathString("/Test");
|
||||
var ac = new HttpContextAccessor() { HttpContext = request.HttpContext };
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { new RequestTelemetry() });
|
||||
var initializer = new OperationNameTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET /Test", telemetry.Context.Operation.Name);
|
||||
|
@ -72,28 +70,118 @@
|
|||
public void InitializeSetsRequestNameToMethodAndPath()
|
||||
{
|
||||
var telemetry = new RequestTelemetry();
|
||||
var request = new DefaultHttpContext().Request;
|
||||
request.Method = "GET";
|
||||
request.Path = new Microsoft.AspNet.Http.PathString("/Test");
|
||||
var ac = new HttpContextAccessor() { HttpContext = request.HttpContext };
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { new RequestTelemetry() });
|
||||
var initializer = new OperationNameTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(telemetry, null);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET /Test", telemetry.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeSetsTelemetryOperationNameToControllerFromActionContext()
|
||||
{
|
||||
var actionContext = new ActionContext();
|
||||
actionContext.RouteData = new RouteData();
|
||||
actionContext.RouteData.Values.Add("controller", "home");
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), actionContext);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET home", telemetry.Context.Operation.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeSetsTelemetryOperationNameToControllerAndActionFromActionContext()
|
||||
{
|
||||
var actionContext = new ActionContext();
|
||||
actionContext.RouteData = new RouteData();
|
||||
actionContext.RouteData.Values.Add("controller", "account");
|
||||
actionContext.RouteData.Values.Add("action", "login");
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), actionContext);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET account/login", telemetry.Context.Operation.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeSetsTelemetryOperationNameToControllerAndActionAndParameterFromActionContext()
|
||||
{
|
||||
var actionContext = new ActionContext();
|
||||
actionContext.RouteData = new RouteData();
|
||||
actionContext.RouteData.Values.Add("controller", "account");
|
||||
actionContext.RouteData.Values.Add("action", "login");
|
||||
actionContext.RouteData.Values.Add("parameter", "myName");
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), actionContext);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET account/login [parameter]", telemetry.Context.Operation.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeSortsParameters()
|
||||
{
|
||||
var actionContext = new ActionContext();
|
||||
actionContext.RouteData = new RouteData();
|
||||
actionContext.RouteData.Values.Add("controller", "account");
|
||||
actionContext.RouteData.Values.Add("action", "login");
|
||||
actionContext.RouteData.Values.Add("parameterZ", "myName1");
|
||||
actionContext.RouteData.Values.Add("parameterA", "myName2");
|
||||
actionContext.RouteData.Values.Add("parameterN", "myName1");
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), actionContext);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET account/login [parameterA/parameterN/parameterZ]", telemetry.Context.Operation.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeDoesNotIncludeRouteGroupKeyInParametersList()
|
||||
{
|
||||
var actionContext = new ActionContext();
|
||||
actionContext.RouteData = new RouteData();
|
||||
actionContext.RouteData.Values.Add("controller", "account");
|
||||
actionContext.RouteData.Values.Add("action", "login");
|
||||
actionContext.RouteData.Values.Add(AttributeRouting.RouteGroupKey, "RouteGroupKey");
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), actionContext);
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
var telemetry = new EventTelemetry();
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
Assert.Equal("GET account/login", telemetry.Context.Operation.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeSetsRequestNameToMethodAndPathForPostRequest()
|
||||
{
|
||||
var telemetry = new RequestTelemetry();
|
||||
var request = new DefaultHttpContext().Request;
|
||||
request.Method = "POST";
|
||||
request.Path = new Microsoft.AspNet.Http.PathString("/Test");
|
||||
var ac = new HttpContextAccessor() { HttpContext = request.HttpContext };
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { new RequestTelemetry() });
|
||||
var initializer = new OperationNameTelemetryInitializer(ac);
|
||||
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(telemetry);
|
||||
contextAccessor.HttpContext.Request.Method = "POST";
|
||||
|
||||
var initializer = new OperationNameTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(telemetry);
|
||||
|
||||
|
|
|
@ -42,10 +42,9 @@
|
|||
public void InitializeSetsUserAgentFromHeader()
|
||||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers.Add("User-Agent", new[] { "test" });
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new UserAgentTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers.Add("User-Agent", new[] { "test" });
|
||||
var initializer = new UserAgentTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
@ -57,10 +56,9 @@
|
|||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
requestTelemetry.Context.User.UserAgent = "Inline";
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers.Add("User-Agent", new[] { "test" });
|
||||
var serviceProvider = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new UserAgentTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers.Add("User-Agent", new[] { "test" });
|
||||
var initializer = new UserAgentTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.ApplicationInsights.AspNet.TelemetryInitializers;
|
||||
using Microsoft.ApplicationInsights.AspNet.Tests.Helpers;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using Microsoft.ApplicationInsights.AspNet.Tests.Helpers;
|
||||
|
||||
public class WebSessionTelemetryInitializerTests
|
||||
{
|
||||
|
@ -42,10 +41,9 @@
|
|||
public void InitializeSetsSessionFromCookie()
|
||||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers["Cookie"] = "ai_session=test|2015-04-10T17:11:38.378Z|2015-04-10T17:11:39.180Z";
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new WebSessionTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers["Cookie"] = "ai_session=test|2015-04-10T17:11:38.378Z|2015-04-10T17:11:39.180Z";
|
||||
var initializer = new WebSessionTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
@ -57,10 +55,9 @@
|
|||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
requestTelemetry.Context.Session.Id = "Inline";
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers["Cookie"] = "ai_session=test|2015-04-10T17:11:38.378Z|2015-04-10T17:11:39.180Z";
|
||||
var serviceProvider = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new WebSessionTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers["Cookie"] = "ai_session=test|2015-04-10T17:11:38.378Z|2015-04-10T17:11:39.180Z";
|
||||
var initializer = new WebSessionTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
using Microsoft.ApplicationInsights.AspNet.Tests.Helpers;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -43,10 +42,9 @@
|
|||
public void InitializeSetsUserFromCookie()
|
||||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers["Cookie"] = "ai_user=test|2015-04-09T21:51:59.993Z";
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new WebUserTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers["Cookie"] = "ai_user=test|2015-04-09T21:51:59.993Z";
|
||||
var initializer = new WebUserTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
@ -59,10 +57,9 @@
|
|||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
requestTelemetry.Context.User.Id = "Inline";
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers["Cookie"] = "ai_user=test|2015-04-09T21:51:59.993Z";
|
||||
var serviceProvider = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new WebUserTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers["Cookie"] = "ai_user=test|2015-04-09T21:51:59.993Z";
|
||||
var initializer = new WebUserTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
@ -73,10 +70,9 @@
|
|||
public void InitializeDoesNotThrowOnMalformedUserCookie()
|
||||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers["Cookie"] = "ai_user=test";
|
||||
var serviceProvider = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new WebUserTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers["Cookie"] = "ai_user=test";
|
||||
var initializer = new WebUserTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
|
||||
|
@ -87,10 +83,9 @@
|
|||
public void InitializeDoesNotNotThrowOnMalformedAcquisitionDate()
|
||||
{
|
||||
var requestTelemetry = new RequestTelemetry();
|
||||
var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
|
||||
ac.HttpContext.Request.Headers["Cookie"] = "ai_user=test|malformeddate";
|
||||
ac.HttpContext.RequestServices = new TestServiceProvider(new List<object>() { requestTelemetry });
|
||||
var initializer = new WebUserTelemetryInitializer(ac);
|
||||
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(requestTelemetry);
|
||||
contextAccessor.HttpContext.Request.Headers["Cookie"] = "ai_user=test|malformeddate";
|
||||
var initializer = new WebUserTelemetryInitializer(contextAccessor);
|
||||
|
||||
initializer.Initialize(requestTelemetry);
|
||||
Assert.Equal(null, requestTelemetry.Context.User.Id);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>41409009-8c50-4835-8777-cf9706f50ab1</ProjectGuid>
|
||||
<RootNamespace>Aspnet5_EmptyApp_46</RootNamespace>
|
||||
|
@ -15,5 +14,6 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<DevelopmentServerPort>28238</DevelopmentServerPort>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" />
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,14 @@
|
|||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace Aspnet5_EmptyApp_46.Controllers
|
||||
{
|
||||
public class ExceptionController : Controller
|
||||
{
|
||||
public string Throw()
|
||||
{
|
||||
throw new System.Exception("Unhandled Exception from controller.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ using Microsoft.Framework.DependencyInjection;
|
|||
|
||||
namespace Aspnet5_EmptyApp_46
|
||||
{
|
||||
public class Startup2
|
||||
public class Startup
|
||||
{
|
||||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
|
@ -17,14 +17,14 @@ namespace Aspnet5_EmptyApp_46
|
|||
// Add MVC to the request pipeline.
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
//routes.MapRoute(
|
||||
// name: "default",
|
||||
// template: "{controller}/{action}/{id?}",
|
||||
// defaults: new { controller = "Home", action = "Index" });
|
||||
|
||||
routes.MapRoute(
|
||||
name: "Request",
|
||||
template: "{controller}/{action}/{loadTimeInMs}");
|
||||
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller}/{action}/{id?}");
|
||||
//defaults: new { controller = "Home", action = "Index" });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ using Microsoft.Framework.DependencyInjection;
|
|||
|
||||
namespace Aspnet5_EmptyApp_46
|
||||
{
|
||||
public class Startup
|
||||
public class Startup2
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
public Startup2(IHostingEnvironment env)
|
||||
{
|
||||
// Setup configuration sources.
|
||||
Configuration = new Configuration()
|
||||
|
@ -37,14 +37,14 @@ namespace Aspnet5_EmptyApp_46
|
|||
// Add MVC to the request pipeline.
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
//routes.MapRoute(
|
||||
// name: "default",
|
||||
// template: "{controller}/{action}/{id?}",
|
||||
// defaults: new { controller = "Home", action = "Index" });
|
||||
|
||||
routes.MapRoute(
|
||||
name: "Request",
|
||||
template: "{controller}/{action}/{loadTimeInMs}");
|
||||
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller}/{action}/{id?}");
|
||||
//defaults: new { controller = "Home", action = "Index" });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.22609.0
|
||||
VisualStudioVersion = 14.0.22823.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfTest", "PerfTest\PerfTest.csproj", "{12569DBE-2396-46BF-9ED0-B5221F1C30AE}"
|
||||
EndProject
|
||||
|
@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
Local.testsettings = Local.testsettings
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Aspnet5_EmptyApp_46", "Aspnet5_EmptyApp_46\Aspnet5_EmptyApp_46.kproj", "{41409009-8C50-4835-8777-CF9706F50AB1}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Aspnet5_EmptyApp_46", "Aspnet5_EmptyApp_46\Aspnet5_EmptyApp_46.xproj", "{41409009-8C50-4835-8777-CF9706F50AB1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LoadTest Name="DoRequestLoad" Description="" Owner="" storage="c:\projects\github\aspnetv5\test\perftest\perftest\dorequestload.loadtest" Priority="2147483647" Enabled="true" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" WorkItemIds="" TraceLevel="None" CurrentRunConfig="10MinRun" Id="0caba400-f694-47b3-8c7a-523703b3c661" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<LoadTest Name="DoRequestLoad" Description="" Owner="" storage="c:\projects\github\aspnetv5\test\perftest\perftest\loadtests\dorequestload.loadtest" Priority="2147483647" Enabled="true" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" WorkItemIds="" TraceLevel="None" CurrentRunConfig="Run" Id="0caba400-f694-47b3-8c7a-523703b3c661" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<Scenarios>
|
||||
<Scenario Name="BasicRequestTest" DelayBetweenIterations="0" PercentNewUsers="0" IPSwitching="false" TestMixType="PercentageOfTestsStarted" ApplyDistributionToPacingDelay="true" MaxTestIterations="0" DisableDuringWarmup="false" DelayStartTime="0" AllowedAgents="">
|
||||
<ThinkProfile Value="0" Pattern="Off" />
|
||||
<LoadProfile Pattern="Constant" InitialUsers="5" />
|
||||
<TestMix>
|
||||
<TestProfile Name="DoRequest" Path="dorequest.webtest" Id="b06a2618-3c02-4383-8f9e-c896980b8dd4" Percentage="100" Type="Microsoft.VisualStudio.TestTools.WebStress.DeclarativeWebTestElement, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestProfile Name="DoRequest" Path="..\webtests\dorequest.webtest" Id="b06a2618-3c02-4383-8f9e-c896980b8dd4" Percentage="100" Type="Microsoft.VisualStudio.TestTools.WebStress.DeclarativeWebTestElement, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</TestMix>
|
||||
<BrowserMix>
|
||||
<BrowserProfile Percentage="100">
|
||||
|
@ -1029,7 +1029,7 @@
|
|||
</CounterSet>
|
||||
</CounterSets>
|
||||
<RunConfigurations>
|
||||
<RunConfiguration Name="10MinRun" Description="" ResultsStoreType="Database" TimingDetailsStorage="None" SaveTestLogsOnError="true" SaveTestLogsFrequency="0" MaxErrorDetails="200" MaxErrorsPerType="1000" MaxThresholdViolations="1000" MaxRequestUrlsReported="1000" UseTestIterations="false" RunDuration="600" WarmupTime="60" CoolDownTime="0" TestIterations="100" WebTestConnectionModel="ConnectionPerUser" WebTestConnectionPoolSize="50" SampleRate="5" ValidationLevel="High" SqlTracingConnectString="" SqlTracingConnectStringDisplayValue="" SqlTracingDirectory="" SqlTracingEnabled="false" SqlTracingFileCount="2" SqlTracingRolloverEnabled="true" SqlTracingMinimumDuration="500" RunUnitTestsInAppDomain="true" CoreCount="0">
|
||||
<RunConfiguration Name="Run" Description="" ResultsStoreType="Database" TimingDetailsStorage="None" SaveTestLogsOnError="true" SaveTestLogsFrequency="0" MaxErrorDetails="200" MaxErrorsPerType="1000" MaxThresholdViolations="1000" MaxRequestUrlsReported="1000" UseTestIterations="false" RunDuration="600" WarmupTime="60" CoolDownTime="0" TestIterations="100" WebTestConnectionModel="ConnectionPerUser" WebTestConnectionPoolSize="50" SampleRate="5" ValidationLevel="High" SqlTracingConnectString="" SqlTracingConnectStringDisplayValue="" SqlTracingDirectory="" SqlTracingEnabled="false" SqlTracingFileCount="2" SqlTracingRolloverEnabled="true" SqlTracingMinimumDuration="500" RunUnitTestsInAppDomain="true" CoreCount="0">
|
||||
<CounterSetMappings>
|
||||
<CounterSetMapping ComputerName="CN-PERFTESTS">
|
||||
<CounterSetReferences>
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -51,12 +51,18 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="DoRequestLoad.loadtest">
|
||||
<None Include="LoadTests\DoRequestLoad.loadtest">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="DoRequest.webtest">
|
||||
<None Include="WebTests\DoRequest.webtest">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="WebTests\ExceptionThrow.webtest">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="LoadTests\MixRequestAndExceptions.loadtest">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<WebTest Name="DoRequest" Id="b06a2618-3c02-4383-8f9e-c896980b8dd4" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
|
||||
<Items>
|
||||
<Request Method="GET" Guid="069ef073-8fb2-41cc-b3a6-e13489f49a74" Version="1.1" Url="http://cn-perftests/aspnetv5app/request/do/50" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
|
||||
<Request Method="GET" Guid="069ef073-8fb2-41cc-b3a6-e13489f49a74" Version="1.1" Url="http://cn-perftests/aspnetv5app/request/do/10" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
|
||||
<QueryStringParameters>
|
||||
<QueryStringParameter Name="Parameter1" Value="{{dynamicParameter}}" RecordedValue="" CorrelationBinding="" UrlEncode="True" UseToGroupResults="False" />
|
||||
</QueryStringParameters>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<WebTest Name="ExceptionThrow" Id="e0ccc292-9892-4674-8144-ead581272737" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
|
||||
<Items>
|
||||
<Request Method="GET" Guid="359af05c-ca6c-4b66-8a62-742f36227872" Version="1.1" Url="http://cn-perftests/aspnetv5app/exception/throw" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
|
||||
</Items>
|
||||
</WebTest>
|
Загрузка…
Ссылка в новой задаче