Skip to content

Commit c75e52f

Browse files
committed
Refactor NhlGameService and update PlayerTests
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.
1 parent 07e4017 commit c75e52f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Nhl.Api.Domain/Services/NhlGameService.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface INhlGameService
2727
/// </summary>
2828
public class NhlGameService : INhlGameService
2929
{
30-
private readonly INhlApiHttpClient _nhlScoresHtmlReportsApiHttpClient = new NhlScoresHtmlReportsApiHttpClient();
30+
private readonly NhlScoresHtmlReportsApiHttpClient _nhlScoresHtmlReportsApiHttpClient = new();
3131

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

170-
var multiplier = this.CalculateMultiplier(startTime, endTime, playsForPeriod.Value.Count);
170+
var multiplier = CalculateMultiplier(startTime, endTime, playsForPeriod.Value.Count);
171171
for (var i = 0; i < playsForPeriod.Value.Count; i++)
172172
{
173173
var play = playsForPeriod.Value[i];
@@ -192,9 +192,8 @@ public async Task<GameCenterPlayByPlay> AddEstimatedDateTimeOfPlayForEachPlay(Ga
192192
/// <param name="endTime">The end time of the period</param>
193193
/// <param name="events">The number of events in the period</param>
194194
/// <returns>A multiplier value for time distribution calculations</returns>
195-
private double CalculateMultiplier(DateTime startTime, DateTime endTime, int events)
195+
private static double CalculateMultiplier(DateTime startTime, DateTime endTime, int events)
196196
{
197-
198197
// Constants for the multiplier formula
199198
var DURATION_COEFFICIENT = 41.0;
200199
var EVENTS_COEFFICIENT = 2.0;

Nhl.Api.Tests/PlayerTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ public async Task SearchAllActivePlayersAsync_Returns_Valid_Information(string q
145145
Assert.AreEqual("6\u00274\"", playerSearchResult.Height);
146146
Assert.AreEqual(31, playerSearchResult.PlayerNumber);
147147
break;
148+
149+
default:
150+
throw new ArgumentException(null, nameof(query));
148151
}
149152

150153
}

0 commit comments

Comments
 (0)