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

loresoft / MediatR.CommandQuery / 8410320720

24 Mar 2024 03:15PM CUT coverage: 58.562%. Remained the same
8410320720

push

github

pwelter34
Update EntityQueryEndpointBase.cs

230 of 438 branches covered (52.51%)

Branch coverage included in aggregate %.

560 of 911 relevant lines covered (61.47%)

19.53 hits per line

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

0.0
/src/MediatR.CommandQuery.Cosmos/Handlers/EntityIdentifiersQueryHandler.cs
1
using System.Collections.Generic;
2
using System.Linq;
3
using System.Threading;
4
using System.Threading.Tasks;
5

6
using AutoMapper;
7

8
using Cosmos.Abstracts;
9
using Cosmos.Abstracts.Extensions;
10

11
using MediatR.CommandQuery.Definitions;
12
using MediatR.CommandQuery.Queries;
13

14
using Microsoft.Azure.Cosmos;
15
using Microsoft.Extensions.Logging;
16

17
namespace MediatR.CommandQuery.Cosmos.Handlers;
18

19
public class EntityIdentifiersQueryHandler<TRepository, TEntity, TReadModel>
20
    : RepositoryHandlerBase<TRepository, TEntity, EntityIdentifiersQuery<string, TReadModel>, IReadOnlyCollection<TReadModel>>
21
    where TRepository : ICosmosRepository<TEntity>
22
    where TEntity : class, IHaveIdentifier<string>, new()
23
{
24
    public EntityIdentifiersQueryHandler(ILoggerFactory loggerFactory, TRepository repository, IMapper mapper) : base(loggerFactory, repository, mapper)
×
25
    {
26
    }
×
27

28
    protected override async Task<IReadOnlyCollection<TReadModel>> Process(EntityIdentifiersQuery<string, TReadModel> request, CancellationToken cancellationToken)
29
    {
30
        if (request is null)
31
            throw new System.ArgumentNullException(nameof(request));
32

33
        var keys = new HashSet<string>();
34
        foreach (var requestId in request.Ids)
35
        {
36
            if (CosmosKey.TryDecode(requestId, out var id, out PartitionKey partitionKey))
37
                keys.Add(id);
38
        }
39

40
        var query = await Repository
41
            .GetQueryableAsync()
42
            .ConfigureAwait(false);
43

44
        var results = await query
45
            .Where(p => keys.Contains(p.Id))
46
            .ToListAsync(cancellationToken)
47
            .ConfigureAwait(false);
48

49
        return Mapper.Map<IList<TEntity>, IReadOnlyCollection<TReadModel>>(results);
50
    }
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