• 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

90.91
/src/MediatR.CommandQuery.MongoDB/Handlers/EntityCreateCommandHandler.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 EntityCreateCommandHandler<TRepository, TEntity, TKey, TCreateModel, TReadModel>
13
    : RepositoryHandlerBase<TRepository, TEntity, TKey, EntityCreateCommand<TCreateModel, TReadModel>, TReadModel>
14
    where TRepository : IMongoRepository<TEntity, TKey>
15
    where TEntity : class, IHaveIdentifier<TKey>, new()
16
{
17
    public EntityCreateCommandHandler(ILoggerFactory loggerFactory, TRepository repository, IMapper mapper)
18
        : base(loggerFactory, repository, mapper)
9✔
19
    {
20
    }
9✔
21

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

27
        // create new entity from model
28
        var entity = Mapper.Map<TEntity>(request.Model);
9✔
29

30
        // apply create metadata
31
        if (entity is ITrackCreated createdModel)
9✔
32
        {
33
            createdModel.Created = request.Activated;
9✔
34
            createdModel.CreatedBy = request.ActivatedBy;
9✔
35
        }
36

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

44
        var result = await Repository
9✔
45
            .InsertAsync(entity, cancellationToken)
9✔
46
            .ConfigureAwait(false);
9✔
47

48
        // convert to read model
49
        return Mapper.Map<TReadModel>(result);
9✔
50
    }
9✔
51
}
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