public void InitializeThrowIfHttpContextAccessorIsNull()
 {
     Assert.Throws<ArgumentNullException>(() => 
     {
         var initializer = new OperationNameTelemetryInitializer(null, new DiagnosticListener(TestListenerName));
     });
 }
        public void InitializeDoesNotThrowIfHttpContextIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = null };

            var initializer = new OperationNameTelemetryInitializer(ac);

            initializer.Initialize(new RequestTelemetry());
        }
        public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };

            var initializer = new OperationNameTelemetryInitializer(ac, new Notifier(new ProxyNotifierMethodAdapter()));

            initializer.Initialize(new RequestTelemetry());
        }
        public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };

            var initializer = new OperationNameTelemetryInitializer(ac, new DiagnosticListener(TestListenerName));

            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 InitializeSetsRequestNameToMethodAndPath()
        {
            var telemetry = new RequestTelemetry();
            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(telemetry, null);

            var initializer = new OperationNameTelemetryInitializer(contextAccessor, new Notifier(new ProxyNotifierMethodAdapter()));

            initializer.Initialize(telemetry);

            Assert.Equal("GET /Test", telemetry.Name);
        }
        public void InitializeDoesNotOverrideOperationNameProvidedInline()
        {
            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null);

            var initializer = new OperationNameTelemetryInitializer(contextAccessor, new Notifier(new ProxyNotifierMethodAdapter()));

            var telemetry = new EventTelemetry();
            telemetry.Context.Operation.Name = "Name";
            initializer.Initialize(telemetry);

            Assert.Equal("Name", telemetry.Context.Operation.Name);
        }
        public void InitializeDoesNotOverrideOperationNameProvidedInline()
        {
            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null);

            var initializer = new OperationNameTelemetryInitializer(contextAccessor, new DiagnosticListener(TestListenerName));

            var telemetry = new EventTelemetry();
            telemetry.Context.Operation.Name = "Name";
            initializer.Initialize(telemetry);

            Assert.Equal("Name", 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 initializer = new OperationNameTelemetryInitializer(contextAccessor);

            var telemetry = new EventTelemetry();
            initializer.Initialize(telemetry);

            Assert.Equal("GET account/login", 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 notifier = new Notifier(new ProxyNotifierMethodAdapter());
            var initializer = new OperationNameTelemetryInitializer(contextAccessor, notifier);
            notifier.Notify(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);
        }
        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 InitializeSetsRequestNameToMethodAndPathForPostRequest()
        {
            var telemetry = new RequestTelemetry();

            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(telemetry);
            contextAccessor.HttpContext.Request.Method = "POST";

            var initializer = new OperationNameTelemetryInitializer(contextAccessor);

            initializer.Initialize(telemetry);

            Assert.Equal("POST /Test", telemetry.Name);
        }
 public void InitializeThrowIfHttpContextAccessorIsNull()
 {
     Assert.Throws<ArgumentNullException>(() =>
     {
         var initializer = new OperationNameTelemetryInitializer(null, new Notifier(new ProxyNotifierMethodAdapter()));
     });
 }
        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 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);
        }
        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);
        }
 public void InitializeThrowIfHttpContextAccessorIsNull()
 {
     Assert.Throws<ArgumentNullException>(() => { var initializer = new OperationNameTelemetryInitializer(null); });
 }
        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 InitializeSetsTelemetryOperationNameToControllerFromActionContext()
        {
            var actionContext = new ActionContext();
            actionContext.RouteData = new RouteData();
            actionContext.RouteData.Values.Add("controller", "home");

            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), actionContext);

            var notifier = new Notifier(new ProxyNotifierMethodAdapter());
            var initializer = new OperationNameTelemetryInitializer(contextAccessor, notifier);
            notifier.Notify(OperationNameTelemetryInitializer.BeforeActionNotificationName,
                new { httpContext = contextAccessor.HttpContext, routeData = actionContext.RouteData });

            var telemetry = new EventTelemetry();
            initializer.Initialize(telemetry);

            Assert.Equal("GET home", telemetry.Context.Operation.Name);
        }