Skip to content

Commit

Permalink
Merge pull request #221 from AdrianJSClark/warnings-resolution
Browse files Browse the repository at this point in the history
Resolution of Compiler Warnings
  • Loading branch information
AdrianJSClark authored Sep 3, 2024
2 parents 4162143 + c9fa495 commit 6f3b0e8
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public async Task GetSeasonResultsHandlesBadRequestAsync()
Assert.That(async () =>
{
var badRequestResult = await sut.GetSeasonResultsAsync(0, Common.EventType.Race, 0, CancellationToken.None).ConfigureAwait(false);
}, Throws.Exception.InstanceOf(typeof(HttpRequestException)).And.Message.Contains("400 (Bad Request)"));
}, Throws.Exception.InstanceOf<HttpRequestException>().And.Message.Contains("400 (Bad Request)"));
}

[Test(TestOf = typeof(DataClient))]
Expand Down Expand Up @@ -720,7 +720,7 @@ public async Task GetSubSessionResultSuccessfulAsync()

var raceResults = subSessionResult.SessionResults.Single(r => r.SimSessionName == "RACE");
Assert.That(raceResults.Results, Has.All.Property(nameof(Result.DriverResults)).Null); // Single-driver events don't have driver results.

var sampleDriver = raceResults.Results.FirstOrDefault(r => r.Position == 0);
Assert.That(sampleDriver, Is.Not.Null);
Assert.That(sampleDriver!.CarClassName, Is.EqualTo("Cadillac CTS-VR"));
Expand Down Expand Up @@ -1539,7 +1539,7 @@ public async Task GetLookupWithExpiredAuthWorksAsync()
}

var lookupGroups = await sut.GetLookupsAsync().ConfigureAwait(false);
Assert.ThrowsAsync<iRacingUnauthorizedResponseException>(async () => await sut.GetLookupsAsync().ConfigureAwait(false));
_ = Assert.ThrowsAsync<iRacingUnauthorizedResponseException>(async () => await sut.GetLookupsAsync().ConfigureAwait(false));
var lookupGroups2 = await sut.GetLookupsAsync().ConfigureAwait(false);

Assert.Multiple(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ public string WriteValue(TimeSpan[] input)
return UTF8.GetString(result);
}

public static IEnumerable<TestCaseData> ReadValueTestCases() => Examples().ToReadValueTestCases();
public static IEnumerable<TestCaseData> WriteValueTestCases() => Examples().ToWriteValueTestCases();
public static IEnumerable<TestCaseData> ReadValueTestCases()
{
return Examples().ToReadValueTestCases();
}

public static IEnumerable<TestCaseData> WriteValueTestCases()
{
return Examples().ToWriteValueTestCases();
}

