Beispiel #1
0
        public async Task RouteAsync_Notifies_ActionSelected()
        {
            // Arrange
            var listener = new TestTelemetryListener();

            var context = CreateRouteContext(telemetryListener: listener);

            context.RouteData.Values.Add("tag", "value");

            var handler = new MvcRouteHandler();

            // Act
            await handler.RouteAsync(context);

            // Assert
            Assert.NotNull(listener.BeforeAction?.ActionDescriptor);
            Assert.NotNull(listener.BeforeAction?.HttpContext);

            var routeValues = listener.BeforeAction?.RouteData?.Values;

            Assert.NotNull(routeValues);

            Assert.Equal(1, routeValues.Count);
            Assert.Contains(routeValues, kvp => kvp.Key == "tag" && string.Equals(kvp.Value, "value"));
        }
Beispiel #2
0
        public async Task RouteAsync_Notifies_ActionInvoked()
        {
            // Arrange
            var listener = new TestTelemetryListener();

            var context = CreateRouteContext(telemetryListener: listener);

            var handler = new MvcRouteHandler();

            // Act
            await handler.RouteAsync(context);

            // Assert
            Assert.NotNull(listener.AfterAction?.ActionDescriptor);
            Assert.NotNull(listener.AfterAction?.HttpContext);
        }
Beispiel #3
0
        public async Task ExceptionTelemetryAvailable()
        {
            TelemetryListener telemetryListener = null;
            var server = TestServer.Create(app =>
            {
                telemetryListener = app.ApplicationServices.GetRequiredService <TelemetryListener>();
                app.Run(context =>
                {
                    throw new Exception("Test exception");
                });
            });
            var listener = new TestTelemetryListener();

            telemetryListener.SubscribeWithAdapter(listener);
            await Assert.ThrowsAsync <Exception>(() => server.CreateClient().GetAsync("/path"));

            Assert.NotNull(listener.BeginRequest?.HttpContext);
            Assert.Null(listener.EndRequest?.HttpContext);
            Assert.NotNull(listener.UnhandledException?.HttpContext);
            Assert.NotNull(listener.UnhandledException?.Exception);
        }
Beispiel #4
0
        public async Task BeginEndTelemetryAvailable()
        {
            TelemetryListener telemetryListener = null;
            var server = TestServer.Create(app =>
            {
                telemetryListener = app.ApplicationServices.GetRequiredService <TelemetryListener>();
                app.Run(context =>
                {
                    return(context.Response.WriteAsync("Hello World"));
                });
            });
            var listener = new TestTelemetryListener();

            telemetryListener.SubscribeWithAdapter(listener);
            var result = await server.CreateClient().GetStringAsync("/path");

            Assert.Equal("Hello World", result);
            Assert.NotNull(listener.BeginRequest?.HttpContext);
            Assert.NotNull(listener.EndRequest?.HttpContext);
            Assert.Null(listener.UnhandledException);
        }
Beispiel #5
0
        public async Task ExceptionTelemetryAvailable()
        {
            TelemetryListener telemetryListener = null;
            var server = TestServer.Create(app =>
            {
                telemetryListener = app.ApplicationServices.GetRequiredService<TelemetryListener>();
                app.Run(context =>
                {
                    throw new Exception("Test exception");
                });
            });
            var listener = new TestTelemetryListener();
            telemetryListener.SubscribeWithAdapter(listener);
            await Assert.ThrowsAsync<Exception>(() => server.CreateClient().GetAsync("/path"));

            Assert.NotNull(listener.BeginRequest?.HttpContext);
            Assert.Null(listener.EndRequest?.HttpContext);
            Assert.NotNull(listener.UnhandledException?.HttpContext);
            Assert.NotNull(listener.UnhandledException?.Exception);
        }
Beispiel #6
0
        public async Task BeginEndTelemetryAvailable()
        {
            TelemetryListener telemetryListener = null;
            var server = TestServer.Create(app =>
            {
                telemetryListener = app.ApplicationServices.GetRequiredService<TelemetryListener>();
                app.Run(context =>
                {
                    return context.Response.WriteAsync("Hello World");
                });
            });
            var listener = new TestTelemetryListener();
            telemetryListener.SubscribeWithAdapter(listener);
            var result = await server.CreateClient().GetStringAsync("/path");

            Assert.Equal("Hello World", result);
            Assert.NotNull(listener.BeginRequest?.HttpContext);
            Assert.NotNull(listener.EndRequest?.HttpContext);
            Assert.Null(listener.UnhandledException);
        }
        public async Task RouteAsync_Notifies_ActionInvoked()
        {
            // Arrange
            var listener = new TestTelemetryListener();

            var context = CreateRouteContext(telemetryListener: listener);

            var handler = new MvcRouteHandler();

            // Act
            await handler.RouteAsync(context);

            // Assert
            Assert.NotNull(listener.AfterAction?.ActionDescriptor);
            Assert.NotNull(listener.AfterAction?.HttpContext);
        }
        public async Task RouteAsync_Notifies_ActionSelected()
        {
            // Arrange
            var listener = new TestTelemetryListener();

            var context = CreateRouteContext(telemetryListener: listener);
            context.RouteData.Values.Add("tag", "value");

            var handler = new MvcRouteHandler();

            // Act
            await handler.RouteAsync(context);

            // Assert
            Assert.NotNull(listener.BeforeAction?.ActionDescriptor);
            Assert.NotNull(listener.BeforeAction?.HttpContext);

            var routeValues = listener.BeforeAction?.RouteData?.Values;
            Assert.NotNull(routeValues);

            Assert.Equal(1, routeValues.Count);
            Assert.Contains(routeValues, kvp => kvp.Key == "tag" && string.Equals(kvp.Value, "value"));
        }