< Summary

Information
Class: event_list.modules.eventlist.services.EventListSaveService
Assembly: event-list
File(s): /Users/tiagoamaral/Workspace/desafio/event-list-api/Src/Modules/Eventlist/Services/EventListSaveService.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 38
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%
Add()100%22100%

File(s)

/Users/tiagoamaral/Workspace/desafio/event-list-api/Src/Modules/Eventlist/Services/EventListSaveService.cs

#LineLine coverage
 1/*
 2* eventListSave.cs
 3* event-list
 4*
 5* Created by Tiago Amaral on 06/09/2025.
 6* Copyright ©2024 Tiago Amaral. All rights reserved.
 7*/
 8
 9using System.ComponentModel.DataAnnotations;
 10using event_list.modules.eventlist.storage;
 11
 12namespace event_list.modules.eventlist.services;
 13
 14public interface IEventListSaveService
 15{
 16     Task Add(EventFormDto dto);
 17}
 18public class EventListSaveService : IEventListSaveService
 19{
 20    private readonly IEventListStorage _storage;
 21
 222    public EventListSaveService(IEventListStorage storage)
 223    {
 224        _storage = storage;
 225    }
 26
 227    public async Task Add(EventFormDto dto) {
 28
 229        var results = new List<ValidationResult>();
 230        var context = new ValidationContext(dto);
 231        if (!Validator.TryValidateObject(dto, context, results, true))
 132        {
 133            throw new ValidationException(results.First().ErrorMessage);
 34        }
 135        dto.Id = Guid.NewGuid();
 136        await _storage.CreateAsync(dto);
 137    }
 38}