< Summary

Information
Class: Syki.Back.Features.Academic.CreateAcademicPeriod.AcademicPeriod
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/CreateAcademicPeriod/AcademicPeriod.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 41
Uncovered lines: 0
Coverable lines: 41
Total lines: 80
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_InstitutionId()100%11100%
get_StartAt()100%11100%
get_EndAt()100%11100%
.ctor(...)100%11100%
New(...)100%22100%
Validate(...)100%1616100%
ToOut()100%11100%
op_Implicit(...)100%11100%

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/CreateAcademicPeriod/AcademicPeriod.cs

#LineLine coverage
 1namespace Syki.Back.Features.Academic.CreateAcademicPeriod;
 2
 3public class AcademicPeriod
 4{
 4805    public string Id { get; }
 66    public Guid InstitutionId { get; }
 8977    public DateOnly StartAt { get; private set; }
 310668    public DateOnly EndAt { get; private set; }
 9
 44910    public AcademicPeriod(
 44911        string id,
 44912        Guid institutionId,
 44913        DateOnly startAt,
 44914        DateOnly endAt
 44915    ) {
 44916        Id = id;
 44917        InstitutionId = institutionId;
 44918        StartAt = startAt;
 44919        EndAt = endAt;
 44920    }
 21
 22    public static OneOf<AcademicPeriod, SykiError> New(
 23        string id,
 24        Guid institutionId,
 25        DateOnly startAt,
 26        DateOnly endAt
 27    ) {
 28228        var result = Validate(id, startAt, endAt);
 29
 31330        if (result.IsError()) return result.GetError();
 31
 25132        return new AcademicPeriod(result.GetSuccess(), institutionId, startAt, endAt);
 33    }
 34
 35    private static OneOf<string, SykiError> Validate(
 36        string id,
 37        DateOnly startAt,
 38        DateOnly endAt
 39    ) {
 28240        var numbers = id.OnlyNumbers();
 41
 28242        if (numbers.Length != 5)
 1443            return new InvalidAcademicPeriod();
 44
 26845        var year = int.Parse(numbers.Substring(0, 4));
 26846        var digit = int.Parse(numbers.Substring(4, 1));
 47
 26848        if (year < 1970 || year > 2070)
 249            return new InvalidAcademicPeriod();
 50
 26651        if (digit < 1 || digit > 2)
 852            return new InvalidAcademicPeriod();
 53
 25854        if (startAt.Year != year)
 255            return new InvalidAcademicPeriodStartDate();
 56
 25657        if (endAt.Year != year)
 258            return new InvalidAcademicPeriodEndDate();
 59
 25460        if (startAt >= endAt)
 361            return new InvalidAcademicPeriodDates();
 62
 25163        return $"{year}.{digit}";
 64    }
 65
 66    public AcademicPeriodOut ToOut()
 67    {
 23768        return new()
 23769        {
 23770            Id = Id,
 23771            StartAt = StartAt,
 23772            EndAt = EndAt,
 23773        };
 74    }
 75
 76    public static implicit operator AcademicPeriod(OneOf<AcademicPeriod, SykiError> value)
 77    {
 978        return value.GetSuccess();
 79    }
 80}