Skip to content

Commit

Permalink
Update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Christdej committed Jul 24, 2024
1 parent 1cc8013 commit 20f0e05
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 91 deletions.
18 changes: 9 additions & 9 deletions backend/api.test/Client/AreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task AreaTest()
Assert.True(deckResponse.IsSuccessStatusCode);
Assert.True(areaResponse.IsSuccessStatusCode);
var area = await areaResponse.Content.ReadFromJsonAsync<AreaResponse>(_serializerOptions);
Assert.True(area != null);
Assert.NotNull(area);
}

[Fact]
Expand All @@ -145,7 +145,7 @@ public async Task MissionIsCreatedInArea()
var robotResponse = await _client.GetAsync(robotUrl);
Assert.True(robotResponse.IsSuccessStatusCode);
var robots = await robotResponse.Content.ReadFromJsonAsync<List<Robot>>(_serializerOptions);
Assert.True(robots != null);
Assert.NotNull(robots);
var robot = robots.Where(robot => robot.Name == "Shockwave").First();
string robotId = robot.Id;

Expand All @@ -154,15 +154,15 @@ public async Task MissionIsCreatedInArea()
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installations = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installations != null);
Assert.NotNull(installations);
var installation = installations.Where(installation => installation.InstallationCode == robot.CurrentInstallation?.InstallationCode).First();

// Area
string areaUrl = "/areas";
var areaResponse = await _client.GetAsync(areaUrl);
Assert.True(areaResponse.IsSuccessStatusCode);
var areas = await areaResponse.Content.ReadFromJsonAsync<List<AreaResponse>>(_serializerOptions);
Assert.True(areas != null);
Assert.NotNull(areas);
var area = areas.Where(area => area.InstallationCode == installation.InstallationCode).First();
string areaId = area.Id;

Expand Down Expand Up @@ -229,7 +229,7 @@ public async Task SafePositionTest()
var areaResponse = await _client.GetAsync(areaUrl);
Assert.True(areaResponse.IsSuccessStatusCode);
var areaResponses = await areaResponse.Content.ReadFromJsonAsync<List<AreaResponse>>(_serializerOptions);
Assert.True(areaResponses != null);
Assert.NotNull(areaResponses);
var area = areaResponses[0];
string areaName = area.AreaName;
string installationCode = area.InstallationCode;
Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task SafePositionTest()
areaResponse = await _client.PostAsync(addSafePositionUrl, content);
Assert.True(areaResponse.IsSuccessStatusCode);
var areaContent = await areaResponse.Content.ReadFromJsonAsync<AreaResponse>(_serializerOptions);
Assert.True(areaContent != null);
Assert.NotNull(areaContent);

// Act
string goToSafePositionUrl = $"/emergency-action/{installationCode}/abort-current-missions-and-send-all-robots-to-safe-zone";
Expand All @@ -282,7 +282,7 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
var deckResponse = await _client.GetAsync(deckUrl);
Assert.True(deckResponse.IsSuccessStatusCode);
var decks = await deckResponse.Content.ReadFromJsonAsync<List<DeckResponse>>(_serializerOptions);
Assert.True(decks != null);
Assert.NotNull(decks);
var deck = decks[0];
string deckId = deck.Id;

