< Summary - Syki

Information
Class: Syki.Back.Features.Student.CreateStudentEnrollment.CreateStudentEnrollmentService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Student/CreateStudentEnrollment/CreateStudentEnrollmentService.cs
Tag: 4_16869239191
Line coverage
90%
Covered lines: 20
Uncovered lines: 2
Coverable lines: 22
Total lines: 35
Line coverage: 90.9%
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%
Create()100%22100%
CreateWithThrowOnError()100%210%

File(s)

/home/runner/work/syki/syki/Back/Features/Student/CreateStudentEnrollment/CreateStudentEnrollmentService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Student.CreateStudentEnrollment;
 2
 943public class CreateStudentEnrollmentService(SykiDbContext ctx) : IStudentService
 4{
 5    public async Task<OneOf<SykiSuccess, SykiError>> Create(Guid institutionId, Guid userId, Guid courseCurriculumId, Cr
 6    {
 947        var today = DateOnly.FromDateTime(DateTime.UtcNow);
 948        var enrollmentPeriod = await ctx.EnrollmentPeriods.AsNoTracking()
 949            .Where(p => p.InstitutionId == institutionId && p.StartAt <= today && p.EndAt >= today)
 9410            .FirstOrDefaultAsync();
 9611        if (enrollmentPeriod == null) return new EnrollmentPeriodNotFound();
 12
 9213        var courseCurriculum = await ctx.CourseCurriculums.Where(g => g.Id == courseCurriculumId).AsNoTracking()
 9214            .Include(g => g.Links)
 9215            .FirstAsync();
 119616        var disciplines = courseCurriculum.Links.ConvertAll(d => d.DisciplineId);
 9217        var classes = await ctx.Classes.AsNoTracking()
 9218            .Where(t => t.InstitutionId == institutionId && t.PeriodId == enrollmentPeriod.Id && t.Status == ClassStatus
 9219            .ToListAsync();
 106820        var ids = classes.Where(t => data.Classes.Contains(t.Id)).Select(t => t.Id).ToList();
 21
 9222        var classesStudents = await ctx.ClassesStudents.Where(x => x.SykiStudentId == userId && x.StudentDisciplineStatu
 9223        ctx.RemoveRange(classesStudents);
 57824        ids.ForEach(id => ctx.Add(new ClassStudent(id, userId)));
 25
 9226        await ctx.SaveChangesAsync();
 27
 9228        return new SykiSuccess();
 9429    }
 30
 31    public async Task CreateWithThrowOnError(Guid institutionId, Guid userId, Guid courseCurriculumId, CreateStudentEnro
 32    {
 033        (await Create(institutionId, userId, courseCurriculumId, data)).ThrowOnError();
 034    }
 35}