< Summary

Information
Class: Syki.Back.Features.Cross.CreateUser.CreateUserService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Cross/CreateUser/CreateUserService.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 24
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
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()87.5%88100%

File(s)

/home/runner/work/syki/syki/Back/Features/Cross/CreateUser/CreateUserService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Cross.CreateUser;
 2
 7713public class CreateUserService(SykiDbContext ctx, UserManager<SykiUser> userManager) : ICrossService
 4{
 5    public async Task<OneOf<UserOut, SykiError>> Create(CreateUserIn data)
 6    {
 4927        var institutionExists = await ctx.Institutions.AnyAsync(c => c.Id == data.InstitutionId);
 4928        if (!institutionExists) return new InstitutionNotFound();
 9
 52610        if (!data.Email.IsValidEmail()) return new InvalidEmail();
 11
 45812        var emailUsed = await ctx.Users.AnyAsync(u => u.Email == data.Email);
 46013        if (emailUsed) return new EmailAlreadyUsed();
 14
 45615        var user = new SykiUser(data.InstitutionId, data.Name, data.Email, data.PhoneNumber);
 16
 45617        var result = await userManager.CreateAsync(user, data.Password);
 46418        if (!result.Succeeded) return new WeakPassword();
 19
 44820        await userManager.AddToRoleAsync(user, data.Role.ToString());
 21
 44822        return user.ToOut();
 49223    }
 24}