Adds unit tests improving presentation api project code coverage

This commit is contained in:
BinaryAlley committed 2026-09-02 10:30:12 -07:00
1 parent 042c5e4729
commit f3578f88d1
8 files changed
+373 -10

No files matched your search

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NSubstitute;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
@@ -85,6 +86,31 @@ public class ExceptionHandlingMiddlewareTests
Arg.Any<Func<object, Exception?, string>>());
}
[Fact]
public async Task InvokeAsync_WhenNextThrowsExceptionAndActivityIsCurrent_ShouldUseTheActivityIdAsTraceId()
{
// Arrange
using (Activity activity = new Activity("TestActivity"))
{
activity.Start();
DefaultHttpContext context = new()
{
Response = { Body = new MemoryStream() }
};
_nextDelegate = _ => throw new InvalidOperationException("sensitive internal details");
// Act
await _sut.InvokeAsync(context);
// Assert
context.Response.Body.Seek(0, SeekOrigin.Begin);
using StreamReader reader = new(context.Response.Body, Encoding.UTF8);
string responseBody = await reader.ReadToEndAsync();
ProblemDetails problemDetails = JsonSerializer.Deserialize<ProblemDetails>(responseBody, _jsonOptions)!;
Assert.Equal(activity.Id, problemDetails.Extensions["traceId"]?.ToString());
}
}
[Fact]
public async Task InvokeAsync_WhenNextThrowsOperationCanceledException_ShouldRethrow()
{