< Summary

Information
Class: Syki.Back.Features.Academic.ReleaseClassesForEnrollment.ReleaseClassesForEnrollmentService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/ReleaseClassesForEnrollment/ReleaseClassesForEnrollmentService.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 30
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%
Release()100%1010100%

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/ReleaseClassesForEnrollment/ReleaseClassesForEnrollmentService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Academic.ReleaseClassesForEnrollment;
 2
 3163public class ReleaseClassesForEnrollmentService(SykiDbContext ctx) : IAcademicService
 4{
 5    public async Task<OneOf<SykiSuccess, SykiError>> Release(Guid institutionId, ReleaseClassesForEnrollmentIn data)
 6    {
 507        var classes = await ctx.Classes
 508            .Where(c => c.InstitutionId == institutionId && data.Classes.Contains(c.Id))
 509            .ToListAsync();
 10
 5011        var today = DateTime.Now.ToDateOnly();
 5012        var periods = await ctx.EnrollmentPeriods.AsNoTracking().Where(x => x.InstitutionId == institutionId).ToListAsyn
 44413        foreach (var @class in classes)
 14        {
 34615            var period = periods.FirstOrDefault(x => x.Id == @class.PeriodId);
 17616            if (period == null) return new EnrollmentPeriodNotFound();
 17317            if (today < period.StartAt) return new EnrollmentPeriodNotStarted();
 17218            if (today > period.EndAt) return new EnrollmentPeriodFinalized();
 19        }
 20
 21621        var statusOk = classes.All(x => x.Status == ClassStatus.OnPreEnrollment);
 4722        if (!statusOk) return new AllClassesMustHaveOnPreEnrollmentStatus();
 23
 21424        classes.ForEach(c => c.Status = ClassStatus.OnEnrollment);
 25
 4526        await ctx.SaveChangesAsync();
 27
 4528        return new SykiSuccess();
 5029    }
 30}