-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from mcbrown87/master
Add initial unit test
- Loading branch information
Showing
9 changed files
with
356 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<ProjectReference Include="..\..\src\BaseballSharp.csproj" /> | ||
<None Update="Schedule.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="PitchingReports.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="TeamData.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
using System.Net; | ||
using Moq; | ||
using Moq.Protected; | ||
|
||
namespace BaseballSharp.Test | ||
{ | ||
public class MLBClientShould | ||
{ | ||
private HttpClient BuildMockedHttpClient(string returnContent) | ||
{ | ||
var handlerMock = new Mock<HttpMessageHandler>(MockBehavior.Strict); | ||
|
||
handlerMock | ||
.Protected() | ||
// Setup the PROTECTED method to mock | ||
.Setup<Task<HttpResponseMessage>>( | ||
"SendAsync", | ||
ItExpr.IsAny<HttpRequestMessage>(), | ||
ItExpr.IsAny<CancellationToken>() | ||
) | ||
// Prepare the expected response of the mocked HttpClient | ||
.ReturnsAsync(new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK, | ||
Content = new StringContent(returnContent), | ||
}) | ||
.Verifiable(); | ||
|
||
return new HttpClient(handlerMock.Object); | ||
} | ||
|
||
[Fact] | ||
public async void ReturnAScheduleGivenAValidDate() | ||
{ | ||
var sut = new MLBClient | ||
{ | ||
HttpClient = BuildMockedHttpClient(File.ReadAllText("Schedule.json")), | ||
}; | ||
|
||
var game = (await sut.GetScheduleAsync(DateTime.Now)).ToList().Single(); | ||
|
||
Assert.Equal("Toronto Blue Jays", game.AwayTeam); | ||
Assert.Equal("Comerica Park", game.Ballpark); | ||
Assert.Equal(746470, game.gameID); | ||
Assert.Equal("Detroit Tigers", game.HomeTeam); | ||
Assert.Equal(9, game.ScheduledInnings); | ||
Assert.Equal(Enums.GameStatus.PreGame, game.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async void ReturnAValidPitchingReportGivenAValidDate() | ||
{ | ||
var sut = new MLBClient | ||
{ | ||
HttpClient = BuildMockedHttpClient(File.ReadAllText("PitchingReports.json")), | ||
}; | ||
|
||
var pitchingReport = (await sut.GetPitchingReportsAsync(DateTime.Now)).ToList().Single(); | ||
|
||
Assert.Equal(607192, pitchingReport.AwayProbablePitcherId); | ||
Assert.Equal("Tyler Glasnow", pitchingReport.AwayProbablePitcherName); | ||
Assert.Equal("", pitchingReport.AwayProbablePitcherNotes); | ||
Assert.Equal("Los Angeles Dodgers", pitchingReport.AwayTeam); | ||
Assert.Equal(656731, pitchingReport.HomeProbablePitcherId); | ||
Assert.Equal("Tylor Megill", pitchingReport.HomeProbablePitcherName); | ||
Assert.Equal("", pitchingReport.HomeProbablePitcherNotes); | ||
Assert.Equal("New York Mets", pitchingReport.HomeTeam); | ||
} | ||
|
||
[Fact] | ||
public async void ReturnValidTeamData() | ||
{ | ||
var sut = new MLBClient | ||
{ | ||
HttpClient = BuildMockedHttpClient(File.ReadAllText("TeamData.json")), | ||
}; | ||
|
||
var teamData = (await sut.GetTeamDataAsync()).ToList().Single(); | ||
|
||
Assert.Equal("OAK", teamData.Abbreviation); | ||
Assert.Equal(200, teamData.DivisionId); | ||
Assert.Equal("American League West", teamData.DivisionName); | ||
Assert.Equal("Oakland Athletics", teamData.FullName); | ||
Assert.Equal(133, teamData.Id); | ||
Assert.Equal(103, teamData.LeagueId); | ||
Assert.Equal("American League", teamData.LeagueName); | ||
Assert.Equal("Oakland", teamData.Location); | ||
Assert.Equal("Athletics", teamData.Name); | ||
Assert.Equal(10, teamData.VenueId); | ||
Assert.Equal("Oakland Coliseum", teamData.VenueName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"dates": [ | ||
{ | ||
"date": "2024-05-28", | ||
"games": [ | ||
{ | ||
"gamePk": 745818, | ||
"gameDate": "2024-05-28T20:10:00Z", | ||
"status": { | ||
"abstractGameState": "Final" | ||
}, | ||
"teams": { | ||
"away": { | ||
"team": { | ||
"id": 119, | ||
"name": "Los Angeles Dodgers" | ||
}, | ||
"probablePitcher": { | ||
"id": 607192, | ||
"fullName": "Tyler Glasnow" | ||
} | ||
}, | ||
"home": { | ||
"team": { | ||
"id": 121, | ||
"name": "New York Mets" | ||
}, | ||
"probablePitcher": { | ||
"id": 656731, | ||
"fullName": "Tylor Megill" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"copyright": "Copyright 2024 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt", | ||
"totalItems": 15, | ||
"totalEvents": 0, | ||
"totalGames": 15, | ||
"totalGamesInProgress": 0, | ||
"dates": [ | ||
{ | ||
"date": "2024-05-25", | ||
"totalItems": 15, | ||
"totalEvents": 0, | ||
"totalGames": 15, | ||
"totalGamesInProgress": 0, | ||
"games": [ | ||
{ | ||
"gamePk": 746470, | ||
"gameGuid": "02f1258c-fe62-41ae-ab53-374dec7bca3d", | ||
"link": "/api/v1.1/game/746470/feed/live", | ||
"gameType": "R", | ||
"season": "2024", | ||
"gameDate": "2024-05-25T17:10:00Z", | ||
"officialDate": "2024-05-25", | ||
"status": { | ||
"abstractGameState": "Preview", | ||
"codedGameState": "P", | ||
"detailedState": "Pre-Game", | ||
"statusCode": "P", | ||
"startTimeTBD": false, | ||
"abstractGameCode": "P" | ||
}, | ||
"teams": { | ||
"away": { | ||
"leagueRecord": { | ||
"wins": 23, | ||
"losses": 27, | ||
"pct": ".460" | ||
}, | ||
"score": 0, | ||
"team": { | ||
"id": 141, | ||
"name": "Toronto Blue Jays", | ||
"link": "/api/v1/teams/141" | ||
}, | ||
"splitSquad": false, | ||
"seriesNumber": 17 | ||
}, | ||
"home": { | ||
"leagueRecord": { | ||
"wins": 24, | ||
"losses": 27, | ||
"pct": ".471" | ||
}, | ||
"score": 0, | ||
"team": { | ||
"id": 116, | ||
"name": "Detroit Tigers", | ||
"link": "/api/v1/teams/116" | ||
}, | ||
"splitSquad": false, | ||
"seriesNumber": 17 | ||
} | ||
}, | ||
"venue": { | ||
"id": 2394, | ||
"name": "Comerica Park", | ||
"link": "/api/v1/venues/2394" | ||
}, | ||
"content": { | ||
"link": "/api/v1/game/746470/content" | ||
}, | ||
"gameNumber": 1, | ||
"publicFacing": true, | ||
"doubleHeader": "N", | ||
"gamedayType": "P", | ||
"tiebreaker": "N", | ||
"calendarEventID": "14-746470-2024-05-25", | ||
"seasonDisplay": "2024", | ||
"dayNight": "day", | ||
"scheduledInnings": 9, | ||
"reverseHomeAwayStatus": false, | ||
"inningBreakLength": 120, | ||
"gamesInSeries": 4, | ||
"seriesGameNumber": 3, | ||
"seriesDescription": "Regular Season", | ||
"recordSource": "S", | ||
"ifNecessary": "N", | ||
"ifNecessaryDescription": "Normal Game" | ||
} | ||
], | ||
"events": [] | ||
} | ||
] | ||
} |
Oops, something went wrong.