< Summary - Syki

Information
Class: Syki.Back.Features.Students.CreateStudent.CreateStudentService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Students/CreateStudent/CreateStudentService.cs
Tag: 97_27801654829
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 26
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
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()50%22100%

File(s)

/home/runner/work/syki/syki/Back/Features/Students/CreateStudent/CreateStudentService.cs

#LineLine coverage
 1using Syki.Back.Domain.Identity;
 2using Syki.Back.Domain.Students;
 3
 4namespace Syki.Back.Features.Students.CreateStudent;
 5
 66public class CreateStudentService(SykiDbContext ctx, UserManager<SykiUser> userManager) : ISykiService
 7{
 8    public async Task<OneOf<CreateStudentOut, SykiError>> Create(CreateStudentIn data)
 9    {
 610        var email = data.Email.ToLowerInvariant();
 611        var emailUsed = await ctx.Users.AnyAsync(u => u.Email == email);
 612        if (emailUsed) return EmailAlreadyUsed.I;
 13
 614        var studentRole = await ctx.GetStudentRole();
 615        var institutionId = ctx.RequestUser.InstitutionId;
 16
 617        var user = new SykiUser(institutionId, data.Name, email);
 618        var student = new SykiStudent(user, institutionId, data.Name);
 619        var userRole = new SykiUserRole(institutionId, user, studentRole.Id);
 620        ctx.AddRange(student, userRole);
 21
 622        await userManager.CreateAsync(user, $"Syki@{Guid.NewGuid()}");
 23
 624        return new CreateStudentOut { Id = student.Id };
 625    }
 26}