Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix csharpier not running in pipeline #1907

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .github/workflows/backend_lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ jobs:
with:
dotnet-version: "8.0.x"

# Dotnet format is included in the .NET8 SDK
# By default, the task ensures the exit code is 0
# If a file needs to be edited by dotnet format, the exit code will be a non-zero value
# We are using severity level 'info' here.
- name: Run dotnet format
run: dotnet format --severity info --verbosity diagnostic --verify-no-changes --exclude ./api/migrations

- name: Run csharpier format
run: |
dotnet tool restore
dotnet csharpier --check
dotnet csharpier . --check
1 change: 1 addition & 0 deletions backend/.csharpierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/Migrations/*.cs
24 changes: 2 additions & 22 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,30 +257,10 @@ 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.

### Dotnet format

The formatting of the backend is defined in the [.editorconfig file](../.editorconfig).

We use [dotnet format](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-format)
to format and verify code style in backend based on the
[C# coding conventions](https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions).

Dotnet format is included in the .NET SDK.

To check the formatting, run the following command in the backend folder:

```
cd backend
dotnet format --severity info --verbosity diagnostic --verify-no-changes --exclude ./api/migrations
```

dotnet format is used to detect naming conventions and other code-related issues. They can be fixed by

```
dotnet format --severity info
```
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`

## SignalR

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
Loading