< Summary

Information
Class: LGDXRobotCloud.Data.Services.DataSeeder
Assembly: LGDXRobotCloud.Data
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/Services/DataSeeder.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 100
Coverable lines: 100
Total lines: 125
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%620%
Seed()0%620%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/Services/DataSeeder.cs

#LineLine coverage
 1using LGDXRobotCloud.Data.DbContexts;
 2using LGDXRobotCloud.Data.Entities;
 3using LGDXRobotCloud.Utilities.Enums;
 4using Microsoft.EntityFrameworkCore;
 5
 6namespace LGDXRobotCloud.Data.Services;
 7
 8public record WaypointData(string Name, double X, double Y, double Rotation);
 9
 010public class DataSeeder(LgdxContext context)
 11{
 012  private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context));
 13
 014  private readonly List<WaypointData> waypoints = [
 015    new WaypointData("Waypoint 1", 1.5, 0.5, 0),
 016    new WaypointData("Waypoint 2", 1.5, 2.5, 0),
 017    new WaypointData("Waypoint 3", 1.5, 4.5, 0),
 018    new WaypointData("Waypoint 4", 1.5, 6.5, 0),
 019    new WaypointData("Waypoint 5", 1.5, 8.5, 0),
 020    new WaypointData("Waypoint 6", 6.5, 8.5, 3.14159265),
 021    new WaypointData("Waypoint 7", 6.5, 6.5, 3.14159265),
 022    new WaypointData("Waypoint 8", 6.5, 4.5, 3.14159265),
 023    new WaypointData("Waypoint 9", 6.5, 2.5, 3.14159265),
 024    new WaypointData("Waypoint 10",6.5, 0.5, 0),
 025  ];
 26
 27  public async Task Seed()
 028  {
 29    // Realm
 030    var realm = await _context.Realms.FirstOrDefaultAsync();
 031    realm!.Resolution = 0.05;
 032    realm.OriginX = -0.951;
 033    realm.OriginY = -1.11;
 34
 35    // Waypoint
 036    foreach (var waypoint in waypoints)
 037    {
 038      var wp = new Waypoint
 039      {
 040        Name = waypoint.Name,
 041        X = waypoint.X,
 042        Y = waypoint.Y,
 043        Rotation = waypoint.Rotation,
 044        RealmId = realm.Id
 045      };
 046      await _context.Waypoints.AddAsync(wp);
 047    }
 48
 49    // Flow
 050    var flow = new Flow
 051    {
 052      Name = "Flow 1",
 053      FlowDetails = [new FlowDetail
 054      {
 055        ProgressId = (int)ProgressState.Moving,
 056        AutoTaskNextControllerId = (int)AutoTaskNextController.Robot,
 057      }]
 058    };
 059    await _context.Flows.AddAsync(flow);
 60
 61    // Robots
 062    var robots = new List<Robot>
 063    {
 064      new() {
 065        Id = Guid.Parse("0198276e-97f7-7dd1-982e-56ea02c6d921"),
 066        Name = "Robot1",
 067        RealmId = realm.Id,
 068        IsProtectingHardwareSerialNumber = false,
 069      },
 070      new (){
 071        Id = Guid.Parse("0198276e-e868-733b-b9e7-d67c0ab84afd"),
 072        Name = "Robot2",
 073        RealmId = realm.Id,
 074        IsProtectingHardwareSerialNumber = false,
 075      }
 076    };
 77
 078    var robotChassisInfo = new List<RobotChassisInfo>
 079    {
 080      new (){
 081        RobotTypeId = (int)LgdxRobotType.LGDXRobot2Classic,
 082        BatteryCount = 2,
 083        BatteryMaxVoltage = 12.0,
 084        BatteryMinVoltage = 10.0,
 085        ChassisLengthX = 1.0,
 086        ChassisLengthY = 1.0,
 087        ChassisWheelCount = 4,
 088        ChassisWheelRadius = 0.1,
 089      },
 090      new (){
 091        RobotTypeId = (int)LgdxRobotType.LGDXRobot2Classic,
 092        BatteryCount = 2,
 093        BatteryMaxVoltage = 12.0,
 094        BatteryMinVoltage = 10.0,
 095        ChassisLengthX = 1.0,
 096        ChassisLengthY = 1.0,
 097        ChassisWheelCount = 4,
 098        ChassisWheelRadius = 0.1,
 099      }
 0100    };
 0101    robots[0].RobotChassisInfo = robotChassisInfo[0];
 0102    robots[1].RobotChassisInfo = robotChassisInfo[1];
 103
 0104    var robotCertificate = new List<RobotCertificate> {
 0105      new() {
 0106        Thumbprint = "DD53D5856E815B10B9B04B0D85B3BA5A622C184A",
 0107        ThumbprintBackup = string.Empty,
 0108        NotBefore = DateTime.UtcNow,
 0109        NotAfter = DateTime.UtcNow.AddYears(100),
 0110      },
 0111      new() {
 0112        Thumbprint = "08970F71CED907B1064FA3AD43F82992900FA905",
 0113        ThumbprintBackup = string.Empty,
 0114        NotBefore = DateTime.UtcNow,
 0115        NotAfter = DateTime.UtcNow.AddYears(100),
 0116      }
 0117    };
 0118    robots[0].RobotCertificate = robotCertificate[0];
 0119    robots[1].RobotCertificate = robotCertificate[1];
 120
 0121    await _context.Robots.AddRangeAsync(robots);
 122
 0123    await _context.SaveChangesAsync();
 0124  }
 125}