Skip to content

Commit

Permalink
Fix csharpier not running in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Christdej committed Dec 19, 2024
1 parent 1739672 commit 5fb3a8b
Show file tree
Hide file tree
Showing 140 changed files with 6,298 additions and 2,779 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend_lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ jobs:
- name: Run csharpier format
run: |
dotnet tool restore
dotnet csharpier --check
dotnet csharpier . --check
3 changes: 2 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ psql U Username -d postgres -h host_name_or_adress -p port -f ouput_file_name.sl

### CSharpier

In everyday development we use [CSharpier](https://csharpier.com/) to auto-format code on save. Installation procedure is described [here](https://csharpier.com/docs/About). No configuration should be required.
In everyday development we use [CSharpier](https://csharpier.com/) to auto-format code on save. Installation procedure is described [here](https://csharpier.com/docs/About). No configuration should be required. To run csharpier locally, go to the backend folder and run:
`dotnet csharpier . --check`

### Dotnet format

Expand Down
102 changes: 63 additions & 39 deletions backend/api.test/Client/AreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Api.Test.Database;
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;

namespace Api.Test.Client
{
[Collection("Database collection")]
Expand All @@ -23,27 +24,27 @@ public class AreaTests : IClassFixture<TestWebApplicationFactory<Program>>
private readonly JsonSerializerOptions _serializerOptions =
new()
{
Converters =
{
new JsonStringEnumConverter()
},
PropertyNameCaseInsensitive = true
Converters = { new JsonStringEnumConverter() },
PropertyNameCaseInsensitive = true,
};

public AreaTests(TestWebApplicationFactory<Program> factory)
{
_client = factory.CreateClient(new WebApplicationFactoryClientOptions
{
AllowAutoRedirect = false,
BaseAddress = new Uri("https://localhost:8000")
});
_client = factory.CreateClient(
new WebApplicationFactoryClientOptions
{
AllowAutoRedirect = false,
BaseAddress = new Uri("https://localhost:8000"),
}
);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
TestAuthHandler.AuthenticationScheme
);

object? context = factory.Services.GetService(typeof(FlotillaDbContext)) as FlotillaDbContext ?? throw new ArgumentNullException(nameof(factory));
object? context =
factory.Services.GetService(typeof(FlotillaDbContext)) as FlotillaDbContext
?? throw new ArgumentNullException(nameof(factory));
_databaseUtilities = new DatabaseUtilities((FlotillaDbContext)context);

}

[Fact]
Expand All @@ -56,38 +57,38 @@ public async Task AreaTest()
{
X = 1,
Y = 2,
Z = 2
Z = 2,
},
Orientation = new Orientation
{
X = 0,
Y = 0,
Z = 0,
W = 1
}
W = 1,
},
};

string testInstallation = "TestInstallationAreaTest";
var installationQuery = new CreateInstallationQuery
{
InstallationCode = testInstallation,
Name = testInstallation
Name = testInstallation,
};

string testPlant = "TestPlantAreaTest";
var plantQuery = new CreatePlantQuery
{
InstallationCode = testInstallation,
PlantCode = testPlant,
Name = testPlant
Name = testPlant,
};

string testDeck = "testDeckAreaTest";
var deckQuery = new CreateDeckQuery
{
InstallationCode = testInstallation,
PlantCode = testPlant,
Name = testDeck
Name = testDeck,
};

string testArea = "testAreaAreaTest";
Expand All @@ -97,7 +98,7 @@ public async Task AreaTest()
PlantCode = testPlant,
DeckName = testDeck,
AreaName = testArea,
DefaultLocalizationPose = testPose
DefaultLocalizationPose = testPose,
};

var installationContent = new StringContent(
Expand Down Expand Up @@ -126,7 +127,10 @@ public async Task AreaTest()

// Act
string installationUrl = "/installations";
var installationResponse = await _client.PostAsync(installationUrl, installationContent);
var installationResponse = await _client.PostAsync(
installationUrl,
installationContent
);
string plantUrl = "/plants";
var plantResponse = await _client.PostAsync(plantUrl, plantContent);
string deckUrl = "/decks";
Expand All @@ -139,7 +143,9 @@ public async Task AreaTest()
Assert.True(plantResponse.IsSuccessStatusCode);
Assert.True(deckResponse.IsSuccessStatusCode);
Assert.True(areaResponse.IsSuccessStatusCode);
var area = await areaResponse.Content.ReadFromJsonAsync<AreaResponse>(_serializerOptions);
var area = await areaResponse.Content.ReadFromJsonAsync<AreaResponse>(
_serializerOptions
);
Assert.NotNull(area);
}

