Skip to content

Commit

Permalink
Refactor NhlGameService and update PlayerTests
Browse files Browse the repository at this point in the history
Refactored NhlGameService to use concise object initialization with `new()` syntax for `_nhlScoresHtmlReportsApiHttpClient`. Changed `CalculateMultiplier` to a private static method. Added a `default` case in `PlayerTests` switch statement to throw `ArgumentException` for unmatched `query` values.
  • Loading branch information
Afischbacher committed Mar 8, 2025
1 parent 07e4017 commit c75e52f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Nhl.Api.Domain/Services/NhlGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface INhlGameService
/// </summary>
public class NhlGameService : INhlGameService
{
private readonly INhlApiHttpClient _nhlScoresHtmlReportsApiHttpClient = new NhlScoresHtmlReportsApiHttpClient();
private readonly NhlScoresHtmlReportsApiHttpClient _nhlScoresHtmlReportsApiHttpClient = new();

/// <summary>
/// A method to add the estimated time of play for each play in the game center play by play
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task<GameCenterPlayByPlay> AddEstimatedDateTimeOfPlayForEachPlay(Ga
var distanceBetweenPlays = endTime - startTime;
var timeBetweenPlays = distanceBetweenPlays / playsForPeriod.Value.Count;

var multiplier = this.CalculateMultiplier(startTime, endTime, playsForPeriod.Value.Count);
var multiplier = CalculateMultiplier(startTime, endTime, playsForPeriod.Value.Count);
for (var i = 0; i < playsForPeriod.Value.Count; i++)
{
var play = playsForPeriod.Value[i];
Expand All @@ -192,9 +192,8 @@ public async Task<GameCenterPlayByPlay> AddEstimatedDateTimeOfPlayForEachPlay(Ga
/// <param name="endTime">The end time of the period</param>
/// <param name="events">The number of events in the period</param>
/// <returns>A multiplier value for time distribution calculations</returns>
private double CalculateMultiplier(DateTime startTime, DateTime endTime, int events)
private static double CalculateMultiplier(DateTime startTime, DateTime endTime, int events)
{

// Constants for the multiplier formula
var DURATION_COEFFICIENT = 41.0;
var EVENTS_COEFFICIENT = 2.0;
Expand Down
3 changes: 3 additions & 0 deletions Nhl.Api.Tests/PlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public async Task SearchAllActivePlayersAsync_Returns_Valid_Information(string q
Assert.AreEqual("6\u00274\"", playerSearchResult.Height);
Assert.AreEqual(31, playerSearchResult.PlayerNumber);
break;

default:
throw new ArgumentException(null, nameof(query));
}

}
Expand Down

0 comments on commit c75e52f

Please sign in to comment.