Expand Down Expand Up @@ -314,8 +314,8 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
var putResponse = await _client.PutAsync(url, content);
Assert.True(putResponse.IsSuccessStatusCode);
var putDeck = await putResponse.Content.ReadFromJsonAsync<DeckResponse>(_serializerOptions);
Assert.True(putDeck != null);
Assert.True(putDeck.DefaultLocalizationPose != null);
Assert.NotNull(putDeck);
Assert.NotNull(putDeck.DefaultLocalizationPose);
Assert.True(putDeck.DefaultLocalizationPose.Position.Z.Equals(query.Pose.Position.Z));
Assert.True(putDeck.DefaultLocalizationPose.Orientation.W.Equals(query.Pose.Orientation.W));
}
Expand Down
60 changes: 30 additions & 30 deletions backend/api.test/Client/MissionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private async Task<T> PostToDb<T, TQueryType>(string postUrl, TQueryType stringC
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installationResponses = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installationResponses != null);
Assert.NotNull(installationResponses);
return installationResponses.Where((i) => i.InstallationCode.Equals(installationCode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
}

Expand All @@ -73,14 +73,14 @@ private async Task<T> PostToDb<T, TQueryType>(string postUrl, TQueryType stringC
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installationResponses = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installationResponses != null);
Assert.NotNull(installationResponses);
if (!installationResponses.Where((i) => i.InstallationCode.Equals(installationCode, StringComparison.OrdinalIgnoreCase)).Any()) return null;

string plantUrl = "/plants";
var plantResponse = await _client.GetAsync(plantUrl);
Assert.True(plantResponse.IsSuccessStatusCode);
var plantResponses = await plantResponse.Content.ReadFromJsonAsync<List<Plant>>(_serializerOptions);
Assert.True(plantResponses != null);
Assert.NotNull(plantResponses);
return plantResponses.Where((p) => p.PlantCode.Equals(plantCode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
}

Expand All @@ -90,21 +90,21 @@ private async Task<T> PostToDb<T, TQueryType>(string postUrl, TQueryType stringC
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installationResponses = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installationResponses != null);
Assert.NotNull(installationResponses);
if (!installationResponses.Where((i) => i.InstallationCode.Equals(installationCode.ToLower(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase)).Any()) return null;

string plantUrl = "/plants";
var plantResponse = await _client.GetAsync(plantUrl);
Assert.True(plantResponse.IsSuccessStatusCode);
var plantResponses = await plantResponse.Content.ReadFromJsonAsync<List<Plant>>(_serializerOptions);
Assert.True(plantResponses != null);
Assert.NotNull(plantResponses);
if (!plantResponses.Where((p) => p.PlantCode.Equals(plantCode.ToLower(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase)).Any()) return null;

string deckUrl = "/decks";
var deckResponse = await _client.GetAsync(deckUrl);
Assert.True(deckResponse.IsSuccessStatusCode);
var deckResponses = await deckResponse.Content.ReadFromJsonAsync<List<DeckResponse>>(_serializerOptions);
Assert.True(deckResponses != null);
Assert.NotNull(deckResponses);
return deckResponses.Where((d) => d.DeckName.Equals(deckName.ToLower(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
}

Expand All @@ -114,7 +114,7 @@ private async Task VerifyNonDuplicateAreaDbNames(string areaName)
var areaResponse = await _client.GetAsync(areaUrl);
Assert.True(areaResponse.IsSuccessStatusCode);
var areaResponses = await areaResponse.Content.ReadFromJsonAsync<List<AreaResponse>>(_serializerOptions);
Assert.True(areaResponses != null);
Assert.NotNull(areaResponses);
Assert.False(areaResponses.Where((a) => a.AreaName == areaName).Any(), $"Duplicate area name detected: {areaName}");
}

Expand All @@ -124,7 +124,7 @@ private async Task VerifyNonDuplicateInstallationDbName(string installationCode)
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installationResponses = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installationResponses != null);
Assert.NotNull(installationResponses);
Assert.False(installationResponses.Where((i) => i.InstallationCode == installationCode).Any(), $"Duplicate installation name detected: {installationCode}");
}

Expand Down Expand Up @@ -269,7 +269,7 @@ public async Task ScheduleOneEchoMissionTest()
var response = await _client.GetAsync(robotUrl);
Assert.True(response.IsSuccessStatusCode, $"Failed to get robot from path: {robotUrl}, with status code {response.StatusCode}");
var robots = await response.Content.ReadFromJsonAsync<List<Robot>>(_serializerOptions);
Assert.True(robots != null);
Assert.NotNull(robots);
var robot = robots.Where(robot => robot.Name == "Shockwave").First();
string robotId = robot.Id;

Expand Down Expand Up @@ -302,9 +302,9 @@ public async Task ScheduleOneEchoMissionTest()
// Assert
Assert.True(response.IsSuccessStatusCode);
var missionRun = await response.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.True(missionRun != null);
Assert.True(missionRun.Id != null);
Assert.True(missionRun.Status == MissionStatus.Pending);
Assert.NotNull(missionRun);
Assert.NotNull(missionRun.Id);
Assert.Equal(MissionStatus.Pending, missionRun.Status);
}

[Fact]
Expand All @@ -316,7 +316,7 @@ public async Task Schedule3EchoMissionsTest()
var robotResponse = await _client.GetAsync(robotUrl);
Assert.True(robotResponse.IsSuccessStatusCode);
var robots = await robotResponse.Content.ReadFromJsonAsync<List<Robot>>(_serializerOptions);
Assert.True(robots != null);
Assert.NotNull(robots);
var robot = robots.Where(robot => robot.Name == "Shockwave").First();
string robotId = robot.Id;

Expand Down Expand Up @@ -351,7 +351,7 @@ public async Task Schedule3EchoMissionsTest()
_serializerOptions
);
Assert.True(response.IsSuccessStatusCode);
Assert.True(missionRuns != null);
Assert.NotNull(missionRuns);
int missionRunsBefore = missionRuns.Count;

response = await _client.PostAsync(missionsUrl, content);
Expand All @@ -362,17 +362,17 @@ public async Task Schedule3EchoMissionsTest()
response = await _client.PostAsync(missionsUrl, content);
var missionRun1 = await response.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.True(response.IsSuccessStatusCode);
Assert.True(missionRun1 != null);
Assert.NotNull(missionRun1);

response = await _client.PostAsync(missionsUrl, content);
var missionRun2 = await response.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.True(response.IsSuccessStatusCode);
Assert.True(missionRun2 != null);
Assert.NotNull(missionRun2);

response = await _client.PostAsync(missionsUrl, content);
var missionRun3 = await response.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.True(response.IsSuccessStatusCode);
Assert.True(missionRun3 != null);
Assert.NotNull(missionRun3);

response = await _client.GetAsync(urlMissionRuns);
missionRuns = await response.Content.ReadFromJsonAsync<List<MissionRun>>(
Expand All @@ -381,10 +381,10 @@ public async Task Schedule3EchoMissionsTest()

// Assert
Assert.True(response.IsSuccessStatusCode);
Assert.True(missionRuns != null);
Assert.True(missionRuns.Where((m) => m.Id == missionRun1.Id).ToList().Count == 1);
Assert.True(missionRuns.Where((m) => m.Id == missionRun2.Id).ToList().Count == 1);
Assert.True(missionRuns.Where((m) => m.Id == missionRun3.Id).ToList().Count == 1);
Assert.NotNull(missionRuns);
Assert.Single(missionRuns.Where((m) => m.Id == missionRun1.Id).ToList());
Assert.Single(missionRuns.Where((m) => m.Id == missionRun2.Id).ToList());
Assert.Single(missionRuns.Where((m) => m.Id == missionRun3.Id).ToList());
}

[Fact]
Expand Down Expand Up @@ -521,7 +521,7 @@ public async Task ScheduleDuplicateCustomMissionDefinitions()
var missionDefinitionsResponse = await _client.GetAsync(missionDefinitionsUrl);
var missionDefinitions = await missionDefinitionsResponse.Content.ReadFromJsonAsync<List<MissionDefinition>>(_serializerOptions);
Assert.NotNull(missionDefinitions);
Assert.True(missionDefinitions.Where(m => m.Id == missionId1).Count() == 1);
Assert.Single(missionDefinitions.Where(m => m.Id == missionId1));
}

