< Summary

Information
Class: LGDXRobotCloud.Data.DbContexts.LgdxContext
Assembly: LGDXRobotCloud.Data
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/DbContexts/LgdxContext.cs
Line coverage
100%
Covered lines: 191
Uncovered lines: 0
Coverable lines: 191
Total lines: 224
Line coverage: 100%
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%
get_ApiKeys()100%11100%
get_AutoTasks()100%11100%
get_AutoTasksDetail()100%11100%
get_AutoTasksJourney()100%11100%
get_Flows()100%11100%
get_FlowDetails()100%11100%
get_Progresses()100%11100%
get_Triggers()100%11100%
get_TriggerRetries()100%11100%
get_Realms()100%11100%
get_Robots()100%11100%
get_RobotCertificates()100%11100%
get_RobotChassisInfos()100%11100%
get_RobotSystemInfos()100%11100%
get_Waypoints()100%11100%
ConfigureConventions(...)100%11100%
OnModelCreating(...)100%22100%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/DbContexts/LgdxContext.cs

#LineLine coverage
 1using LGDXRobotCloud.Data.Entities;
 2using LGDXRobotCloud.Utilities.Enums;
 3using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
 4using Microsoft.EntityFrameworkCore;
 5using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
 6
 7namespace LGDXRobotCloud.Data.DbContexts;
 8
 5809public class LgdxContext(DbContextOptions<LgdxContext> options) : IdentityDbContext<LgdxUser, LgdxRole, string>(options)
 10{
 11  // Administration
 29012  public virtual DbSet<ApiKey> ApiKeys { get; set; }
 13
 14  // Automation
 29015  public virtual DbSet<AutoTask> AutoTasks { get; set; }
 29016  public virtual DbSet<AutoTaskDetail> AutoTasksDetail { get; set; }
 29017  public virtual DbSet<AutoTaskJourney> AutoTasksJourney { get; set; }
 29018  public virtual DbSet<Flow> Flows { get; set; }
 29019  public virtual DbSet<FlowDetail> FlowDetails { get; set; }
 29020  public virtual DbSet<Progress> Progresses { get; set; }
 29021  public virtual DbSet<Trigger> Triggers { get; set; }
 29022  public virtual DbSet<TriggerRetry> TriggerRetries { get; set; }
 23
 24  // Navigation
 29025  public virtual DbSet<Realm> Realms { get; set; }
 29026  public virtual DbSet<Robot> Robots { get; set; }
 29027  public virtual DbSet<RobotCertificate> RobotCertificates { get; set; }
 29028  public virtual DbSet<RobotChassisInfo> RobotChassisInfos { get; set; }
 29029  public virtual DbSet<RobotSystemInfo> RobotSystemInfos { get; set; }
 29030  public virtual DbSet<Waypoint> Waypoints { get; set; }
 31
 32  protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
 133  {
 134    configurationBuilder
 135      .Properties<DateTime>()
 136      .HaveConversion(typeof(UtcValueConverter));
 137  }
 38
 39  protected override void OnModelCreating(ModelBuilder modelBuilder)
 140  {
 6341    foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
 1942    {
 1943      relationship.DeleteBehavior = DeleteBehavior.Restrict;
 1944    }
 45
 46    // Automation.AutoTasks
 147    modelBuilder.Entity<AutoTask>()
 148      .HasMany(e => e.AutoTaskDetails)
 149      .WithOne(e => e.AutoTask)
 150      .HasForeignKey(e => e.AutoTaskId)
 151      .OnDelete(DeleteBehavior.Cascade)
 152      .IsRequired();
 153    modelBuilder.Entity<AutoTask>()
 154      .HasOne(e => e.Realm)
 155      .WithMany()
 156      .OnDelete(DeleteBehavior.Cascade)
 157      .IsRequired();
 158    modelBuilder.Entity<AutoTask>()
 159      .HasOne(e => e.AssignedRobot)
 160      .WithMany(e => e.AssignedTasks)
 161      .HasForeignKey(e => e.AssignedRobotId)
 162      .IsRequired(false)
 163      .OnDelete(DeleteBehavior.SetNull);
 164    modelBuilder.Entity<AutoTask>()
 165      .HasOne(e => e.Flow)
 166      .WithMany()
 167      .HasForeignKey(e => e.FlowId)
 168      .IsRequired(false)
 169      .OnDelete(DeleteBehavior.SetNull);
 170    modelBuilder.Entity<AutoTaskDetail>()
 171      .HasOne(e => e.Waypoint)
 172      .WithMany()
 173      .HasForeignKey(e => e.WaypointId)
 174      .OnDelete(DeleteBehavior.SetNull)
 175      .IsRequired(false);
 176    modelBuilder.Entity<AutoTaskJourney>()
 177      .HasOne(e => e.CurrentProgress)
 178      .WithMany()
 179      .HasForeignKey(e => e.CurrentProgressId)
 180      .OnDelete(DeleteBehavior.SetNull)
 181      .IsRequired(false);
 82    // Automation.FlowDetails
 183    modelBuilder.Entity<Flow>()
 184      .HasMany(e => e.FlowDetails)
 185      .WithOne(e => e.Flow)
 186      .HasForeignKey(e => e.FlowId)
 187      .OnDelete(DeleteBehavior.Cascade)
 188      .IsRequired();
 89    // Automation.TriggerRetries
 190    modelBuilder.Entity<TriggerRetry>()
 191      .HasOne(e => e.Trigger)
 192      .WithMany()
 193      .HasForeignKey(e => e.TriggerId)
 194      .IsRequired(true)
 195      .OnDelete(DeleteBehavior.Cascade);
 196    modelBuilder.Entity<TriggerRetry>()
 197      .HasOne(e => e.AutoTask)
 198      .WithMany()
 199      .HasForeignKey(e => e.AutoTaskId)
 1100      .IsRequired(true)
 1101      .OnDelete(DeleteBehavior.Cascade);
 102    // Automation.Triggers
 1103    modelBuilder.Entity<Trigger>()
 1104      .HasOne(e => e.ApiKey)
 1105      .WithMany()
 1106      .HasForeignKey(e => e.ApiKeyId)
 1107      .IsRequired(false)
 1108      .OnDelete(DeleteBehavior.SetNull);
 109
 110    // Navigation.Robots
 1111    modelBuilder.Entity<Robot>()
 1112      .HasOne(e => e.RobotSystemInfo)
 1113      .WithOne(e => e.Robot)
 1114      .HasForeignKey<RobotSystemInfo>(e => e.RobotId)
 1115      .IsRequired(false)
 1116      .OnDelete(DeleteBehavior.Cascade);
 1117    modelBuilder.Entity<Robot>()
 1118      .HasOne(e => e.RobotChassisInfo)
 1119      .WithOne(e => e.Robot)
 1120      .HasForeignKey<RobotChassisInfo>(e => e.RobotId)
 1121      .IsRequired(false)
 1122      .OnDelete(DeleteBehavior.Cascade);
 1123    modelBuilder.Entity<Robot>()
 1124      .HasOne(e => e.RobotCertificate)
 1125      .WithOne(e => e.Robot)
 1126      .HasForeignKey<RobotCertificate>(e => e.RobotId)
 1127      .IsRequired()
 1128      .OnDelete(DeleteBehavior.Cascade);
 129
 1130    modelBuilder.Entity<Realm>().HasData(
 1131      new Realm
 1132      {
 1133        Id = 1,
 1134        Name = "First Realm",
 1135        Description = "Please update this realm",
 1136        Image = [],
 1137        Resolution = 0,
 1138        OriginX = 0,
 1139        OriginY = 0,
 1140        OriginRotation = 0,
 1141      }
 1142    );
 143
 1144    modelBuilder.Entity<Progress>().HasData(
 1145      new Progress
 1146      {
 1147        Id = (int)ProgressState.Template,
 1148        Name = "Template",
 1149        System = true,
 1150        Reserved = true
 1151      },
 1152      new Progress
 1153      {
 1154        Id = (int)ProgressState.Waiting,
 1155        Name = "Waiting",
 1156        System = true,
 1157        Reserved = true
 1158      },
 1159      new Progress
 1160      {
 1161        Id = (int)ProgressState.Completed,
 1162        Name = "Completed",
 1163        System = true,
 1164        Reserved = true
 1165      },
 1166      new Progress
 1167      {
 1168        Id = (int)ProgressState.Aborted,
 1169        Name = "Aborted",
 1170        System = true,
 1171        Reserved = true
 1172      },
 1173      new Progress
 1174      {
 1175        Id = (int)ProgressState.Starting,
 1176        Name = "Starting",
 1177        System = true
 1178      },
 1179      new Progress
 1180      {
 1181        Id = (int)ProgressState.Loading,
 1182        Name = "Loading",
 1183        System = true
 1184      },
 1185      new Progress
 1186      {
 1187        Id = (int)ProgressState.PreMoving,
 1188        Name = "PreMoving",
 1189        System = true
 1190      },
 1191      new Progress
 1192      {
 1193        Id = (int)ProgressState.Moving,
 1194        Name = "Moving",
 1195        System = true
 1196      },
 1197      new Progress
 1198      {
 1199        Id = (int)ProgressState.Unloading,
 1200        Name = "Unloading",
 1201        System = true
 1202      },
 1203      new Progress
 1204      {
 1205        Id = (int)ProgressState.Completing,
 1206        Name = "Completing",
 1207        System = true
 1208      },
 1209      new Progress
 1210      {
 1211        Id = (int)ProgressState.Reserved,
 1212        Name = "Reserved",
 1213        System = true,
 1214        Reserved = true
 1215      }
 1216    );
 1217    base.OnModelCreating(modelBuilder);
 1218  }
 219}
 220
 221class UtcValueConverter : ValueConverter<DateTime, DateTime>
 222{
 223  public UtcValueConverter() : base(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc)) {}
 224}