Repository: dotnet/aspnetcore
File: src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerMiddlewareTest.cs (C#)

Code before:

        // Act & Assert
        await middleware.Invoke(httpContext);

        Assert.True(httpContext.Items.ContainsKey("1"));
        Assert.True(httpContext.Items.ContainsKey("2"));
        Assert.True(httpContext.Items.ContainsKey("3"));

        // IExceptionHandlers handling an exception suppress diagnostics by default.
        Assert.Empty(sink.Writes);
    }

    [Theory]
    [InlineData(null)]
    [InlineData(true)]
    [InlineData(false)]
    public async Task IExceptionHandlers_SuppressDiagnostics_TestLogs(bool? suppressDiagnostics)
    {
        // Arrange
        var sink = new TestSink();
        var httpContext = CreateHttpContext();

        var metricsTagsFeature = new TestHttpMetricsTagsFeature();
        httpContext.Features.Set<IHttpMetricsTagsFeature>(metricsTagsFeature);

        Func<ExceptionHandlerSuppressDiagnosticsContext, bool>? suppressDiagnosticsCallback = null;
        if (suppressDiagnostics != null)
        {
            suppressDiagnosticsCallback = c => suppressDiagnostics.Value;
        }

        var optionsAccessor = CreateOptionsAccessor(suppressDiagnosticsCallback: suppressDiagnosticsCallback);

        var exceptionHandlers = new List<IExceptionHandler>
        {
            new TestExceptionHandler(true, "1")
        };

        var middleware = CreateMiddleware(_ => throw new InvalidOperationException(), optionsAccessor, exceptionHandlers, loggerFactory: new TestLoggerFactory(sink, true));

        // Act & Assert
        await middleware.Invoke(httpContext);

        Assert.True(httpContext.Items.ContainsKey("1"));

        if (suppressDiagnostics == null || suppressDiagnostics == true)
        {
            Assert.Empty(sink.Writes);
            Assert.Empty(metricsTagsFeature.Tags);
        }
        else

Review comment (suggestion):
```suggestion
        Func<ExceptionHandlerSuppressDiagnosticsContext, bool> suppressDiagnosticsCallback = null;
```

Code after:

        // Act & Assert
        await middleware.Invoke(httpContext);

        Assert.True(httpContext.Items.ContainsKey("1"));
        Assert.True(httpContext.Items.ContainsKey("2"));
        Assert.True(httpContext.Items.ContainsKey("3"));

        // IExceptionHandlers handling an exception suppress diagnostics by default.
        Assert.Empty(sink.Writes);
    }

    [Theory]
    [InlineData(null)]
    [InlineData(true)]
    [InlineData(false)]
    public async Task IExceptionHandlers_SuppressDiagnostics_TestLogs(bool? suppressDiagnostics)
    {
        // Arrange
        var sink = new TestSink();
        var httpContext = CreateHttpContext();

        var metricsTagsFeature = new TestHttpMetricsTagsFeature();
        httpContext.Features.Set<IHttpMetricsTagsFeature>(metricsTagsFeature);

        Func<ExceptionHandlerSuppressDiagnosticsContext, bool> suppressDiagnosticsCallback = null;
        if (suppressDiagnostics != null)
        {
            suppressDiagnosticsCallback = c => suppressDiagnostics.Value;
        }

        var optionsAccessor = CreateOptionsAccessor(suppressDiagnosticsCallback: suppressDiagnosticsCallback);

        var exceptionHandlers = new List<IExceptionHandler>
        {
            new TestExceptionHandler(true, "1")
        };

        var middleware = CreateMiddleware(_ => throw new InvalidOperationException(), optionsAccessor, exceptionHandlers, loggerFactory: new TestLoggerFactory(sink, true));

        // Act & Assert
        await middleware.Invoke(httpContext);

        Assert.True(httpContext.Items.ContainsKey("1"));

        if (suppressDiagnostics == null || suppressDiagnostics == true)
        {
            Assert.Empty(sink.Writes);
            Assert.Empty(metricsTagsFeature.Tags);
        }
        else