• 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

74.07
/src/MediatR.CommandQuery/Behaviors/TenantDefaultCommandBehavior.cs
1
using MediatR.CommandQuery.Commands;
2
using MediatR.CommandQuery.Definitions;
3

4
using Microsoft.Extensions.Logging;
5

6
namespace MediatR.CommandQuery.Behaviors;
7

8
public class TenantDefaultCommandBehavior<TKey, TEntityModel, TResponse>
9
    : PipelineBehaviorBase<EntityModelCommand<TEntityModel, TResponse>, TResponse>
10
    where TEntityModel : class
11
{
12
    private readonly ITenantResolver<TKey> _tenantResolver;
13

14

15
    public TenantDefaultCommandBehavior(ILoggerFactory loggerFactory, ITenantResolver<TKey> tenantResolver) : base(loggerFactory)
24✔
16
    {
17
        _tenantResolver = tenantResolver ?? throw new ArgumentNullException(nameof(tenantResolver));
24!
18
    }
24✔
19

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

28
        if (next is null)
24!
29
            throw new ArgumentNullException(nameof(next));
×
30

31
        await SetTenantId(request).ConfigureAwait(false);
24✔
32

33
        // continue pipeline
34
        return await next().ConfigureAwait(false);
24✔
35
    }
20✔
36

37
    private async Task SetTenantId(EntityModelCommand<TEntityModel, TResponse> request)
38
    {
39
        if (request.Model is not IHaveTenant<TKey> tenantModel)
24!
40
            return;
×
41

42
        if (!Equals(tenantModel.TenantId, default(TKey)))
24✔
43
            return;
20✔
44

45
        var tenantId = await _tenantResolver.GetTenantId(request.Principal);
4✔
46
        tenantModel.TenantId = tenantId!;
4✔
47
    }
24✔
48
}
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