private static IEnumerable<(byte[] JsonBytes, TimeSpan[] Value, string Name)> Examples()
{
yield return (@"{""value"":[0,0]}"u8.ToArray(), [TimeSpan.Zero, TimeSpan.Zero], "Value [0,0] returns [TimeSpan.Zero,TimeSpan.Zero]");
yield return (@"{""value"":[-240]}"u8.ToArray(), [TimeSpan.FromHours(-4)], "Value [-240] returns [TimeSpan.FromHours(-4)]");
yield return (@"{""value"":[240,0]}"u8.ToArray(), [TimeSpan.FromHours(4),TimeSpan.Zero], "Value [240,0] returns [TimeSpan.FromHours(4),TimeSpan.Zero]");
yield return (@"{""value"":[240,0]}"u8.ToArray(), [TimeSpan.FromHours(4), TimeSpan.Zero], "Value [240,0] returns [TimeSpan.FromHours(4),TimeSpan.Zero]");
yield return (@"{""value"":[630]}"u8.ToArray(), [TimeSpan.FromHours(10.5)], "Value [630] returns [TimeSpan.FromHours(10.5)]");
}
}
10 changes: 5 additions & 5 deletions src/Aydsko.iRacingData.UnitTests/UrlExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public Uri ValidateToUrlWithQueryMethod(string url, IEnumerable<KeyValuePair<str
private static IEnumerable<TestCaseData> ValidateToUrlWithQueryMethodTestCases()
{
yield return new TestCaseData("https://example.com", Array.Empty<KeyValuePair<string, object?>>()) { ExpectedResult = new Uri("https://example.com") };
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("foo", "bar" ) }) { ExpectedResult = new Uri("https://example.com?foo=bar") };
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("foo", "bar") }) { ExpectedResult = new Uri("https://example.com?foo=bar") };
#pragma warning disable CA1861 // Avoid constant arrays as arguments
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("foo", new[] { "bar", "baz" } ) }) { ExpectedResult = new Uri("https://example.com?foo=bar,baz") };
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("foo", new[] { "bar", "baz" }) }) { ExpectedResult = new Uri("https://example.com?foo=bar,baz") };
#pragma warning restore CA1861 // Avoid constant arrays as arguments
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("=&?", "=?&=?&" ) }) { ExpectedResult = new Uri("https://example.com?%3D%26%3F=%3D%3F%26%3D%3F%26") };
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("foo", "bar" ), new("baz", "bat" ) }) { ExpectedResult = new Uri("https://example.com?foo=bar&baz=bat") };
yield return new TestCaseData("https://example.com?a=b", new KeyValuePair<string, object?>[] { new("foo", "bar" ), new("baz", "bat" ) }) { ExpectedResult = new Uri("https://example.com?a=b&foo=bar&baz=bat") };
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("=&?", "=?&=?&") }) { ExpectedResult = new Uri("https://example.com?%3D%26%3F=%3D%3F%26%3D%3F%26") };
yield return new TestCaseData("https://example.com", new KeyValuePair<string, object?>[] { new("foo", "bar"), new("baz", "bat") }) { ExpectedResult = new Uri("https://example.com?foo=bar&baz=bat") };
yield return new TestCaseData("https://example.com?a=b", new KeyValuePair<string, object?>[] { new("foo", "bar"), new("baz", "bat") }) { ExpectedResult = new Uri("https://example.com?a=b&foo=bar&baz=bat") };
}
}
2 changes: 1 addition & 1 deletion src/Aydsko.iRacingData/Aydsko.iRacingData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/Aydsko.iRacingData/Cars/CarAssetDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CarAssetDetail
[JsonPropertyName("car_id")]
public int CarId { get; set; }

[JsonPropertyName("car_rules")]
[JsonPropertyName("car_rules")]
public CarRule[] CarRules { get; set; } = default!;

[JsonPropertyName("detail_copy")]
Expand Down
16 changes: 8 additions & 8 deletions src/Aydsko.iRacingData/Cars/CarInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public class CarInfo
[JsonPropertyName("first_sale")]
public DateTimeOffset FirstSale { get; set; }

[JsonPropertyName("forum_url")]
[JsonPropertyName("forum_url")]
public string ForumUrl { get; set; } = default!;

[JsonPropertyName("free_with_subscription")]
public bool FreeWithSubscription { get; set; }

Expand All @@ -66,13 +66,13 @@ public class CarInfo

[JsonPropertyName("has_multiple_dry_tire_types")]
public bool HasMultipleDryTireTypes { get; set; }

[JsonPropertyName("has_rain_capable_tire_types")]
public bool HasRainCapableTireTypes { get; set; }

[JsonPropertyName("hp")]
public int Hp { get; set; }

[JsonPropertyName("is_ps_purchasable")]
public bool IsPsPurchasable { get; set; }

Expand All @@ -93,8 +93,8 @@ public class CarInfo

[JsonPropertyName("price")]
public float Price { get; set; }
[JsonPropertyName("price_display")]

[JsonPropertyName("price_display")]
public string PriceDisplay { get; set; } = default!;

[JsonPropertyName("retired")]
Expand All @@ -117,8 +117,8 @@ public class CarInfo

[JsonPropertyName("site_url"), JsonConverter(typeof(UriConverter))]
public Uri? SiteUrl { get; set; } = default!;
[JsonPropertyName("rain_enabled")]

