using Heimdall.Application.Behaviors; using Heimdall.Application.Common; using MediatR; using Microsoft.Extensions.Logging; using NSubstitute; namespace Heimdall.Application.Tests.Behaviors; public class LoggingBehaviorTests { // Must be public for NSubstitute to proxy with strong-named assembly constraints public sealed class TestRequest : IRequest; [Fact] public async Task Successful_request_should_log() { var logger = Substitute.For>>(); var behavior = new LoggingBehavior(logger); var next = Substitute.For>(); next().Returns(ServiceResult.Success()); var result = await behavior.Handle(new TestRequest(), next, CancellationToken.None); result.IsSuccess.ShouldBeTrue(); } [Fact] public async Task Failed_request_should_rethrow() { var logger = Substitute.For>>(); var behavior = new LoggingBehavior(logger); var next = Substitute.For>(); next().Returns(Task.FromException(new InvalidOperationException("Test error"))); var ex = await Should.ThrowAsync(() => behavior.Handle(new TestRequest(), next, CancellationToken.None)); ex.Message.ShouldBe("Test error"); } }