Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbrown87 committed May 29, 2024
1 parent ba513db commit d277aa1
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/MLBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public async Task<IEnumerable<PitchingReport>> GetPitchingReportsAsync(DateTime
{
teamsList.Add(new Models.Team()
{
Name = team.name,
FullName = team.name,
Name = team.teamName,
Location = team.locationName,
Id = team.id,
LeagueId = team.league?.id,
Expand Down
6 changes: 6 additions & 0 deletions test/BaseballSharp.Test/BaseballSharp.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<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>
43 changes: 43 additions & 0 deletions test/BaseballSharp.Test/MLBClientShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,48 @@ public async void ReturnAScheduleGivenAValidDate()
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);
}
}
}
38 changes: 38 additions & 0 deletions test/BaseballSharp.Test/PitchingReports.json
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"
}
}
}
}
]
}
]
}
52 changes: 52 additions & 0 deletions test/BaseballSharp.Test/TeamData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"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",
"teams": [
{
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"allStarStatus": "N",
"id": 133,
"name": "Oakland Athletics",
"link": "/api/v1/teams/133",
"season": 2024,
"venue": {
"id": 10,
"name": "Oakland Coliseum",
"link": "/api/v1/venues/10"
},
"springVenue": {
"id": 2507,
"link": "/api/v1/venues/2507"
},
"teamCode": "oak",
"fileCode": "oak",
"abbreviation": "OAK",
"teamName": "Athletics",
"locationName": "Oakland",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 200,
"name": "American League West",
"link": "/api/v1/divisions/200"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Oakland",
"franchiseName": "Oakland",
"clubName": "Athletics",
"active": true
}
]
}

0 comments on commit d277aa1

Please sign in to comment.