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

Update StyleCop.Analyzers and fix violations #82

Merged
merged 7 commits into from
Nov 27, 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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ dotnet_diagnostic.SA1202.severity = none
dotnet_diagnostic.SA1203.severity = warning
dotnet_diagnostic.SA1204.severity = warning
dotnet_diagnostic.SA1208.severity = warning
dotnet_diagnostic.SA1210.severity = none
dotnet_diagnostic.SA1311.severity = warning
dotnet_diagnostic.SA1402.severity = warning
dotnet_diagnostic.SA1412.severity = warning
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Geodatenbezug.Test/Geodatenbezug.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Geodatenbezug</RootNamespace>
<NoWarn>SA0001,CS1591,CS8604,CS8618,CS8620,CS8629,CA1001,CA1014,CS8625,CA2000,CA2007</NoWarn>
<NoWarn>SA0001,SA1402,CS1591,CS8604,CS8618,CS8620,CS8629,CA1001,CA1014,CS8625,CA2000,CA2007</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
64 changes: 32 additions & 32 deletions Geodatenbezug.Test/GeodiensteApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Geodatenbezug;
[DeploymentItem("testdata/lwb_perimeter_terrassenreben_lv95_no_gpkg.zip", "testdata")]
public class GeodiensteApiTest
{
private readonly Topic topic = new ()
private readonly Topic topic = new()
{
BaseTopic = BaseTopic.lwb_perimeter_ln_sf,
TopicTitle = "Perimeter LN- und Sömmerungsflächen",
Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task RequestTopicInfoAsync()
var responseBody = JsonSerializer.Serialize(data);
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.OK, Content = responseBody },
new() { Code = HttpStatusCode.OK, Content = responseBody },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Rufe die Themeninformationen ab: https://geodienste.ch/info/services.json?base_topics=lwb_perimeter_ln_sf,lwb_rebbaukataster,lwb_perimeter_terrassenreben,lwb_biodiversitaetsfoerderflaechen,lwb_bewirtschaftungseinheit,lwb_nutzungsflaechen&topics=lwb_perimeter_ln_sf_v2_0,lwb_rebbaukataster_v2_0,lwb_perimeter_terrassenreben_v2_0,lwb_biodiversitaetsfoerderflaechen_v2_0,lwb_bewirtschaftungseinheit_v2_0,lwb_nutzungsflaechen_v2_0&cantons=AG,AI,AR,BE,BL,FR,GE,GL,GR,JU,LU,NE,NW,OW,SG,SH,SO,SZ,TG,TI,UR,VD,VS,ZG,ZH&language=de");
Expand All @@ -80,7 +80,7 @@ public async Task RequestTopicInfoAsyncFails()
{
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.InternalServerError },
new() { Code = HttpStatusCode.InternalServerError },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Rufe die Themeninformationen ab: https://geodienste.ch/info/services.json?base_topics=lwb_perimeter_ln_sf,lwb_rebbaukataster,lwb_perimeter_terrassenreben,lwb_biodiversitaetsfoerderflaechen,lwb_bewirtschaftungseinheit,lwb_nutzungsflaechen&topics=lwb_perimeter_ln_sf_v2_0,lwb_rebbaukataster_v2_0,lwb_perimeter_terrassenreben_v2_0,lwb_biodiversitaetsfoerderflaechen_v2_0,lwb_bewirtschaftungseinheit_v2_0,lwb_nutzungsflaechen_v2_0&cantons=AG,AI,AR,BE,BL,FR,GE,GL,GR,JU,LU,NE,NW,OW,SG,SH,SO,SZ,TG,TI,UR,VD,VS,ZG,ZH&language=de");
Expand All @@ -95,8 +95,8 @@ public async Task StartExportAsync()
{
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.OK, Content = "{\"info\":\"Data export successfully started. Call the URL of status_url to get the current status of the export.\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.OK, Content = "{\"info\":\"Data export successfully started. Call the URL of status_url to get the current status of the export.\"}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
Expand All @@ -111,17 +111,17 @@ public async Task StartExportAsyncTimeout()
{
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
new() { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
Expand All @@ -137,7 +137,7 @@ public async Task StartExportAsyncFails()
{
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.Unauthorized },
new() { Code = HttpStatusCode.Unauthorized },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
Expand Down Expand Up @@ -166,9 +166,9 @@ public async Task CheckExportStatusAsync()

httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"success\", \"info\":\"Data ready to be downloaded. Provide your credentials to download the data.\", \"download_url\":\"test.com/data.zip\", \"exported_at\":\"2022-03-24T09:31:05.508\"}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"success\", \"info\":\"Data ready to be downloaded. Provide your credentials to download the data.\", \"download_url\":\"test.com/data.zip\", \"exported_at\":\"2022-03-24T09:31:05.508\"}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
Expand All @@ -185,17 +185,17 @@ public async Task CheckExportStatusAsyncTimeout()
{
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"queued\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
new() { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
Expand All @@ -213,7 +213,7 @@ public async Task CheckExportStatusAsyncFails()
{
httpTestMessageHandler.SetTestMessageResponses(
[
new () { Code = HttpStatusCode.Unauthorized },
new() { Code = HttpStatusCode.Unauthorized },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
Expand Down
34 changes: 17 additions & 17 deletions Geodatenbezug.Test/HttpTestMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@

namespace Geodatenbezug;

/// <summary>
/// A simplified version of the HttpResponseMessage class that can be used to mock HTTP responses.
/// </summary>
public record TestMessageResponse()
{
/// <summary>
/// The HTTP status code of the response.
/// </summary>
required public HttpStatusCode Code { get; set; }

/// <summary>
/// The content as a JSON string.
/// </summary>
public string? Content { get; set; }
}

/// <summary>
/// A test message handler that can be used to mock multiple HTTP responses.
/// </summary>
Expand Down Expand Up @@ -68,5 +52,21 @@ public void VerifyNoOutstandingExpectation()
/// <summary>
/// Converts the test message handler to an HttpClient.
/// </summary>
public HttpClient ToHttpClient() => new (this);
public HttpClient ToHttpClient() => new(this);
}

/// <summary>
/// A simplified version of the HttpResponseMessage class that can be used to mock HTTP responses.
/// </summary>
public record TestMessageResponse()
{
/// <summary>
/// The HTTP status code of the response.
/// </summary>
public required HttpStatusCode Code { get; set; }

/// <summary>
/// The content as a JSON string.
/// </summary>
public string? Content { get; set; }
}
14 changes: 7 additions & 7 deletions Geodatenbezug.Test/MailServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void BuildMailMessage()
{
var results = new List<ProcessingResult>
{
new ()
new()
{
Code = HttpStatusCode.OK,
Reason = "Success",
Expand All @@ -53,7 +53,7 @@ public void BuildMailMessageWithNotOkProcessingResult()
{
var results = new List<ProcessingResult>
{
new ()
new()
{
Code = HttpStatusCode.OK,
Reason = "Success",
Expand All @@ -63,7 +63,7 @@ public void BuildMailMessageWithNotOkProcessingResult()
UpdatedAt = new DateTime(2023, 11, 05, 15, 33, 22),
DownloadUrl = "https://a-test.ch/link.zip",
},
new ()
new()
{
Code = HttpStatusCode.NotFound,
Reason = "Kein Wert für Key SH gefunden",
Expand Down Expand Up @@ -132,7 +132,7 @@ public void BuildMailBody()

var results = new List<ProcessingResult>
{
new ()
new()
{
Code = HttpStatusCode.OK,
Reason = "Success",
Expand All @@ -142,7 +142,7 @@ public void BuildMailBody()
UpdatedAt = new DateTime(2023, 11, 05, 15, 33, 22),
DownloadUrl = "https://a-test.ch/link.zip",
},
new ()
new()
{
Code = HttpStatusCode.NotFound,
Reason = "Not Found",
Expand All @@ -151,15 +151,15 @@ public void BuildMailBody()
Canton = Canton.SH,
UpdatedAt = new DateTime(2023, 11, 05, 15, 33, 22),
},
new ()
new()
{
Code = HttpStatusCode.NotFound,
Reason = "Kein Wert für Key SH gefunden",
TopicTitle = "Perimeter Terrassenreben",
Canton = Canton.SH,
UpdatedAt = new DateTime(2023, 11, 05, 15, 33, 22),
},
new ()
new()
{
Code = HttpStatusCode.OK,
Reason = "Success",
Expand Down
8 changes: 4 additions & 4 deletions Geodatenbezug.Test/ProcessingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ public async Task GetTopicsToUpdate()
.Setup(api => api.RequestTopicInfoAsync())
.ReturnsAsync(
[
new ()
new()
{
BaseTopic = BaseTopic.lwb_perimeter_ln_sf,
TopicTitle = "Perimeter LN- und Sömmerungsflächen",
Canton = Canton.SH,
UpdatedAt = datestring_delta4,
},
new ()
new()
{
BaseTopic = BaseTopic.lwb_perimeter_ln_sf,
TopicTitle = "Perimeter LN- und Sömmerungsflächen",
Canton = Canton.ZG,
UpdatedAt = datestring_delta23,
},
new ()
new()
{
BaseTopic = BaseTopic.lwb_rebbaukataster,
TopicTitle = "Rebbaukataster",
Canton = Canton.SH,
UpdatedAt = datestring_delta30,
},
new ()
new()
{
BaseTopic = BaseTopic.lwb_rebbaukataster,
TopicTitle = "Rebbaukataster",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Geodatenbezug.Processors;
[DeploymentItem("testdata/lwb_bewirtschaftungseinheit_v2_0_lv95_testdaten.gpkg", "testdata")]
public class BewirtschaftungseinheitProcessorTest
{
private readonly Topic topic = new ()
private readonly Topic topic = new()
{
TopicTitle = BaseTopic.lwb_bewirtschaftungseinheit.GetDescription(),
Canton = Canton.NE,
Expand Down
Loading
Loading