< Summary

Information
Class: Syki.Back.Database.SykiDbContext
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Database/SykiDbContext.cs
Tag: 22_11348620282
Line coverage
87%
Covered lines: 48
Uncovered lines: 7
Coverable lines: 55
Total lines: 120
Line coverage: 87.2%
Branch coverage
64%
Covered branches: 9
Total branches: 14
Branch coverage: 64.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Campi()100%11100%
get_Classes()100%11100%
get_Lessons()100%11100%
get_Courses()100%11100%
get_Tasks()100%11100%
get_AuditLogs()100%11100%
get_Teachers()100%11100%
get_Students()100%11100%
get_ExamGrades()100%11100%
get_Disciplines()100%11100%
get_Institutions()100%11100%
get_Configs()100%11100%
get_FeatureFlags()100%11100%
get_UserRegisters()100%11100%
get_Notifications()100%11100%
get_Attendances()100%11100%
get_ClassesStudents()100%11100%
get_AcademicPeriods()100%11100%
get_CourseOfferings()100%11100%
get_CourseCurriculums()100%11100%
get_EnrollmentPeriods()100%11100%
get_UserNotifications()100%11100%
get_CoursesDisciplines()100%11100%
get_ResetPasswordTokens()100%11100%
get_CourseCurriculumDisciplines()100%11100%
OnConfiguring(...)100%11100%
OnModelCreating(...)87.5%88100%
ConfigureConventions(...)100%11100%
ResetDbAsync()100%22100%
ResetDb()0%620%
MigrateDb()0%620%
AcademicPeriodExists()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Database/SykiDbContext.cs

#LineLine coverage
 1using Syki.Back.Audit;
 2using Audit.EntityFramework;
 3using Syki.Back.Features.Cross.CreateUser;
 4using Syki.Back.Features.Academic.CreateClass;
 5using Syki.Back.Features.Academic.CreateCourse;
 6using Syki.Back.Features.Academic.CreateCampus;
 7using Syki.Back.Features.Academic.CreateStudent;
 8using Syki.Back.Features.Academic.CreateTeacher;
 9using Syki.Back.Features.Cross.CreateInstitution;
 10using Syki.Back.Features.Cross.SetupFeatureFlags;
 11using Syki.Back.Features.Academic.CreateDiscipline;
 12using Syki.Back.Features.Academic.CreateNotification;
 13using Syki.Back.Features.Cross.SendResetPasswordToken;
 14using Syki.Back.Features.Academic.CreateCourseOffering;
 15using Syki.Back.Features.Academic.CreateAcademicPeriod;
 16using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
 17using Syki.Back.Features.Teacher.CreateLessonAttendance;
 18using Syki.Back.Features.Cross.CreatePendingUserRegister;
 19using Syki.Back.Features.Academic.CreateCourseCurriculum;
 20using Syki.Back.Features.Academic.CreateEnrollmentPeriod;
 21using Syki.Back.Features.Student.CreateStudentEnrollment;
 22
 23namespace Syki.Back.Database;
 24
 619925public class SykiDbContext(DbContextOptions<SykiDbContext> options, DatabaseSettings settings) : IdentityDbContext<SykiU
 26{
 642327    public DbSet<Campus> Campi { get; set; }
 713428    public DbSet<Class> Classes { get; set; }
 627529    public DbSet<Lesson> Lessons { get; set; }
 844030    public DbSet<Course> Courses { get; set; }
 620431    public DbSet<SykiTask> Tasks { get; set; }
 620132    public DbSet<AuditLog> AuditLogs { get; set; }
 640033    public DbSet<SykiTeacher> Teachers { get; set; }
 645934    public DbSet<SykiStudent> Students { get; set; }
 624935    public DbSet<ExamGrade> ExamGrades { get; set; }
 640336    public DbSet<Discipline> Disciplines { get; set; }
 671337    public DbSet<Institution> Institutions { get; set; }
 620038    public DbSet<InstitutionConfigs> Configs { get; set; }
 619939    public DbSet<FeatureFlags> FeatureFlags { get; set; }
 741740    public DbSet<UserRegister> UserRegisters { get; set; }
 638141    public DbSet<Notification> Notifications { get; set; }
 623642    public DbSet<LessonAttendance> Attendances { get; set; }
 626643    public DbSet<ClassStudent> ClassesStudents { get; set; }
 695144    public DbSet<AcademicPeriod> AcademicPeriods { get; set; }
 679345    public DbSet<CourseOffering> CourseOfferings { get; set; }
 667646    public DbSet<CourseCurriculum> CourseCurriculums { get; set; }
 645347    public DbSet<EnrollmentPeriod> EnrollmentPeriods { get; set; }
 640348    public DbSet<UserNotification> UserNotifications { get; set; }
 642649    public DbSet<CourseDiscipline> CoursesDisciplines { get; set; }
 666350    public DbSet<ResetPasswordToken> ResetPasswordTokens { get; set; }
 620651    public DbSet<CourseCurriculumDiscipline> CourseCurriculumDisciplines { get; set; }
 52
 53    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 54    {
 592655        optionsBuilder.UseNpgsql(settings.ConnectionString);
 592656        optionsBuilder.UseSnakeCaseNamingConvention();
 592657        optionsBuilder.AddInterceptors(new AuditSaveChangesInterceptor());
 592658    }
 59
 60    protected override void OnModelCreating(ModelBuilder builder)
 61    {
 262        base.OnModelCreating(builder);
 63
 264        builder.HasDefaultSchema("syki");
 65
 266        builder.ApplyConfigurationsFromAssembly(GetType().Assembly);
 67
 14468        foreach (var entity in builder.Model.GetEntityTypes())
 69        {
 7070            entity.SetTableName(entity.GetTableName()!.ToSnakeCase().Replace("asp_net_", ""));
 71
 32872            foreach (var fk in entity.GetForeignKeys())
 73            {
 9474                fk.SetConstraintName(fk.GetConstraintName().Replace("1", ""));
 75            }
 76
 30477            foreach (var index in entity.GetIndexes())
 78            {
 8279                index.SetDatabaseName(index.GetDatabaseName()?.ToSnakeCase());
 80            }
 81        }
 282    }
 83
 84    protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
 85    {
 286        configurationBuilder.Properties<Enum>().HaveConversion<string>();
 287    }
 88
 89    public async Task ResetDbAsync()
 90    {
 191        if (Env.IsTesting())
 92        {
 193            await Database.EnsureDeletedAsync();
 194            await Database.EnsureCreatedAsync();
 95        }
 196    }
 97
 98    public void ResetDb()
 99    {
 0100        if (Env.IsDevelopment())
 101        {
 0102            Database.EnsureDeleted();
 0103            Database.EnsureCreated();
 104        }
 0105    }
 106
 107    public void MigrateDb()
 108    {
 0109        if (!Env.IsTesting())
 110        {
 0111            Database.Migrate();
 112        }
 0113    }
 114
 115
 116    public async Task<bool> AcademicPeriodExists(Guid institutionId, string id)
 117    {
 515118        return await AcademicPeriods.AnyAsync(p => p.InstitutionId == institutionId && p.Id == id);
 515119    }
 120}