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

loresoft / MediatR.CommandQuery / 8911801772

01 May 2024 04:09PM UTC coverage: 57.379% (-1.8%) from 59.163%
8911801772

push

github

pwelter34
tweak build

342 of 700 branches covered (48.86%)

Branch coverage included in aggregate %.

1011 of 1658 relevant lines covered (60.98%)

18.48 hits per line

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

83.33
/src/MediatR.CommandQuery/Behaviors/EntityChangeNotificationBehavior.cs
1
using MediatR.CommandQuery.Commands;
2
using MediatR.CommandQuery.Notifications;
3

4
using Microsoft.Extensions.Logging;
5

6
namespace MediatR.CommandQuery.Behaviors;
7

8
public class EntityChangeNotificationBehavior<TKey, TEntityModel, TResponse>
9
    : PipelineBehaviorBase<PrincipalCommandBase<TResponse>, TResponse>
10
    where TEntityModel : class
11
{
12
    private readonly IMediator _mediator;
13

14
    public EntityChangeNotificationBehavior(ILoggerFactory loggerFactory, IMediator mediator) : base(loggerFactory)
56✔
15
    {
16
        _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
56!
17
    }
56✔
18

19
    protected override async Task<TResponse> Process(
20
        PrincipalCommandBase<TResponse> request,
21
        RequestHandlerDelegate<TResponse> next,
22
        CancellationToken cancellationToken)
23
    {
24
        if (request is null)
52!
25
            throw new ArgumentNullException(nameof(request));
×
26

27
        if (next is null)
52!
28
            throw new ArgumentNullException(nameof(next));
×
29

30
        var response = await next().ConfigureAwait(false);
52✔
31

32
        await SendNotification(request, response, cancellationToken);
52✔
33

34
        return response;
52✔
35
    }
52✔
36

37
    private async Task SendNotification(
38
        PrincipalCommandBase<TResponse> request,
39
        TResponse response,
40
        CancellationToken cancellationToken)
41
    {
42
        var operation = request switch
52✔
43
        {
52✔
44
            EntityCreateCommand<TEntityModel, TResponse> _ => EntityChangeOperation.Created,
12✔
45
            EntityDeleteCommand<TKey, TResponse> _ => EntityChangeOperation.Deleted,
8✔
46
            _ => EntityChangeOperation.Updated
32✔
47
        };
52✔
48

49
        var notification = new EntityChangeNotification<TResponse>(response, operation);
52✔
50
        await _mediator.Publish(notification, cancellationToken);
52✔
51
    }
52✔
52
}
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

© 2025 Coveralls, Inc