Skip to content

Commit

Permalink
Fix party matching (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
idormenco authored Aug 1, 2024
1 parent 6899cc8 commit 39a687f
Show file tree
Hide file tree
Showing 7 changed files with 1,801 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/ElectionResults.Core/Elections/ResultsProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public static ElectionResultsResponse PopulateElectionResults(Turnout electionTu
results.Candidates = [];
foreach (var candidate in candidates)
{
var matchingParty = parties.GetMatchingParty(candidate.ShortName)
?? parties.FirstOrDefault(p => p.Name.ContainsString(candidate.Name))
?? parties.FirstOrDefault(p => p.Alias.ContainsString(candidate.Name));

var matchingParty = parties.GetMatchingParty(candidate.ShortName)
?? parties.FirstOrDefault(p => p.Alias.GenerateSlug().Equals(candidate.Name.GenerateSlug()))
?? parties.FirstOrDefault(p => p.Name.GenerateSlug().Equals(candidate.Name.GenerateSlug()))
?? parties.FirstOrDefault(p => p.Alias.GenerateSlug().ContainsString(candidate.Name.GenerateSlug()))
?? parties.FirstOrDefault(p => p.Name.GenerateSlug().ContainsString(candidate.Name.GenerateSlug()));

var name = candidate.GetCandidateName(ballot);
var shortName = candidate.GetCandidateShortName(ballot);

Expand Down
2 changes: 0 additions & 2 deletions src/ElectionResults.Hangfire/ElectionResults.Hangfire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Hangfire" Version="8.0.1" />
<PackageReference Include="Azure.Identity" Version="1.10.3" />
<PackageReference Include="CsvHelper" Version="32.0.3" />
<PackageReference Include="Diacritics" Version="3.3.29" />
<PackageReference Include="EFCore.BulkExtensions" Version="8.0.4" />
Expand All @@ -19,7 +18,6 @@
<PackageReference Include="Hangfire.Dashboard.Basic.Authentication" Version="7.0.1" />
<PackageReference Include="Hangfire.InMemory" Version="0.9.0" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
Expand Down
30 changes: 30 additions & 0 deletions src/ElectionResults.Tests/ElectionResults.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ElectionResults.Core\ElectionResults.Core.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/ElectionResults.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
21 changes: 21 additions & 0 deletions src/ElectionResults.Tests/PartiesExtensionsShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json;
using ElectionResults.Core.Entities;
using ElectionResults.Core.Extensions;
using FluentAssertions;

namespace ElectionResults.Tests;

public class PartiesExtensionsShould
{
private readonly List<Party> _parties = JsonSerializer.Deserialize<List<Party>>(TestData.SerializedParties);

[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData("\t")]
[InlineData(null)]
public void ReturnNullWhenShortnameIsNullOrEmpty(string testValue)
{
_parties.GetMatchingParty(testValue).Should().BeNull();
}
}
Loading

0 comments on commit 39a687f

Please sign in to comment.