< Summary

Information
Class: LGDXRobotCloud.Data.Services.WaypointData
Assembly: LGDXRobotCloud.Data
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/Services/DataSeeder.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 125
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
get_Name()100%210%

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
 08public record WaypointData(string Name, double X, double Y, double Rotation);
 9
 10public class DataSeeder(LgdxContext context)
 11{
 12  private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context));
 13
 14  private readonly List<WaypointData> waypoints = [
 15    new WaypointData("Waypoint 1", 1.5, 0.5, 0),
 16    new WaypointData("Waypoint 2", 1.5, 2.5, 0),
 17    new WaypointData("Waypoint 3", 1.5, 4.5, 0),
 18    new WaypointData("Waypoint 4", 1.5, 6.5, 0),
 19    new WaypointData("Waypoint 5", 1.5, 8.5, 0),
 20    new WaypointData("Waypoint 6", 6.5, 8.5, 3.14159265),
 21    new WaypointData("Waypoint 7", 6.5, 6.5, 3.14159265),
 22    new WaypointData("Waypoint 8", 6.5, 4.5, 3.14159265),
 23    new WaypointData("Waypoint 9", 6.5, 2.5, 3.14159265),
 24    new WaypointData("Waypoint 10",6.5, 0.5, 0),
 25  ];
 26
 27  public async Task Seed()
 28  {
 29    // Realm
 30    var realm = await _context.Realms.FirstOrDefaultAsync();
 31    realm!.Resolution = 0.05;
 32    realm.OriginX = -0.951;
 33    realm.OriginY = -1.11;
 34
 35    // Waypoint
 36    foreach (var waypoint in waypoints)
 37    {
 38      var wp = new Waypoint
 39      {
 40        Name = waypoint.Name,
 41        X = waypoint.X,
 42        Y = waypoint.Y,
 43        Rotation = waypoint.Rotation,
 44        RealmId = realm.Id
 45      };
 46      await _context.Waypoints.AddAsync(wp);
 47    }
 48
 49    // Flow
 50    var flow = new Flow
 51    {
 52      Name = "Flow 1",
 53      FlowDetails = [new FlowDetail
 54      {
 55        ProgressId = (int)ProgressState.Moving,
 56        AutoTaskNextControllerId = (int)AutoTaskNextController.Robot,
 57      }]
 58    };
 59    await _context.Flows.AddAsync(flow);
 60
 61    // Robots
 62    var robots = new List<Robot>
 63    {
 64      new() {
 65        Id = Guid.Parse("0198276e-97f7-7dd1-982e-56ea02c6d921"),
 66        Name = "Robot1",
 67        RealmId = realm.Id,
 68        IsProtectingHardwareSerialNumber = false,
 69      },
 70      new (){
 71        Id = Guid.Parse("0198276e-e868-733b-b9e7-d67c0ab84afd"),
 72        Name = "Robot2",
 73        RealmId = realm.Id,
 74        IsProtectingHardwareSerialNumber = false,
 75      }
 76    };
 77
 78    var robotChassisInfo = new List<RobotChassisInfo>
 79    {
 80      new (){
 81        RobotTypeId = (int)LgdxRobotType.LGDXRobot2Classic,
 82        BatteryCount = 2,
 83        BatteryMaxVoltage = 12.0,
 84        BatteryMinVoltage = 10.0,
 85        ChassisLengthX = 1.0,
 86        ChassisLengthY = 1.0,
 87        ChassisWheelCount = 4,
 88        ChassisWheelRadius = 0.1,
 89      },
 90      new (){
 91        RobotTypeId = (int)LgdxRobotType.LGDXRobot2Classic,
 92        BatteryCount = 2,
 93        BatteryMaxVoltage = 12.0,
 94        BatteryMinVoltage = 10.0,
 95        ChassisLengthX = 1.0,
 96        ChassisLengthY = 1.0,
 97        ChassisWheelCount = 4,
 98        ChassisWheelRadius = 0.1,
 99      }
 100    };
 101    robots[0].RobotChassisInfo = robotChassisInfo[0];
 102    robots[1].RobotChassisInfo = robotChassisInfo[1];
 103
 104    var robotCertificate = new List<RobotCertificate> {
 105      new() {
 106        Thumbprint = "DD53D5856E815B10B9B04B0D85B3BA5A622C184A",
 107        ThumbprintBackup = string.Empty,
 108        NotBefore = DateTime.UtcNow,
 109        NotAfter = DateTime.UtcNow.AddYears(100),
 110      },
 111      new() {
 112        Thumbprint = "08970F71CED907B1064FA3AD43F82992900FA905",
 113        ThumbprintBackup = string.Empty,
 114        NotBefore = DateTime.UtcNow,
 115        NotAfter = DateTime.UtcNow.AddYears(100),
 116      }
 117    };
 118    robots[0].RobotCertificate = robotCertificate[0];
 119    robots[1].RobotCertificate = robotCertificate[1];
 120
 121    await _context.Robots.AddRangeAsync(robots);
 122
 123    await _context.SaveChangesAsync();
 124  }
 125}

Methods/Properties

get_Name()