< Summary

Information
Class: ClutterStock.Domain.Features.Locations.DeleteLocation.DeleteLocationCommandHandler
Assembly: Domain
File(s): /home/runner/work/ClutterStock/ClutterStock/backend/src/Domain/Features/Locations/DeleteLocation/DeleteLocationCommandHandler.cs
Tag: 58_25416222083
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 25
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
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%22100%

File(s)

/home/runner/work/ClutterStock/ClutterStock/backend/src/Domain/Features/Locations/DeleteLocation/DeleteLocationCommandHandler.cs

#LineLine coverage
 1using ClutterStock.Domain.Abstractions;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace ClutterStock.Domain.Features.Locations.DeleteLocation;
 5
 6public interface IDeleteLocationCommandHandler : ICommandHandler
 7{
 8    Task<bool> HandleAsync(Command command, CancellationToken cancellationToken = default);
 9
 10    record Command(int Id);
 11}
 12
 213public class DeleteLocationCommandHandler(IAppDbContext context) : IDeleteLocationCommandHandler
 14{
 15    public async Task<bool> HandleAsync(IDeleteLocationCommandHandler.Command command, CancellationToken cancellationTok
 16    {
 217        var location = await context.Locations.FirstOrDefaultAsync(l => l.Id == command.Id, cancellationToken);
 218        if (location is null)
 119            return false;
 20
 121        context.Locations.Remove(location);
 122        await context.SaveChangesAsync(cancellationToken);
 123        return true;
 224    }
 25}