-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,716 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Api.Controllers.Models; | ||
using Api.Database.Models; | ||
using Api.Services; | ||
using Api.Test.Database; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Testcontainers.PostgreSql; | ||
using Xunit; | ||
|
||
namespace Api.Test.Services | ||
{ | ||
public class InspectionAreaServiceTest : IAsyncLifetime | ||
{ | ||
public required DatabaseUtilities DatabaseUtilities; | ||
public required PostgreSqlContainer Container; | ||
public required IMissionRunService MissionRunService; | ||
public required IInspectionAreaService InspectionAreaService; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
(Container, string connectionString, var connection) = | ||
await TestSetupHelpers.ConfigurePostgreSqlDatabase(); | ||
var factory = TestSetupHelpers.ConfigureWebApplicationFactory( | ||
postgreSqlConnectionString: connectionString | ||
); | ||
var serviceProvider = TestSetupHelpers.ConfigureServiceProvider(factory); | ||
|
||
DatabaseUtilities = new DatabaseUtilities( | ||
TestSetupHelpers.ConfigurePostgreSqlContext(connectionString) | ||
); | ||
MissionRunService = serviceProvider.GetRequiredService<IMissionRunService>(); | ||
InspectionAreaService = serviceProvider.GetRequiredService<IInspectionAreaService>(); | ||
} | ||
|
||
public Task DisposeAsync() => Task.CompletedTask; | ||
|
||
[Fact] | ||
public async Task TestTasksInsidePolygon() | ||
{ | ||
var installation = await DatabaseUtilities.NewInstallation(); | ||
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode); | ||
var inspectionArea = await DatabaseUtilities.NewInspectionArea( | ||
installation.InstallationCode, | ||
plant.PlantCode | ||
); | ||
inspectionArea.AreaPolygonJson = | ||
@"{ | ||
""zmin"": 0, | ||
""zmax"": 10, | ||
""positions"": [ | ||
{ ""x"": 0, ""y"": 0 }, | ||
{ ""x"": 0, ""y"": 10 }, | ||
{ ""x"": 10, ""y"": 10 }, | ||
{ ""x"": 10, ""y"": 0 } | ||
] | ||
}"; | ||
|
||
List<MissionTask> missionTasks = | ||
[ | ||
new(new Pose(1, 1, 1, 0, 0, 0, 1), MissionTaskType.Inspection), | ||
new(new Pose(2, 2, 2, 0, 0, 0, 1), MissionTaskType.ReturnHome), | ||
]; | ||
|
||
var testBool = InspectionAreaService.MissionTasksAreInsideInspectionAreaPolygon( | ||
missionTasks, | ||
inspectionArea | ||
); | ||
Assert.True(testBool); | ||
} | ||
|
||
[Fact] | ||
public async Task TestTasksOutsidePolygon() | ||
{ | ||
var installation = await DatabaseUtilities.NewInstallation(); | ||
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode); | ||
var inspectionArea = await DatabaseUtilities.NewInspectionArea( | ||
installation.InstallationCode, | ||
plant.PlantCode | ||
); | ||
inspectionArea.AreaPolygonJson = | ||
@"{ | ||
""zmin"": 0, | ||
""zmax"": 10, | ||
""positions"": [ | ||
{ ""x"": 0, ""y"": 0 }, | ||
{ ""x"": 0, ""y"": 10 }, | ||
{ ""x"": 10, ""y"": 10 }, | ||
{ ""x"": 10, ""y"": 0 } | ||
] | ||
}"; | ||
List<MissionTask> missionTasks = | ||
[ | ||
new(new Pose(1, 1, 1, 0, 0, 0, 1), MissionTaskType.ReturnHome), | ||
new(new Pose(11, 11, 11, 0, 0, 0, 1), MissionTaskType.ReturnHome), | ||
]; | ||
|
||
var testBool = InspectionAreaService.MissionTasksAreInsideInspectionAreaPolygon( | ||
missionTasks, | ||
inspectionArea | ||
); | ||
Assert.False(testBool); | ||
} | ||
} | ||
} |
Oops, something went wrong.