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

loresoft / MediatR.CommandQuery / 11418431610

19 Oct 2024 02:43PM UTC coverage: 58.337% (+0.9%) from 57.424%
11418431610

push

github

pwelter34
add HybridCache, misc refactors

331 of 675 branches covered (49.04%)

Branch coverage included in aggregate %.

28 of 176 new or added lines in 24 files covered. (15.91%)

156 existing lines in 33 files now uncovered.

1163 of 1886 relevant lines covered (61.66%)

19.49 hits per line

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

92.31
/src/MediatR.CommandQuery.EntityFrameworkCore/Handlers/EntityPatchCommandHandler.cs
1
using AutoMapper;
2

3
using MediatR.CommandQuery.Commands;
4
using MediatR.CommandQuery.Definitions;
5

6
using Microsoft.EntityFrameworkCore;
7
using Microsoft.Extensions.Logging;
8

9
namespace MediatR.CommandQuery.EntityFrameworkCore.Handlers;
10

11
public class EntityPatchCommandHandler<TContext, TEntity, TKey, TReadModel>
12
    : EntityDataContextHandlerBase<TContext, TEntity, TKey, TReadModel, EntityPatchCommand<TKey, TReadModel>, TReadModel>
13
    where TContext : DbContext
14
    where TEntity : class, IHaveIdentifier<TKey>, new()
15
{
16
    public EntityPatchCommandHandler(ILoggerFactory loggerFactory, TContext dataContext, IMapper mapper)
17
        : base(loggerFactory, dataContext, mapper)
4✔
18
    {
19
    }
4✔
20

21
    protected override async Task<TReadModel> Process(EntityPatchCommand<TKey, TReadModel> request, CancellationToken cancellationToken)
22
    {
23
        ArgumentNullException.ThrowIfNull(request);
4✔
24

25
        var dbSet = DataContext
4✔
26
            .Set<TEntity>();
4✔
27

28
        var keyValue = new object[] { request.Id };
4✔
29

30
        // find entity to update by message id, not model id
31
        var entity = await dbSet
4✔
32
            .FindAsync(keyValue, cancellationToken)
4✔
33
            .ConfigureAwait(false);
4✔
34

35
        if (entity == null)
4!
UNCOV
36
            return default!;
×
37

38
        // apply json patch to entity
39
        var jsonPatch = request.Patch;
4✔
40
        jsonPatch.ApplyTo(entity);
4✔
41

42
        // apply update metadata
43
        if (entity is ITrackUpdated updateEntity)
4✔
44
        {
45
            updateEntity.Updated = request.Activated;
4✔
46
            updateEntity.UpdatedBy = request.ActivatedBy;
4✔
47
        }
48

49
        await DataContext
4✔
50
            .SaveChangesAsync(cancellationToken)
4✔
51
            .ConfigureAwait(false);
4✔
52

53
        // return read model
54
        var model = await Read(entity.Id, cancellationToken).ConfigureAwait(false);
4✔
55

56
        return model;
4✔
57
    }
4✔
58
}
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