Skip to content

Commit c4d2959

Browse files
committed
Use invariant culture as format provider
1 parent a3bb643 commit c4d2959

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

App/Api/Setup/Endpoints.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using Asp.Versioning;
23
using Microsoft.OpenApi.Any;
34
using Services;
@@ -6,8 +7,8 @@ namespace Api.Setup;
67

78
public static class Endpoints
89
{
9-
private static readonly OpenApiString ExampleFromDate = new(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd"));
10-
private static readonly OpenApiString ExampleToDate = new(DateTime.Now.ToString("yyyy-MM-dd"));
10+
private static readonly OpenApiString ExampleFromDate = new(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
11+
private static readonly OpenApiString ExampleToDate = new(DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
1112

1213
public static void ConfigureEndpoints(this WebApplication app)
1314
{

App/Services/Utility/QueryHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using Services.Extensions;
23

34
namespace Services.Utility;
@@ -6,8 +7,8 @@ public static class QueryHelper
67
{
78
public static Dictionary<string, string?> CreateQueryParams(DateOnly fromDate, DateOnly toDate, string currency = "eur")
89
{
9-
var from = fromDate.ToUnixTimestamp().ToString();
10-
var to = toDate.ToUnixTimestamp().ToString();
10+
var from = fromDate.ToUnixTimestamp().ToString(CultureInfo.InvariantCulture);
11+
var to = toDate.ToUnixTimestamp().ToString(CultureInfo.InvariantCulture);
1112
var parameters = new Dictionary<string, string?>
1213
{
1314
{ "vs_currency", currency },

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<EnforeCodeStyleInBuild>true</EnforeCodeStyleInBuild>
1515
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1616
<EnableCodeAnalysis>true</EnableCodeAnalysis>
17-
<NoWarn>S6678;CA2007;CA1848;CA1002;CA1305;CA1062;CA2000;CA5394;CA1724;CA1031;S3267;CA1515;S1118;CA1707;CA2234;CA1051;CA1063;S3881</NoWarn>
17+
<NoWarn>S6678;CA2007;CA1848;CA1002;CA1062;CA2000;CA5394;CA1724;CA1031;S3267;CA1515;S1118;CA1707;CA2234;CA1051;CA1063;S3881</NoWarn>
1818
</PropertyGroup>
1919
<ItemGroup Condition="'$(MSBuildProjectExtension)' != '.dcproj'">
2020
<PackageReference Include="SonarAnalyzer.CSharp">

Tests/IntegrationTests/IntegrationTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using System.Net;
23
using FluentAssertions;
34
using Xunit;
@@ -12,8 +13,8 @@ public class IntegrationTests(IntegrationFixture fixture) : IClassFixture<Integr
1213
public static TheoryData<string?, string?, HttpStatusCode> Cases =>
1314
new TheoryData<string?, string?, HttpStatusCode>
1415
{
15-
{DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd"), HttpStatusCode.OK},
16-
{DateTime.Now.AddMonths(-13).ToString("yyyy-MM-dd"), DateTime.Now.AddMonths(-12).ToString("yyyy-MM-dd"), HttpStatusCode.Unauthorized}, //Unauthorized for over 365 days old queries
16+
{DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), HttpStatusCode.OK},
17+
{DateTime.Now.AddMonths(-13).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), DateTime.Now.AddMonths(-12).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), HttpStatusCode.Unauthorized}, //Unauthorized for over 365 days old queries
1718
{"", null, HttpStatusCode.BadRequest},
1819
};
1920

Tests/UnitTests/UtilityTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using FluentAssertions;
23
using Services.Exceptions;
34
using Services.Extensions;
@@ -200,8 +201,8 @@ public void CreateQueryParams_ShouldReturnCorrectDictionary()
200201
var fromDate = new DateOnly(2024, 8, 11);
201202
var toDate = new DateOnly(2024, 8, 12);
202203
var currency = "eur";
203-
var expectedFrom = fromDate.ToUnixTimestamp().ToString();
204-
var expectedTo = toDate.ToUnixTimestamp().ToString();
204+
var expectedFrom = fromDate.ToUnixTimestamp().ToString(CultureInfo.InvariantCulture);
205+
var expectedTo = toDate.ToUnixTimestamp().ToString(CultureInfo.InvariantCulture);
205206

206207
var result = QueryHelper.CreateQueryParams(fromDate, toDate, currency);
207208

0 commit comments

Comments
 (0)