[Fact]
Expand Down Expand Up @@ -583,10 +583,10 @@ public async Task GetNextRun()
var response = await _client.PostAsync(customMissionsUrl, content);
Assert.True(response.IsSuccessStatusCode);
var missionRun = await response.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.True(missionRun != null);
Assert.True(missionRun.MissionId != null);
Assert.True(missionRun.Id != null);
Assert.True(missionRun.Status == MissionStatus.Pending);
Assert.NotNull(missionRun);
Assert.NotNull(missionRun.MissionId);
Assert.NotNull(missionRun.Id);
Assert.Equal(MissionStatus.Pending, missionRun.Status);

// Arrange - Schedule missions from mission definition
var scheduleQuery1 = new ScheduleMissionQuery
Expand Down Expand Up @@ -659,7 +659,7 @@ public async Task ScheduleDuplicateEchoMissionDefinitions()
var response = await _client.GetAsync(robotUrl);
Assert.True(response.IsSuccessStatusCode);
var robots = await response.Content.ReadFromJsonAsync<List<Robot>>(_serializerOptions);
Assert.True(robots != null);
Assert.NotNull(robots);
var robot = robots.Where(robot => robot.Name == "Shockwave").First();
string robotId = robot.Id;
int echoMissionId = 1; // Corresponds to mock in EchoServiceMock.cs
Expand Down Expand Up @@ -770,7 +770,7 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
// Act
string customMissionsUrl = "/missions/custom";
var response = await _client.PostAsync(customMissionsUrl, content);
Assert.True(response.StatusCode == HttpStatusCode.Conflict);
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
}

