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

loresoft / MediatR.CommandQuery / 8911801772

01 May 2024 04:09PM CUT 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

84.0
/src/MediatR.CommandQuery.MongoDB/Handlers/EntityUpdateCommandHandler.cs
1
using AutoMapper;
2

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

6
using Microsoft.Extensions.Logging;
7

8
using MongoDB.Abstracts;
9

10
namespace MediatR.CommandQuery.MongoDB.Handlers;
11

12
public class EntityUpdateCommandHandler<TRepository, TEntity, TKey, TUpdateModel, TReadModel>
13
    : RepositoryHandlerBase<TRepository, TEntity, TKey, EntityUpdateCommand<TKey, TUpdateModel, TReadModel>, TReadModel>
14
    where TRepository : IMongoRepository<TEntity, TKey>
15
    where TEntity : class, IHaveIdentifier<TKey>, new()
16
{
17
    public EntityUpdateCommandHandler(ILoggerFactory loggerFactory, TRepository repository, IMapper mapper)
18
        : base(loggerFactory, repository, mapper)
6✔
19
    {
20
    }
6✔
21

22
    protected override async Task<TReadModel> Process(EntityUpdateCommand<TKey, TUpdateModel, TReadModel> request, CancellationToken cancellationToken)
23
    {
24
        if (request is null)
6!
25
            throw new ArgumentNullException(nameof(request));
×
26

27
        var entity = await Repository
6✔
28
            .FindAsync(request.Id, cancellationToken)
6✔
29
            .ConfigureAwait(false);
6✔
30

31
        if (entity == null)
6!
32
            return default!;
×
33

34
        // copy updates from model to entity
35
        Mapper.Map(request.Model, entity);
6✔
36

37
        // apply update metadata
38
        if (entity is ITrackUpdated updateEntity)
6✔
39
        {
40
            updateEntity.Updated = request.Activated;
6✔
41
            updateEntity.UpdatedBy = request.ActivatedBy;
6✔
42
        }
43

44
        // save updates
45
        var savedEntity = await Repository
6✔
46
            .UpdateAsync(entity, cancellationToken)
6✔
47
            .ConfigureAwait(false);
6✔
48

49
        // return read model
50
        var model = Mapper.Map<TReadModel>(savedEntity);
6✔
51
        return model;
6✔
52
    }
6✔
53
}
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