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

Project Clean Up and Update #187

Merged
merged 5 commits into from
Aug 15, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/_build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
fetch-depth: 0 # Required for MinVer to work properly

- name: 'Setup .NET SDK'
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.x'
dotnet-version: '8.x'

- run: dotnet tool update -g docfx
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
fetch-depth: 0 # Required for MinVer to work properly

- name: 'Setup .NET SDK'
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.x'
dotnet-version: '8.x'

- name: 'Build Solution'
id: build-solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/Aydsko.iRacingData.IntegrationTests/Member/Security.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Aydsko.iRacingData.IntegrationTests.Member;

internal class Security
internal static class Security
{
public static string ObfuscateUsernameOrEmail(string input)
internal static string ObfuscateUsernameOrEmail(string input)
{
var segments = input.Split('@', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal sealed class GetTracksTests : DataClientIntegrationFixture
{
private Track[] tracksData;

[SetUp]
public async Task SetUp()
[OneTimeSetUp]
public async Task GetTrackDataAsync()
{
var tracksResponse = await Client.GetTracksAsync(CancellationToken.None).ConfigureAwait(false);
tracksData = tracksResponse.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="coverlet.collector" Version="6.0.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
@@ -1,6 +1,7 @@
// © 2023 Adrian Clark
// This file is licensed to you under the MIT license.

using System.Net.Http;
using Aydsko.iRacingData.Constants;
using Aydsko.iRacingData.Exceptions;
using Aydsko.iRacingData.Leagues;
Expand All @@ -14,6 +15,8 @@ namespace Aydsko.iRacingData.UnitTests;

public class CapturedResponseValidationTests : MockedHttpTestBase
{
private static readonly int[] TestCustomerIds = new[] { 123456 };

// NUnit will ensure that "SetUp" runs before each test so these can all be forced to "null".
private DataClient sut = null!;

Expand Down Expand Up @@ -208,7 +211,7 @@ public async Task GetDriverInfoWithLicensesSuccessfulAsync()
{
await MessageHandler.QueueResponsesAsync(nameof(GetDriverInfoWithLicensesSuccessfulAsync)).ConfigureAwait(false);

var carAssets = await sut.GetDriverInfoAsync(new[] { 123456 }, true).ConfigureAwait(false);
var carAssets = await sut.GetDriverInfoAsync(TestCustomerIds, true).ConfigureAwait(false);

Assert.That(carAssets, Is.Not.Null);
Assert.That(carAssets!.Data, Is.Not.Null);
Expand All @@ -228,7 +231,7 @@ public async Task GetDriverInfoWithoutLicensesSuccessfulAsync()
{
await MessageHandler.QueueResponsesAsync(nameof(GetDriverInfoWithoutLicensesSuccessfulAsync)).ConfigureAwait(false);

var carAssets = await sut.GetDriverInfoAsync(new[] { 123456 }, false).ConfigureAwait(false);
var carAssets = await sut.GetDriverInfoAsync(TestCustomerIds, false).ConfigureAwait(false);

Assert.That(carAssets, Is.Not.Null);
Assert.That(carAssets!.Data, Is.Not.Null);
Expand Down
2 changes: 2 additions & 0 deletions src/Aydsko.iRacingData.UnitTests/DictionaryExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public KeyValuePair<string, string> CheckAddParameterIfNotNull<T>(T value)
return parameters.ElementAt(0);
}

#pragma warning disable CA1861 // Avoid constant arrays as arguments - not worth it for these unit test cases.
public static IEnumerable<TestCaseData> GetTestCases()
{
yield return new TestCaseData("foo").Returns(new KeyValuePair<string, string>("value", "foo"));
Expand All @@ -19,4 +20,5 @@ public static IEnumerable<TestCaseData> GetTestCases()
yield return new TestCaseData(true).Returns(new KeyValuePair<string, string>("value", "true"));
yield return new TestCaseData(Common.EventType.Practice).Returns(new KeyValuePair<string, string>("value", "2"));
}
#pragma warning restore CA1861 // Avoid constant arrays as arguments
}
26 changes: 11 additions & 15 deletions src/Aydsko.iRacingData.UnitTests/MockedHttpMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This file is licensed to you under the MIT license.

using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.Json;
Expand All @@ -16,6 +17,8 @@ public class MockedHttpMessageHandler : HttpMessageHandler
public Queue<MockedHttpRequest> RequestContent { get; } = new();
public Queue<HttpResponseMessage> Responses { get; } = new();

private static readonly string[] SuccessfulLoginResponse = new[] { "Aydsko.iRacingData.UnitTests.Responses.SuccessfulLogin.json" };

public MockedHttpMessageHandler(CookieContainer cookieContainer)
{
this.cookieContainer = cookieContainer;
Expand Down Expand Up @@ -66,11 +69,9 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques

public async Task QueueResponsesAsync(string testName, bool prefixLoginResponse = true)
{
var manifestResourceNames = (prefixLoginResponse
? new[] { "Aydsko.iRacingData.UnitTests.Responses.SucessfulLogin.json" }
: Array.Empty<string>()
).Concat(ResourceAssembly.GetManifestResourceNames()
.Where(mrn => mrn.StartsWith($"Aydsko.iRacingData.UnitTests.Responses.{testName}", StringComparison.InvariantCultureIgnoreCase)));
var manifestResourceNames = (prefixLoginResponse ? SuccessfulLoginResponse : Array.Empty<string>())
.Concat(ResourceAssembly.GetManifestResourceNames()
.Where(mrn => mrn.StartsWith($"Aydsko.iRacingData.UnitTests.Responses.{testName}", StringComparison.InvariantCultureIgnoreCase)));

foreach (var manifestName in manifestResourceNames)
{
Expand All @@ -87,8 +88,8 @@ public async Task QueueResponsesAsync(string testName, bool prefixLoginResponse
var responseDictionary = responseDocument!.RootElement.EnumerateObject()
.ToDictionary(prop => prop.Name, prop => prop.Value);

if (!responseDictionary.ContainsKey("statuscode")
|| !Enum.TryParse<HttpStatusCode>(responseDictionary["statuscode"].ToString(), out var statusCode))
if (!responseDictionary.TryGetValue("statuscode", out var value)
|| !Enum.TryParse<HttpStatusCode>(value.ToString(), out var statusCode))
{
statusCode = HttpStatusCode.OK;
}
Expand All @@ -104,14 +105,9 @@ public async Task QueueResponsesAsync(string testName, bool prefixLoginResponse
.ToDictionary(prop => prop.Name,
prop =>
{
if (prop.Value.ValueKind == JsonValueKind.Array)
{
return prop.Value.EnumerateArray().Select(e => e.ToString()).ToArray();
}
else
{
return new[] { prop.Value.GetString() };
}
return prop.Value.ValueKind == JsonValueKind.Array
? prop.Value.EnumerateArray().Select(e => e.ToString()).ToArray()
: (new[] { prop.Value.GetString() });
}).ToArray())
{
responseMessage.Headers.Add(header.Key, header.Value);
Expand Down
2 changes: 2 additions & 0 deletions src/Aydsko.iRacingData.UnitTests/MockedHttpRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// © 2023 Adrian Clark
// This file is licensed to you under the MIT license.

using System.Net.Http;

namespace Aydsko.iRacingData.UnitTests;

public class MockedHttpRequest
Expand Down
1 change: 1 addition & 0 deletions src/Aydsko.iRacingData.UnitTests/MockedHttpTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This file is licensed to you under the MIT license.

using System.Net;
using System.Net.Http;

namespace Aydsko.iRacingData.UnitTests;

Expand Down
4 changes: 2 additions & 2 deletions src/Aydsko.iRacingData/Aydsko.iRacingData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Package Validation (https://docs.microsoft.com/en-us/dotnet/fundamentals/package-validation/overview) -->
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>0.9.0</PackageValidationBaselineVersion>
<PackageValidationBaselineVersion>2303.1.0</PackageValidationBaselineVersion>
<GenerateCompatibilitySuppressionFile>true</GenerateCompatibilitySuppressionFile>
<EnableStrictModeForCompatibleFrameworksInPackage>true</EnableStrictModeForCompatibleFrameworksInPackage>
<EnableStrictModeForCompatibleTfms>true</EnableStrictModeForCompatibleTfms>
Expand Down Expand Up @@ -77,7 +77,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
21 changes: 6 additions & 15 deletions src/Aydsko.iRacingData/CachingDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@

namespace Aydsko.iRacingData;

internal class CachingDataClient : DataClient
internal class CachingDataClient(HttpClient httpClient,
ILogger<CachingDataClient> logger,
iRacingDataClientOptions options,
CookieContainer cookieContainer,
IMemoryCache memoryCache)
: DataClient(httpClient, logger, options, cookieContainer)
{
private readonly IMemoryCache memoryCache;
private readonly ILogger<CachingDataClient> logger;

public CachingDataClient(HttpClient httpClient,
ILogger<CachingDataClient> logger,
iRacingDataClientOptions options,
CookieContainer cookieContainer,
IMemoryCache memoryCache)
: base(httpClient, logger, options, cookieContainer)
{
this.logger = logger;
this.memoryCache = memoryCache;
}

protected override async Task<DataResponse<TData>> CreateResponseViaInfoLinkAsync<TData>(Uri infoLinkUri,
JsonTypeInfo<TData> jsonTypeInfo,
CancellationToken cancellationToken)
Expand Down
Loading
Loading