|
2 | 2 | using Api.Controllers.Models; |
3 | 3 | using Api.Database.Models; |
4 | 4 | using Api.Services; |
| 5 | +using Api.Services.Models; |
5 | 6 | using Api.Test.Database; |
6 | 7 | using Microsoft.Extensions.DependencyInjection; |
7 | 8 | using Testcontainers.PostgreSql; |
@@ -75,5 +76,165 @@ await DatabaseUtilities.NewMissionRun( |
75 | 76 | // We expect two new missions since a return home mission will also be scheduled |
76 | 77 | Assert.Equal(nReportsBefore + 1, nReportsAfter); |
77 | 78 | } |
| 79 | + |
| 80 | + [Fact] |
| 81 | + public async Task CheckThatReturnHomeIsNotDeletedWhenPreviousMissionWasOutsideInspectionArea() |
| 82 | + { |
| 83 | + // Arrange |
| 84 | + var installation = await DatabaseUtilities.NewInstallation(); |
| 85 | + var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode); |
| 86 | + var inspectionArea1 = await DatabaseUtilities.NewInspectionArea( |
| 87 | + installation.InstallationCode, |
| 88 | + plant.PlantCode, |
| 89 | + inspectionAreaName: "Inspection area 1", |
| 90 | + new InspectionAreaPolygon |
| 91 | + { |
| 92 | + ZMin = 0, |
| 93 | + ZMax = 10, |
| 94 | + Positions = |
| 95 | + [ |
| 96 | + new XYPosition(x: 0, y: 0), |
| 97 | + new XYPosition(x: 0, y: 10), |
| 98 | + new XYPosition(x: 10, y: 10), |
| 99 | + new XYPosition(x: 10, y: 0), |
| 100 | + ], |
| 101 | + } |
| 102 | + ); |
| 103 | + var inspectionArea2 = await DatabaseUtilities.NewInspectionArea( |
| 104 | + installation.InstallationCode, |
| 105 | + plant.PlantCode, |
| 106 | + inspectionAreaName: "Inspection area 2", |
| 107 | + new InspectionAreaPolygon |
| 108 | + { |
| 109 | + ZMin = 0, |
| 110 | + ZMax = 10, |
| 111 | + Positions = |
| 112 | + [ |
| 113 | + new XYPosition(x: 0, y: 0), |
| 114 | + new XYPosition(x: 0, y: -10), |
| 115 | + new XYPosition(x: -10, y: -10), |
| 116 | + new XYPosition(x: -10, y: 0), |
| 117 | + ], |
| 118 | + } |
| 119 | + ); |
| 120 | + |
| 121 | + var taskOutsideInspectionArea = new MissionTask( |
| 122 | + new Pose(-5, -5, 0, 0, 0, 0, 0), |
| 123 | + MissionTaskType.Inspection |
| 124 | + ); |
| 125 | + var returnHomeTask = new MissionTask( |
| 126 | + new Pose(0, 0, 0, 0, 0, 0, 0), |
| 127 | + MissionTaskType.Inspection |
| 128 | + ); |
| 129 | + |
| 130 | + var robot = await DatabaseUtilities.NewRobot( |
| 131 | + RobotStatus.Available, |
| 132 | + installation, |
| 133 | + inspectionArea2 |
| 134 | + ); |
| 135 | + await DatabaseUtilities.NewMissionRun( |
| 136 | + installation.InstallationCode, |
| 137 | + robot, |
| 138 | + inspectionArea1, |
| 139 | + writeToDatabase: true, |
| 140 | + missionRunType: MissionRunType.ReturnHome, |
| 141 | + tasks: [returnHomeTask] |
| 142 | + ); |
| 143 | + await DatabaseUtilities.NewMissionRun( |
| 144 | + installation.InstallationCode, |
| 145 | + robot, |
| 146 | + inspectionArea1, |
| 147 | + writeToDatabase: true, |
| 148 | + tasks: [taskOutsideInspectionArea] |
| 149 | + ); |
| 150 | + |
| 151 | + // Act |
| 152 | + await MissionSchedulingService.StartNextMissionRunIfSystemIsAvailable(robot); |
| 153 | + |
| 154 | + // Assert |
| 155 | + var reportsAfter = await MissionRunService.ReadAll( |
| 156 | + new MissionRunQueryStringParameters() |
| 157 | + ); |
| 158 | + |
| 159 | + // TODO: the mission still exists, it is however aborted. Need to check why no return home mission scheduled |
| 160 | + |
| 161 | + Assert.Equal(2, reportsAfter.Count); |
| 162 | + Assert.False(reportsAfter[0].IsReturnHomeMission()); |
| 163 | + Assert.Equal(MissionStatus.Aborted, reportsAfter[0].Status); |
| 164 | + Assert.True(reportsAfter[1].IsReturnHomeMission()); |
| 165 | + Assert.Equal(MissionStatus.Ongoing, reportsAfter[1].Status); |
| 166 | + } |
| 167 | + |
| 168 | + [Fact] |
| 169 | + public async Task CheckThatReturnHomeIsNotScheduledWhenFailingToStartFirstMission() |
| 170 | + { |
| 171 | + // Arrange |
| 172 | + var installation = await DatabaseUtilities.NewInstallation(); |
| 173 | + var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode); |
| 174 | + var inspectionArea1 = await DatabaseUtilities.NewInspectionArea( |
| 175 | + installation.InstallationCode, |
| 176 | + plant.PlantCode, |
| 177 | + inspectionAreaName: "Inspection area 1", |
| 178 | + new InspectionAreaPolygon |
| 179 | + { |
| 180 | + ZMin = 0, |
| 181 | + ZMax = 10, |
| 182 | + Positions = |
| 183 | + [ |
| 184 | + new XYPosition(x: 0, y: 0), |
| 185 | + new XYPosition(x: 0, y: 10), |
| 186 | + new XYPosition(x: 10, y: 10), |
| 187 | + new XYPosition(x: 10, y: 0), |
| 188 | + ], |
| 189 | + } |
| 190 | + ); |
| 191 | + var inspectionArea2 = await DatabaseUtilities.NewInspectionArea( |
| 192 | + installation.InstallationCode, |
| 193 | + plant.PlantCode, |
| 194 | + inspectionAreaName: "Inspection area 2", |
| 195 | + new InspectionAreaPolygon |
| 196 | + { |
| 197 | + ZMin = 0, |
| 198 | + ZMax = 10, |
| 199 | + Positions = |
| 200 | + [ |
| 201 | + new XYPosition(x: 0, y: 0), |
| 202 | + new XYPosition(x: 0, y: -10), |
| 203 | + new XYPosition(x: -10, y: -10), |
| 204 | + new XYPosition(x: -10, y: 0), |
| 205 | + ], |
| 206 | + } |
| 207 | + ); |
| 208 | + |
| 209 | + var taskOutsideInspectionArea = new MissionTask( |
| 210 | + new Pose(-5, -5, 0, 0, 0, 0, 0), |
| 211 | + MissionTaskType.Inspection |
| 212 | + ); |
| 213 | + |
| 214 | + var robot = await DatabaseUtilities.NewRobot( |
| 215 | + RobotStatus.Available, |
| 216 | + installation, |
| 217 | + inspectionArea2 |
| 218 | + ); |
| 219 | + await DatabaseUtilities.NewMissionRun( |
| 220 | + installation.InstallationCode, |
| 221 | + robot, |
| 222 | + inspectionArea1, |
| 223 | + writeToDatabase: true, |
| 224 | + tasks: [taskOutsideInspectionArea] |
| 225 | + ); |
| 226 | + |
| 227 | + // Act |
| 228 | + await MissionSchedulingService.StartNextMissionRunIfSystemIsAvailable(robot); |
| 229 | + |
| 230 | + // Assert |
| 231 | + var reportsAfter = await MissionRunService.ReadAll( |
| 232 | + new MissionRunQueryStringParameters() |
| 233 | + ); |
| 234 | + |
| 235 | + Assert.Single(reportsAfter); |
| 236 | + Assert.False(reportsAfter[0].IsReturnHomeMission()); |
| 237 | + Assert.Equal(MissionStatus.Aborted, reportsAfter[0].Status); |
| 238 | + } |
78 | 239 | } |
79 | 240 | } |
0 commit comments