< Summary

Information
Class: LGDXRobotCloud.Data.DbContexts.UtcValueConverter
Assembly: LGDXRobotCloud.Data
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/DbContexts/LgdxContext.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 217
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%

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
 9public class LgdxContext(DbContextOptions<LgdxContext> options) : IdentityDbContext<LgdxUser, LgdxRole, string>(options)
 10{
 11  // Administration
 12  public virtual DbSet<ApiKey> ApiKeys { get; set; }
 13
 14  // Automation
 15  public virtual DbSet<AutoTask> AutoTasks { get; set; }
 16  public virtual DbSet<AutoTaskDetail> AutoTasksDetail { get; set; }
 17  public virtual DbSet<Flow> Flows { get; set; }
 18  public virtual DbSet<FlowDetail> FlowDetails { get; set; }
 19  public virtual DbSet<Progress> Progresses { get; set; }
 20  public virtual DbSet<Trigger> Triggers { get; set; }
 21  public virtual DbSet<TriggerRetry> TriggerRetries { get; set; }
 22
 23  // Navigation
 24  public virtual DbSet<Realm> Realms { get; set; }
 25  public virtual DbSet<Robot> Robots { get; set; }
 26  public virtual DbSet<RobotCertificate> RobotCertificates { get; set; }
 27  public virtual DbSet<RobotChassisInfo> RobotChassisInfos { get; set; }
 28  public virtual DbSet<RobotSystemInfo> RobotSystemInfos { get; set; }
 29  public virtual DbSet<Waypoint> Waypoints { get; set; }
 30
 31  protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
 32  {
 33    configurationBuilder
 34      .Properties<DateTime>()
 35      .HaveConversion(typeof(UtcValueConverter));
 36  }
 37
 38  protected override void OnModelCreating(ModelBuilder modelBuilder)
 39  {
 40    foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
 41    {
 42      relationship.DeleteBehavior = DeleteBehavior.Restrict;
 43    }
 44
 45    // Automation.AutoTasks
 46    modelBuilder.Entity<AutoTask>()
 47      .HasMany(e => e.AutoTaskDetails)
 48      .WithOne(e => e.AutoTask)
 49      .HasForeignKey(e => e.AutoTaskId)
 50      .OnDelete(DeleteBehavior.Cascade)
 51      .IsRequired();
 52    modelBuilder.Entity<AutoTask>()
 53      .HasOne(e => e.Realm)
 54      .WithMany()
 55      .OnDelete(DeleteBehavior.Cascade)
 56      .IsRequired();
 57    modelBuilder.Entity<AutoTask>()
 58      .HasOne(e => e.AssignedRobot)
 59      .WithMany(e => e.AssignedTasks)
 60      .HasForeignKey(e => e.AssignedRobotId)
 61      .IsRequired(false)
 62      .OnDelete(DeleteBehavior.SetNull);
 63    modelBuilder.Entity<AutoTask>()
 64      .HasOne(e => e.Flow)
 65      .WithMany()
 66      .HasForeignKey(e => e.FlowId)
 67      .IsRequired(false)
 68      .OnDelete(DeleteBehavior.SetNull);
 69    modelBuilder.Entity<AutoTaskDetail>()
 70      .HasOne(e => e.Waypoint)
 71      .WithMany()
 72      .HasForeignKey(e => e.WaypointId)
 73      .OnDelete(DeleteBehavior.SetNull)
 74      .IsRequired(false);
 75    // Automation.FlowDetails
 76    modelBuilder.Entity<Flow>()
 77      .HasMany(e => e.FlowDetails)
 78      .WithOne(e => e.Flow)
 79      .HasForeignKey(e => e.FlowId)
 80      .OnDelete(DeleteBehavior.Cascade)
 81      .IsRequired();
 82    // Automation.TriggerRetries
 83    modelBuilder.Entity<TriggerRetry>()
 84      .HasOne(e => e.Trigger)
 85      .WithMany()
 86      .HasForeignKey(e => e.TriggerId)
 87      .IsRequired(true)
 88      .OnDelete(DeleteBehavior.Cascade);
 89    modelBuilder.Entity<TriggerRetry>()
 90      .HasOne(e => e.AutoTask)
 91      .WithMany()
 92      .HasForeignKey(e => e.AutoTaskId)
 93      .IsRequired(true)
 94      .OnDelete(DeleteBehavior.Cascade);
 95    // Automation.Triggers
 96    modelBuilder.Entity<Trigger>()
 97      .HasOne(e => e.ApiKey)
 98      .WithMany()
 99      .HasForeignKey(e => e.ApiKeyId)
 100      .IsRequired(false)
 101      .OnDelete(DeleteBehavior.SetNull);
 102
 103    // Navigation.Robots
 104    modelBuilder.Entity<Robot>()
 105      .HasOne(e => e.RobotSystemInfo)
 106      .WithOne(e => e.Robot)
 107      .HasForeignKey<RobotSystemInfo>(e => e.RobotId)
 108      .IsRequired(false)
 109      .OnDelete(DeleteBehavior.Cascade);
 110    modelBuilder.Entity<Robot>()
 111      .HasOne(e => e.RobotChassisInfo)
 112      .WithOne(e => e.Robot)
 113      .HasForeignKey<RobotChassisInfo>(e => e.RobotId)
 114      .IsRequired(false)
 115      .OnDelete(DeleteBehavior.Cascade);
 116    modelBuilder.Entity<Robot>()
 117      .HasOne(e => e.RobotCertificate)
 118      .WithOne(e => e.Robot)
 119      .HasForeignKey<RobotCertificate>(e => e.RobotId)
 120      .IsRequired()
 121      .OnDelete(DeleteBehavior.Cascade);
 122
 123    modelBuilder.Entity<Realm>().HasData(
 124      new Realm
 125      {
 126        Id = 1,
 127        Name = "First Realm",
 128        Description = "Please update this realm",
 129        Image = [],
 130        Resolution = 0,
 131        OriginX = 0,
 132        OriginY = 0,
 133        OriginRotation = 0,
 134      }
 135    );
 136
 137    modelBuilder.Entity<Progress>().HasData(
 138      new Progress
 139      {
 140        Id = (int)ProgressState.Template,
 141        Name = "Template",
 142        System = true,
 143        Reserved = true
 144      },
 145      new Progress
 146      {
 147        Id = (int)ProgressState.Waiting,
 148        Name = "Waiting",
 149        System = true,
 150        Reserved = true
 151      },
 152      new Progress
 153      {
 154        Id = (int)ProgressState.Completed,
 155        Name = "Completed",
 156        System = true,
 157        Reserved = true
 158      },
 159      new Progress
 160      {
 161        Id = (int)ProgressState.Aborted,
 162        Name = "Aborted",
 163        System = true,
 164        Reserved = true
 165      },
 166      new Progress
 167      {
 168        Id = (int)ProgressState.Starting,
 169        Name = "Starting",
 170        System = true
 171      },
 172      new Progress
 173      {
 174        Id = (int)ProgressState.Loading,
 175        Name = "Loading",
 176        System = true
 177      },
 178      new Progress
 179      {
 180        Id = (int)ProgressState.PreMoving,
 181        Name = "PreMoving",
 182        System = true
 183      },
 184      new Progress
 185      {
 186        Id = (int)ProgressState.Moving,
 187        Name = "Moving",
 188        System = true
 189      },
 190      new Progress
 191      {
 192        Id = (int)ProgressState.Unloading,
 193        Name = "Unloading",
 194        System = true
 195      },
 196      new Progress
 197      {
 198        Id = (int)ProgressState.Completing,
 199        Name = "Completing",
 200        System = true
 201      },
 202      new Progress
 203      {
 204        Id = (int)ProgressState.Reserved,
 205        Name = "Reserved",
 206        System = true,
 207        Reserved = true
 208      }
 209    );
 210    base.OnModelCreating(modelBuilder);
 211  }
 212}
 213
 214class UtcValueConverter : ValueConverter<DateTime, DateTime>
 215{
 0216  public UtcValueConverter() : base(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc)) {}
 217}

Methods/Properties

.ctor()