< Summary

Information
Class: ClutterStock.Domain.Features.Locations.AddLocation.AddLocationCommandHandler
Assembly: Domain
File(s): /home/runner/work/ClutterStock/ClutterStock/backend/src/Domain/Features/Locations/AddLocation/AddLocationCommandHandler.cs
Tag: 58_25416222083
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 29
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync()100%11100%

File(s)

/home/runner/work/ClutterStock/ClutterStock/backend/src/Domain/Features/Locations/AddLocation/AddLocationCommandHandler.cs

#LineLine coverage
 1using ClutterStock.Domain.Abstractions;
 2using ClutterStock.Entities;
 3
 4namespace ClutterStock.Domain.Features.Locations.AddLocation;
 5
 6public interface IAddLocationCommandHandler : ICommandHandler
 7{
 8    Task<Location> HandleAsync(Command command, CancellationToken cancellationToken = default);
 9
 10    record Command(string Name, string? Description);
 11}
 12
 613public class AddLocationCommandHandler(IAppDbContext context) : IAddLocationCommandHandler
 14{
 15    public async Task<Location> HandleAsync(IAddLocationCommandHandler.Command command, CancellationToken cancellationTo
 16    {
 417        var now = DateTime.UtcNow;
 418        var location = new Location
 419        {
 420            Name = command.Name,
 421            Description = command.Description,
 422            CreatedAtUtc = now
 423        };
 24
 425        context.Locations.Add(location);
 426        await context.SaveChangesAsync(cancellationToken);
 427        return location;
 428    }
 29}