13
13
using Api . Test . Database ;
14
14
using Microsoft . AspNetCore . Mvc . Testing ;
15
15
using Xunit ;
16
+
16
17
namespace Api . Test . Client
17
18
{
18
19
[ Collection ( "Database collection" ) ]
@@ -23,27 +24,27 @@ public class AreaTests : IClassFixture<TestWebApplicationFactory<Program>>
23
24
private readonly JsonSerializerOptions _serializerOptions =
24
25
new ( )
25
26
{
26
- Converters =
27
- {
28
- new JsonStringEnumConverter ( )
29
- } ,
30
- PropertyNameCaseInsensitive = true
27
+ Converters = { new JsonStringEnumConverter ( ) } ,
28
+ PropertyNameCaseInsensitive = true ,
31
29
} ;
32
30
33
31
public AreaTests ( TestWebApplicationFactory < Program > factory )
34
32
{
35
- _client = factory . CreateClient ( new WebApplicationFactoryClientOptions
36
- {
37
- AllowAutoRedirect = false ,
38
- BaseAddress = new Uri ( "https://localhost:8000" )
39
- } ) ;
33
+ _client = factory . CreateClient (
34
+ new WebApplicationFactoryClientOptions
35
+ {
36
+ AllowAutoRedirect = false ,
37
+ BaseAddress = new Uri ( "https://localhost:8000" ) ,
38
+ }
39
+ ) ;
40
40
_client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue (
41
41
TestAuthHandler . AuthenticationScheme
42
42
) ;
43
43
44
- object ? context = factory . Services . GetService ( typeof ( FlotillaDbContext ) ) as FlotillaDbContext ?? throw new ArgumentNullException ( nameof ( factory ) ) ;
44
+ object ? context =
45
+ factory . Services . GetService ( typeof ( FlotillaDbContext ) ) as FlotillaDbContext
46
+ ?? throw new ArgumentNullException ( nameof ( factory ) ) ;
45
47
_databaseUtilities = new DatabaseUtilities ( ( FlotillaDbContext ) context ) ;
46
-
47
48
}
48
49
49
50
[ Fact ]
@@ -56,38 +57,38 @@ public async Task AreaTest()
56
57
{
57
58
X = 1 ,
58
59
Y = 2 ,
59
- Z = 2
60
+ Z = 2 ,
60
61
} ,
61
62
Orientation = new Orientation
62
63
{
63
64
X = 0 ,
64
65
Y = 0 ,
65
66
Z = 0 ,
66
- W = 1
67
- }
67
+ W = 1 ,
68
+ } ,
68
69
} ;
69
70
70
71
string testInstallation = "TestInstallationAreaTest" ;
71
72
var installationQuery = new CreateInstallationQuery
72
73
{
73
74
InstallationCode = testInstallation ,
74
- Name = testInstallation
75
+ Name = testInstallation ,
75
76
} ;
76
77
77
78
string testPlant = "TestPlantAreaTest" ;
78
79
var plantQuery = new CreatePlantQuery
79
80
{
80
81
InstallationCode = testInstallation ,
81
82
PlantCode = testPlant ,
82
- Name = testPlant
83
+ Name = testPlant ,
83
84
} ;
84
85
85
86
string testDeck = "testDeckAreaTest" ;
86
87
var deckQuery = new CreateDeckQuery
87
88
{
88
89
InstallationCode = testInstallation ,
89
90
PlantCode = testPlant ,
90
- Name = testDeck
91
+ Name = testDeck ,
91
92
} ;
92
93
93
94
string testArea = "testAreaAreaTest" ;
@@ -97,7 +98,7 @@ public async Task AreaTest()
97
98
PlantCode = testPlant ,
98
99
DeckName = testDeck ,
99
100
AreaName = testArea ,
100
- DefaultLocalizationPose = testPose
101
+ DefaultLocalizationPose = testPose ,
101
102
} ;
102
103
103
104
var installationContent = new StringContent (
@@ -126,7 +127,10 @@ public async Task AreaTest()
126
127
127
128
// Act
128
129
string installationUrl = "/installations" ;
129
- var installationResponse = await _client . PostAsync ( installationUrl , installationContent ) ;
130
+ var installationResponse = await _client . PostAsync (
131
+ installationUrl ,
132
+ installationContent
133
+ ) ;
130
134
string plantUrl = "/plants" ;
131
135
var plantResponse = await _client . PostAsync ( plantUrl , plantContent ) ;
132
136
string deckUrl = "/decks" ;
@@ -139,7 +143,9 @@ public async Task AreaTest()
139
143
Assert . True ( plantResponse . IsSuccessStatusCode ) ;
140
144
Assert . True ( deckResponse . IsSuccessStatusCode ) ;
141
145
Assert . True ( areaResponse . IsSuccessStatusCode ) ;
142
- var area = await areaResponse . Content . ReadFromJsonAsync < AreaResponse > ( _serializerOptions ) ;
146
+ var area = await areaResponse . Content . ReadFromJsonAsync < AreaResponse > (
147
+ _serializerOptions
148
+ ) ;
143
149
Assert . NotNull ( area ) ;
144
150
}
145
151
@@ -149,7 +155,10 @@ public async Task MissionIsCreatedInInspectionArea()
149
155
// Arrange - Initialise area
150
156
var installation = await _databaseUtilities . ReadOrNewInstallation ( ) ;
151
157
var plant = await _databaseUtilities . ReadOrNewPlant ( installation . InstallationCode ) ;
152
- var deck = await _databaseUtilities . ReadOrNewDeck ( installation . InstallationCode , plant . PlantCode ) ;
158
+ var deck = await _databaseUtilities . ReadOrNewDeck (
159
+ installation . InstallationCode ,
160
+ plant . PlantCode
161
+ ) ;
153
162
154
163
// Arrange - Robot
155
164
var robot = await _databaseUtilities . NewRobot ( RobotStatus . Available , installation ) ;
@@ -161,7 +170,7 @@ public async Task MissionIsCreatedInInspectionArea()
161
170
{
162
171
AnalysisType = AnalysisType . CarSeal ,
163
172
InspectionTarget = new Position ( ) ,
164
- InspectionType = InspectionType . Image
173
+ InspectionType = InspectionType . Image ,
165
174
} ;
166
175
var tasks = new List < CustomTaskQuery >
167
176
{
@@ -170,8 +179,8 @@ public async Task MissionIsCreatedInInspectionArea()
170
179
Inspection = inspection ,
171
180
TagId = "test" ,
172
181
RobotPose = new Pose ( ) ,
173
- TaskOrder = 0
174
- }
182
+ TaskOrder = 0 ,
183
+ } ,
175
184
} ;
176
185
var missionQuery = new CustomMissionQuery
177
186
{
@@ -180,7 +189,7 @@ public async Task MissionIsCreatedInInspectionArea()
180
189
InstallationCode = installation . InstallationCode ,
181
190
InspectionAreaName = deck . Name ,
182
191
Name = testMissionName ,
183
- Tasks = tasks
192
+ Tasks = tasks ,
184
193
} ;
185
194
186
195
var missionContent = new StringContent (
@@ -194,17 +203,25 @@ public async Task MissionIsCreatedInInspectionArea()
194
203
var missionResponse = await _client . PostAsync ( missionUrl , missionContent ) ;
195
204
196
205
Assert . True ( missionResponse . IsSuccessStatusCode ) ;
197
- var mission = await missionResponse . Content . ReadFromJsonAsync < MissionRun > ( _serializerOptions ) ;
206
+ var mission = await missionResponse . Content . ReadFromJsonAsync < MissionRun > (
207
+ _serializerOptions
208
+ ) ;
198
209
Assert . NotNull ( mission ) ;
199
210
Assert . NotNull ( mission . MissionId ) ;
200
211
string inspectionAreaUrl = "/decks" ;
201
- var inspectionareaMissionsResponse = await _client . GetAsync ( inspectionAreaUrl + $ "/{ deck . Id } /mission-definitions") ;
212
+ var inspectionareaMissionsResponse = await _client . GetAsync (
213
+ inspectionAreaUrl + $ "/{ deck . Id } /mission-definitions"
214
+ ) ;
202
215
203
216
// Assert
204
217
Assert . True ( inspectionareaMissionsResponse . IsSuccessStatusCode ) ;
205
- var missions = await inspectionareaMissionsResponse . Content . ReadFromJsonAsync < IList < MissionDefinitionResponse > > ( _serializerOptions ) ;
218
+ var missions = await inspectionareaMissionsResponse . Content . ReadFromJsonAsync <
219
+ IList < MissionDefinitionResponse >
220
+ > ( _serializerOptions ) ;
206
221
Assert . NotNull ( missions ) ;
207
- Assert . Single ( missions . Where ( m => m . Id . Equals ( mission . MissionId , StringComparison . Ordinal ) ) ) ;
222
+ Assert . Single (
223
+ missions . Where ( m => m . Id . Equals ( mission . MissionId , StringComparison . Ordinal ) )
224
+ ) ;
208
225
}
209
226
210
227
[ Fact ]
@@ -214,9 +231,9 @@ public async Task EmergencyDockTest()
214
231
var installation = await _databaseUtilities . ReadOrNewInstallation ( ) ;
215
232
string installationCode = installation . InstallationCode ;
216
233
217
-
218
234
// Act
219
- string goToDockingPositionUrl = $ "/emergency-action/{ installationCode } /abort-current-missions-and-send-all-robots-to-safe-zone";
235
+ string goToDockingPositionUrl =
236
+ $ "/emergency-action/{ installationCode } /abort-current-missions-and-send-all-robots-to-safe-zone";
220
237
var missionResponse = await _client . PostAsync ( goToDockingPositionUrl , null ) ;
221
238
222
239
// Assert
@@ -233,7 +250,10 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
233
250
// Arrange
234
251
var installation = await _databaseUtilities . ReadOrNewInstallation ( ) ;
235
252
var plant = await _databaseUtilities . ReadOrNewPlant ( installation . InstallationCode ) ;
236
- var deck = await _databaseUtilities . ReadOrNewDeck ( installation . InstallationCode , plant . PlantCode ) ;
253
+ var deck = await _databaseUtilities . ReadOrNewDeck (
254
+ installation . InstallationCode ,
255
+ plant . PlantCode
256
+ ) ;
237
257
238
258
string deckId = deck . Id ;
239
259
@@ -246,16 +266,16 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
246
266
{
247
267
X = 1 ,
248
268
Y = 2 ,
249
- Z = 3
269
+ Z = 3 ,
250
270
} ,
251
271
Orientation = new Orientation
252
272
{
253
273
X = 0 ,
254
274
Y = 0 ,
255
275
Z = 0 ,
256
- W = 1
257
- }
258
- }
276
+ W = 1 ,
277
+ } ,
278
+ } ,
259
279
} ;
260
280
var content = new StringContent (
261
281
JsonSerializer . Serialize ( query ) ,
@@ -266,13 +286,17 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
266
286
// Act
267
287
var putResponse = await _client . PutAsync ( url , content ) ;
268
288
Assert . True ( putResponse . IsSuccessStatusCode ) ;
269
- var putDeck = await putResponse . Content . ReadFromJsonAsync < DeckResponse > ( _serializerOptions ) ;
289
+ var putDeck = await putResponse . Content . ReadFromJsonAsync < DeckResponse > (
290
+ _serializerOptions
291
+ ) ;
270
292
271
293
// Assert
272
294
Assert . NotNull ( putDeck ) ;
273
295
Assert . NotNull ( putDeck . DefaultLocalizationPose ) ;
274
296
Assert . True ( putDeck . DefaultLocalizationPose . Position . Z . Equals ( query . Pose . Position . Z ) ) ;
275
- Assert . True ( putDeck . DefaultLocalizationPose . Orientation . W . Equals ( query . Pose . Orientation . W ) ) ;
297
+ Assert . True (
298
+ putDeck . DefaultLocalizationPose . Orientation . W . Equals ( query . Pose . Orientation . W )
299
+ ) ;
276
300
}
277
301
}
278
302
}
0 commit comments