[JsonPropertyName("rain_enabled")]
public bool RainEnabled { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion src/Aydsko.iRacingData/Cars/CarRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class CarRule
{
[JsonPropertyName("rule_category")]
public string RuleCategory { get; set; } = default!;

[JsonPropertyName("text")]
public string Text { get; set; } = default!;
}
2 changes: 1 addition & 1 deletion src/Aydsko.iRacingData/Common/CarClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CarClass

[JsonPropertyName("rain_enabled")]
public bool RainEnabled { get; set; }

[JsonPropertyName("relative_speed")]
public int RelativeSpeed { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Aydsko.iRacingData/Common/CarsInClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CarsInClass

[JsonPropertyName("rain_enabled")]
public bool RainEnabled { get; set; }

[JsonPropertyName("retired")]
public bool Retired { get; set; }
}
77 changes: 77 additions & 0 deletions src/Aydsko.iRacingData/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Aydsko.iRacingData.Leagues.LeagePointsSystems</Target>
<Left>lib/net6.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net6.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Aydsko.iRacingData.Leagues.LeagePointsSystems</Target>
<Left>lib/net8.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net8.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Aydsko.iRacingData.Converters.DateOnlyConverter</Target>
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net6.0/Aydsko.iRacingData.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Aydsko.iRacingData.Leagues.LeagePointsSystems</Target>
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/netstandard2.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.DataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/net6.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net6.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.Hosted.Car.get_PowerAdjustPercent</Target>
<Left>lib/net6.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net6.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.IDataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/net6.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net6.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.DataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/net8.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net8.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.Hosted.Car.get_PowerAdjustPercent</Target>
<Left>lib/net8.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net8.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.IDataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/net8.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net8.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.Member.MemberChartDataPoint.get_Day</Target>
Expand Down Expand Up @@ -87,13 +136,41 @@
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net6.0/Aydsko.iRacingData.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.DataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/netstandard2.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.Hosted.Car.get_PowerAdjustPercent</Target>
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/netstandard2.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Aydsko.iRacingData.IDataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/netstandard2.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0006</DiagnosticId>
<Target>M:Aydsko.iRacingData.IDataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/net8.0/Aydsko.iRacingData.dll</Left>
<Right>lib/net8.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0006</DiagnosticId>
<Target>M:Aydsko.iRacingData.IDataClient.GetLeaguePointsSystemsAsync(System.Int32,System.Nullable{System.Int32},System.Threading.CancellationToken)</Target>
<Left>lib/netstandard2.0/Aydsko.iRacingData.dll</Left>
<Right>lib/netstandard2.0/Aydsko.iRacingData.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0008</DiagnosticId>
<Target>T:Aydsko.iRacingData.Common.EventType</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ public class OneDecimalPointValueConverter : JsonConverter<decimal>
{
public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TryGetInt32(out var intValue))
{
return intValue / 10m;
}

return default;
return reader.TryGetInt32(out var intValue) ? intValue / 10m : default;
}

public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options)
Expand All @@ -27,7 +22,7 @@ public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerO
throw new ArgumentNullException(nameof(writer));
}
#endif

writer.WriteNumberValue(value * 10);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ internal class TrackConfigNameNaConverter : JsonConverter<string?>
{
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
#pragma warning disable IDE0072 // Add missing cases - Correct behaviour is already the default case
var value = reader.TokenType switch
{
JsonTokenType.String => reader.GetString(),
_ => null
};
#pragma warning restore IDE0072 // Add missing cases

return string.IsNullOrWhiteSpace(value) || string.Equals(value, "N/A", StringComparison.OrdinalIgnoreCase) ? null : value;
return string.IsNullOrWhiteSpace(value) || string.Equals(value, "N/A", StringComparison.OrdinalIgnoreCase) ? null : value;
}

public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ public class TwoDecimalPointsValueConverter : JsonConverter<decimal>
{
public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TryGetInt32(out var intValue))
{
return intValue / 100m;
}

return default;
return reader.TryGetInt32(out var intValue) ? intValue / 100m : default;
}

public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options)
Expand All @@ -27,7 +22,7 @@ public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerO
throw new ArgumentNullException(nameof(writer));
}
#endif

writer.WriteNumberValue(value * 100);
}
}
Loading

0 comments on commit 6f3b0e8

Please sign in to comment.