diff --git a/EDTS/EdtsApi.cs b/EDTS/EdtsApi.cs index 430e8a2..e38628f 100644 --- a/EDTS/EdtsApi.cs +++ b/EDTS/EdtsApi.cs @@ -33,63 +33,29 @@ namespace alterNERDtive.Edna.Edts public struct StarSystem { /// - /// Initializes a new instance of the struct. + /// Gets or sets the system’s name. /// - /// The system’s name. - /// The system’s coordinates. - public StarSystem(string name, Location coordinates) + public string Name { get; set; } + + /// + /// Gets or sets the system’s coordinates. + /// + public Coordinates Position { get; set; } + + /// + /// Gets or sets the system’s positional uncertainty in light years. + /// + public decimal Uncertainty { get; set; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Really? For this?")] + public struct Coordinates { - (this.Name, this.Coordinates) = (name, coordinates); + public decimal X { get; set; } + + public decimal Y { get; set; } + + public decimal Z { get; set; } } - - /// - /// Gets the system’s name. - /// - public string Name { get; } - - /// - /// Gets the system’s coordinates. - /// - public Location Coordinates { get; } - } - - /// - /// A location in the galaxy, represented by coordinates and a value for - /// precision (all in ly). - /// - public struct Location - { - /// - /// Initializes a new instance of the struct. - /// - /// The x coordinate. - /// The y coordinate. - /// The z coordinate. - /// The available precision. - public Location(int x, int y, int z, int precision) - { - (this.X, this.Y, this.Z, this.Precision) = (x, y, z, precision); - } - - /// - /// Gets the x coordinate. - /// - public int X { get; } - - /// - /// Gets the y coordinate. - /// - public int Y { get; } - - /// - /// Gets the z coordinate. - /// - public int Z { get; } - - /// - /// Gets the precision to which the location can be calculated. - /// - public int Precision { get; private set; } } /// @@ -111,17 +77,8 @@ namespace alterNERDtive.Edna.Edts { try { - ApiResult response = await ApiClient.GetAsync(new RestRequest($"system_position/{name}")); - - ApiResult.ApiSystem result = response.Result!.Value; - - return new StarSystem( - name: name, - coordinates: new Location( - x: (int)result.Position.X, - y: (int)result.Position.Y, - z: (int)result.Position.Z, - precision: (int)result.Uncertainty)); + ApiResult result = await ApiClient.GetAsync(new RestRequest($"system_position/{name}")); + return result.Result!.Value; } catch (HttpRequestException e) { @@ -140,25 +97,7 @@ namespace alterNERDtive.Edna.Edts private struct ApiResult { - public ApiSystem? Result { get; set; } - - public struct ApiSystem - { - public string Name { get; set; } - - public ApiLocation Position { get; set; } - - public decimal Uncertainty { get; set; } - - public struct ApiLocation - { - public decimal X { get; set; } - - public decimal Y { get; set; } - - public decimal Z { get; set; } - } - } + public StarSystem? Result { get; set; } } } } \ No newline at end of file diff --git a/Test/EDTS/LocationTest.cs b/Test/EDTS/LocationTest.cs index 7af76da..0089e91 100644 --- a/Test/EDTS/LocationTest.cs +++ b/Test/EDTS/LocationTest.cs @@ -39,8 +39,8 @@ namespace Test.Edts /// /// The system name. [Theory] - [InlineData("Oevasy SG-Y D0")] - [InlineData("Oevasy AB-C D0-1")] + [InlineData("Oevasy SG-Y d0")] + [InlineData("Oevasy AB-C d1-2")] public async Task ProcGen_Valid(string name) { StarSystem system = await EdtsApi.FindSystem(name: name); @@ -53,9 +53,9 @@ namespace Test.Edts /// /// The system name. [Theory] - [InlineData("Ysaveo YG-S D0")] + [InlineData("Ysaveo YG-S d0")] [InlineData("Oevasy SG-Y")] - [InlineData("Oevasy SG-Y D")] + [InlineData("Oevasy SG-Y d")] [InlineData("Oevasy SG-Y 0")] public async Task ProcGen_Invalid(string name) { @@ -67,17 +67,16 @@ namespace Test.Edts /// Pulls some systems from the EDTS API and checks if they still have /// the previously known coordinates. /// - /// The system name. - /// The expected coordinates. + /// The expected system/coordinates. [Theory] [MemberData(nameof(Systems))] - public async Task ProcGen_Coordinates(string name, Location coords) + public async Task ProcGen_Coordinates(StarSystem testSystem) { - StarSystem system = await EdtsApi.FindSystem(name: name); - Assert.Equal(expected: coords.X, actual: system.Coordinates.X); - Assert.Equal(expected: coords.Y, actual: system.Coordinates.Y); - Assert.Equal(expected: coords.Z, actual: system.Coordinates.Z); - Assert.Equal(expected: coords.Precision, actual: system.Coordinates.Precision); + StarSystem system = await EdtsApi.FindSystem(name: testSystem.Name); + Assert.Equal(expected: testSystem.Position.X, actual: system.Position.X); + Assert.Equal(expected: testSystem.Position.Y, actual: system.Position.Y); + Assert.Equal(expected: testSystem.Position.Z, actual: system.Position.Z); + Assert.Equal(expected: testSystem.Uncertainty, actual: system.Uncertainty); } /// @@ -86,10 +85,10 @@ namespace Test.Edts public static IEnumerable Systems => new List { - new object[] { "Oevasy SG-Y D0", new Location(x: -1465, y: 15, z: 65615, precision: 40) }, - new object[] { "Lysoorb AA-A b0", new Location(x: -55, y: -15, z: 6625, precision: 10) }, - new object[] { "Dryau Aowsy AB-C D1-234", new Location(x: 775, y: 1615, z: 18255, precision: 40) }, - new object[] { "Dryau Aowsy DC-B A4-321", new Location(x: 1170, y: 400, z: 18180, precision: 5) }, + new object[] { new StarSystem { Name = "Oevasy SG-Y D0", Position = new StarSystem.Coordinates { X = -1465, Y = 15, Z = 65615 }, Uncertainty = 40 } }, + new object[] { new StarSystem { Name = "Lysoorb AA-A b0", Position = new StarSystem.Coordinates { X = -55, Y = -15, Z = 6625 }, Uncertainty = 10 } }, + new object[] { new StarSystem { Name = "Dryau Aowsy AB-C D1-234", Position = new StarSystem.Coordinates { X = 775, Y = 1615, Z = 18255 }, Uncertainty = 40 } }, + new object[] { new StarSystem { Name = "Dryau Aowsy DC-B A4-321", Position = new StarSystem.Coordinates { X = 1170, Y = 400, Z = 18180 }, Uncertainty = 5 } }, }; } }