< Summary

Information
Class: FLP.Application.Handlers.Bugs.CreateBugHandler
Assembly: FLP.Application
File(s): /home/runner/work/FLP.AzureFunctions/FLP.AzureFunctions/FLP.Application/Handlers/Bugs/CreateBugHandler.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 45
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%
Handle()100%22100%

File(s)

/home/runner/work/FLP.AzureFunctions/FLP.AzureFunctions/FLP.Application/Handlers/Bugs/CreateBugHandler.cs

#LineLine coverage
 1using AutoMapper;
 2using FLP.Application.Requests.Bugs;
 3using FLP.Application.Responses.Bugs;
 4using FLP.Application.Validators.Bugs;
 5using FLP.Core.Context.Main;
 6using FLP.Core.Context.Shared;
 7using FLP.Core.Interfaces.Repository;
 8using MediatR;
 9using Microsoft.Extensions.Logging;
 10
 11namespace FLP.Application.Handlers.Bugs;
 12
 313public class CreateBugHandler(IUnitOfWork _uow, IMapper _mapper, ILogger<CreateBugHandler> _logger) : IRequestHandler<Cr
 14{
 15    public async Task<BaseResponse<GetBugByIdResponse>> Handle(CreateBugRequest request, CancellationToken cancellationT
 316    {
 317        cancellationToken.ThrowIfCancellationRequested();
 318        _logger.LogInformation("Handling CreateBugRequest for Title: {Title}", request.Title);
 19        // Validate the request
 320        var validator = new CreateBugValidator();
 321        var validationResult = validator.Validate(request);
 322        if (!validationResult.IsValid)
 123        {
 124            _logger.LogWarning("Validation failed for CreateBugRequest: {Errors}", validationResult.Errors);
 125            return new BaseResponse<GetBugByIdResponse>(false,validationResult.Errors.Select(e => e.ErrorMessage));
 26        }
 27
 28        // Map the request to a domain entity
 229        var bug = _mapper.Map<Bug>(request);
 230        _uow.BeginTransaction(cancellationToken);
 31        // Add the bug to the repository
 232        var addedBug = await _uow.BugRepository.AddAsync(bug, cancellationToken);
 133        await _uow.SaveChangesAsync(cancellationToken);
 34
 35        // Map the added bug to a response DTO
 136        var response = _mapper.Map<GetBugByIdResponse>(addedBug);
 37
 38        // Commit the transaction
 139        _uow.CommitTransaction(cancellationToken);
 40
 141        _logger.LogInformation("Bug created successfully with ID: {Id}", response.Id);
 42
 143        return new BaseResponse<GetBugByIdResponse>(response);
 244    }
 45}