From 0d81634354e5eb8d945a09135e5d06394456aadf Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Fri, 1 Sep 2023 16:21:26 -0400 Subject: [PATCH 1/8] added readme --- Nhl.Api/Nhl.Api.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Nhl.Api/Nhl.Api.csproj b/Nhl.Api/Nhl.Api.csproj index 001523b0..d29735f6 100644 --- a/Nhl.Api/Nhl.Api.csproj +++ b/Nhl.Api/Nhl.Api.csproj @@ -8,6 +8,7 @@ Copyright (c) 2023 Andre Fischbacher Andre Fischbacher The official unofficial .NET NHL API + README.md https://github.com/Afischbacher/Nhl.Api https://github.com/Afischbacher/Nhl.Api Github @@ -50,6 +51,7 @@ + From e4ce25718a48dddf79987864829cbc4a1ae378e4 Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Fri, 1 Sep 2023 16:42:03 -0400 Subject: [PATCH 2/8] reducing parallelisim --- Nhl.Api.Tests/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nhl.Api.Tests/AssemblyInfo.cs b/Nhl.Api.Tests/AssemblyInfo.cs index 53ba7251..856987ec 100644 --- a/Nhl.Api.Tests/AssemblyInfo.cs +++ b/Nhl.Api.Tests/AssemblyInfo.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -[assembly: Parallelize(Workers = 16, Scope = ExecutionScope.MethodLevel)] +[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.MethodLevel)] namespace Nhl.Api.Tests { internal class AssemblyInfo From 7700c6b7c7ccb475718fdeb2d67ad408d58e40b3 Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Fri, 1 Sep 2023 17:44:33 -0400 Subject: [PATCH 3/8] added ms test attribute, removed polly and updated tests to have a policy in place --- Nhl.Api.Tests/CachingServiceTests.cs | 7 +- Nhl.Api.Tests/ConferenceTests.cs | 9 +- Nhl.Api.Tests/CountryCodeHelperTests.cs | 3 +- Nhl.Api.Tests/DateTimeHelperTests.cs | 7 +- Nhl.Api.Tests/DivisionTests.cs | 9 +- Nhl.Api.Tests/DraftTests.cs | 9 +- Nhl.Api.Tests/FranchiseTests.cs | 13 +- Nhl.Api.Tests/GameTests.cs | 67 ++--- .../TestMethodWithRetryAttribute.cs | 54 ++++ Nhl.Api.Tests/LeagueTests.cs | 27 +- Nhl.Api.Tests/LinqExtensionTests.cs | 3 +- Nhl.Api.Tests/Nhl.Api.Tests.csproj | 1 - Nhl.Api.Tests/NhlApiAsyncHelperTests.cs | 5 +- Nhl.Api.Tests/PlayerEnumHelperTests.cs | 3 +- Nhl.Api.Tests/PlayerTests.cs | 278 +++++++++--------- Nhl.Api.Tests/ProspectEnumHelperTests.cs | 3 +- Nhl.Api.Tests/ResourceDisposeTests.cs | 5 +- Nhl.Api.Tests/SeasonTests.cs | 15 +- Nhl.Api.Tests/StatisticsTests.cs | 243 ++++++++------- Nhl.Api.Tests/TeamTests.cs | 51 ++-- Nhl.Api.Tests/VenueEnumHelperTests.cs | 3 +- Nhl.Api.Tests/VenueTests.cs | 7 +- Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs | 2 +- 23 files changed, 433 insertions(+), 391 deletions(-) create mode 100644 Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs diff --git a/Nhl.Api.Tests/CachingServiceTests.cs b/Nhl.Api.Tests/CachingServiceTests.cs index c8c1b630..8279bc34 100644 --- a/Nhl.Api.Tests/CachingServiceTests.cs +++ b/Nhl.Api.Tests/CachingServiceTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Common.Services; +using Nhl.Api.Tests.Helpers.Attributes; using System.Threading.Tasks; namespace Nhl.Api.Tests @@ -8,7 +9,7 @@ namespace Nhl.Api.Tests public class CachingServiceTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestTryAddAsync() { ICachingService service = new CachingService(); @@ -22,7 +23,7 @@ public async Task TestTryAddAsync() Assert.IsNotNull(retrievedValue); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestTryAddUpdateAsync() { ICachingService service = new CachingService(); @@ -42,7 +43,7 @@ public async Task TestTryAddUpdateAsync() Assert.AreEqual(retrievedValue, "new value"); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestTryRemoveAsync() { ICachingService service = new CachingService(); diff --git a/Nhl.Api.Tests/ConferenceTests.cs b/Nhl.Api.Tests/ConferenceTests.cs index dffd673a..e574374f 100644 --- a/Nhl.Api.Tests/ConferenceTests.cs +++ b/Nhl.Api.Tests/ConferenceTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Conference; +using Nhl.Api.Tests.Helpers.Attributes; using System.Threading.Tasks; namespace Nhl.Api.Tests @@ -8,7 +9,7 @@ namespace Nhl.Api.Tests public class ConferenceTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetConferencesAsync() { // Arrange @@ -32,7 +33,7 @@ public async Task TestGetConferencesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetConferenceByIdAsync() { // Arrange @@ -50,7 +51,7 @@ public async Task TestGetConferenceByIdAsync() Assert.IsNotNull(conference.ShortName); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetConferenceByIdEnumAsync() { // Arrange @@ -68,7 +69,7 @@ public async Task TestGetConferenceByIdEnumAsync() Assert.IsNotNull(conference.ShortName); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetConferenceWithInvalidIdAsync() { // Arrange diff --git a/Nhl.Api.Tests/CountryCodeHelperTests.cs b/Nhl.Api.Tests/CountryCodeHelperTests.cs index 8586a72f..dc2e5751 100644 --- a/Nhl.Api.Tests/CountryCodeHelperTests.cs +++ b/Nhl.Api.Tests/CountryCodeHelperTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Common.Helpers; +using Nhl.Api.Tests.Helpers.Attributes; namespace Nhl.Api.Tests { @@ -255,7 +256,7 @@ public class CountryCodeHelperTests [DataRow("YEM")] [DataRow("ZMB")] [DataRow("ZWE")] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void TestCountryCodeHelper(string countryCode) { // Act + Arrange diff --git a/Nhl.Api.Tests/DateTimeHelperTests.cs b/Nhl.Api.Tests/DateTimeHelperTests.cs index 513aae6b..2d4935b2 100644 --- a/Nhl.Api.Tests/DateTimeHelperTests.cs +++ b/Nhl.Api.Tests/DateTimeHelperTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Common.Helpers; +using Nhl.Api.Tests.Helpers.Attributes; using System; namespace Nhl.Api.Tests @@ -12,7 +13,7 @@ public class DateTimeHelperTests [DataRow("20211105_201423")] [DataRow("20201015_201423")] [DataRow("19950210_201423")] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void TestValidDateTimeOffsetHelper(string dateTimeString) { // Act/Arrange @@ -27,7 +28,7 @@ public void TestValidDateTimeOffsetHelper(string dateTimeString) [DataRow("19950210_20142423234543")] [DataRow(" ")] [DataRow("19950210_201424232_34543")] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void TestInValidDateTimeOffsetHelper(string dateTimeString) { // Act/Arrange @@ -43,7 +44,7 @@ public void TestInValidDateTimeOffsetHelper(string dateTimeString) [DataRow("11/11/2003 6:25:13 PM -00:00")] [DataRow("02/12/1985 3:05:23 PM -04:00")] [DataRow("08/18/1995 10:05:23 PM +06:00")] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void TestDateTimeOffsetParsesToTimeStampString(string dateTimeOffsetAsString) { // Act/Arrange diff --git a/Nhl.Api.Tests/DivisionTests.cs b/Nhl.Api.Tests/DivisionTests.cs index b4631d01..9c1253ea 100644 --- a/Nhl.Api.Tests/DivisionTests.cs +++ b/Nhl.Api.Tests/DivisionTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Division; +using Nhl.Api.Tests.Helpers.Attributes; using System.Threading.Tasks; namespace Nhl.Api.Tests @@ -9,7 +10,7 @@ namespace Nhl.Api.Tests public class DivisionTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllDivisionsAsync() { // Arrange @@ -32,7 +33,7 @@ public async Task TestGetAllDivisionsAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetDivisionByIdAsync() { // Arrange @@ -50,7 +51,7 @@ public async Task TestGetDivisionByIdAsync() Assert.IsNotNull(division.NameShort); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetDivisionByIdEnumAsync() { // Arrange @@ -68,7 +69,7 @@ public async Task TestGetDivisionByIdEnumAsync() Assert.IsNotNull(division.NameShort); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetDivisionWithInvalidIdAsync() { // Arrange diff --git a/Nhl.Api.Tests/DraftTests.cs b/Nhl.Api.Tests/DraftTests.cs index ca5b6be3..49535576 100644 --- a/Nhl.Api.Tests/DraftTests.cs +++ b/Nhl.Api.Tests/DraftTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Draft; +using Nhl.Api.Tests.Helpers.Attributes; using System.Linq; using System.Threading.Tasks; @@ -9,7 +10,7 @@ namespace Nhl.Api.Tests public class DraftTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetDraftByYearAsync() { // Arrange @@ -46,7 +47,7 @@ public async Task TestGetDraftByYearAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetProspectsAsync() { // Arrange @@ -75,7 +76,7 @@ public async Task TestGetProspectsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetProspectsByIdAsync() { // Arrange @@ -100,7 +101,7 @@ public async Task TestGetProspectsByIdAsync() Assert.IsNotNull(prospect.LastName); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetProspectsByIdEnumAsync() { // Arrange diff --git a/Nhl.Api.Tests/FranchiseTests.cs b/Nhl.Api.Tests/FranchiseTests.cs index fd3d5810..ef707a75 100644 --- a/Nhl.Api.Tests/FranchiseTests.cs +++ b/Nhl.Api.Tests/FranchiseTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Franchise; +using Nhl.Api.Tests.Helpers.Attributes; using System.Threading.Tasks; namespace Nhl.Api.Tests @@ -8,7 +9,7 @@ namespace Nhl.Api.Tests public class FranchisesTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetFranchisesAsync() { // Arrange @@ -31,7 +32,7 @@ public async Task TestGetFranchisesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllActiveFranchisesAsync() { // Arrange @@ -55,7 +56,7 @@ public async Task TestGetAllActiveFranchisesAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllInactiveFranchisesAsync() { // Arrange @@ -79,7 +80,7 @@ public async Task TestGetAllInactiveFranchisesAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetFranchiseByIdEnumAsync() { // Arrange @@ -97,7 +98,7 @@ public async Task TestGetFranchiseByIdEnumAsync() Assert.IsNotNull(franchise.MostRecentTeamId); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetFranchiseByIdAsync() { // Arrange @@ -115,7 +116,7 @@ public async Task TestGetFranchiseByIdAsync() Assert.IsNotNull(franchise.MostRecentTeamId); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetFranchiseWithInvalidIdAsync() { // Arrange diff --git a/Nhl.Api.Tests/GameTests.cs b/Nhl.Api.Tests/GameTests.cs index 843b223b..59469e24 100644 --- a/Nhl.Api.Tests/GameTests.cs +++ b/Nhl.Api.Tests/GameTests.cs @@ -2,8 +2,7 @@ using Nhl.Api.Common.Exceptions; using Nhl.Api.Models.Enumerations.Team; using Nhl.Api.Models.Game; -using Polly; -using Polly.Retry; +using Nhl.Api.Tests.Helpers.Attributes; using System; using System.Linq; using System.Threading.Tasks; @@ -13,10 +12,8 @@ namespace Nhl.Api.Tests [TestClass] public class GameTests { - private readonly AsyncRetryPolicy _nhlGameAsyncRetryPolicy = Policy.Handle().WaitAndRetryAsync(3, (attempt) => TimeSpan.FromSeconds(attempt * 5)); - - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGameTypesAsync() { // Arrange @@ -36,7 +33,7 @@ public async Task TestGetGameTypesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGameStatusesAsync() { // Arrange @@ -59,7 +56,7 @@ public async Task TestGetGameStatusesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGamePlayTypesAsync() { // Arrange @@ -82,7 +79,7 @@ public async Task TestGetGamePlayTypesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTournamentTypesAsync() { // Arrange @@ -103,7 +100,7 @@ public async Task TestGetTournamentTypesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayoffTournamentTypesAsync() { // Arrange @@ -119,7 +116,7 @@ public async Task TestGetPlayoffTournamentTypesAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleByDateAsync() { // Arrange @@ -147,7 +144,7 @@ public async Task TestGetGetGameScheduleByDateAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleByDateNotNullAsync() { // Arrange @@ -208,7 +205,7 @@ public async Task TestGetGetGameScheduleByDateNotNullAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleWithConfigurationEnabledAsync() { @@ -264,7 +261,7 @@ public async Task TestGetGetGameScheduleWithConfigurationEnabledAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleAsync() { // Arrange @@ -292,7 +289,7 @@ public async Task TestGetGetGameScheduleAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleByDateNotNullWithIntegerAsync() { // Arrange @@ -331,7 +328,7 @@ public async Task TestGetGetGameScheduleByDateNotNullWithIntegerAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleByDateWithTeamEnumAsync() { // Arrange @@ -375,7 +372,7 @@ public async Task TestGetGetGameScheduleByDateWithTeamEnumAsync() [DataRow("19971998", true, false)] [DataRow("20092010", true, true)] [DataRow("20202021", false, true)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGameSchedulesBySeasonAsync(string seasonYear, bool includePlayoffGames, bool includeGameScheduleConfiguration) { @@ -387,10 +384,8 @@ public async Task TestGetGameSchedulesBySeasonAsync(string seasonYear, bool incl : null; // Act - var gameSchedule = await _nhlGameAsyncRetryPolicy.ExecuteAsync(async () => - { - return await nhlApi.GetGameScheduleBySeasonAsync(seasonYear, includePlayoffGames, gameScheduleConfiguration); - }); + var gameSchedule = await nhlApi.GetGameScheduleBySeasonAsync(seasonYear, includePlayoffGames, gameScheduleConfiguration); + // Assert Assert.IsNotNull(gameSchedule); @@ -437,7 +432,7 @@ public async Task TestGetGameSchedulesBySeasonAsync(string seasonYear, bool incl } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameSchedulesBySeasonInvalidSeasonYearLengthAsync() { // Arrange @@ -452,7 +447,7 @@ await Assert.ThrowsExceptionAsync(async () => } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameSchedulesBySeasonInvalidSeasonYearValueAsync() { // Arrange @@ -466,7 +461,7 @@ await Assert.ThrowsExceptionAsync(async () => }); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGetGameScheduleByDateWithTeamIdAsync() { // Arrange @@ -506,7 +501,7 @@ public async Task TestGetGetGameScheduleByDateWithTeamIdAsync() - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedWithConfigurationSettingsAsync() { // Arrange @@ -530,7 +525,7 @@ public async Task TestGetLiveGameFeedWithConfigurationSettingsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedWithConfigurationSettingsWithCancellationAsync() { // Arrange @@ -556,7 +551,7 @@ public async Task TestGetLiveGameFeedWithConfigurationSettingsWithCancellationAs } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedWithDefaultConfigurationSettingsAsync() { // Arrange @@ -575,7 +570,7 @@ public async Task TestGetLiveGameFeedWithDefaultConfigurationSettingsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedAsync() { // Arrange @@ -732,7 +727,7 @@ public async Task TestGetLiveGameFeedAsync() Assert.IsNotNull(firstStar.Link); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedInvalidGamePkAsync() { // Arrange @@ -889,7 +884,7 @@ public async Task TestGetLiveGameFeedInvalidGamePkAsync() [DataRow(2019020249)] [DataRow(2019020902)] [DataRow(2020020290)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedGetCorrectRinkSideAsync(int gameId) { // Arrange @@ -916,7 +911,7 @@ public async Task TestGetLiveGameFeedGetCorrectRinkSideAsync(int gameId) Assert.AreNotEqual(awayRinkSide, awayCorrectedRinkSide); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLineScoreAsync() { // Arrange @@ -948,7 +943,7 @@ public async Task TestGetLineScoreAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLineScoreWithInvalidIdAsync() { // Arrange @@ -966,7 +961,7 @@ public async Task TestGetLineScoreWithInvalidIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetBoxScoreAsync() { // Arrange @@ -1010,7 +1005,7 @@ public async Task TestGetBoxScoreAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetBoxScoreWithInvalidIdAsync() { // Arrange @@ -1026,7 +1021,7 @@ public async Task TestGetBoxScoreWithInvalidIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedShiftChartAsync() { // Arrange @@ -1053,7 +1048,7 @@ public async Task TestGetLiveGameFeedShiftChartAsync() Assert.IsNotNull(firstShift.HexValue); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedShiftChartInvalidGameIdAsync() { // Arrange @@ -1075,7 +1070,7 @@ public async Task TestGetLiveGameFeedShiftChartInvalidGameIdAsync() [DataRow(2018020652)] [DataRow(2019020663)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLiveGameFeedContentAsync(int gameId) { // Arrange diff --git a/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs b/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs new file mode 100644 index 00000000..b535a3a3 --- /dev/null +++ b/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs @@ -0,0 +1,54 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Nhl.Api.Tests.Helpers.Attributes; + +/// +/// An Microsoft Test custom attribute for retrying on failed test methods +/// +public class TestMethodWithRetryAttribute : TestMethodAttribute +{ + + /// + /// A property to set for the number of retries a test method should attempt to re-test the function method + /// + public int RetryCount { get; set; } = 1; + + /// + /// A delay time between each test execution retry attempt + /// + public TimeSpan RetryDelay { get; set; } = TimeSpan.Zero; + + public override TestResult[] Execute(ITestMethod testMethod) + { + var count = RetryCount; + var backOffDelay = RetryDelay; + + TestResult[] result = null; + while (count > 0) + { + try + { + Thread.Sleep(backOffDelay); + result = base.Execute(testMethod); + if (result.Any(r => r.TestFailureException != null)) + { + throw result.First(r => r.TestFailureException != null).TestFailureException; + } + } + catch (Exception) when (count > 0) + { + } + finally + { + count--; + } + } + + return result; + } +} + diff --git a/Nhl.Api.Tests/LeagueTests.cs b/Nhl.Api.Tests/LeagueTests.cs index 8c9d4215..0aaa0793 100644 --- a/Nhl.Api.Tests/LeagueTests.cs +++ b/Nhl.Api.Tests/LeagueTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Award; +using Nhl.Api.Tests.Helpers.Attributes; using System; using System.Threading.Tasks; @@ -8,7 +9,7 @@ namespace Nhl.Api.Tests [TestClass] public class LeagueTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsNullDateAsync() { // Arrange @@ -31,7 +32,7 @@ public async Task TestGetLeagueStandingsNullDateAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsAsync() { // Arrange @@ -55,7 +56,7 @@ public async Task TestGetLeagueStandingsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsByConferenceAsync() { // Arrange @@ -78,7 +79,7 @@ public async Task TestGetLeagueStandingsByConferenceAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsByDivisionAsync() { // Arrange @@ -101,7 +102,7 @@ public async Task TestGetLeagueStandingsByDivisionAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsByDivisionWithDateAsync() { // Arrange @@ -122,7 +123,7 @@ public async Task TestGetLeagueStandingsByDivisionWithDateAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsByConferenceWithDateAsync() { // Arrange @@ -144,7 +145,7 @@ public async Task TestGetLeagueStandingsByConferenceWithDateAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsByDivisionWithNullDateAsync() { // Arrange @@ -165,7 +166,7 @@ public async Task TestGetLeagueStandingsByDivisionWithNullDateAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsByConferenceWithNullDateAsync() { // Arrange @@ -188,7 +189,7 @@ public async Task TestGetLeagueStandingsByConferenceWithNullDateAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingsWithDateAsync() { // Arrange @@ -211,7 +212,7 @@ public async Task TestGetLeagueStandingsWithDateAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueAwardsAsync() { // Arrange @@ -236,7 +237,7 @@ public async Task TestGetLeagueAwardsAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueAwardsByIdAsync() { // Arrange @@ -259,7 +260,7 @@ public async Task TestGetLeagueAwardsByIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueAwardsByIdEnumAsync() { // Arrange @@ -284,7 +285,7 @@ public async Task TestGetLeagueAwardsByIdEnumAsync() - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetEventTypesAsync() { // Arrange diff --git a/Nhl.Api.Tests/LinqExtensionTests.cs b/Nhl.Api.Tests/LinqExtensionTests.cs index a7fa534c..5aa19e29 100644 --- a/Nhl.Api.Tests/LinqExtensionTests.cs +++ b/Nhl.Api.Tests/LinqExtensionTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Nhl.Api.Tests.Helpers.Attributes; using System.Collections.Generic; using System.Linq; @@ -13,7 +14,7 @@ class TestLinqClass public int Number { get; set; } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void TestDistinctByLinqMethod() { var testCollection = new List() diff --git a/Nhl.Api.Tests/Nhl.Api.Tests.csproj b/Nhl.Api.Tests/Nhl.Api.Tests.csproj index 0fbd64fe..1fcc8d92 100644 --- a/Nhl.Api.Tests/Nhl.Api.Tests.csproj +++ b/Nhl.Api.Tests/Nhl.Api.Tests.csproj @@ -18,7 +18,6 @@ - diff --git a/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs b/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs index 3b703061..d9349161 100644 --- a/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs +++ b/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Common.Services; +using Nhl.Api.Tests.Helpers.Attributes; using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; @@ -9,13 +10,13 @@ namespace Nhl.Api.Tests [TestClass] public class NhlApiAsyncHelperTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestRunSyncAsync() { NhlApiAsyncHelper.RunSync(async () => await Task.Run(() => Task.Delay(100)) ); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestForEachAsync() { var numbers = new ConcurrentBag(new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, }); diff --git a/Nhl.Api.Tests/PlayerEnumHelperTests.cs b/Nhl.Api.Tests/PlayerEnumHelperTests.cs index 31acdc0f..326a3b03 100644 --- a/Nhl.Api.Tests/PlayerEnumHelperTests.cs +++ b/Nhl.Api.Tests/PlayerEnumHelperTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Player; +using Nhl.Api.Tests.Helpers.Attributes; namespace Nhl.Api.Tests { @@ -7,7 +8,7 @@ namespace Nhl.Api.Tests [TestClass] public class PlayerEnumHelperTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void GetAllPlayersTest() { var players = PlayerEnumHelper.GetAllPlayers(); diff --git a/Nhl.Api.Tests/PlayerTests.cs b/Nhl.Api.Tests/PlayerTests.cs index 05755cb9..9cad1664 100644 --- a/Nhl.Api.Tests/PlayerTests.cs +++ b/Nhl.Api.Tests/PlayerTests.cs @@ -3,7 +3,7 @@ using Nhl.Api.Models.Enumerations.Player; using Nhl.Api.Models.Player; using Nhl.Api.Models.Season; -using Polly; +using Nhl.Api.Tests.Helpers.Attributes; using System; using System.Collections.Generic; using System.Diagnostics; @@ -16,7 +16,7 @@ namespace Nhl.Api.Tests [TestClass] public class PlayerTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerByIdAsync() { // Arrange @@ -61,7 +61,7 @@ public async Task TestGetPlayerByIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerByIdEnumAsync() { // Arrange @@ -104,7 +104,7 @@ public async Task TestGetPlayerByIdEnumAsync() Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Large)); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetManyPlayersByIdEnumAsync() { // Arrange @@ -149,7 +149,7 @@ public async Task TestGetManyPlayersByIdEnumAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetManyPlayersByIdAsync() { // Arrange @@ -194,7 +194,7 @@ public async Task TestGetManyPlayersByIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerByInvalidIdAsync() { // Arrange @@ -207,7 +207,7 @@ public async Task TestGetPlayerByInvalidIdAsync() Assert.IsNull(player); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsByTypeAndSeasonAsync() { // Arrange @@ -258,7 +258,7 @@ public async Task TestGetPlayerStatisticsByTypeAndSeasonAsync() Assert.IsNotNull(statisticsSplits.PlayerStatisticsData.EvenTimeOnIcePerGame); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsYearByYearAsync() { // Arrange @@ -308,7 +308,7 @@ public async Task TestGetPlayerStatisticsYearByYearAsync() Assert.IsNotNull(statisticsSplits.PlayerStatisticsData.FaceOffPct); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsHomeAndAwayAsync() { // Arrange @@ -356,7 +356,7 @@ public async Task TestGetPlayerStatisticsHomeAndAwayAsync() Assert.IsNotNull(statisticsSplits.PlayerStatisticsData.FaceOffPct); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsYearByYearWithPlayerIdAsync() { // Arrange @@ -400,7 +400,7 @@ public async Task TestGetPlayerStatisticsYearByYearWithPlayerIdAsync() Assert.IsNotNull(statisticsSplits.PlayerStatisticsData.FaceOffPct); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsHomeAndAwayWithPlayerIdAsync() { // Arrange @@ -446,7 +446,7 @@ public async Task TestGetPlayerStatisticsHomeAndAwayWithPlayerIdAsync() Assert.IsNotNull(statisticsSplits.PlayerStatisticsData.FaceOffPct); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsByTypeAndSeasonWithPlayerIdAsync() { // Arrange @@ -498,7 +498,7 @@ public async Task TestGetPlayerStatisticsByTypeAndSeasonWithPlayerIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerStatisticsByTypeAndSeasonWithPlayerInvalidPlayerTypeAsync() { // Arrange @@ -511,7 +511,7 @@ await Assert.ThrowsExceptionAsync((System.Func(async () => }); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsByTypeAndSeasonAsync() { // Arrange @@ -575,7 +575,7 @@ public async Task TestGetGoalieStatisticsByTypeAndSeasonAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsYearByYearWithPlayerIdAsync() { // Arrange @@ -625,7 +625,7 @@ public async Task TestGetGoalieStatisticsYearByYearWithPlayerIdAsync() - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsYearByYearAsync() { // Arrange @@ -674,7 +674,7 @@ public async Task TestGetGoalieStatisticsYearByYearAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsHomeAndAwayWithPlayerIdAsync() { // Arrange @@ -725,7 +725,7 @@ public async Task TestGetGoalieStatisticsHomeAndAwayWithPlayerIdAsync() - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsHomeAndAwayAsync() { // Arrange @@ -776,7 +776,7 @@ public async Task TestGetGoalieStatisticsHomeAndAwayAsync() - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsWithPlayerIdAndSeasonAsync() { // Arrange @@ -825,7 +825,7 @@ public async Task TestGetGoalieStatisticsWithPlayerIdAndSeasonAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] [DataRow("Wayne Gretzky")] [DataRow("Alex Ovechkin")] [DataRow("Connor McDavid")] @@ -891,7 +891,7 @@ public async Task TestSearchAllPlayersAsync(string query) } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] [DataRow("Carter Hart")] [DataRow("Auston Matthews")] [DataRow("Connor McDavid")] @@ -971,7 +971,7 @@ public async Task TestSearchAllActivePlayersAsync(string query) } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestSearchAllPlayersNoResultsAsync() { // Arrange @@ -987,7 +987,7 @@ public async Task TestSearchAllPlayersNoResultsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestSearchAllActivePlayersNoResultsAsync() { // Arrange @@ -1002,7 +1002,7 @@ public async Task TestSearchAllActivePlayersNoResultsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestPlayersByIdWithTasksAsync() { // Arrange @@ -1034,7 +1034,7 @@ public async Task TestPlayersByIdWithTasksAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] [DataRow(PlayerEnum.SidneyCrosby8471675)] [DataRow(PlayerEnum.ConnorMcDavid8478402)] [DataRow(PlayerEnum.AustonMatthews8479318)] @@ -1094,7 +1094,7 @@ public async Task TestGetOnPaceRegularSeasonPlayerStatisticsWithEnumAsync(Player } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] [DataRow(8471675)] [DataRow(8478402)] [DataRow(8479318)] @@ -1154,7 +1154,7 @@ public async Task TestGetOnPaceRegularSeasonPlayerStatisticsWithIdAsync(int play } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsByTypeAndSeasonWithPlayerInvalidPlayerTypeAsync() { // Arrange @@ -1167,7 +1167,7 @@ await Assert.ThrowsExceptionAsync((async () => })); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieStatisticsByTypeAndSeasonWithPlayerIdInvalidPlayerTypeAsync() { // Arrange @@ -1180,127 +1180,115 @@ await Assert.ThrowsExceptionAsync(async () => }); } - [TestMethod] - public void TestGetAllPlayersAsync() + [TestMethodWithRetry(RetryCount = 5)] + public async Task TestGetAllPlayersAsync() { - Policy - .Handle() - .WaitAndRetryAsync(3, (attempt) => TimeSpan.FromSeconds(attempt * 5), - async (exception, timeSpan) => - { - // Arrange - await using INhlApi nhlApi = new NhlApi(); - - var stopWatch = new Stopwatch(); - - stopWatch.Start(); - // Act - var players = await nhlApi.GetAllPlayersAsync(); - - stopWatch.Stop(); - - Assert.IsTrue(stopWatch.Elapsed.TotalSeconds < 60); - - stopWatch.Reset(); - stopWatch.Start(); - - // Calling again to ensure caching is enabled - players = await nhlApi.GetAllPlayersAsync(); - stopWatch.Stop(); - - Assert.IsTrue(stopWatch.Elapsed.TotalSeconds < 10); - - // Assert - Assert.IsNotNull(players); - CollectionAssert.AllItemsAreUnique(players); - Assert.IsTrue(players.Any()); - Assert.IsTrue(players.Count() > 21000); - - var lastPlayer = players.Last(); - - Assert.IsNotNull(lastPlayer); - - Assert.IsNotNull(lastPlayer.Active); - Assert.IsNotNull(lastPlayer.AlternateCaptain); - Assert.IsNotNull(lastPlayer.BirthCountry); - Assert.IsNotNull(lastPlayer.BirthCity); - - Assert.IsNotNull(lastPlayer.BirthDate); - Assert.IsNotNull(lastPlayer.Captain); - Assert.IsNotNull(lastPlayer.CurrentAge); - - Assert.IsNotNull(lastPlayer.FirstName); - Assert.IsNotNull(lastPlayer.LastName); - Assert.IsNotNull(lastPlayer.FullName); - Assert.IsNotNull(lastPlayer.Height); - Assert.IsNotNull(lastPlayer.ShootsCatches); - Assert.IsNotNull(lastPlayer.RosterStatus); - Assert.IsNotNull(lastPlayer.Weight); - Assert.IsNotNull(lastPlayer.Rookie); - Assert.IsNotNull(lastPlayer.Nationality); - Assert.IsNotNull(lastPlayer.Id); - Assert.IsNotNull(lastPlayer.Link); - Assert.IsNotNull(lastPlayer.PlayerHeadshotImageLink); - Assert.IsNotNull(lastPlayer.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Small)); - Assert.IsNotNull(lastPlayer.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Medium)); - Assert.IsNotNull(lastPlayer.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Large)); - }); + // Arrange + await using INhlApi nhlApi = new NhlApi(); + + var stopWatch = new Stopwatch(); + + stopWatch.Start(); + // Act + var players = await nhlApi.GetAllPlayersAsync(); + + stopWatch.Stop(); + + Assert.IsTrue(stopWatch.Elapsed.TotalSeconds < 60); + + stopWatch.Reset(); + stopWatch.Start(); + + // Calling again to ensure caching is enabled + players = await nhlApi.GetAllPlayersAsync(); + stopWatch.Stop(); + + Assert.IsTrue(stopWatch.Elapsed.TotalSeconds < 10); + + // Assert + Assert.IsNotNull(players); + Assert.IsTrue(players.Any()); + Assert.IsTrue(players.Count() > 21000); + + var lastPlayer = players.Last(); + + Assert.IsNotNull(lastPlayer); + + Assert.IsNotNull(lastPlayer.Active); + Assert.IsNotNull(lastPlayer.AlternateCaptain); + Assert.IsNotNull(lastPlayer.BirthCountry); + Assert.IsNotNull(lastPlayer.BirthCity); + + Assert.IsNotNull(lastPlayer.BirthDate); + Assert.IsNotNull(lastPlayer.Captain); + Assert.IsNotNull(lastPlayer.CurrentAge); + + Assert.IsNotNull(lastPlayer.FirstName); + Assert.IsNotNull(lastPlayer.LastName); + Assert.IsNotNull(lastPlayer.FullName); + Assert.IsNotNull(lastPlayer.Height); + Assert.IsNotNull(lastPlayer.ShootsCatches); + Assert.IsNotNull(lastPlayer.RosterStatus); + Assert.IsNotNull(lastPlayer.Weight); + Assert.IsNotNull(lastPlayer.Rookie); + Assert.IsNotNull(lastPlayer.Nationality); + Assert.IsNotNull(lastPlayer.Id); + Assert.IsNotNull(lastPlayer.Link); + Assert.IsNotNull(lastPlayer.PlayerHeadshotImageLink); + Assert.IsNotNull(lastPlayer.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Small)); + Assert.IsNotNull(lastPlayer.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Medium)); + Assert.IsNotNull(lastPlayer.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Large)); } - [TestMethod] - public void TestGetAllPlayersAsAsyncEnumerable() + [TestMethodWithRetry(RetryCount = 5)] + public async Task TestGetAllPlayersAsAsyncEnumerable() { - Policy - .Handle() - .WaitAndRetryAsync(3, (attempt) => TimeSpan.FromSeconds(attempt * 5), - async (exception, timeSpan) => - { - // Arrange - await using INhlApi nhlApi = new NhlApi(); - - // Act - var players = nhlApi.GetAllPlayersAsAsyncEnumerable(); - - int count = 0; - await foreach (var player in players) - { - if (count > 10) break; - - // Assert - Assert.IsNotNull(player); - - Assert.IsNotNull(player.Active); - Assert.IsNotNull(player.AlternateCaptain); - Assert.IsNotNull(player.BirthCountry); - Assert.IsNotNull(player.BirthCity); - - Assert.IsNotNull(player.BirthDate); - Assert.IsNotNull(player.Captain); - Assert.IsNotNull(player.CurrentAge); - - Assert.IsNotNull(player.FirstName); - Assert.IsNotNull(player.LastName); - Assert.IsNotNull(player.FullName); - Assert.IsNotNull(player.Height); - Assert.IsNotNull(player.ShootsCatches); - Assert.IsNotNull(player.RosterStatus); - Assert.IsNotNull(player.Weight); - Assert.IsNotNull(player.Rookie); - Assert.IsNotNull(player.Nationality); - Assert.IsNotNull(player.Id); - Assert.IsNotNull(player.Link); - Assert.IsNotNull(player.PlayerHeadshotImageLink); - Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Small)); - Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Medium)); - Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Large)); - count++; - } - - }); + + // Arrange + await using INhlApi nhlApi = new NhlApi(); + + // Act + var players = nhlApi.GetAllPlayersAsAsyncEnumerable(); + + int count = 0; + await foreach (var player in players) + { + if (count > 10) break; + + // Assert + Assert.IsNotNull(player); + + Assert.IsNotNull(player.Active); + Assert.IsNotNull(player.AlternateCaptain); + Assert.IsNotNull(player.BirthCountry); + Assert.IsNotNull(player.BirthCity); + + Assert.IsNotNull(player.BirthDate); + Assert.IsNotNull(player.Captain); + Assert.IsNotNull(player.CurrentAge); + + Assert.IsNotNull(player.FirstName); + Assert.IsNotNull(player.LastName); + Assert.IsNotNull(player.FullName); + Assert.IsNotNull(player.Height); + Assert.IsNotNull(player.ShootsCatches); + Assert.IsNotNull(player.RosterStatus); + Assert.IsNotNull(player.Weight); + Assert.IsNotNull(player.Rookie); + Assert.IsNotNull(player.Nationality); + Assert.IsNotNull(player.Id); + Assert.IsNotNull(player.Link); + Assert.IsNotNull(player.PlayerHeadshotImageLink); + Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Small)); + Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Medium)); + Assert.IsNotNull(player.GetPlayerHeadshotImageLink(PlayerHeadshotImageSize.Large)); + count++; + } + } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestDownloadPlayerHeadshotImageAsync() { // Arrange @@ -1314,7 +1302,7 @@ public async Task TestDownloadPlayerHeadshotImageAsync() Assert.IsTrue(image.Length > 5000); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestDownloadPlayerHeadshotImageWithIdAsync() { // Arrange @@ -1328,7 +1316,7 @@ public async Task TestDownloadPlayerHeadshotImageWithIdAsync() Assert.IsTrue(image.Length > 5000); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestDownloadPlayerHeadshotImageWithInvalidIdAsync() { // Arrange diff --git a/Nhl.Api.Tests/ProspectEnumHelperTests.cs b/Nhl.Api.Tests/ProspectEnumHelperTests.cs index 95d0ec5a..d8d1dab3 100644 --- a/Nhl.Api.Tests/ProspectEnumHelperTests.cs +++ b/Nhl.Api.Tests/ProspectEnumHelperTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Prospect; +using Nhl.Api.Tests.Helpers.Attributes; namespace Nhl.Api.Tests { @@ -7,7 +8,7 @@ namespace Nhl.Api.Tests [TestClass] public class ProspectEnumHelperTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void GetAllProspects() { var prospects = ProspectEnumHelper.GetAllProspects(); diff --git a/Nhl.Api.Tests/ResourceDisposeTests.cs b/Nhl.Api.Tests/ResourceDisposeTests.cs index df321bd5..4f78a02c 100644 --- a/Nhl.Api.Tests/ResourceDisposeTests.cs +++ b/Nhl.Api.Tests/ResourceDisposeTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Nhl.Api.Tests.Helpers.Attributes; using System; using System.Collections.Generic; using System.Linq; @@ -10,7 +11,7 @@ namespace Nhl.Api.Tests [TestClass] public class ResourceDisposeTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task ResourceDisposeAsyncTest() { await using var nhlApi = new NhlApi(); @@ -18,7 +19,7 @@ public async Task ResourceDisposeAsyncTest() await nhlApi.DisposeAsync(); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void ResourceDisposeTest() { using var nhlApi = new NhlApi(); diff --git a/Nhl.Api.Tests/SeasonTests.cs b/Nhl.Api.Tests/SeasonTests.cs index 9b63e316..7b3f0854 100644 --- a/Nhl.Api.Tests/SeasonTests.cs +++ b/Nhl.Api.Tests/SeasonTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Season; +using Nhl.Api.Tests.Helpers.Attributes; using System.Threading.Tasks; namespace Nhl.Api.Tests @@ -8,7 +9,7 @@ namespace Nhl.Api.Tests public class SeasonTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueStandingTypesAsync() { // Arrange @@ -28,7 +29,7 @@ public async Task TestGetLeagueStandingTypesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetSeasonBySeasonYearAsync() { // Arrange @@ -51,7 +52,7 @@ public async Task TestGetSeasonBySeasonYearAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetCurrentSeasonAsync() { // Arrange @@ -73,7 +74,7 @@ public async Task TestGetCurrentSeasonAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllSeasonsAsync() { // Arrange @@ -98,7 +99,7 @@ public async Task TestGetAllSeasonsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestIsSeasonActiveAsync() { // Arrange @@ -111,7 +112,7 @@ public async Task TestIsSeasonActiveAsync() Assert.IsNotNull(isSeasonActive); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestIsRegularSeasonActiveAsync() { // Arrange @@ -124,7 +125,7 @@ public async Task TestIsRegularSeasonActiveAsync() Assert.IsNotNull(isSeasonActive); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestIsPlayoffSeasonActiveAsync() { // Arrange diff --git a/Nhl.Api.Tests/StatisticsTests.cs b/Nhl.Api.Tests/StatisticsTests.cs index 214e3103..618d86a2 100644 --- a/Nhl.Api.Tests/StatisticsTests.cs +++ b/Nhl.Api.Tests/StatisticsTests.cs @@ -3,8 +3,7 @@ using Nhl.Api.Models.Enumerations.Player; using Nhl.Api.Models.Enumerations.Team; using Nhl.Api.Models.Season; -using Polly; -using Polly.Retry; +using Nhl.Api.Tests.Helpers.Attributes; using System; using System.Threading.Tasks; @@ -13,9 +12,8 @@ namespace Nhl.Api.Tests [TestClass] public class StatisticsTests { - private readonly AsyncRetryPolicy _nhlPlayerStatisticsAsyncRetryPolicy = Policy.Handle().WaitAndRetryAsync(3, (attempt) => TimeSpan.FromSeconds(attempt * 5)); - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetStatisticsTypesAsync() { // Arrange @@ -35,7 +33,7 @@ public async Task TestGetStatisticsTypesAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamStatisticByIdAsync() { // Arrange @@ -101,7 +99,7 @@ public async Task TestGetTeamStatisticByIdAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamStatisticByIdEnumAsync() { // Arrange @@ -167,7 +165,7 @@ public async Task TestGetTeamStatisticByIdEnumAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamStatisticByIdWithSeasonYearAsync() { // Arrange @@ -233,7 +231,7 @@ public async Task TestGetTeamStatisticByIdWithSeasonYearAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamStatisticByIdWithEnumAndSeasonYearAsync() { // Arrange @@ -299,7 +297,7 @@ public async Task TestGetTeamStatisticByIdWithEnumAndSeasonYearAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayerByStatisticTypeBySeasonAsync() { await using INhlApi nhlApi = new NhlApi(); @@ -308,33 +306,31 @@ public async Task TestGetPlayerByStatisticTypeBySeasonAsync() foreach (var playerStatistic in enumValues) { - await _nhlPlayerStatisticsAsyncRetryPolicy.ExecuteAsync(async () => - { - var player = await nhlApi.GetPlayerByStatisticTypeBySeasonAsync(playerStatistic, SeasonYear.season20192020); + var player = await nhlApi.GetPlayerByStatisticTypeBySeasonAsync(playerStatistic, SeasonYear.season20192020); + + Assert.IsNotNull(player); + Assert.IsNotNull(player.PlayerStatisticsData); + Assert.IsNotNull(player.PlayerStatisticsData.Shifts); + Assert.IsNotNull(player.PlayerStatisticsData.Shots); + Assert.IsNotNull(player.PlayerStatisticsData.ShortHandedGoals); + Assert.IsNotNull(player.PlayerStatisticsData.Assists); + Assert.IsNotNull(player.PlayerStatisticsData.Points); + + Assert.IsNotNull(player.PlayerStatisticsData.Hits); + Assert.IsNotNull(player.PlayerStatisticsData.Pim); + Assert.IsNotNull(player.PlayerStatisticsData.FaceOffPct); + Assert.IsNotNull(player.PlayerStatisticsData.Games); + Assert.IsNotNull(player.PlayerStatisticsData.TimeOnIce); + + Assert.IsNotNull(player.Player); + Assert.IsNotNull(player.Player); + Assert.IsNotNull(player.Player.Id); + Assert.IsNotNull(player.Player.FullName); - Assert.IsNotNull(player); - Assert.IsNotNull(player.PlayerStatisticsData); - Assert.IsNotNull(player.PlayerStatisticsData.Shifts); - Assert.IsNotNull(player.PlayerStatisticsData.Shots); - Assert.IsNotNull(player.PlayerStatisticsData.ShortHandedGoals); - Assert.IsNotNull(player.PlayerStatisticsData.Assists); - Assert.IsNotNull(player.PlayerStatisticsData.Points); - - Assert.IsNotNull(player.PlayerStatisticsData.Hits); - Assert.IsNotNull(player.PlayerStatisticsData.Pim); - Assert.IsNotNull(player.PlayerStatisticsData.FaceOffPct); - Assert.IsNotNull(player.PlayerStatisticsData.Games); - Assert.IsNotNull(player.PlayerStatisticsData.TimeOnIce); - - Assert.IsNotNull(player.Player); - Assert.IsNotNull(player.Player); - Assert.IsNotNull(player.Player.Id); - Assert.IsNotNull(player.Player.FullName); - }); } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoalieByStatisticTypeBySeasonAsync() { await using INhlApi nhlApi = new NhlApi(); @@ -343,31 +339,29 @@ public async Task TestGetGoalieByStatisticTypeBySeasonAsync() foreach (var goalieStatistic in enumValues) { - await _nhlPlayerStatisticsAsyncRetryPolicy.ExecuteAsync(async () => - { - var goalie = await nhlApi.GetGoalieByStatisticTypeBySeasonAsync(goalieStatistic, SeasonYear.season19992000); + var goalie = await nhlApi.GetGoalieByStatisticTypeBySeasonAsync(goalieStatistic, SeasonYear.season19992000); - Assert.IsNotNull(goalie); + Assert.IsNotNull(goalie); - Assert.IsNotNull(goalie.GoalieStatisticsData.SavePercentage); - Assert.IsNotNull(goalie.GoalieStatisticsData.EvenSaves); - Assert.IsNotNull(goalie.GoalieStatisticsData.Games); - Assert.IsNotNull(goalie.GoalieStatisticsData.GamesStarted); - Assert.IsNotNull(goalie.GoalieStatisticsData.TimeOnIcePerGame); - Assert.IsNotNull(goalie.GoalieStatisticsData.PowerPlaySavePercentage); - Assert.IsNotNull(goalie.GoalieStatisticsData.Wins); - Assert.IsNotNull(goalie.GoalieStatisticsData.Losses); - Assert.IsNotNull(goalie.GoalieStatisticsData.Shutouts); - Assert.IsNotNull(goalie.GoalieStatisticsData.ShotsAgainst); + Assert.IsNotNull(goalie.GoalieStatisticsData.SavePercentage); + Assert.IsNotNull(goalie.GoalieStatisticsData.EvenSaves); + Assert.IsNotNull(goalie.GoalieStatisticsData.Games); + Assert.IsNotNull(goalie.GoalieStatisticsData.GamesStarted); + Assert.IsNotNull(goalie.GoalieStatisticsData.TimeOnIcePerGame); + Assert.IsNotNull(goalie.GoalieStatisticsData.PowerPlaySavePercentage); + Assert.IsNotNull(goalie.GoalieStatisticsData.Wins); + Assert.IsNotNull(goalie.GoalieStatisticsData.Losses); + Assert.IsNotNull(goalie.GoalieStatisticsData.Shutouts); + Assert.IsNotNull(goalie.GoalieStatisticsData.ShotsAgainst); + + Assert.IsNotNull(goalie.Player); + Assert.IsNotNull(goalie.Player.Id); + Assert.IsNotNull(goalie.Player.FullName); - Assert.IsNotNull(goalie.Player); - Assert.IsNotNull(goalie.Player.Id); - Assert.IsNotNull(goalie.Player.FullName); - }); } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayersByStatisticTypeBySeasonAsync() { await using INhlApi nhlApi = new NhlApi(); @@ -376,37 +370,35 @@ public async Task TestGetPlayersByStatisticTypeBySeasonAsync() foreach (var playerStatistic in enumValues) { - await _nhlPlayerStatisticsAsyncRetryPolicy.ExecuteAsync(async () => + + var players = await nhlApi.GetPlayersByStatisticTypeBySeasonAsync(playerStatistic, SeasonYear.season20192020); + foreach (var player in players) { - var players = await nhlApi.GetPlayersByStatisticTypeBySeasonAsync(playerStatistic, SeasonYear.season20192020); - foreach (var player in players) - { - - Assert.IsNotNull(player); - Assert.IsNotNull(player.PlayerStatisticsData); - Assert.IsNotNull(player.PlayerStatisticsData.Shifts); - Assert.IsNotNull(player.PlayerStatisticsData.Shots); - Assert.IsNotNull(player.PlayerStatisticsData.ShortHandedGoals); - Assert.IsNotNull(player.PlayerStatisticsData.Assists); - Assert.IsNotNull(player.PlayerStatisticsData.Points); - - Assert.IsNotNull(player.PlayerStatisticsData.Hits); - Assert.IsNotNull(player.PlayerStatisticsData.Pim); - Assert.IsNotNull(player.PlayerStatisticsData.FaceOffPct); - Assert.IsNotNull(player.PlayerStatisticsData.Games); - Assert.IsNotNull(player.PlayerStatisticsData.TimeOnIce); - - Assert.IsNotNull(player.Player); - Assert.IsNotNull(player.Player); - Assert.IsNotNull(player.Player.Id); - Assert.IsNotNull(player.Player.FullName); - } - }); + + Assert.IsNotNull(player); + Assert.IsNotNull(player.PlayerStatisticsData); + Assert.IsNotNull(player.PlayerStatisticsData.Shifts); + Assert.IsNotNull(player.PlayerStatisticsData.Shots); + Assert.IsNotNull(player.PlayerStatisticsData.ShortHandedGoals); + Assert.IsNotNull(player.PlayerStatisticsData.Assists); + Assert.IsNotNull(player.PlayerStatisticsData.Points); + + Assert.IsNotNull(player.PlayerStatisticsData.Hits); + Assert.IsNotNull(player.PlayerStatisticsData.Pim); + Assert.IsNotNull(player.PlayerStatisticsData.FaceOffPct); + Assert.IsNotNull(player.PlayerStatisticsData.Games); + Assert.IsNotNull(player.PlayerStatisticsData.TimeOnIce); + + Assert.IsNotNull(player.Player); + Assert.IsNotNull(player.Player); + Assert.IsNotNull(player.Player.Id); + Assert.IsNotNull(player.Player.FullName); + } } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetPlayersByStatisticTypeBySeasonAscendingAsync() { await using INhlApi nhlApi = new NhlApi(); @@ -415,37 +407,36 @@ public async Task TestGetPlayersByStatisticTypeBySeasonAscendingAsync() foreach (var playerStatistic in enumValues) { - await _nhlPlayerStatisticsAsyncRetryPolicy.ExecuteAsync(async () => + + var players = await nhlApi.GetPlayersByStatisticTypeBySeasonAsync(playerStatistic, SeasonYear.season20192020, isDescending: false, numberOfPlayers: 25); + foreach (var player in players) { - var players = await nhlApi.GetPlayersByStatisticTypeBySeasonAsync(playerStatistic, SeasonYear.season20192020, isDescending: false, numberOfPlayers: 25); - foreach (var player in players) - { - - Assert.IsNotNull(player); - Assert.IsNotNull(player.PlayerStatisticsData); - Assert.IsNotNull(player.PlayerStatisticsData.Shifts); - Assert.IsNotNull(player.PlayerStatisticsData.Shots); - Assert.IsNotNull(player.PlayerStatisticsData.ShortHandedGoals); - Assert.IsNotNull(player.PlayerStatisticsData.Assists); - Assert.IsNotNull(player.PlayerStatisticsData.Points); - - Assert.IsNotNull(player.PlayerStatisticsData.Hits); - Assert.IsNotNull(player.PlayerStatisticsData.Pim); - Assert.IsNotNull(player.PlayerStatisticsData.FaceOffPct); - Assert.IsNotNull(player.PlayerStatisticsData.Games); - Assert.IsNotNull(player.PlayerStatisticsData.TimeOnIce); - - Assert.IsNotNull(player.Player); - Assert.IsNotNull(player.Player); - Assert.IsNotNull(player.Player.Id); - Assert.IsNotNull(player.Player.FullName); - } - }); + + Assert.IsNotNull(player); + Assert.IsNotNull(player.PlayerStatisticsData); + Assert.IsNotNull(player.PlayerStatisticsData.Shifts); + Assert.IsNotNull(player.PlayerStatisticsData.Shots); + Assert.IsNotNull(player.PlayerStatisticsData.ShortHandedGoals); + Assert.IsNotNull(player.PlayerStatisticsData.Assists); + Assert.IsNotNull(player.PlayerStatisticsData.Points); + + Assert.IsNotNull(player.PlayerStatisticsData.Hits); + Assert.IsNotNull(player.PlayerStatisticsData.Pim); + Assert.IsNotNull(player.PlayerStatisticsData.FaceOffPct); + Assert.IsNotNull(player.PlayerStatisticsData.Games); + Assert.IsNotNull(player.PlayerStatisticsData.TimeOnIce); + + Assert.IsNotNull(player.Player); + Assert.IsNotNull(player.Player); + Assert.IsNotNull(player.Player.Id); + Assert.IsNotNull(player.Player.FullName); + } + } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetGoaliesWithTopStatisticBySeasonAsync() { await using INhlApi nhlApi = new NhlApi(); @@ -454,31 +445,29 @@ public async Task TestGetGoaliesWithTopStatisticBySeasonAsync() foreach (var goalieStatistic in enumValues) { - await _nhlPlayerStatisticsAsyncRetryPolicy.ExecuteAsync(async () => + + var goalies = await nhlApi.GetGoaliesByStatisticTypeBySeasonAsync(goalieStatistic, SeasonYear.season20212022); + + var test = JsonConvert.SerializeObject(goalies); + foreach (var goalie in goalies) { - var goalies = await nhlApi.GetGoaliesByStatisticTypeBySeasonAsync(goalieStatistic, SeasonYear.season20212022); - - var test = JsonConvert.SerializeObject(goalies); - foreach (var goalie in goalies) - { - Assert.IsNotNull(goalie); - - Assert.IsNotNull(goalie.GoalieStatisticsData.SavePercentage); - Assert.IsNotNull(goalie.GoalieStatisticsData.EvenSaves); - Assert.IsNotNull(goalie.GoalieStatisticsData.Games); - Assert.IsNotNull(goalie.GoalieStatisticsData.GamesStarted); - Assert.IsNotNull(goalie.GoalieStatisticsData.TimeOnIcePerGame); - Assert.IsNotNull(goalie.GoalieStatisticsData.PowerPlaySavePercentage); - Assert.IsNotNull(goalie.GoalieStatisticsData.Wins); - Assert.IsNotNull(goalie.GoalieStatisticsData.Losses); - Assert.IsNotNull(goalie.GoalieStatisticsData.Shutouts); - Assert.IsNotNull(goalie.GoalieStatisticsData.ShotsAgainst); - - Assert.IsNotNull(goalie.Player); - Assert.IsNotNull(goalie.Player.Id); - Assert.IsNotNull(goalie.Player.FullName); - } - }); + Assert.IsNotNull(goalie); + + Assert.IsNotNull(goalie.GoalieStatisticsData.SavePercentage); + Assert.IsNotNull(goalie.GoalieStatisticsData.EvenSaves); + Assert.IsNotNull(goalie.GoalieStatisticsData.Games); + Assert.IsNotNull(goalie.GoalieStatisticsData.GamesStarted); + Assert.IsNotNull(goalie.GoalieStatisticsData.TimeOnIcePerGame); + Assert.IsNotNull(goalie.GoalieStatisticsData.PowerPlaySavePercentage); + Assert.IsNotNull(goalie.GoalieStatisticsData.Wins); + Assert.IsNotNull(goalie.GoalieStatisticsData.Losses); + Assert.IsNotNull(goalie.GoalieStatisticsData.Shutouts); + Assert.IsNotNull(goalie.GoalieStatisticsData.ShotsAgainst); + + Assert.IsNotNull(goalie.Player); + Assert.IsNotNull(goalie.Player.Id); + Assert.IsNotNull(goalie.Player.FullName); + } } } } diff --git a/Nhl.Api.Tests/TeamTests.cs b/Nhl.Api.Tests/TeamTests.cs index 9756b077..41f9b136 100644 --- a/Nhl.Api.Tests/TeamTests.cs +++ b/Nhl.Api.Tests/TeamTests.cs @@ -2,6 +2,7 @@ using Nhl.Api.Models.Enumerations.Team; using Nhl.Api.Models.Season; using Nhl.Api.Models.Team; +using Nhl.Api.Tests.Helpers.Attributes; using System; using System.Collections.Generic; using System.Linq; @@ -13,7 +14,7 @@ namespace Nhl.Api.Tests public class TeamTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamsAsync() { // Arrange @@ -47,7 +48,7 @@ public async Task TestGetTeamsAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllActiveTeamsAsync() { @@ -83,7 +84,7 @@ public async Task TestGetAllActiveTeamsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllInactiveTeamsAsync() { // Arrange @@ -119,7 +120,7 @@ public async Task TestGetAllInactiveTeamsAsync() - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamByIdAsync() { // Arrange @@ -148,7 +149,7 @@ public async Task TestGetTeamByIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamByIdInvalidAsync() { // Arrange @@ -162,7 +163,7 @@ public async Task TestGetTeamByIdInvalidAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamColorsAsync() { // Arrange @@ -178,7 +179,7 @@ public async Task TestGetTeamColorsAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamColorsInvalidTeamIdAsync() { // Arrange @@ -191,7 +192,7 @@ public async Task TestGetTeamColorsInvalidTeamIdAsync() Assert.IsNull(teamColor); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamColorsEnumAsync() { // Arrange @@ -208,7 +209,7 @@ public async Task TestGetTeamColorsEnumAsync() Assert.IsNotNull(teamColor.QuinaryColor); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllTeamColorsEnumAsync() { // Arrange @@ -228,7 +229,7 @@ public async Task TestGetAllTeamColorsEnumAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamByIdEnumAsync() { // Arrange @@ -256,7 +257,7 @@ public async Task TestGetTeamByIdEnumAsync() Assert.IsNotNull(team.FirstYearOfPlay); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamsByIdsEnumAsync() { // Arrange @@ -288,7 +289,7 @@ public async Task TestGetTeamsByIdsEnumAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamsByIdsEnumEmptyArrayAsync() { // Arrange @@ -303,7 +304,7 @@ public async Task TestGetTeamsByIdsEnumEmptyArrayAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamsByIdsIntAsync() { // Arrange @@ -338,7 +339,7 @@ public async Task TestGetTeamsByIdsIntAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamsByIdsIntEmptyArrayAsync() { // Arrange @@ -353,7 +354,7 @@ public async Task TestGetTeamsByIdsIntEmptyArrayAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetManyTeamsByTasksAsync() { // Arrange @@ -368,7 +369,7 @@ public async Task TestGetManyTeamsByTasksAsync() Assert.AreEqual(2, teams.Count()); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllPlayersAsync() { // Arrange @@ -452,7 +453,7 @@ public async Task TestSearchLeagueTeamRosterMembersAsync(string query) } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestSearchLeagueTeamRosterMembersNullQueryAsync() { // Arrange @@ -465,7 +466,7 @@ public async Task TestSearchLeagueTeamRosterMembersNullQueryAsync() Assert.AreEqual(0, players.Count); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamWithInvalidIdAsync() { // Arrange @@ -482,7 +483,7 @@ public async Task TestGetTeamWithInvalidIdAsync() [DataRow(TeamEnum.ArizonaCoyotes)] [DataRow(TeamEnum.DetroitRedWings)] [DataRow(TeamEnum.AnaheimDucks)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamLogoLightAsync(TeamEnum teamEnum) { // Arrange @@ -506,7 +507,7 @@ public async Task TestGetTeamLogoLightAsync(TeamEnum teamEnum) [DataRow(TeamEnum.SanJoseSharks)] [DataRow(TeamEnum.ColumbusBlueJackets)] [DataRow(TeamEnum.ChicagoBlackhawks)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamLogoDarkAsync(TeamEnum teamEnum) { // Arrange @@ -529,7 +530,7 @@ public async Task TestGetTeamLogoDarkAsync(TeamEnum teamEnum) [DataRow(55)] [DataRow(7)] [DataRow(24)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamLogoLightAsIntAsync(int teamId) { // Arrange @@ -553,7 +554,7 @@ public async Task TestGetTeamLogoLightAsIntAsync(int teamId) [DataRow(28)] [DataRow(6)] [DataRow(5)] - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamLogoDarkAsIntAsync(int teamId) { // Arrange @@ -572,7 +573,7 @@ public async Task TestGetTeamLogoDarkAsIntAsync(int teamId) Assert.IsTrue(teamLogo.ImageAsBase64String.Length > 0); } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamStatisticsBySeasonWithEnumAsync() { @@ -678,7 +679,7 @@ public async Task TestGetTeamStatisticsBySeasonWithEnumAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetTeamStatisticsBySeasonWithIntAsync() { @@ -784,7 +785,7 @@ public async Task TestGetTeamStatisticsBySeasonWithIntAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllTeamStatisticsBySeasonWithIntAsync() { diff --git a/Nhl.Api.Tests/VenueEnumHelperTests.cs b/Nhl.Api.Tests/VenueEnumHelperTests.cs index 41ff0d36..ecc7ab02 100644 --- a/Nhl.Api.Tests/VenueEnumHelperTests.cs +++ b/Nhl.Api.Tests/VenueEnumHelperTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Team; +using Nhl.Api.Tests.Helpers.Attributes; namespace Nhl.Api.Tests { @@ -7,7 +8,7 @@ namespace Nhl.Api.Tests [TestClass] public class VenueEnumHelperTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public void GetAllVenuesTest() { var venues = VenueEnumHelper.GetAllVenues(); diff --git a/Nhl.Api.Tests/VenueTests.cs b/Nhl.Api.Tests/VenueTests.cs index ed6cf407..0f284ec2 100644 --- a/Nhl.Api.Tests/VenueTests.cs +++ b/Nhl.Api.Tests/VenueTests.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Nhl.Api.Models.Enumerations.Venue; +using Nhl.Api.Tests.Helpers.Attributes; using System.Threading.Tasks; namespace Nhl.Api.Tests @@ -7,7 +8,7 @@ namespace Nhl.Api.Tests [TestClass] public class VenueTests { - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetAllVenuesAsync() { // Arrange @@ -28,7 +29,7 @@ public async Task TestGetAllVenuesAsync() } } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueVenueByIdAsync() { // Arrange @@ -46,7 +47,7 @@ public async Task TestGetLeagueVenueByIdAsync() } - [TestMethod] + [TestMethodWithRetry(RetryCount = 5)] public async Task TestGetLeagueVenueByIdEnumAsync() { // Arrange diff --git a/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs b/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs index 78bc1f4e..43880223 100644 --- a/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs +++ b/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs @@ -78,7 +78,7 @@ public async Task> GetAllPlayersAsync() await _cachingService.TryAddUpdateAsync(nameof(GetAllPlayersAsync), players); // Return all known NHL players - return players; + return players.Distinct().ToList(); } From 30707223d3ec01f27b353b2dbc646b8dbbb53cb3 Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Sat, 7 Oct 2023 13:28:21 -0400 Subject: [PATCH 4/8] fixed test issue --- Nhl.Api.Tests/GameTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nhl.Api.Tests/GameTests.cs b/Nhl.Api.Tests/GameTests.cs index 59469e24..456a6bf7 100644 --- a/Nhl.Api.Tests/GameTests.cs +++ b/Nhl.Api.Tests/GameTests.cs @@ -251,7 +251,7 @@ public async Task TestGetGetGameScheduleWithConfigurationEnabledAsync() Assert.IsNotNull(game.Broadcasts.First().Id); Assert.IsNotNull(game.Broadcasts.First().Type); - if (game.Tickets != null) + if (game.Tickets != null && game.Tickets.Any()) { Assert.IsNotNull(game.Tickets.First()); Assert.IsNotNull(game.Tickets.First().TicketLink); From 853009b9e2d98ca172630d4db9c4e112765fd80c Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Sun, 8 Oct 2023 12:39:05 -0400 Subject: [PATCH 5/8] fixed some errors with update resource uri's and fixed tests --- .../Http/NhlStaticAssetsApiHttpClient.cs | 2 +- .../Http/NhlSuggestionApiHttpClient.cs | 2 +- .../Models/Player/PlayerSearchResponse.cs | 5 +- .../Models/Player/PlayerSearchResult.cs | 77 ++++++++++++++--- .../TestMethodWithRetryAttribute.cs | 4 + Nhl.Api.Tests/PlayerTests.cs | 57 ++++++------- Nhl.Api/Src/Api/NhlApi.cs | 7 +- Nhl.Api/Src/LeagueApi/NhlLeagueApi.cs | 49 ++++++++++- Nhl.Api/Src/PlayerApi/INhlPlayerApi.cs | 6 +- Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs | 83 ++----------------- 10 files changed, 164 insertions(+), 128 deletions(-) diff --git a/Nhl.Api.Common/Http/NhlStaticAssetsApiHttpClient.cs b/Nhl.Api.Common/Http/NhlStaticAssetsApiHttpClient.cs index 7a19c0b0..9186dea9 100644 --- a/Nhl.Api.Common/Http/NhlStaticAssetsApiHttpClient.cs +++ b/Nhl.Api.Common/Http/NhlStaticAssetsApiHttpClient.cs @@ -13,7 +13,7 @@ public class NhlStaticAssetsApiHttpClient : NhlApiHttpClient /// /// The dedicated NHL static assets NHL HTTP API endpoint /// - public const string ClientApiUrl = "https://www-league.nhlstatic.com"; + public const string ClientApiUrl = "https://assets.nhle.com"; /// /// The dedicated NHL static assets HTTP Client for the Nhl.Api diff --git a/Nhl.Api.Common/Http/NhlSuggestionApiHttpClient.cs b/Nhl.Api.Common/Http/NhlSuggestionApiHttpClient.cs index 843869b9..5a407030 100644 --- a/Nhl.Api.Common/Http/NhlSuggestionApiHttpClient.cs +++ b/Nhl.Api.Common/Http/NhlSuggestionApiHttpClient.cs @@ -14,7 +14,7 @@ public class NhlSuggestionApiHttpClient : NhlApiHttpClient /// /// The NHL HTTP API endpoint for the NHL suggestion API /// - public const string ClientApiUrl = "https://suggest.svc.nhl.com/svc/suggest/"; + public const string ClientApiUrl = "https://search.d3.nhle.com/api/"; /// /// The dedicated NHL HTTP Client for the NHL suggestion API diff --git a/Nhl.Api.Domain/Models/Player/PlayerSearchResponse.cs b/Nhl.Api.Domain/Models/Player/PlayerSearchResponse.cs index 58712103..53651727 100644 --- a/Nhl.Api.Domain/Models/Player/PlayerSearchResponse.cs +++ b/Nhl.Api.Domain/Models/Player/PlayerSearchResponse.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System; using System.Collections.Generic; namespace Nhl.Api.Models.Player @@ -6,12 +6,13 @@ namespace Nhl.Api.Models.Player /// /// NHL Player Search Response /// + [Obsolete("This class is obsolete use the PlayerSearchResult class instead")] public class PlayerSearchResponse { /// /// A collection of suggestions for NHL player search /// - [JsonProperty("suggestions")] + [Obsolete("This property is obsolete use the PlayerSearchResult class instead")] public List Suggestions { get; set; } } } diff --git a/Nhl.Api.Domain/Models/Player/PlayerSearchResult.cs b/Nhl.Api.Domain/Models/Player/PlayerSearchResult.cs index 619f757f..73eb9503 100644 --- a/Nhl.Api.Domain/Models/Player/PlayerSearchResult.cs +++ b/Nhl.Api.Domain/Models/Player/PlayerSearchResult.cs @@ -17,19 +17,24 @@ public class PlayerSearchResult [JsonProperty("playerId")] public int PlayerId { get; set; } + /// + /// The full name of the NHL player
+ /// Example: Connor Bedard + ///
+ [JsonProperty("name")] + public string Name { get; set; } + /// /// First name of NHL player
/// Example: Wayne ///
- [JsonProperty("firstName")] - public string FirstName { get; set; } + public string FirstName => Name?.Split(' ')[0]; /// /// Last name of NHL player
/// Example: Gretzky ///
- [JsonProperty("lastName")] - public string LastName { get; set; } + public string LastName => Name?.Split(' ')[1]; /// /// Height of the NHL player in feet and inches
@@ -38,13 +43,28 @@ public class PlayerSearchResult [JsonProperty("height")] public string Height { get; set; } + /// + /// Height of the NHL player in centimeters
+ /// Example: 183 + ///
+ [JsonProperty("heightInCentimeters")] + public string HeightInCentimeters { get; set; } + /// /// Weight of the NHL player in pounds
/// Example: 185 ///
- [JsonProperty("weight")] + [JsonProperty("weightInPounds")] public string Weight { get; set; } + /// + /// Weight of the NHL player in kilograms
+ /// Example: 185 + ///
+ [JsonProperty("weightInKilograms")] + public string WeightInKilograms { get; set; } + + /// /// City of birth for the NHL player
/// Example: Brantford @@ -56,7 +76,7 @@ public class PlayerSearchResult /// Province or state of birth for the NHL player
/// Example: ON ///
- [JsonProperty("birthProvinceState")] + [JsonProperty("birthStateProvince")] public string BirthProvinceState { get; set; } /// @@ -82,13 +102,14 @@ public string FullBirthCountry /// /// Is the player currently active in the NHL /// - [JsonProperty("isActive")] + [JsonProperty("active")] public bool IsActive { get; set; } /// /// Date of birth for the NHL player
/// Example: 1961-01-26 ///
+ [Obsolete("This property is not longer available in the NHL API for player search")] [JsonProperty("birthDate")] public DateTime BirthDate { get; set; } @@ -104,15 +125,51 @@ public string FullBirthCountry /// The position for the NHL player
/// Example: C ///
- [JsonProperty("position")] + [JsonProperty("positionCode")] public string Position { get; set; } /// /// The jersey number for the NHL player
/// Example: C ///
- [JsonProperty("playerNumber")] - public int PlayerNumber { get; set; } + [JsonProperty("sweaterNumber")] + public int? PlayerNumber { get; set; } + + /// + /// The team identifier for the NHL team the NHL player played with
+ /// Example: 5 + ///
+ [JsonProperty("teamId")] + public string TeamId { get; set; } + + /// + /// The team abbreviation for the NHL team the NHL player played with
+ /// Example: PIT + ///
+ [JsonProperty("teamAbbrev")] + public string TeamAbbreviation { get; set; } + + /// + /// The team name for the NHL team the NHL player played last with
+ /// Example: 5 + ///
+ [JsonProperty("lastTeamId")] + public string LastTeamId { get; set; } + + /// + /// The last team abbreviation for the NHL team the NHL player played with
+ /// Example: TOR + ///
+ [JsonProperty("lastTeamAbbrev")] + public string LastTeamAbbreviation { get; set; } + + /// + /// The last season identifier for the NHL team the NHL player played with
+ /// Example: 20232024 + ///
+ [JsonProperty("lastSeasonId")] + public object LastSeasonId { get; set; } + } } diff --git a/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs b/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs index b535a3a3..21d770b5 100644 --- a/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs +++ b/Nhl.Api.Tests/Helpers/Attributes/TestMethodWithRetryAttribute.cs @@ -38,6 +38,10 @@ public override TestResult[] Execute(ITestMethod testMethod) { throw result.First(r => r.TestFailureException != null).TestFailureException; } + else + { + return result; + } } catch (Exception) when (count > 0) { diff --git a/Nhl.Api.Tests/PlayerTests.cs b/Nhl.Api.Tests/PlayerTests.cs index 9cad1664..9a18daa4 100644 --- a/Nhl.Api.Tests/PlayerTests.cs +++ b/Nhl.Api.Tests/PlayerTests.cs @@ -826,10 +826,10 @@ public async Task TestGetGoalieStatisticsWithPlayerIdAndSeasonAsync() [TestMethodWithRetry(RetryCount = 5)] - [DataRow("Wayne Gretzky")] - [DataRow("Alex Ovechkin")] - [DataRow("Connor McDavid")] - public async Task TestSearchAllPlayersAsync(string query) + [DataRow("Wayne Gretzky", 99)] + [DataRow("Alex Ovechkin", 8)] + [DataRow("Connor McDavid", 97)] + public async Task TestSearchAllPlayersAsync(string query, int numberOfPlayer) { // Arrange await using INhlApi nhlApi = new NhlApi(); @@ -841,7 +841,7 @@ public async Task TestSearchAllPlayersAsync(string query) Assert.IsNotNull(results); CollectionAssert.AllItemsAreNotNull(results); - var playerSearchResult = results.First(); + var playerSearchResult = results.First(r => r.PlayerNumber == numberOfPlayer); switch (query) { @@ -849,12 +849,11 @@ public async Task TestSearchAllPlayersAsync(string query) Assert.AreEqual("Brantford", playerSearchResult.BirthCity); Assert.AreEqual("CAN", playerSearchResult.BirthCountry); Assert.AreEqual("Canada", playerSearchResult.FullBirthCountry); - Assert.AreEqual("ON", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1961-01-26"), playerSearchResult.BirthDate); + Assert.AreEqual("Ontario", playerSearchResult.BirthProvinceState); Assert.AreEqual("Wayne", playerSearchResult.FirstName); Assert.AreEqual("Gretzky", playerSearchResult.LastName); - Assert.AreEqual("NYR", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 0\"", playerSearchResult.Height); + Assert.AreEqual("NYR", playerSearchResult.LastTeamAbbreviation); + Assert.AreEqual("6\u00270\"", playerSearchResult.Height); Assert.AreEqual(false, playerSearchResult.IsActive); Assert.AreEqual(99, playerSearchResult.PlayerNumber); break; @@ -863,13 +862,12 @@ public async Task TestSearchAllPlayersAsync(string query) Assert.AreEqual("Moscow", playerSearchResult.BirthCity); Assert.AreEqual("RUS", playerSearchResult.BirthCountry); Assert.AreEqual("Russian Federation", playerSearchResult.FullBirthCountry); - Assert.AreEqual("", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1985-09-17"), playerSearchResult.BirthDate); + Assert.AreEqual(null, playerSearchResult.BirthProvinceState); Assert.AreEqual("Alex", playerSearchResult.FirstName); Assert.AreEqual("Ovechkin", playerSearchResult.LastName); Assert.AreEqual(true, playerSearchResult.IsActive); - Assert.AreEqual("WSH", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 3\"", playerSearchResult.Height); + Assert.AreEqual("WSH", playerSearchResult.LastTeamAbbreviation); + Assert.AreEqual("6\u00273\"", playerSearchResult.Height); Assert.AreEqual(8, playerSearchResult.PlayerNumber); break; @@ -877,13 +875,12 @@ public async Task TestSearchAllPlayersAsync(string query) Assert.AreEqual("Richmond Hill", playerSearchResult.BirthCity); Assert.AreEqual("CAN", playerSearchResult.BirthCountry); Assert.AreEqual("Canada", playerSearchResult.FullBirthCountry); - Assert.AreEqual("ON", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1997-01-13"), playerSearchResult.BirthDate); + Assert.AreEqual("Ontario", playerSearchResult.BirthProvinceState); Assert.AreEqual("Connor", playerSearchResult.FirstName); Assert.AreEqual("McDavid", playerSearchResult.LastName); Assert.AreEqual(true, playerSearchResult.IsActive); - Assert.AreEqual("EDM", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 1\"", playerSearchResult.Height); + Assert.AreEqual("EDM", playerSearchResult.LastTeamAbbreviation); + Assert.AreEqual("6\u00271\"", playerSearchResult.Height); Assert.AreEqual(97, playerSearchResult.PlayerNumber); break; } @@ -917,11 +914,10 @@ public async Task TestSearchAllActivePlayersAsync(string query) Assert.AreEqual("CZE", playerSearchResult.BirthCountry); Assert.AreEqual("Czech Republic", playerSearchResult.FullBirthCountry); Assert.AreEqual("", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1996-05-25"), playerSearchResult.BirthDate); Assert.AreEqual("David", playerSearchResult.FirstName); Assert.AreEqual("Pastrnak", playerSearchResult.LastName); - Assert.AreEqual("BOS", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 0\"", playerSearchResult.Height); + Assert.AreEqual("BOS", playerSearchResult.TeamAbbreviation); + Assert.AreEqual("6\u00270\"", playerSearchResult.Height); Assert.AreEqual(true, playerSearchResult.IsActive); Assert.AreEqual(88, playerSearchResult.PlayerNumber); break; @@ -930,13 +926,12 @@ public async Task TestSearchAllActivePlayersAsync(string query) Assert.AreEqual("Sherwood Park", playerSearchResult.BirthCity); Assert.AreEqual("CAN", playerSearchResult.BirthCountry); Assert.AreEqual("Canada", playerSearchResult.FullBirthCountry); - Assert.AreEqual("AB", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1998-08-13"), playerSearchResult.BirthDate); + Assert.AreEqual("Alberta", playerSearchResult.BirthProvinceState); Assert.AreEqual("Carter", playerSearchResult.FirstName); Assert.AreEqual("Hart", playerSearchResult.LastName); Assert.AreEqual(true, playerSearchResult.IsActive); - Assert.AreEqual("PHI", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 2\"", playerSearchResult.Height); + Assert.AreEqual("PHI", playerSearchResult.TeamAbbreviation); + Assert.AreEqual("6\u00272\"", playerSearchResult.Height); Assert.AreEqual(79, playerSearchResult.PlayerNumber); break; @@ -944,13 +939,12 @@ public async Task TestSearchAllActivePlayersAsync(string query) Assert.AreEqual("Richmond Hill", playerSearchResult.BirthCity); Assert.AreEqual("CAN", playerSearchResult.BirthCountry); Assert.AreEqual("Canada", playerSearchResult.FullBirthCountry); - Assert.AreEqual("ON", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1997-01-13"), playerSearchResult.BirthDate); + Assert.AreEqual("Ontario", playerSearchResult.BirthProvinceState); Assert.AreEqual("Connor", playerSearchResult.FirstName); Assert.AreEqual("McDavid", playerSearchResult.LastName); Assert.AreEqual(true, playerSearchResult.IsActive); - Assert.AreEqual("EDM", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 1\"", playerSearchResult.Height); + Assert.AreEqual("EDM", playerSearchResult.TeamAbbreviation); + Assert.AreEqual("6\u00271\"", playerSearchResult.Height); Assert.AreEqual(97, playerSearchResult.PlayerNumber); break; @@ -958,13 +952,12 @@ public async Task TestSearchAllActivePlayersAsync(string query) Assert.AreEqual("Herning", playerSearchResult.BirthCity); Assert.AreEqual("DNK", playerSearchResult.BirthCountry); Assert.AreEqual("Denmark", playerSearchResult.FullBirthCountry); - Assert.AreEqual("", playerSearchResult.BirthProvinceState); - Assert.AreEqual(DateTime.Parse("1989-10-02"), playerSearchResult.BirthDate); + Assert.AreEqual(null, playerSearchResult.BirthProvinceState); Assert.AreEqual("Frederik", playerSearchResult.FirstName); Assert.AreEqual("Andersen", playerSearchResult.LastName); Assert.AreEqual(true, playerSearchResult.IsActive); - Assert.AreEqual("CAR", playerSearchResult.LastTeamOfPlay); - Assert.AreEqual("6\u0027 4\"", playerSearchResult.Height); + Assert.AreEqual("CAR", playerSearchResult.TeamAbbreviation); + Assert.AreEqual("6\u00274\"", playerSearchResult.Height); Assert.AreEqual(31, playerSearchResult.PlayerNumber); break; } diff --git a/Nhl.Api/Src/Api/NhlApi.cs b/Nhl.Api/Src/Api/NhlApi.cs index 5755710e..8a62c618 100644 --- a/Nhl.Api/Src/Api/NhlApi.cs +++ b/Nhl.Api/Src/Api/NhlApi.cs @@ -398,8 +398,9 @@ public async Task> SearchLeagueTeamRosterMembersAsync(str /// Returns any active or inactive NHL players based on the search query provided ///
/// A search term to find NHL players, Example: "Jack Adams" or "Wayne Gretzky" or "Mats Sundin" + /// A parameter to limit the number of search results returned when searching for a player /// A collection of all NHL players based on the search query provided - public async Task> SearchAllPlayersAsync(string query) + public async Task> SearchAllPlayersAsync(string query, int limit = 25) { return await _nhlPlayerApi.SearchAllPlayersAsync(query); } @@ -417,11 +418,11 @@ public IAsyncEnumerable GetAllPlayersAsAsyncEnumerable() /// Returns only active NHL players based on the search query provided ///
/// A search term to find NHL players, Example: "Owen Power" or "Carter Hart" or "Nathan MacKinnon" + /// A parameter to limit the number of search results returned when searching for a player /// A collection of all NHL players based on the search query provided - public async Task> SearchAllActivePlayersAsync(string query) + public async Task> SearchAllActivePlayersAsync(string query, int limit = 25) { return await _nhlPlayerApi.SearchAllActivePlayersAsync(query); - } /// diff --git a/Nhl.Api/Src/LeagueApi/NhlLeagueApi.cs b/Nhl.Api/Src/LeagueApi/NhlLeagueApi.cs index 98fa12e2..9a116931 100644 --- a/Nhl.Api/Src/LeagueApi/NhlLeagueApi.cs +++ b/Nhl.Api/Src/LeagueApi/NhlLeagueApi.cs @@ -375,7 +375,7 @@ public async Task GetTeamByIdAsync(TeamEnum team) /// Returns NHL team logo information including a byte array, base64 encoded string and the Uri endpoint public async Task GetTeamLogoAsync(TeamEnum team, TeamLogoType teamLogoType = TeamLogoType.Light) { - var endpoint = $"images/logos/teams-current-primary-{teamLogoType.ToString().ToLower()}/{(int)team}.svg"; + var endpoint = $"logos/nhl/svg/{GetTeamCodeIdentfier((int)team)}_{GetTeamLogoColorIdentfier(teamLogoType)}.svg"; var imageContent = await _nhlStaticAssetsApiHttpClient.GetByteArrayAsync(endpoint); return new TeamLogo @@ -394,7 +394,7 @@ public async Task GetTeamLogoAsync(TeamEnum team, TeamLogoType teamLog /// Returns NHL team logo information including a byte array, base64 encoded string and the Uri endpoint public async Task GetTeamLogoAsync(int teamId, TeamLogoType teamLogoType = TeamLogoType.Light) { - var endpoint = $"images/logos/teams-current-primary-{teamLogoType.ToString().ToLower()}/{teamId}.svg"; + var endpoint = $"logos/nhl/svg/{GetTeamCodeIdentfier(teamId)}_{GetTeamLogoColorIdentfier(teamLogoType)}.svg"; var imageContent = await _nhlStaticAssetsApiHttpClient.GetByteArrayAsync(endpoint); return new TeamLogo @@ -765,5 +765,50 @@ public async Task GetTeamColorsAsync(int teamId) return await GetTeamColorsAsync(teamEnum); } + + + private static string GetTeamLogoColorIdentfier(TeamLogoType teamLogoType) =>teamLogoType switch + { + TeamLogoType.Dark => "dark", + TeamLogoType.Light => "light", + _ => null + }; + + private static string GetTeamCodeIdentfier(int team) => team switch + { + (int)TeamEnum.AnaheimDucks => TeamCodes.MightyDucksofAnaheimAnaheimDucks, + (int)TeamEnum.ArizonaCoyotes => TeamCodes.ArizonaCoyotes, + (int)TeamEnum.BostonBruins => TeamCodes.BostonBruins, + (int)TeamEnum.BuffaloSabres => TeamCodes.BuffaloSabres, + (int)TeamEnum.CalgaryFlames => TeamCodes.CalgaryFlames, + (int)TeamEnum.CarolinaHurricanes => TeamCodes.CarolinaHurricanes, + (int)TeamEnum.ChicagoBlackhawks => TeamCodes.ChicagoBlackHawksBlackhawks, + (int)TeamEnum.ColoradoAvalanche => TeamCodes.ColoradoAvalanche, + (int)TeamEnum.ColumbusBlueJackets => TeamCodes.ColumbusBlueJackets, + (int)TeamEnum.DallasStars => TeamCodes.DallasStars, + (int)TeamEnum.DetroitRedWings => TeamCodes.DetroitRedWings, + (int)TeamEnum.EdmontonOilers => TeamCodes.EdmontonOilers, + (int)TeamEnum.FloridaPanthers => TeamCodes.FloridaPanthers, + (int)TeamEnum.LosAngelesKings => TeamCodes.LosAngelesKings, + (int)TeamEnum.MinnesotaWild => TeamCodes.MinnesotaWild, + (int)TeamEnum.MontrealCanadiens => TeamCodes.MontrealCanadiens, + (int)TeamEnum.NashvillePredators => TeamCodes.NashvillePredators, + (int)TeamEnum.NewJerseyDevils => TeamCodes.NewJerseyDevils, + (int)TeamEnum.NewYorkIslanders => TeamCodes.NewYorkIslanders, + (int)TeamEnum.NewYorkRangers => TeamCodes.NewYorkRangers, + (int)TeamEnum.OttawaSenators => TeamCodes.OttawaSenators, + (int)TeamEnum.PhiladelphiaFlyers => TeamCodes.PhiladelphiaFlyers, + (int)TeamEnum.PittsburghPenguins => TeamCodes.PittsburghPenguins, + (int)TeamEnum.SanJoseSharks => TeamCodes.SanJoseSharks, + (int)TeamEnum.SeattleKraken => TeamCodes.SeattleKraken, + (int)TeamEnum.StLouisBlues => TeamCodes.StLouisBlues, + (int)TeamEnum.TampaBayLightning => TeamCodes.TampaBayLightning, + (int)TeamEnum.TorontoMapleLeafs => TeamCodes.TorontoMapleLeafs, + (int)TeamEnum.VancouverCanucks => TeamCodes.VancouverCanucks, + (int)TeamEnum.VegasGoldenKnights => TeamCodes.VegasGoldenKnights, + (int)TeamEnum.WashingtonCapitals => TeamCodes.WashingtonCapitals, + (int)TeamEnum.WinnipegJets => TeamCodes.WinnipegJets, + _ => null + }; } } diff --git a/Nhl.Api/Src/PlayerApi/INhlPlayerApi.cs b/Nhl.Api/Src/PlayerApi/INhlPlayerApi.cs index 9ca8f073..e9b63531 100644 --- a/Nhl.Api/Src/PlayerApi/INhlPlayerApi.cs +++ b/Nhl.Api/Src/PlayerApi/INhlPlayerApi.cs @@ -66,15 +66,17 @@ public interface INhlPlayerApi : IDisposable /// Returns any active or inactive NHL players based on the search query provided /// /// An search term to find NHL players, Example: "Jack Adams" or "Wayne Gretzky" or "Mats Sundin" + /// A parameter to limit the number of search results returned when searching for a player /// A collection of all NHL players based on the search query provided - Task> SearchAllPlayersAsync(string query); + Task> SearchAllPlayersAsync(string query, int limit = 25); /// /// Returns only active NHL players based on the search query provided /// /// A search term to find NHL players, Example: "Owen Power" or "Carter Hart" or "Nathan MacKinnon" + /// A parameter to limit the number of search results returned when searching for a player /// A collection of all NHL players based on the search query provided - Task> SearchAllActivePlayersAsync(string query); + Task> SearchAllActivePlayersAsync(string query, int limit = 25); /// /// Returns NHL player since the league inception in 1917-1918 diff --git a/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs b/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs index 43880223..d0ffe89e 100644 --- a/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs +++ b/Nhl.Api/Src/PlayerApi/NhlPlayerApi.cs @@ -1,4 +1,5 @@ -using Nhl.Api.Common.Http; +using Newtonsoft.Json; +using Nhl.Api.Common.Http; using Nhl.Api.Common.Services; using Nhl.Api.Models.Draft; using Nhl.Api.Models.Enumerations.Player; @@ -247,100 +248,32 @@ public async Task> GetPlayersByIdAsync(IEnumerable play /// Returns any active or inactive NHL players based on the search query provided /// /// A search term to find NHL players, Example: "Jack Adams" or "Wayne Gretzky" or "Mats Sundin" + /// A parameter to limit the number of search results returned when searching for a player /// A collection of all NHL players based on the search query provided - public async Task> SearchAllPlayersAsync(string query) + public async Task> SearchAllPlayersAsync(string query, int limit = 25) { if (string.IsNullOrWhiteSpace(query)) { return new List(); } - var playerSearchResults = new List(); - var rawPlayerSearchResults = await _nhlSuggestionApiHttpClient.GetAsync($"/minplayers/{query}"); - foreach (var rawPlayerSearchResult in rawPlayerSearchResults.Suggestions) - { - try - { - var playerDataPoints = rawPlayerSearchResult.Split('|'); - - if (playerDataPoints.Count() < 15) - { - continue; - } - - playerSearchResults.Add(new PlayerSearchResult - { - PlayerId = int.Parse(playerDataPoints[0]), - LastName = playerDataPoints[1], - FirstName = playerDataPoints[2], - IsActive = int.Parse(playerDataPoints[3]) == 1, - Height = playerDataPoints[5], - Weight = playerDataPoints[6], - BirthCity = playerDataPoints[7], - BirthProvinceState = playerDataPoints[8], - BirthCountry = playerDataPoints[9], - BirthDate = DateTime.Parse(playerDataPoints[10]), - LastTeamOfPlay = playerDataPoints[11], - Position = playerDataPoints[12], - PlayerNumber = int.Parse(playerDataPoints[13]), - }); - } - catch - { - } - } - - return playerSearchResults; + return await _nhlSuggestionApiHttpClient.GetAsync>($"/search/player?culture=en-us&q={query}&limit={limit}"); } /// /// Returns only active NHL players based on the search query provided /// /// A search term to find NHL players, Example: "Owen Power" or "Carter Hart" or "Nathan MacKinnon" + /// A parameter to limit the number of search results returned when searching for a player /// A collection of all NHL players based on the search query provided - public async Task> SearchAllActivePlayersAsync(string query) + public async Task> SearchAllActivePlayersAsync(string query, int limit = 25) { if (string.IsNullOrWhiteSpace(query)) { return new List(); } - var playerSearchResults = new List(); - var rawPlayerSearchResults = await _nhlSuggestionApiHttpClient.GetAsync($"/minactiveplayers/{query}"); - foreach (var rawPlayerSearchResult in rawPlayerSearchResults.Suggestions) - { - try - { - var playerDataPoints = rawPlayerSearchResult.Split('|'); - - if (playerDataPoints.Count() < 15) - { - continue; - } - - playerSearchResults.Add(new PlayerSearchResult - { - PlayerId = int.Parse(playerDataPoints[0]), - LastName = playerDataPoints[1], - FirstName = playerDataPoints[2], - IsActive = int.Parse(playerDataPoints[3]) == 1, - Height = playerDataPoints[5], - Weight = playerDataPoints[6], - BirthCity = playerDataPoints[7], - BirthProvinceState = playerDataPoints[8], - BirthCountry = playerDataPoints[9], - BirthDate = DateTime.Parse(playerDataPoints[10]), - LastTeamOfPlay = playerDataPoints[11], - Position = playerDataPoints[12], - PlayerNumber = int.Parse(playerDataPoints[13]), - }); - } - catch - { - } - } - - return playerSearchResults; + return await _nhlSuggestionApiHttpClient.GetAsync>($"/search/player?culture=en-us&q={query}&active=true&limit={limit}"); } /// From 33c29be42f58b0261ea9ade1ef9e8e4f9da9b4db Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Sun, 8 Oct 2023 17:39:32 -0400 Subject: [PATCH 6/8] spacing --- Nhl.Api.Tests/NhlApiAsyncHelperTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs b/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs index d9349161..6bd63003 100644 --- a/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs +++ b/Nhl.Api.Tests/NhlApiAsyncHelperTests.cs @@ -11,27 +11,27 @@ namespace Nhl.Api.Tests public class NhlApiAsyncHelperTests { [TestMethodWithRetry(RetryCount = 5)] - public async Task TestRunSyncAsync() + public async Task TestRunSyncAsync() { - NhlApiAsyncHelper.RunSync(async () => await Task.Run(() => Task.Delay(100)) ); + NhlApiAsyncHelper.RunSync(async () => await Task.Run(() => Task.Delay(100))); } [TestMethodWithRetry(RetryCount = 5)] public async Task TestForEachAsync() { - var numbers = new ConcurrentBag(new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, }); + var numbers = new ConcurrentBag(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }); var sumOfNumbers = numbers.Sum(); // Arrange + Act - await NhlApiAsyncHelper.ForEachAsync(numbers, 2, async(i) => + await NhlApiAsyncHelper.ForEachAsync(numbers, 2, async (i) => { var value = numbers.TryTake(out i); numbers.Add(i * 2); }); Assert.AreNotEqual(numbers.Sum(), sumOfNumbers); - + } } } From 10d84ccfd0a458dff04f9c50c49e06d9b5373125 Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Sun, 8 Oct 2023 17:46:35 -0400 Subject: [PATCH 7/8] updated read me and versions --- Nhl.Api.Common/Nhl.Api.Common.csproj | 2 +- Nhl.Api.Domain/Nhl.Api.Domain.csproj | 2 +- Nhl.Api.Tests/Nhl.Api.Tests.csproj | 2 +- Nhl.Api/Nhl.Api.csproj | 2 +- README.md | 45 ++++++++++++++++++++-------- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Nhl.Api.Common/Nhl.Api.Common.csproj b/Nhl.Api.Common/Nhl.Api.Common.csproj index 9b6b059a..93b0aff3 100644 --- a/Nhl.Api.Common/Nhl.Api.Common.csproj +++ b/Nhl.Api.Common/Nhl.Api.Common.csproj @@ -1,7 +1,7 @@  - 2.2.0 + 2.2.1 netstandard2.0 true diff --git a/Nhl.Api.Domain/Nhl.Api.Domain.csproj b/Nhl.Api.Domain/Nhl.Api.Domain.csproj index f6f03bcd..cd7bce69 100644 --- a/Nhl.Api.Domain/Nhl.Api.Domain.csproj +++ b/Nhl.Api.Domain/Nhl.Api.Domain.csproj @@ -1,7 +1,7 @@  - 2.2.0 + 2.2.1 netstandard2.0 true diff --git a/Nhl.Api.Tests/Nhl.Api.Tests.csproj b/Nhl.Api.Tests/Nhl.Api.Tests.csproj index 1fcc8d92..07455eea 100644 --- a/Nhl.Api.Tests/Nhl.Api.Tests.csproj +++ b/Nhl.Api.Tests/Nhl.Api.Tests.csproj @@ -1,7 +1,7 @@  - 2.2.0 + 2.2.1 net6.0 false diff --git a/Nhl.Api/Nhl.Api.csproj b/Nhl.Api/Nhl.Api.csproj index d29735f6..bdee44e5 100644 --- a/Nhl.Api/Nhl.Api.csproj +++ b/Nhl.Api/Nhl.Api.csproj @@ -1,7 +1,7 @@  - 2.2.0 + 2.2.1 netstandard2.1;net6.0;net7.0 Nhl.Api Nhl.Api diff --git a/README.md b/README.md index 28857145..86acae4a 100644 --- a/README.md +++ b/README.md @@ -95,10 +95,12 @@ included automatically within your .NET Core project. Once registered using your dependency injection library of choice or just using the simple instance of the NHL API. Explore the API and see the all the possibilities. + ### Contents - [NhlApi](#T-Nhl-Api-NhlApi 'Nhl.Api.NhlApi') - [#ctor()](#M-Nhl-Api-NhlApi-#ctor 'Nhl.Api.NhlApi.#ctor') - [Dispose()](#M-Nhl-Api-NhlApi-Dispose 'Nhl.Api.NhlApi.Dispose') + - [DisposeAsync()](#M-Nhl-Api-NhlApi-DisposeAsync 'Nhl.Api.NhlApi.DisposeAsync') - [GetActiveFranchisesAsync()](#M-Nhl-Api-NhlApi-GetActiveFranchisesAsync 'Nhl.Api.NhlApi.GetActiveFranchisesAsync') - [GetActiveTeamsAsync()](#M-Nhl-Api-NhlApi-GetActiveTeamsAsync 'Nhl.Api.NhlApi.GetActiveTeamsAsync') - [GetAllPlayersAsAsyncEnumerable()](#M-Nhl-Api-NhlApi-GetAllPlayersAsAsyncEnumerable 'Nhl.Api.NhlApi.GetAllPlayersAsAsyncEnumerable') @@ -195,8 +197,8 @@ Once registered using your dependency injection library of choice or just using - [IsPlayoffsActiveAsync()](#M-Nhl-Api-NhlApi-IsPlayoffsActiveAsync 'Nhl.Api.NhlApi.IsPlayoffsActiveAsync') - [IsRegularSeasonActiveAsync()](#M-Nhl-Api-NhlApi-IsRegularSeasonActiveAsync 'Nhl.Api.NhlApi.IsRegularSeasonActiveAsync') - [IsSeasonActiveAsync()](#M-Nhl-Api-NhlApi-IsSeasonActiveAsync 'Nhl.Api.NhlApi.IsSeasonActiveAsync') - - [SearchAllActivePlayersAsync(query)](#M-Nhl-Api-NhlApi-SearchAllActivePlayersAsync-System-String- 'Nhl.Api.NhlApi.SearchAllActivePlayersAsync(System.String)') - - [SearchAllPlayersAsync(query)](#M-Nhl-Api-NhlApi-SearchAllPlayersAsync-System-String- 'Nhl.Api.NhlApi.SearchAllPlayersAsync(System.String)') + - [SearchAllActivePlayersAsync(query,limit)](#M-Nhl-Api-NhlApi-SearchAllActivePlayersAsync-System-String,System-Int32- 'Nhl.Api.NhlApi.SearchAllActivePlayersAsync(System.String,System.Int32)') + - [SearchAllPlayersAsync(query,limit)](#M-Nhl-Api-NhlApi-SearchAllPlayersAsync-System-String,System-Int32- 'Nhl.Api.NhlApi.SearchAllPlayersAsync(System.String,System.Int32)') - [SearchLeagueTeamRosterMembersAsync(query)](#M-Nhl-Api-NhlApi-SearchLeagueTeamRosterMembersAsync-System-String- 'Nhl.Api.NhlApi.SearchLeagueTeamRosterMembersAsync(System.String)') - [NhlGameApi](#T-Nhl-Api-NhlGameApi 'Nhl.Api.NhlGameApi') - [#ctor()](#M-Nhl-Api-NhlGameApi-#ctor 'Nhl.Api.NhlGameApi.#ctor') @@ -277,8 +279,8 @@ Once registered using your dependency injection library of choice or just using - [GetPlayerHeadshotImageAsync(playerId,playerHeadshotImageSize)](#M-Nhl-Api-NhlPlayerApi-GetPlayerHeadshotImageAsync-System-Int32,Nhl-Api-Models-Enumerations-Player-PlayerHeadshotImageSize- 'Nhl.Api.NhlPlayerApi.GetPlayerHeadshotImageAsync(System.Int32,Nhl.Api.Models.Enumerations.Player.PlayerHeadshotImageSize)') - [GetPlayersByIdAsync(playerIds)](#M-Nhl-Api-NhlPlayerApi-GetPlayersByIdAsync-System-Collections-Generic-IEnumerable{System-Int32}- 'Nhl.Api.NhlPlayerApi.GetPlayersByIdAsync(System.Collections.Generic.IEnumerable{System.Int32})') - [GetPlayersByIdAsync(players)](#M-Nhl-Api-NhlPlayerApi-GetPlayersByIdAsync-System-Collections-Generic-IEnumerable{Nhl-Api-Models-Enumerations-Player-PlayerEnum}- 'Nhl.Api.NhlPlayerApi.GetPlayersByIdAsync(System.Collections.Generic.IEnumerable{Nhl.Api.Models.Enumerations.Player.PlayerEnum})') - - [SearchAllActivePlayersAsync(query)](#M-Nhl-Api-NhlPlayerApi-SearchAllActivePlayersAsync-System-String- 'Nhl.Api.NhlPlayerApi.SearchAllActivePlayersAsync(System.String)') - - [SearchAllPlayersAsync(query)](#M-Nhl-Api-NhlPlayerApi-SearchAllPlayersAsync-System-String- 'Nhl.Api.NhlPlayerApi.SearchAllPlayersAsync(System.String)') + - [SearchAllActivePlayersAsync(query,limit)](#M-Nhl-Api-NhlPlayerApi-SearchAllActivePlayersAsync-System-String,System-Int32- 'Nhl.Api.NhlPlayerApi.SearchAllActivePlayersAsync(System.String,System.Int32)') + - [SearchAllPlayersAsync(query,limit)](#M-Nhl-Api-NhlPlayerApi-SearchAllPlayersAsync-System-String,System-Int32- 'Nhl.Api.NhlPlayerApi.SearchAllPlayersAsync(System.String,System.Int32)') - [SearchLeagueTeamRosterMembersAsync(query)](#M-Nhl-Api-NhlPlayerApi-SearchLeagueTeamRosterMembersAsync-System-String- 'Nhl.Api.NhlPlayerApi.SearchLeagueTeamRosterMembersAsync(System.String)') - [NhlStatisticsApi](#T-Nhl-Api-NhlStatisticsApi 'Nhl.Api.NhlStatisticsApi') - [#ctor()](#M-Nhl-Api-NhlStatisticsApi-#ctor 'Nhl.Api.NhlStatisticsApi.#ctor') @@ -341,6 +343,21 @@ Releases and disposes all unused or garbage collected resources for the Nhl.Api This method has no parameters. + +### DisposeAsync() `method` + +##### Summary + +Releases and disposes all unused or garbage collected resources for the Nhl.Api asynchronously + +##### Returns + +The await-able result of the asynchronous operation + +##### Parameters + +This method has no parameters. + ### GetActiveFranchisesAsync() `method` @@ -1959,8 +1976,8 @@ A result if the current NHL season is active (true) or inactive (false) This method has no parameters. - -### SearchAllActivePlayersAsync(query) `method` + +### SearchAllActivePlayersAsync(query,limit) `method` ##### Summary @@ -1975,9 +1992,10 @@ A collection of all NHL players based on the search query provided | Name | Type | Description | | ---- | ---- | ----------- | | query | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | A search term to find NHL players, Example: "Owen Power" or "Carter Hart" or "Nathan MacKinnon" | +| limit | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A parameter to limit the number of search results returned when searching for a player | - -### SearchAllPlayersAsync(query) `method` + +### SearchAllPlayersAsync(query,limit) `method` ##### Summary @@ -1992,6 +2010,7 @@ A collection of all NHL players based on the search query provided | Name | Type | Description | | ---- | ---- | ----------- | | query | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | A search term to find NHL players, Example: "Jack Adams" or "Wayne Gretzky" or "Mats Sundin" | +| limit | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A parameter to limit the number of search results returned when searching for a player | ### SearchLeagueTeamRosterMembersAsync(query) `method` @@ -3283,8 +3302,8 @@ An NHL player profile, see [Player](#T-Nhl-Api-Models-Player-Player 'Nhl.Api.Mod | ---- | ---- | ----------- | | players | [System.Collections.Generic.IEnumerable{Nhl.Api.Models.Enumerations.Player.PlayerEnum}](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Collections.Generic.IEnumerable 'System.Collections.Generic.IEnumerable{Nhl.Api.Models.Enumerations.Player.PlayerEnum}') | A collection of NHL player identifiers, Example: 8478402 - Connor McDavid, see [PlayerEnum](#T-Nhl-Api-Models-Enumerations-Player-PlayerEnum 'Nhl.Api.Models.Enumerations.Player.PlayerEnum') for more information on NHL players | - -### SearchAllActivePlayersAsync(query) `method` + +### SearchAllActivePlayersAsync(query,limit) `method` ##### Summary @@ -3299,9 +3318,10 @@ A collection of all NHL players based on the search query provided | Name | Type | Description | | ---- | ---- | ----------- | | query | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | A search term to find NHL players, Example: "Owen Power" or "Carter Hart" or "Nathan MacKinnon" | +| limit | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A parameter to limit the number of search results returned when searching for a player | - -### SearchAllPlayersAsync(query) `method` + +### SearchAllPlayersAsync(query,limit) `method` ##### Summary @@ -3316,6 +3336,7 @@ A collection of all NHL players based on the search query provided | Name | Type | Description | | ---- | ---- | ----------- | | query | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | A search term to find NHL players, Example: "Jack Adams" or "Wayne Gretzky" or "Mats Sundin" | +| limit | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A parameter to limit the number of search results returned when searching for a player | ### SearchLeagueTeamRosterMembersAsync(query) `method` From d97a0b7714f6dd044332958421a2db2de3cb9fcd Mon Sep 17 00:00:00 2001 From: "ANDRE-PC\\ital-" Date: Sun, 8 Oct 2023 18:03:45 -0400 Subject: [PATCH 8/8] test cases added for content cuts --- Nhl.Api.Tests/GameTests.cs | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/Nhl.Api.Tests/GameTests.cs b/Nhl.Api.Tests/GameTests.cs index 456a6bf7..621fe248 100644 --- a/Nhl.Api.Tests/GameTests.cs +++ b/Nhl.Api.Tests/GameTests.cs @@ -1134,6 +1134,90 @@ public async Task TestGetLiveGameFeedContentAsync(int gameId) Assert.IsNotNull(item.Blurb); Assert.IsNotNull(item.AuthFlow); Assert.IsNotNull(item.Image); + + if (item.Image.Cuts._372x210 != null) + { + Assert.IsNotNull(item.Image.Cuts._372x210.At2x); + Assert.IsNotNull(item.Image.Cuts._372x210.At3x); + Assert.IsNotNull(item.Image.Cuts._372x210.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._372x210.Height); + Assert.IsNotNull(item.Image.Cuts._372x210.Width); + Assert.IsNotNull(item.Image.Cuts._372x210.Src); + } + + if (item.Image.Cuts._320x180 != null) + { + Assert.IsNotNull(item.Image.Cuts._320x180.At2x); + Assert.IsNotNull(item.Image.Cuts._320x180.At3x); + Assert.IsNotNull(item.Image.Cuts._320x180.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._320x180.Height); + Assert.IsNotNull(item.Image.Cuts._320x180.Width); + Assert.IsNotNull(item.Image.Cuts._320x180.Src); + } + + if (item.Image.Cuts._768x432 != null) + { + Assert.IsNotNull(item.Image.Cuts._768x432.At2x); + Assert.IsNotNull(item.Image.Cuts._768x432.At3x); + Assert.IsNotNull(item.Image.Cuts._768x432.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._768x432.Height); + Assert.IsNotNull(item.Image.Cuts._768x432.Width); + Assert.IsNotNull(item.Image.Cuts._768x432.Src); + } + + if (item.Image.Cuts._960x540 != null) + { + Assert.IsNotNull(item.Image.Cuts._960x540.At2x); + Assert.IsNotNull(item.Image.Cuts._960x540.At3x); + Assert.IsNotNull(item.Image.Cuts._960x540.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._960x540.Height); + Assert.IsNotNull(item.Image.Cuts._960x540.Width); + Assert.IsNotNull(item.Image.Cuts._960x540.Src); + } + + if (item.Image.Cuts._1024x576 != null) + { + + Assert.IsNotNull(item.Image.Cuts._1024x576.At2x); + Assert.IsNotNull(item.Image.Cuts._1024x576.At3x); + Assert.IsNotNull(item.Image.Cuts._1024x576.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._1024x576.Height); + Assert.IsNotNull(item.Image.Cuts._1024x576.Width); + Assert.IsNotNull(item.Image.Cuts._1024x576.Src); + } + + if (item.Image.Cuts._1200x630 != null) + { + Assert.IsNotNull(item.Image.Cuts._1200x630.At2x); + Assert.IsNotNull(item.Image.Cuts._1200x630.At3x); + Assert.IsNotNull(item.Image.Cuts._1200x630.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._1200x630.Height); + Assert.IsNotNull(item.Image.Cuts._1200x630.Width); + Assert.IsNotNull(item.Image.Cuts._1200x630.Src); + } + + if (item.Image.Cuts._1202x670 != null) + { + Assert.IsNotNull(item.Image.Cuts._1202x670.At2x); + Assert.IsNotNull(item.Image.Cuts._1202x670.At3x); + Assert.IsNotNull(item.Image.Cuts._1202x670.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._1202x670.Height); + Assert.IsNotNull(item.Image.Cuts._1202x670.Width); + Assert.IsNotNull(item.Image.Cuts._1202x670.Src); + } + + if (item.Image.Cuts._2208x1242 != null) + { + + Assert.IsNotNull(item.Image.Cuts._2208x1242.At2x); + Assert.IsNotNull(item.Image.Cuts._2208x1242.At3x); + Assert.IsNotNull(item.Image.Cuts._2208x1242.AspectRatio); + Assert.IsNotNull(item.Image.Cuts._2208x1242.Height); + Assert.IsNotNull(item.Image.Cuts._2208x1242.Width); + Assert.IsNotNull(item.Image.Cuts._2208x1242.Src); + } + + Assert.IsNotNull(item.MediaState); Assert.IsNotNull(item.MediaPlaybackId); Assert.IsNotNull(item.Playbacks);