EDTS: finished tests

This commit is contained in:
alterNERDtive 2022-01-20 15:33:13 +01:00
parent 3f6ad48317
commit c2f5cf3b0c
2 changed files with 46 additions and 7 deletions

View file

@ -20,6 +20,7 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace alterNERDtive.Edna.Edts
{
@ -115,9 +116,9 @@ namespace alterNERDtive.Edna.Edts
/// </summary>
/// <param name="name">A procedurally generated system name.</param>
/// <returns>The system with calculated coordinates.</returns>
public static StarSystem FindSystem(string name)
public static async Task<StarSystem> FindSystem(string name)
{
HttpResponseMessage response = ApiClient.GetAsync($"system_position/{name}").Result;
HttpResponseMessage response = await ApiClient.GetAsync($"system_position/{name}");
// EDTS API gives a 400 status code (and an empty result) if the
// system name is not valid.

View file

@ -17,7 +17,12 @@
// along with EDNA. If not, see &lt;https://www.gnu.org/licenses/&gt;.
// </copyright>
#pragma warning disable SA1615 // Element return value should be documented
#pragma warning disable SA1201 // Elements should appear in the correct order
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using alterNERDtive.Edna.Edts;
using Xunit;
@ -35,10 +40,11 @@ namespace Test.Edts
/// <param name="name">The system name.</param>
[Theory]
[InlineData("Oevasy SG-Y D0")]
public void ProcGen_Valid(string name)
[InlineData("Oevasy AB-C D0-1")]
public async Task ProcGen_Valid(string name)
{
StarSystem system = EdtsApi.FindSystem(name: name);
Assert.Equal(expected: "Oevasy SG-Y D0", actual: system.Name);
StarSystem system = await EdtsApi.FindSystem(name: name);
Assert.Equal(expected: name, actual: system.Name);
}
/// <summary>
@ -48,10 +54,42 @@ namespace Test.Edts
/// <param name="name">The system name.</param>
[Theory]
[InlineData("Ysaveo YG-S D0")]
public void ProcGen_Invalid(string name)
[InlineData("Oevasy SG-Y")]
[InlineData("Oevasy SG-Y D")]
[InlineData("Oevasy SG-Y 0")]
public async Task ProcGen_Invalid(string name)
{
ArgumentException e = Assert.Throws<ArgumentException>(() => EdtsApi.FindSystem(name: name));
ArgumentException e = await Assert.ThrowsAsync<ArgumentException>(() => EdtsApi.FindSystem(name: name));
Assert.Equal(expected: "name", actual: e.ParamName);
}
/// <summary>
/// Pulls some systems from the EDTS API and checks if they still have
/// the previously known coordinates.
/// </summary>
/// <param name="name">The system name.</param>
/// <param name="coords">The expected coordinates.</param>
[Theory]
[MemberData(nameof(Systems))]
public async Task ProcGen_Coordinates(string name, Location coords)
{
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);
}
/// <summary>
/// Gets a list of systems and known coordinates for the ProcGen_Coordinates test.
/// </summary>
public static IEnumerable<object[]> Systems =>
new List<object[]>
{
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) },
};
}
}