Skip to content

Commit ab6ee6d

Browse files
authored
Merge pull request #48 from Afischbacher/develop
v3.2.1
2 parents d68904b + 5ffb0ca commit ab6ee6d

14 files changed

+331
-62
lines changed
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
namespace Nhl.Api.Common.Helpers;
2+
3+
/// <summary>
4+
/// The league helper class for all league related information
5+
/// </summary>
6+
public static class HockeyLeague
7+
8+
{
9+
/// <summary>
10+
/// The National Hockey League
11+
/// </summary>
12+
public const string NationalHockeyLeague = "NHL";
13+
14+
/// <summary>
15+
/// The American Hockey League
16+
/// </summary>
17+
public const string AmericanHockeyLeague = "AHL";
18+
19+
/// <summary>
20+
/// The East Coast Hockey League
21+
/// </summary>
22+
public const string EastCoastHockeyLeague = "ECHL";
23+
24+
/// <summary>
25+
/// The Ontario Hockey League
26+
/// </summary>
27+
public const string OntarioHockeyLeague = "OHL";
28+
29+
/// <summary>
30+
/// The Western Hockey League
31+
/// </summary>
32+
public const string WesternHockeyLeague = "WHL";
33+
34+
/// <summary>
35+
/// The Quebec Major Junior Hockey League
36+
/// </summary>
37+
public const string QuebecMajorJuniorHockeyLeague = "QMJHL";
38+
39+
/// <summary>
40+
/// Kontinental Hockey League (Russia, Belarus, China, Finland, Kazakhstan, Latvia, Slovakia)
41+
/// </summary>
42+
public const string KontinentalHockeyLeague = "KHL";
43+
44+
/// <summary>
45+
/// Swedish Hockey League (Sweden)
46+
/// </summary>
47+
public const string SwedishHockeyLeague = "SHL";
48+
49+
/// <summary>
50+
/// Liiga (Finland)
51+
/// </summary>
52+
public const string Liiga = "Liiga";
53+
54+
/// <summary>
55+
/// National League (Switzerland)
56+
/// </summary>
57+
public const string NationalLeague = "NL";
58+
59+
/// <summary>
60+
/// Czech Extraliga (Czech Republic)
61+
/// </summary>
62+
public const string CzechExtraliga = "CEL";
63+
64+
/// <summary>
65+
/// Deutsche Eishockey Liga (Germany)
66+
/// </summary>
67+
public const string DeutscheEishockeyLiga = "DEL";
68+
69+
/// <summary>
70+
/// Elite Ice Hockey League (United Kingdom)
71+
/// </summary>
72+
public const string EliteIceHockeyLeague = "EIHL";
73+
74+
/// <summary>
75+
/// Australian Ice Hockey League (Australia)
76+
/// </summary>
77+
public const string AustralianIceHockeyLeague = "AIHL";
78+
79+
/// <summary>
80+
/// Asia League Ice Hockey (Japan, South Korea, China, Russia)
81+
/// </summary>
82+
public const string AsiaLeagueIceHockey = "ALIH";
83+
84+
/// <summary>
85+
/// Slovak Extraliga (Slovakia)
86+
/// </summary>
87+
public const string SlovakExtraliga = "SlovakExtraliga";
88+
89+
/// <summary>
90+
/// Danish Metal Ligaen (Denmark)
91+
/// </summary>
92+
public const string DanishMetalLigaen = "DanishMetalLigaen";
93+
94+
/// <summary>
95+
/// GET-ligaen (Norway)
96+
/// </summary>
97+
public const string GETLigaen = "GET-ligaen";
98+
99+
/// <summary>
100+
/// Erste Bank Eishockey Liga (Austria, Hungary, Czech Republic, Italy, Slovenia)
101+
/// </summary>
102+
public const string ErsteBankEishockeyLiga = "EBEL";
103+
104+
/// <summary>
105+
/// French Ligue Magnus (France)
106+
/// </summary>
107+
public const string FrenchLigueMagnus = "LigueMagnus";
108+
109+
/// <summary>
110+
/// Polish Hockey League (Poland)
111+
/// </summary>
112+
public const string PolishHockeyLeague = "PHL";
113+
114+
/// <summary>
115+
/// Belarusian Extraleague (Belarus)
116+
/// </summary>
117+
public const string BelarusianExtraleague = "BelarusianExtraleague";
118+
119+
/// <summary>
120+
/// Slovak 1. Liga (Slovakia - Second-tier league)
121+
/// </summary>
122+
public const string Slovak1Liga = "Slovak1Liga";
123+
124+
/// <summary>
125+
/// The National Womens Hockey League
126+
/// </summary>
127+
public const string NationalWomensHockeyLeague = "NWHL";
128+
129+
/// <summary>
130+
/// The Canadian Womens Hockey League
131+
/// </summary>
132+
public const string CanadianWomensHockeyLeague = "CWHL";
133+
}

Nhl.Api.Common/Nhl.Api.Common.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>3.2.0</Version>
4+
<Version>3.2.1</Version>
55
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
</PropertyGroup>

