• 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/EntityUpdateCommandHandler.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 EntityUpdateCommandHandler<TContext, TEntity, TKey, TUpdateModel, TReadModel>
12
    : EntityDataContextHandlerBase<TContext, TEntity, TKey, TReadModel, EntityUpdateCommand<TKey, TUpdateModel, TReadModel>, TReadModel>
13
    where TContext : DbContext
14
    where TEntity : class, IHaveIdentifier<TKey>, new()
15
{
16
    public EntityUpdateCommandHandler(ILoggerFactory loggerFactory, TContext dataContext, IMapper mapper)
17
        : base(loggerFactory, dataContext, mapper)
6✔
18
    {
19

20
    }
6✔
21

22
    protected override async Task<TReadModel> Process(EntityUpdateCommand<TKey, TUpdateModel, TReadModel> request, CancellationToken cancellationToken)
23
    {
24
        ArgumentNullException.ThrowIfNull(request);
6✔
25

26
        var dbSet = DataContext
6✔
27
            .Set<TEntity>();
6✔
28

29
        var keyValue = new object[] { request.Id };
6✔
30

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

36
        if (entity == null)
6!
UNCOV
37
            return default!;
×
38

39
        // copy updates from model to entity
40
        Mapper.Map(request.Model, entity);
6✔
41

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

49
        // save updates
50
        await DataContext
6✔
51
            .SaveChangesAsync(cancellationToken)
6✔
52
            .ConfigureAwait(false);
6✔
53

54
        // return read model
55
        var readModel = await Read(entity.Id, cancellationToken)
6✔
56
            .ConfigureAwait(false);
6✔
57

58
        return readModel;
6✔
59
    }
6✔
60
}
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