[Fact]
Expand Down Expand Up @@ -844,15 +844,15 @@ public async Task MissionFailsIfRobotIsNotInSameDeckAsMission()
Assert.True(missionResponse.IsSuccessStatusCode);
var missionRun = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.NotNull(missionRun);
Assert.True(missionRun.Status == MissionStatus.Pending);
Assert.Equal(MissionStatus.Pending, missionRun.Status);

await Task.Delay(2000);
string missionRunByIdUrl = $"/missions/runs/{missionRun.Id}";
var missionByIdResponse = await _client.GetAsync(missionRunByIdUrl);
Assert.True(missionByIdResponse.IsSuccessStatusCode);
var missionRunAfterUpdate = await missionByIdResponse.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.NotNull(missionRunAfterUpdate);
Assert.True(missionRunAfterUpdate.Status == MissionStatus.Aborted);
Assert.Equal(MissionStatus.Aborted, missionRunAfterUpdate.Status);
}
}
}
6 changes: 3 additions & 3 deletions backend/api.test/Client/RobotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task RobotsTest()
var response = await _client.GetAsync(url);
var robots = await response.Content.ReadFromJsonAsync<List<RobotResponse>>(_serializerOptions);
Assert.True(response.IsSuccessStatusCode);
Assert.True(robots != null);
Assert.NotNull(robots);
}

[Fact]
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
var areaResponse = await _client.GetAsync(areaUrl);
Assert.True(areaResponse.IsSuccessStatusCode);
var areas = await areaResponse.Content.ReadFromJsonAsync<List<AreaResponse>>(_serializerOptions);
Assert.True(areas != null);
Assert.NotNull(areas);
var area = areas[0];

// Installation
Expand All @@ -106,7 +106,7 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
var installationResponse = await _client.PostAsync(installationUrl, installationContent);
Assert.True(installationResponse.IsSuccessStatusCode);
var wrongInstallation = await installationResponse.Content.ReadFromJsonAsync<Installation>(_serializerOptions);
Assert.True(wrongInstallation != null);
Assert.NotNull(wrongInstallation);

// Arrange - Create robot
var robotQuery = new CreateRobotQuery
Expand Down
8 changes: 4 additions & 4 deletions backend/api.test/Client/RoleAccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task AuthorisedGetPlantTest_NotFound()
Assert.True(plantResponse.IsSuccessStatusCode);

var plant = await plantResponse.Content.ReadFromJsonAsync<Plant>(_serializerOptions);
Assert.True(plant != null);
Assert.NotNull(plant);

// Act
string getPlantUrl = $"/plants/{plant.Id}";
Expand Down Expand Up @@ -244,7 +244,7 @@ public async Task ExplicitlyAuthorisedPostInstallationPlantDeckAndAreaTest()
Assert.True(deckResponse.IsSuccessStatusCode);
Assert.True(areaResponse.IsSuccessStatusCode);
var area = await areaResponse.Content.ReadFromJsonAsync<AreaResponse>(_serializerOptions);
Assert.True(area != null);
Assert.NotNull(area);

// Act
string getAreaUrl = $"/areas/{area.Id}";
Expand All @@ -253,7 +253,7 @@ public async Task ExplicitlyAuthorisedPostInstallationPlantDeckAndAreaTest()
// Assert
Assert.True(sameAreaResponse.IsSuccessStatusCode);
var sameArea = await sameAreaResponse.Content.ReadFromJsonAsync<AreaResponse>(_serializerOptions);
Assert.True(sameArea != null);
Assert.NotNull(sameArea);
Assert.Equal(sameArea.Id, area.Id);
}

Expand Down Expand Up @@ -351,7 +351,7 @@ public async Task AdminAuthorisedPostInstallationPlantDeckAndAreaTest()
Assert.True(deckResponse.IsSuccessStatusCode);
Assert.True(areaResponse.IsSuccessStatusCode);
var area = await areaResponse.Content.ReadFromJsonAsync<AreaResponse>(_serializerOptions);
Assert.True(area != null);
Assert.NotNull(area);
}
}
}
Loading

0 comments on commit 20f0e05

Please sign in to comment.