public void InitializeThrowIfHttpContextAccessorIsNull() { Assert.ThrowsAny <ArgumentNullException>(() => { var initializer = new OperationNameTelemetryInitializer(null); }); }
public void InitializeThrowIfHttpContextAccessorIsNull() { Assert.ThrowsAny <ArgumentNullException>(() => { var initializer = new OperationNameTelemetryInitializer(null, new DiagnosticListener(TestListenerName)); }); }
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 telemetryListener = new DiagnosticListener(TestListenerName); var initializer = new OperationNameTelemetryInitializer(contextAccessor, telemetryListener); telemetryListener.Write(OperationNameTelemetryInitializer.BeforeActionNotificationName, new { httpContext = contextAccessor.HttpContext, routeData = actionContext.RouteData }); var telemetry = new EventTelemetry(); initializer.Initialize(telemetry); Assert.Equal("GET account/login [parameterA/parameterN/parameterZ]", telemetry.Context.Operation.Name); }
public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable() { var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() }; var initializer = new OperationNameTelemetryInitializer(ac); initializer.Initialize(new RequestTelemetry()); }
public void InitializeSetsRequestNameToMethodAndPath() { var telemetry = new RequestTelemetry(); var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(telemetry, null); var initializer = new OperationNameTelemetryInitializer(contextAccessor, new DiagnosticListener(TestListenerName)); initializer.Initialize(telemetry); Assert.Equal("GET /Test", telemetry.Name); }
public void InitializeDoesNotThrowIfHttpContextIsUnavailable() { var ac = new HttpContextAccessor() { HttpContext = null }; var initializer = new OperationNameTelemetryInitializer(ac, new DiagnosticListener(TestListenerName)); initializer.Initialize(new RequestTelemetry()); }
public void InitializeSetsTelemetryOperationNameToMethodAndPath() { 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); }
public void InitializeDoesNotOverrideOperationNameProvidedInline() { var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null); var initializer = new OperationNameTelemetryInitializer(contextAccessor); var telemetry = new EventTelemetry(); telemetry.Context.Operation.Name = "Name"; initializer.Initialize(telemetry); Assert.Equal("Name", telemetry.Context.Operation.Name); }
public void InitializeSetsRequestContextOperationNameToRequestName() { var telemetry = new RequestTelemetry(); telemetry.Name = "POST /Test"; var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(telemetry); var initializer = new OperationNameTelemetryInitializer(contextAccessor); initializer.Initialize(telemetry); Assert.Equal("POST /Test", telemetry.Context.Operation.Name); }
public void RequestNameEqualsOperationName() { var context = new MockOperationContext(); context.EndpointUri = new Uri("net.tcp://localhost/Service1.svc"); context.OperationName = "GetData"; var initializer = new OperationNameTelemetryInitializer(); var telemetry = new RequestTelemetry(); initializer.Initialize(telemetry, context); String name = telemetry.Context.Operation.Name; Assert.AreEqual(name, telemetry.Name); }
public void OperationNameIsCopiedFromRequestIfPresent() { const string Name = "MyOperationName"; var context = new MockOperationContext(); context.EndpointUri = new Uri("net.tcp://localhost/Service1.svc"); context.OperationName = "GetData"; context.Request.Context.Operation.Name = Name; var initializer = new OperationNameTelemetryInitializer(); var telemetry = new EventTelemetry(); initializer.Initialize(telemetry, context); Assert.AreEqual(Name, telemetry.Context.Operation.Name); }
public void HttpEndpointDoesNotHaveMethodInName() { var context = new MockOperationContext(); context.EndpointUri = new Uri("http://localhost/Service1.svc"); context.OperationName = "GetData"; HttpRequestMessageProperty http = new HttpRequestMessageProperty(); http.Method = "POST"; context.IncomingProperties.Add(HttpRequestMessageProperty.Name, http); var initializer = new OperationNameTelemetryInitializer(); var telemetry = new RequestTelemetry(); initializer.Initialize(telemetry, context); String name = telemetry.Context.Operation.Name; Assert.AreEqual(name, "IFakeService.GetData"); }
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 telemetryListener = new DiagnosticListener(TestListenerName); var initializer = new OperationNameTelemetryInitializer(contextAccessor, telemetryListener); telemetryListener.Write(OperationNameTelemetryInitializer.BeforeActionNotificationName, new { httpContext = contextAccessor.HttpContext, routeData = actionContext.RouteData }); var telemetry = new EventTelemetry(); initializer.Initialize(telemetry); Assert.Equal("GET home", telemetry.Context.Operation.Name); }
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 telemetryListener = new DiagnosticListener(TestListenerName); var initializer = new OperationNameTelemetryInitializer(contextAccessor, telemetryListener); telemetryListener.Write(OperationNameTelemetryInitializer.BeforeActionNotificationName, new { httpContext = contextAccessor.HttpContext, routeData = actionContext.RouteData }); var telemetry = new EventTelemetry(); initializer.Initialize(telemetry); Assert.Equal("GET account/login", telemetry.Context.Operation.Name); }