• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / MediatR.CommandQuery / 8953352548

04 May 2024 09:23PM UTC coverage: 57.083% (-0.3%) from 57.379%
8953352548

push

github

pwelter34
wrap exceptions

343 of 702 branches covered (48.86%)

Branch coverage included in aggregate %.

4 of 18 new or added lines in 5 files covered. (22.22%)

5 existing lines in 4 files now uncovered.

1011 of 1670 relevant lines covered (60.54%)

18.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.0
/src/MediatR.CommandQuery/Behaviors/PipelineBehaviorBase.cs
1
using System.Diagnostics;
2

3
using Microsoft.Extensions.Logging;
4

5
namespace MediatR.CommandQuery.Behaviors;
6

7
public abstract partial class PipelineBehaviorBase<TRequest, TResponse>
8
    : IPipelineBehavior<TRequest, TResponse>
9
    where TRequest : class, IRequest<TResponse>
10
{
11
    private readonly string _name;
12

13
    protected PipelineBehaviorBase(ILoggerFactory loggerFactory)
224✔
14
    {
15
        if (loggerFactory is null)
224!
16
            throw new ArgumentNullException(nameof(loggerFactory));
×
17

18
        var type = GetType();
224✔
19

20
        Logger = loggerFactory.CreateLogger(type);
224✔
21
        _name = type.Name;
224✔
22
    }
224✔
23

24
    protected ILogger Logger { get; }
420✔
25

26

27
    public virtual async Task<TResponse> Handle(
28
        TRequest request,
29
        RequestHandlerDelegate<TResponse> next,
30
        CancellationToken cancellationToken)
31
    {
32
        if (request is null)
212!
33
            throw new ArgumentNullException(nameof(request));
×
34

35
        if (next is null)
212!
36
            throw new ArgumentNullException(nameof(next));
×
37

38
        try
39
        {
40
            LogStart(Logger, _name, request);
212✔
41
            var watch = Stopwatch.StartNew();
212✔
42

43
            var response = await Process(request, next, cancellationToken).ConfigureAwait(false);
212✔
44

45
            watch.Stop();
204✔
46
            LogFinish(Logger, _name, request, watch.ElapsedMilliseconds);
204✔
47

48
            return response;
204✔
49
        }
50
        catch (DomainException)
8✔
51
        {
52
            throw;
8✔
53
        }
UNCOV
54
        catch (Exception ex)
×
55
        {
UNCOV
56
            LogError(Logger, _name, request, ex.Message, ex);
×
NEW
57
            throw new DomainException(ex.Message, ex);
×
58
        }
59
    }
204✔
60

61
    protected abstract Task<TResponse> Process(
62
        TRequest request,
63
        RequestHandlerDelegate<TResponse> next,
64
        CancellationToken cancellationToken);
65

66

67
    [LoggerMessage(1, LogLevel.Trace, "Processing behavior '{Behavior}' for request '{Request}' ...")]
68
    static partial void LogStart(ILogger logger, string behavior, IRequest<TResponse> request);
69

70
    [LoggerMessage(2, LogLevel.Trace, "Processed behavior '{Behavior}' for request '{Request}': {Elapsed} ms")]
71
    static partial void LogFinish(ILogger logger, string behavior, IRequest<TResponse> request, long elapsed);
72

73
    [LoggerMessage(3, LogLevel.Error, "Error processing behavior '{Behavior}' for request '{Request}': {ErrorMessage}")]
74
    static partial void LogError(ILogger logger, string behavior, IRequest<TResponse> request, string errorMessage, Exception? exception);
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc