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

v 0.11.0 #184

Merged
merged 7 commits into from
Feb 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
6 changes: 2 additions & 4 deletions src/iRLeagueApiCore.Client/Http/DefaultTokenStore.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.Extensions.Logging;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection.Metadata;
using Microsoft.IdentityModel.JsonWebTokens;

namespace iRLeagueApiCore.Client.Http;
internal sealed class DefaultTokenStore : ITokenStore
Expand Down Expand Up @@ -46,7 +44,7 @@ public async Task SetAccessTokenAsync(string token)
if (string.IsNullOrEmpty(accessToken) == false)
{
// set expiration date
var jwtToken = new JwtSecurityTokenHandler().ReadToken(accessToken);
var jwtToken = new JsonWebTokenHandler().ReadToken(accessToken);
AccessTokenExpires = jwtToken.ValidTo;
}
TokenChanged?.Invoke(this, EventArgs.Empty);
Expand Down
6 changes: 3 additions & 3 deletions src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<PropertyGroup />

<ItemGroup>
<PackageReference Include="iRLeagueApiCore.Common" Version="0.10.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.11.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.10.0" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.3.1" />
</ItemGroup>

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<PackageId>iRLeagueApiCore.Client</PackageId>
<Version>0.10.2</Version>
<Version>0.11.0</Version>
<Authors>Simon Schulze</Authors>
<Company>Simon Schulze</Company>
<PackageDescription>This package contains shared objects for all members of the iRLeagueDatabase-iRLeagueApi stack</PackageDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ protected virtual async Task<ResultConfigurationEntity> MapToResultConfigEntityA
Scorings = resultConfig.Scorings.Select(scoring => new ScoringModel()
{
Id = scoring.ScoringId,
Index = scoring.Index,
MaxResultsPerGroup = scoring.MaxResultsPerGroup,
Name = scoring.Name,
ShowResults = scoring.ShowResults,
Expand Down Expand Up @@ -240,7 +241,7 @@ protected virtual async Task<ResultConfigurationEntity> MapToResultConfigEntityA
Type = penalty.Type,
}).ToList(),
} : null,
}).ToList(),
}).OrderBy(x => x.Index).ToList(),
FiltersForPoints = resultConfig.PointFilters
.Select(filter => new ResultFilterModel()
{
Expand Down
6 changes: 3 additions & 3 deletions src/iRLeagueApiCore.Server/iRLeagueApiCore.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<PackageReference Include="Aydsko.iRacingData" Version="2303.0.0" />
<PackageReference Include="FluentValidation" Version="11.0.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.0.1" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.10.0" CopyToOutputDirectory="lib/net6.0">
<PackageReference Include="iRLeagueApiCore.Common" Version="0.11.0" CopyToOutputDirectory="lib/net6.0">
</PackageReference>
<PackageReference Include="iRLeagueDatabaseCore" Version="0.10.0" />
<PackageReference Include="iRLeagueDatabaseCore" Version="0.11.0" />
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.9" />
Expand Down Expand Up @@ -72,7 +72,7 @@

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>0.10.2</Version>
<Version>0.11.0</Version>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private static IEnumerable<ResultRowCalculationResult> ApplyStartPositionBonusPo

protected static IEnumerable<ResultRowCalculationResult> CalculateCompletedPct(IEnumerable<ResultRowCalculationResult> rows)
{
var laps = rows.Max(x => x.CompletedLaps);
var laps = rows.MaxOrDefault(x => x.CompletedLaps);
if (laps == 0)
{
return rows;
Expand All @@ -463,7 +463,7 @@ protected static IEnumerable<ResultRowCalculationResult> CalculateCompletedPct(I

private static IEnumerable<ResultRowCalculationResult> CalculateIntervals(IEnumerable<ResultRowCalculationResult> rows)
{
int totalLaps = (int)rows.Max(x => x.CompletedLaps);
int totalLaps = (int)rows.MaxOrDefault(x => x.CompletedLaps);
foreach (var row in rows)
{
if (row.Interval.Days > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async Task<IEnumerable<SessionCalculationConfiguration>> DefaultSessionR
SessionId = x.SessionId,
SessionNr = x.SessionNr,
UseResultSetTeam = false,
MaxResultsPerGroup = configurationEntity?.ResultsPerTeam ?? 1,
MaxResultsPerGroup = (configurationEntity?.ResultsPerTeam is null or <=0) ? int.MaxValue : configurationEntity.ResultsPerTeam,
Name = x.Name,
UpdateTeamOnRecalculation = false,
ResultKind = configurationEntity?.ChampSeason.ResultKind ?? ResultKind.Member,
Expand Down Expand Up @@ -112,7 +112,7 @@ private static SessionCalculationConfiguration MapFromScoringEntity(ScoringEntit
SessionCalculationConfiguration sessionConfiguration, bool includePointFilters = true)
{
sessionConfiguration.PointRule = GetPointRuleFromEntity(scoring?.PointsRule, configurationEntity, includePointFilters: includePointFilters);
sessionConfiguration.MaxResultsPerGroup = configurationEntity.ResultsPerTeam;
sessionConfiguration.MaxResultsPerGroup = (configurationEntity.ResultsPerTeam <= 0) ? int.MaxValue : configurationEntity.ResultsPerTeam;
sessionConfiguration.UseResultSetTeam = scoring?.UseResultSetTeam ?? false;
sessionConfiguration.UpdateTeamOnRecalculation = scoring?.UpdateTeamOnRecalculation ?? false;
sessionConfiguration.ScoringId = scoring?.ScoringId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,25 @@ public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> enumerable) where T
/// <param name="predicate"></param>
/// <returns></returns>
public static bool None<T>(this IEnumerable<T> enumerable, Func<T, bool> predicate) => !enumerable.Any(predicate);
/// <summary>
/// Returns the maximum value or the default if the sequence is empty
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="enumerable"></param>
/// <returns></returns>
public static T MaxOrDefault<T>(this IEnumerable<T> enumerable)
{
return enumerable.Any() ? enumerable.Max()! : default(T)!;
}
/// <summary>
/// Returns the maximum value or the default if the sequence is empty
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="enumerable"></param>
/// <param name="selector"></param>
/// <returns></returns>
public static T MaxOrDefault<TSource, T>(this IEnumerable<TSource> enumerable, Func<TSource, T> selector)
{
return enumerable.Any() ? enumerable.Max(selector)! : default(T)!;
}
}
4 changes: 2 additions & 2 deletions src/iRLeagueApiCore.Services/iRLeagueApiCore.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="iRLeagueApiCore.Common" Version="0.10.0" />
<PackageReference Include="iRLeagueDatabaseCore" Version="0.10.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.11.0" />
<PackageReference Include="iRLeagueDatabaseCore" Version="0.11.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,22 @@ public async Task Calculate_ShouldApplyDsqPenalty()
testResultRow.Status.Should().Be((int)RaceStatus.Disqualified);
}

[Fact]
public async Task Calculate_ShouldNotCrashOnEmptyRows()
{
const int rowCount = 0;
var data = GetCalculationData();
data.ResultRows = TestRowBuilder()
.CreateMany(rowCount);
var config = GetCalculationConfiguration(data.LeagueId, data.SessionId);
fixture.Register(() => config);
var sut = CreateSut();

var test = async () => await sut.Calculate(data);

await test.Should().NotThrowAsync();
}

private MemberSessionCalculationService CreateSut()
{
return fixture.Create<MemberSessionCalculationService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ public async Task Calculate_ShouldApplyReviewPenalty()
testRow.TotalPoints.Should().Be(testRow.RacePoints + testRow.BonusPoints - testRow.PenaltyPoints);
}

[Fact]
public async Task Calculate_ShouldNotCrashOnEmptyRows()
{
const int rowCount = 0;
var data = GetCalculationData();
data.ResultRows = TestRowBuilder()
.CreateMany(rowCount);
var config = GetCalculationConfiguration(data.LeagueId, data.SessionId);
fixture.Register(() => config);
var sut = CreateSut();

var test = async () => await sut.Calculate(data);

await test.Should().NotThrowAsync();
}

private TeamSessionCalculationService CreateSut()
{
return fixture.Create<TeamSessionCalculationService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public async Task GetConfigurations_ShouldProvideDefaultConfiguration_WhenConfig
sessionConfig.ScoringId.Should().BeNull();
sessionConfig.UpdateTeamOnRecalculation.Should().BeFalse();
sessionConfig.UseResultSetTeam.Should().BeFalse();
sessionConfig.MaxResultsPerGroup.Should().Be(int.MaxValue);
}
}

Expand Down Expand Up @@ -766,6 +767,29 @@ public async Task GetConfigurations_ShouldProvideBonusPointConfiguration()
}
}

[Theory]
[InlineData(1, 1)]
[InlineData(3, 3)]
[InlineData(0, int.MaxValue)]
[InlineData(-1, int.MaxValue)]
[InlineData(-42, int.MaxValue)]
public async Task GetConfigurations_ShouldProvideConfigWithMaximuResultsPerTeam(int maxResultsPerTeam, int expected)
{
var @event = await GetFirstEventEntity();
var config = accessMockHelper.CreateConfiguration(@event);
config.ResultsPerTeam = maxResultsPerTeam;
dbContext.ResultConfigurations.Add(config);
await dbContext.SaveChangesAsync();
var sut = CreateSut();

var test = await sut.GetConfigurations(@event, config);

foreach(var sessionConfig in test)
{
sessionConfig.MaxResultsPerGroup.Should().Be(expected);
}
}

private SessionCalculationConfigurationProvider CreateSut()
{
return fixture.Create<SessionCalculationConfigurationProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<PackageReference Include="AutoFixture.AutoMoq" Version="4.17.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="FluentIdentityBuilder" Version="0.0.3" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.10.0" />
<PackageReference Include="iRLeagueDatabaseCore" Version="0.10.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.11.0" />
<PackageReference Include="iRLeagueDatabaseCore" Version="0.11.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.9">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading