Skip to content

Commit 5cb4452

Browse files
committed
added type game
1 parent 691542b commit 5cb4452

File tree

11 files changed

+307
-28
lines changed

11 files changed

+307
-28
lines changed

OMDbApiNet.Test/ItemAsyncTest.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async void TestGetItemByTitleGood1()
3535
Assert.Equal("21 Sep 2004", movie.Dvd);
3636
Assert.Equal("20th Century Fox", movie.Production);
3737
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
38-
Assert.Equal(null, movie.TotalSeasons);
38+
Assert.Null(movie.TotalSeasons);
3939
Assert.Equal("True", movie.Response);
4040
}
4141

@@ -50,7 +50,7 @@ public async void TestGetItemByTitleGood2()
5050
Assert.Equal("Rotten Tomatoes", ratings[1].Source);
5151
Assert.Equal("Metacritic", ratings[2].Source);
5252

53-
Assert.Equal("Star Wars: Episode VIII - The Last Jedi", movie.Title);
53+
Assert.Equal("Star Wars: The Last Jedi", movie.Title);
5454
Assert.Equal("2017", movie.Year);
5555
Assert.Equal("PG-13", movie.Rated);
5656
Assert.Equal("15 Dec 2017", movie.Released);
@@ -61,7 +61,7 @@ public async void TestGetItemByTitleGood2()
6161
Assert.Equal("movie", movie.Type);
6262
Assert.Equal("http://www.rottentomatoes.com/m/star_wars_episode_viii/", movie.TomatoUrl);
6363
Assert.Equal("Walt Disney Pictures", movie.Production);
64-
Assert.Equal(null, movie.TotalSeasons);
64+
Assert.Null(movie.TotalSeasons);
6565
Assert.Equal("True", movie.Response);
6666
}
6767

@@ -100,6 +100,16 @@ public async void TestGetItemByTitleBad()
100100
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => omdb.GetItemByTitleAsync("star wars", 1500));
101101
}
102102

103+
/// <summary>
104+
/// Games can't be requested by title. See #2
105+
/// </summary>
106+
[Fact]
107+
public async void TestGetItemByTitleBad2()
108+
{
109+
var omdb = new AsyncOmdbClient(TestData.apikey, true);
110+
await Assert.ThrowsAsync<HttpRequestException>(() => omdb.GetItemByTitleAsync("Skyrim", OmdbType.Game));
111+
}
112+
103113
[Fact]
104114
public async void TestGetItemByIdGood()
105115
{
@@ -127,6 +137,19 @@ public async void TestGetItemByIdGood()
127137
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
128138
Assert.Equal("True", movie.Response);
129139
}
140+
141+
[Fact]
142+
public async void TestGetItemByIdGood2()
143+
{
144+
var omdb = new AsyncOmdbClient(TestData.apikey, true);
145+
var game = await omdb.GetItemByIdAsync("tt1814884");
146+
147+
Assert.Equal("The Elder Scrolls V: Skyrim", game.Title);
148+
Assert.Equal("2011", game.Year);
149+
Assert.Equal("N/A", game.Rated);
150+
Assert.Equal("11 Nov 2011", game.Released);
151+
Assert.Equal("N/A", game.Runtime);
152+
}
130153

131154
[Fact]
132155
public async void TestGetItemByIdBad()

OMDbApiNet.Test/ItemTest.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void TestGetItemByTitleGood1()
3535
Assert.Equal("21 Sep 2004", movie.Dvd);
3636
Assert.Equal("20th Century Fox", movie.Production);
3737
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
38-
Assert.Equal(null, movie.TotalSeasons);
38+
Assert.Null(movie.TotalSeasons);
3939
Assert.Equal("True", movie.Response);
4040
}
4141

@@ -50,7 +50,7 @@ public void TestGetItemByTitleGood2()
5050
Assert.Equal("Rotten Tomatoes", ratings[1].Source);
5151
Assert.Equal("Metacritic", ratings[2].Source);
5252

53-
Assert.Equal("Star Wars: Episode VIII - The Last Jedi", movie.Title);
53+
Assert.Equal("Star Wars: The Last Jedi", movie.Title);
5454
Assert.Equal("2017", movie.Year);
5555
Assert.Equal("PG-13", movie.Rated);
5656
Assert.Equal("15 Dec 2017", movie.Released);
@@ -61,7 +61,7 @@ public void TestGetItemByTitleGood2()
6161
Assert.Equal("movie", movie.Type);
6262
Assert.Equal("http://www.rottentomatoes.com/m/star_wars_episode_viii/", movie.TomatoUrl);
6363
Assert.Equal("Walt Disney Pictures", movie.Production);
64-
Assert.Equal(null, movie.TotalSeasons);
64+
Assert.Null(movie.TotalSeasons);
6565
Assert.Equal("True", movie.Response);
6666
}
6767

@@ -100,6 +100,16 @@ public void TestGetItemByTitleBad()
100100
Assert.Throws<ArgumentOutOfRangeException>(() => omdb.GetItemByTitle("star wars", 1500));
101101
}
102102

103+
/// <summary>
104+
/// Games can't be requested by title. See #2
105+
/// </summary>
106+
[Fact]
107+
public void TestGetItemByTitleBad2()
108+
{
109+
var omdb = new OmdbClient(TestData.apikey, true);
110+
Assert.Throws<HttpRequestException>(() => omdb.GetItemByTitle("Skyrim", OmdbType.Game));
111+
}
112+
103113
[Fact]
104114
public void TestGetItemByIdGood()
105115
{
@@ -127,6 +137,19 @@ public void TestGetItemByIdGood()
127137
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
128138
Assert.Equal("True", movie.Response);
129139
}
140+
141+
[Fact]
142+
public void TestGetItemByIdGood2()
143+
{
144+
var omdb = new OmdbClient(TestData.apikey, true);
145+
var game = omdb.GetItemById("tt1814884");
146+
147+
Assert.Equal("The Elder Scrolls V: Skyrim", game.Title);
148+
Assert.Equal("2011", game.Year);
149+
Assert.Equal("N/A", game.Rated);
150+
Assert.Equal("11 Nov 2011", game.Released);
151+
Assert.Equal("N/A", game.Runtime);
152+
}
130153

131154
[Fact]
132155
public void TestGetItemByIdBad()

OMDbApiNet.Test/SearchAsyncTest.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,27 @@ public async void TestGetSearchListGood()
2727
Assert.Equal("tt0115759", search[1].ImdbId);
2828
Assert.Equal("movie", search[1].Type);
2929

30-
Assert.Equal("Green Arrow", search[5].Title);
31-
Assert.Equal("2010", search[5].Year);
32-
Assert.Equal("tt1663633", search[5].ImdbId);
33-
Assert.Equal("movie", search[5].Type);
30+
Assert.Null(searchList.Error);
31+
Assert.Equal("True", searchList.Response);
32+
}
33+
34+
public async void TestGetSearchListGood2()
35+
{
36+
var omdb = new AsyncOmdbClient(TestData.apikey);
37+
var searchList = await omdb.GetSearchListAsync("Skyrim", OmdbType.Game);
38+
39+
var search = searchList.SearchResults.ToArray();
40+
Assert.Equal("The Elder Scrolls V: Skyrim", search[0].Title);
41+
Assert.Equal("2011", search[0].Year);
42+
Assert.Equal("tt1814884", search[0].ImdbId);
43+
Assert.Equal("game", search[0].Type);
44+
45+
Assert.Equal("The Elder Scrolls V: Skyrim - Dawnguard", search[1].Title);
46+
Assert.Equal("2012", search[1].Year);
47+
Assert.Equal("tt5333506", search[1].ImdbId);
48+
Assert.Equal("game", search[1].Type);
3449

35-
Assert.Equal(null, searchList.Error);
50+
Assert.Null(searchList.Error);
3651
Assert.Equal("True", searchList.Response);
3752
}
3853

OMDbApiNet.Test/SearchTest.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,27 @@ public void TestGetSearchListGood()
2727
Assert.Equal("tt0115759", search[1].ImdbId);
2828
Assert.Equal("movie", search[1].Type);
2929

30-
Assert.Equal("Green Arrow", search[5].Title);
31-
Assert.Equal("2010", search[5].Year);
32-
Assert.Equal("tt1663633", search[5].ImdbId);
33-
Assert.Equal("movie", search[5].Type);
30+
Assert.Null(searchList.Error);
31+
Assert.Equal("True", searchList.Response);
32+
}
33+
34+
public void TestGetSearchListGood2()
35+
{
36+
var omdb = new OmdbClient(TestData.apikey);
37+
var searchList = omdb.GetSearchList("Skyrim", OmdbType.Game);
38+
39+
var search = searchList.SearchResults.ToArray();
40+
Assert.Equal("The Elder Scrolls V: Skyrim", search[0].Title);
41+
Assert.Equal("2011", search[0].Year);
42+
Assert.Equal("tt1814884", search[0].ImdbId);
43+
Assert.Equal("game", search[0].Type);
44+
45+
Assert.Equal("The Elder Scrolls V: Skyrim - Dawnguard", search[1].Title);
46+
Assert.Equal("2012", search[1].Year);
47+
Assert.Equal("tt5333506", search[1].ImdbId);
48+
Assert.Equal("game", search[1].Type);
3449

35-
Assert.Equal(null, searchList.Error);
50+
Assert.Null(searchList.Error);
3651
Assert.Equal("True", searchList.Response);
3752
}
3853

OMDbApiNet/AsyncOmdbClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Net.Http;
33
using System.Net.Http.Headers;
4-
using System.Text.RegularExpressions;
54
using System.Threading.Tasks;
65
using Newtonsoft.Json;
76
using Newtonsoft.Json.Serialization;

OMDbApiNet/IAsyncOmdbClient.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,133 @@ namespace OMDbApiNet
55
{
66
public interface IAsyncOmdbClient
77
{
8+
/// <summary>
9+
/// Get an Item by its title asynchronously.
10+
/// </summary>
11+
/// <param name="title"></param>
12+
/// <param name="fullPlot"></param>
13+
/// <returns>Item</returns>
814
Task<Item> GetItemByTitleAsync(string title, bool fullPlot = false);
915

16+
/// <summary>
17+
/// Get an Item by its title asynchronously.
18+
/// <br/><br/>
19+
/// Games (OmdbType.Game) can only be requested by Id, not by title. This is due to restrictions of the Open Movie Database API and can't be fixed on
20+
/// the client side.
21+
/// </summary>
22+
/// <param name="title"></param>
23+
/// <param name="type"></param>
24+
/// <param name="fullPlot"></param>
25+
/// <returns>Item</returns>
1026
Task<Item> GetItemByTitleAsync(string title, OmdbType type, bool fullPlot = false);
1127

28+
/// <summary>
29+
/// Get an Item by its title asynchronously.
30+
/// </summary>
31+
/// <param name="title"></param>
32+
/// <param name="year"></param>
33+
/// <param name="fullPlot"></param>
34+
/// <returns>Item</returns>
1235
Task<Item> GetItemByTitleAsync(string title, int? year, bool fullPlot = false);
1336

37+
/// <summary>
38+
/// Get an Item by its title asynchronously.
39+
/// <br/><br/>
40+
/// Games (OmdbType.Game) can only be requested by Id, not by title. This is due to restrictions of the Open Movie Database API and can't be fixed on
41+
/// the client side.
42+
/// </summary>
43+
/// <param name="title"></param>
44+
/// <param name="type"></param>
45+
/// <param name="year"></param>
46+
/// <param name="fullPlot"></param>
47+
/// <returns>Item</returns>
1448
Task<Item> GetItemByTitleAsync(string title, OmdbType type, int? year, bool fullPlot = false);
1549

50+
/// <summary>
51+
/// Get an Item by its IMDb id asynchronously.
52+
/// </summary>
53+
/// <param name="id"></param>
54+
/// <param name="fullPlot"></param>
55+
/// <returns>Item</returns>
1656
Task<Item> GetItemByIdAsync(string id, bool fullPlot = false);
1757

1858

59+
/// <summary>
60+
/// Get a list with search results for the given query asynchronously.
61+
/// </summary>
62+
/// <param name="query"></param>
63+
/// <param name="page"></param>
64+
/// <returns>SearchList</returns>
1965
Task<SearchList> GetSearchListAsync(string query, int page = 1);
2066

67+
/// <summary>
68+
/// Get a list with search results for the given query and type asynchronously.
69+
/// </summary>
70+
/// <param name="query"></param>
71+
/// <param name="type"></param>
72+
/// <param name="page"></param>
73+
/// <returns>SearchList</returns>
2174
Task<SearchList> GetSearchListAsync(string query, OmdbType type, int page = 1);
2275

76+
/// <summary>
77+
/// Get a list with search results for the given year and query asynchronously.
78+
/// </summary>
79+
/// <param name="year"></param>
80+
/// <param name="query"></param>
81+
/// <param name="page"></param>
82+
/// <returns>SearchList</returns>
2383
Task<SearchList> GetSearchListAsync(int? year, string query, int page = 1);
2484

85+
/// <summary>
86+
/// Get a list with search results for the given year, query and type asynchronously.
87+
/// </summary>
88+
/// <param name="year"></param>
89+
/// <param name="query"></param>
90+
/// <param name="type"></param>
91+
/// <param name="page"></param>
2592
Task<SearchList> GetSearchListAsync(int? year, string query, OmdbType type, int page = 1);
2693

2794

95+
/// <summary>
96+
/// Get an Episode by the IMDb id of the series, its season number and its episode number asynchronously.
97+
/// </summary>
98+
/// <param name="seriesId"></param>
99+
/// <param name="seasonNumber"></param>
100+
/// <param name="episodeNumber"></param>
101+
/// <returns>Episode</returns>
28102
Task<Episode> GetEpisodeBySeriesIdAsync(string seriesId, int seasonNumber, int episodeNumber);
29103

104+
/// <summary>
105+
/// Get an Episode by the name of the series, its season number and its episode number asynchronously.
106+
/// </summary>
107+
/// <param name="seriesTitle"></param>
108+
/// <param name="seasonNumber"></param>
109+
/// <param name="episodeNumber"></param>
110+
/// <returns>Episode</returns>
30111
Task<Episode> GetEpisodeBySeriesTitleAsync(string seriesTitle, int seasonNumber, int episodeNumber);
31112

113+
/// <summary>
114+
/// Get an Episode by its IMDb id asynchronously.
115+
/// </summary>
116+
/// <param name="episodeId"></param>
117+
/// <returns>Episode</returns>
32118
Task<Episode> GetEpisodeByEpisodeIdAsync(string episodeId);
33119

34120

121+
/// <summary>
122+
/// Get a Season by the IMDb id of the series and its season number asynchronously.
123+
/// </summary>
124+
/// <param name="seriesId"></param>
125+
/// <param name="seasonNumber"></param>
126+
/// <returns>Season</returns>
35127
Task<Season> GetSeasonBySeriesIdAsync(string seriesId, int seasonNumber);
36128

129+
/// <summary>
130+
/// Get a Season by the name of the series and its season number asynchronously.
131+
/// </summary>
132+
/// <param name="seriesTitle"></param>
133+
/// <param name="seasonNumber"></param>
134+
/// <returns>Season</returns>
37135
Task<Season> GetSeasonBySeriesTitleAsync(string seriesTitle, int seasonNumber);
38136
}
39137
}

0 commit comments

Comments
 (0)