Expand All @@ -149,7 +155,10 @@ public async Task MissionIsCreatedInInspectionArea()
// Arrange - Initialise area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var deck = await _databaseUtilities.ReadOrNewDeck(
installation.InstallationCode,
plant.PlantCode
);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation);
Expand All @@ -161,7 +170,7 @@ public async Task MissionIsCreatedInInspectionArea()
{
AnalysisType = AnalysisType.CarSeal,
InspectionTarget = new Position(),
InspectionType = InspectionType.Image
InspectionType = InspectionType.Image,
};
var tasks = new List<CustomTaskQuery>
{
Expand All @@ -170,8 +179,8 @@ public async Task MissionIsCreatedInInspectionArea()
Inspection = inspection,
TagId = "test",
RobotPose = new Pose(),
TaskOrder = 0
}
TaskOrder = 0,
},
};
var missionQuery = new CustomMissionQuery
{
Expand All @@ -180,7 +189,7 @@ public async Task MissionIsCreatedInInspectionArea()
InstallationCode = installation.InstallationCode,
InspectionAreaName = deck.Name,
Name = testMissionName,
Tasks = tasks
Tasks = tasks,
};

var missionContent = new StringContent(
Expand All @@ -194,17 +203,25 @@ public async Task MissionIsCreatedInInspectionArea()
var missionResponse = await _client.PostAsync(missionUrl, missionContent);

Assert.True(missionResponse.IsSuccessStatusCode);
var mission = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
var mission = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(
_serializerOptions
);
Assert.NotNull(mission);
Assert.NotNull(mission.MissionId);
string inspectionAreaUrl = "/decks";
var inspectionareaMissionsResponse = await _client.GetAsync(inspectionAreaUrl + $"/{deck.Id}/mission-definitions");
var inspectionareaMissionsResponse = await _client.GetAsync(
inspectionAreaUrl + $"/{deck.Id}/mission-definitions"
);

// Assert
Assert.True(inspectionareaMissionsResponse.IsSuccessStatusCode);
var missions = await inspectionareaMissionsResponse.Content.ReadFromJsonAsync<IList<MissionDefinitionResponse>>(_serializerOptions);
var missions = await inspectionareaMissionsResponse.Content.ReadFromJsonAsync<
IList<MissionDefinitionResponse>
>(_serializerOptions);
Assert.NotNull(missions);
Assert.Single(missions.Where(m => m.Id.Equals(mission.MissionId, StringComparison.Ordinal)));
Assert.Single(
missions.Where(m => m.Id.Equals(mission.MissionId, StringComparison.Ordinal))
);
}

[Fact]
Expand All @@ -214,9 +231,9 @@ public async Task EmergencyDockTest()
var installation = await _databaseUtilities.ReadOrNewInstallation();
string installationCode = installation.InstallationCode;


// Act
string goToDockingPositionUrl = $"/emergency-action/{installationCode}/abort-current-missions-and-send-all-robots-to-safe-zone";
string goToDockingPositionUrl =
$"/emergency-action/{installationCode}/abort-current-missions-and-send-all-robots-to-safe-zone";
var missionResponse = await _client.PostAsync(goToDockingPositionUrl, null);

// Assert
Expand All @@ -233,7 +250,10 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
// Arrange
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var deck = await _databaseUtilities.ReadOrNewDeck(
installation.InstallationCode,
plant.PlantCode
);

string deckId = deck.Id;

Expand All @@ -246,16 +266,16 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
{
X = 1,
Y = 2,
Z = 3
Z = 3,
},
Orientation = new Orientation
{
X = 0,
Y = 0,
Z = 0,
W = 1
}
}
W = 1,
},
},
};
var content = new StringContent(
JsonSerializer.Serialize(query),
Expand All @@ -266,13 +286,17 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
// Act
var putResponse = await _client.PutAsync(url, content);
Assert.True(putResponse.IsSuccessStatusCode);
var putDeck = await putResponse.Content.ReadFromJsonAsync<DeckResponse>(_serializerOptions);
var putDeck = await putResponse.Content.ReadFromJsonAsync<DeckResponse>(
_serializerOptions
);

// Assert
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));
Assert.True(
putDeck.DefaultLocalizationPose.Orientation.W.Equals(query.Pose.Orientation.W)
);
}
}
}
Loading

0 comments on commit 5fb3a8b

Please sign in to comment.