Nhl.Api.Domain/Enumerations/Game/GameType.cs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
/// </summary>
66
public enum GameType
77
{
8+
/// <summary>
9+
/// The NHL game type is a pre season game, see <see cref="GameType"/> for more information
10+
/// </summary>
11+
PreSeason = 1,
12+
813
/// <summary>
914
/// The NHL game type is a regular season game, see <see cref="GameType"/> for more information
1015
/// </summary>

Nhl.Api.Domain/Nhl.Api.Domain.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>3.2.0</Version>
4+
<Version>3.2.1</Version>
55
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
</PropertyGroup>

Nhl.Api.Tests/GameTests.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ public async Task NhlScoresHtmlReportsApiHttpClient_Can_Parse_Html_Report_For_St
213213
var httpClient = new NhlScoresHtmlReportsApiHttpClient();
214214
var gameReport = await httpClient.GetStringAsync("/20232024/PL020206.HTM");
215215

216-
var regex = Regex.Matches(@"(?<=<td class="" \+ bborder"">)Period(.*?)(?=</td>)", gameReport, RegexOptions.Compiled | RegexOptions.IgnoreCase, TimeSpan.FromSeconds(30)).ToList();
216+
var regex = Regex.Matches(gameReport, @"(?<=<td class="" \+ bborder"">)Period(.*?)(?=</td>)", RegexOptions.Compiled, TimeSpan.FromSeconds(30)).ToList();
217217

218218
for (int i = 0; i < regex.Count; i++)
219219
{
220-
var value = Regex.Match(@"([0-9]{1,2}:[0-9]{2}\s[A-Z]{3})", gameReport, RegexOptions.Compiled | RegexOptions.IgnoreCase, TimeSpan.FromSeconds(30)).Groups[0].Value;
220+
var match = regex[i].Value;
221+
var value = Regex.Match(match, @"([0-9]{1,2}:[0-9]{2}\s[A-Z]{3})", RegexOptions.Compiled | RegexOptions.IgnoreCase, TimeSpan.FromSeconds(30)).Groups[0].Value;
221222
if (i <= 1)
222223
{
223224
dictionary["P1"].Add(value);

Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public class TestMethodWithRetryAttribute : TestMethodAttribute
1717
/// <summary>
1818
/// A delay time between each test execution retry attempt
1919
/// </summary>
20-
public TimeSpan RetryDelay { get; set; } = TimeSpan.Zero;
20+
public int RetryDelayInSeconds { get; set; } = 0;
2121

2222
public override TestResult[] Execute(ITestMethod testMethod)
2323
{
2424
var count = RetryCount;
25-
var backOffDelay = RetryDelay;
25+
var backOffDelay = RetryDelayInSeconds;
2626

2727
TestResult[] result = null;
2828
while (count > 0)
2929
{
3030
try
3131
{
32-
Thread.Sleep(backOffDelay);
32+
Thread.Sleep(backOffDelay * 1000);
3333
result = base.Execute(testMethod);
3434
if (result.Any(r => r.TestFailureException != null))
3535
{

Nhl.Api.Tests/Nhl.Api.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>3.2.0</Version>
4+
<Version>3.2.1</Version>
55
<TargetFramework>net8.0</TargetFramework>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

Nhl.Api.Tests/PlayerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ public async Task GetPlayerSpotlightAsync_Test_Get_Player_Spotlights_When_Season
763763
}
764764
}
765765

766-
[TestMethodWithRetry(RetryCount = 5)]
766+
[TestMethodWithRetry(RetryCount = 10, RetryDelayInSeconds = 10)]
767767
public async Task GetAllPlayersAsync_Returns_All_Players()
768768
{
769769
// Arrange

Nhl.Api.Tests/StatisticsTests.cs

+85-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Nhl.Api.Enumerations.Game;
22
using Nhl.Api.Enumerations.Statistic;
33
using Nhl.Api.Models.Season;
4+
using System.Collections.Concurrent;
45
using System.Linq;
56

67
namespace Nhl.Api.Tests;
@@ -161,7 +162,7 @@ public async Task GetTotalPlayerStatisticValueByTypeAndSeasonAsync_Returns_Valid
161162
await using var nhlApi = new NhlApi();
162163

163164
// Act
164-
var result = await nhlApi.GetAllTotalPlayerStatisticValueBySeasonAsync(playerEnum, seasonYear);
165+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerEnum, seasonYear);
165166

166167
// Assert
167168
Assert.IsNotNull(result);
@@ -183,7 +184,7 @@ public async Task GetTotalPlayerStatisticValueByTypeAndSeasonAsync_Returns_Valid
183184
await using var nhlApi = new NhlApi();
184185

185186
// Act
186-
var result = await nhlApi.GetAllTotalPlayerStatisticValueBySeasonAsync(playerId, seasonYear);
187+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerId, seasonYear);
187188

188189
// Assert
189190
Assert.IsNotNull(result);
@@ -204,7 +205,7 @@ public async Task GetTotalPlayerStatisticValueByTypeAndSeasonAsync_Returns_Valid
204205
await using var nhlApi = new NhlApi();
205206

206207
// Act
207-
var result = await nhlApi.GetAllTotalPlayerStatisticValueBySeasonAsync(playerId, seasonYear);
208+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerId, seasonYear, gameType: null);
208209

209210
// Assert
210211
Assert.IsNotNull(result);
@@ -252,7 +253,7 @@ public async Task GetTotalPlayerStatisticValueByTypeAndSeasonAsync_Returns_Valid
252253
await using var nhlApi = new NhlApi();
253254

254255
// Act
255-
var result = await nhlApi.GetAllTotalPlayerStatisticValueBySeasonAsync(playerEnum, seasonYear);
256+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerEnum, seasonYear);
256257

257258
// Assert
258259
Assert.IsNotNull(result);
@@ -289,4 +290,84 @@ public async Task GetTotalPlayerStatisticValueByTypeAndSeasonAsync_Returns_Valid
289290
break;
290291
}
291292
}
293+
294+
[TestMethodWithRetry(RetryCount = 5)]
295+
[DataRow(8478465, "20232024")]
296+
[DataRow(8482496, "20232024")]
297+
[DataRow(8481479, "20232024")]
298+
[DataRow(8477507, "20232024")]
299+
public async Task GetTotalPlayerStatisticValuesByTypeAndSeasonAsync_Returns_Valid_Information_With_Player_Id_Certain_Cases(int playerId, string seasonYear)
300+
{
301+
// Arrange
302+
await using var nhlApi = new NhlApi();
303+
304+
// Act
305+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerId, seasonYear, GameType.RegularSeason);
306+
307+
// Assert
308+
Assert.IsNotNull(result);
309+
}
310+
311+
[TestMethodWithRetry(RetryCount = 5)]
312+
[DataRow(PlayerEnum.GuillaumeBrisebois8478465, "20232024")]
313+
[DataRow(PlayerEnum.NilsAman8482496, "20232024")]
314+
[DataRow(PlayerEnum.BroganRafferty8481479, "20232024")]
315+
[DataRow(PlayerEnum.NikitaZadorov8477507, "20232024")]
316+
public async Task GetTotalPlayerStatisticValuesByTypeAndSeasonAsync_Returns_Valid_Information_With_Player_Enum_Certain_Cases_For_Regular_Season(PlayerEnum playerEnum, string seasonYear)
317+
{
318+
// Arrange
319+
await using var nhlApi = new NhlApi();
320+
321+
// Act
322+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerEnum, seasonYear, GameType.RegularSeason);
323+
324+
// Assert
325+
Assert.IsNotNull(result);
326+
}
327+
328+
[TestMethodWithRetry(RetryCount = 10)]
329+
public async Task GetTotalPlayerStatisticValuesByTypeAndSeasonAsync_Returns_Valid_Information_For_Random_Players()
330+
{
331+
// Arrange
332+
await using var nhlApi = new NhlApi();
333+
334+
var indexes = new HashSet<int>();
335+
Enumerable.Range(1,50).ToList().ForEach( i => indexes.Add(new Random().Next(0, 1000)));
336+
337+
var concurrentCollection = new ConcurrentBag<PlayerEnum>(Enum.GetValues(typeof(PlayerEnum)).Cast<PlayerEnum>().ToList().Select((value, i) =>
338+
{
339+
if (indexes.Contains(i))
340+
{
341+
return value;
342+
}
343+
344+
return default;
345+
346+
}).Where(x => x != default));
347+
348+
Parallel.ForEach(concurrentCollection, new ParallelOptions { MaxDegreeOfParallelism = 16 }, async (playerEnum) =>
349+
{
350+
// Act
351+
var result = await nhlApi.GetAllTotalPlayerStatisticValuesBySeasonAsync(playerEnum, "20232024", GameType.RegularSeason);
352+
353+
// Assert
354+
Assert.IsNotNull(result);
355+
});
356+
}
357+
358+
[TestMethodWithRetry(RetryCount = 5)]
359+
[DataRow(8471675, "20122013")]
360+
[DataRow(8471214, "20182019")]
361+
public async Task GetTotalPlayerStatisticValueByTypeAndSeasonAsync_Returns_Valid_Information_With_Player_Id_For_Playoffs(int playerId, string seasonYear)
362+
{
363+
// Arrange
364+
await using var nhlApi = new NhlApi();
365+
366+
// Act
367+
var result = await nhlApi.GetTotalPlayerStatisticValueByTypeAndSeasonAsync(playerId, PlayerGameCenterStatistic.MissedShot, seasonYear, gameType: GameType.Playoffs);
368+
369+
// Assert
370+
Assert.IsNotNull(result);
371+
Assert.IsTrue(result > 5);
372+
}
292373
}

Nhl.Api/Nhl.Api.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>3.2.0</Version>
4+
<Version>3.2.1</Version>
55
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
66
<PackageId>Nhl.Api</PackageId>
77
<Title>Nhl.Api</Title>

0 commit comments

Comments
 (0)