Skip to content

Commit

Permalink
added type game
Browse files Browse the repository at this point in the history
  • Loading branch information
torben-w committed Jul 28, 2019
1 parent 691542b commit 5cb4452
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 28 deletions.
29 changes: 26 additions & 3 deletions OMDbApiNet.Test/ItemAsyncTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async void TestGetItemByTitleGood1()
Assert.Equal("21 Sep 2004", movie.Dvd);
Assert.Equal("20th Century Fox", movie.Production);
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
Assert.Equal(null, movie.TotalSeasons);
Assert.Null(movie.TotalSeasons);
Assert.Equal("True", movie.Response);
}

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

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

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

/// <summary>
/// Games can't be requested by title. See #2
/// </summary>
[Fact]
public async void TestGetItemByTitleBad2()
{
var omdb = new AsyncOmdbClient(TestData.apikey, true);
await Assert.ThrowsAsync<HttpRequestException>(() => omdb.GetItemByTitleAsync("Skyrim", OmdbType.Game));
}

[Fact]
public async void TestGetItemByIdGood()
{
Expand Down Expand Up @@ -127,6 +137,19 @@ public async void TestGetItemByIdGood()
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
Assert.Equal("True", movie.Response);
}

[Fact]
public async void TestGetItemByIdGood2()
{
var omdb = new AsyncOmdbClient(TestData.apikey, true);
var game = await omdb.GetItemByIdAsync("tt1814884");

Assert.Equal("The Elder Scrolls V: Skyrim", game.Title);
Assert.Equal("2011", game.Year);
Assert.Equal("N/A", game.Rated);
Assert.Equal("11 Nov 2011", game.Released);
Assert.Equal("N/A", game.Runtime);
}

[Fact]
public async void TestGetItemByIdBad()
Expand Down
29 changes: 26 additions & 3 deletions OMDbApiNet.Test/ItemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void TestGetItemByTitleGood1()
Assert.Equal("21 Sep 2004", movie.Dvd);
Assert.Equal("20th Century Fox", movie.Production);
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
Assert.Equal(null, movie.TotalSeasons);
Assert.Null(movie.TotalSeasons);
Assert.Equal("True", movie.Response);
}

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

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

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

/// <summary>
/// Games can't be requested by title. See #2
/// </summary>
[Fact]
public void TestGetItemByTitleBad2()
{
var omdb = new OmdbClient(TestData.apikey, true);
Assert.Throws<HttpRequestException>(() => omdb.GetItemByTitle("Skyrim", OmdbType.Game));
}

[Fact]
public void TestGetItemByIdGood()
{
Expand Down Expand Up @@ -127,6 +137,19 @@ public void TestGetItemByIdGood()
Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
Assert.Equal("True", movie.Response);
}

[Fact]
public void TestGetItemByIdGood2()
{
var omdb = new OmdbClient(TestData.apikey, true);
var game = omdb.GetItemById("tt1814884");

Assert.Equal("The Elder Scrolls V: Skyrim", game.Title);
Assert.Equal("2011", game.Year);
Assert.Equal("N/A", game.Rated);
Assert.Equal("11 Nov 2011", game.Released);
Assert.Equal("N/A", game.Runtime);
}

[Fact]
public void TestGetItemByIdBad()
Expand Down
25 changes: 20 additions & 5 deletions OMDbApiNet.Test/SearchAsyncTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ public async void TestGetSearchListGood()
Assert.Equal("tt0115759", search[1].ImdbId);
Assert.Equal("movie", search[1].Type);

Assert.Equal("Green Arrow", search[5].Title);
Assert.Equal("2010", search[5].Year);
Assert.Equal("tt1663633", search[5].ImdbId);
Assert.Equal("movie", search[5].Type);
Assert.Null(searchList.Error);
Assert.Equal("True", searchList.Response);
}

public async void TestGetSearchListGood2()
{
var omdb = new AsyncOmdbClient(TestData.apikey);
var searchList = await omdb.GetSearchListAsync("Skyrim", OmdbType.Game);

var search = searchList.SearchResults.ToArray();
Assert.Equal("The Elder Scrolls V: Skyrim", search[0].Title);
Assert.Equal("2011", search[0].Year);
Assert.Equal("tt1814884", search[0].ImdbId);
Assert.Equal("game", search[0].Type);

Assert.Equal("The Elder Scrolls V: Skyrim - Dawnguard", search[1].Title);
Assert.Equal("2012", search[1].Year);
Assert.Equal("tt5333506", search[1].ImdbId);
Assert.Equal("game", search[1].Type);

Assert.Equal(null, searchList.Error);
Assert.Null(searchList.Error);
Assert.Equal("True", searchList.Response);
}

Expand Down
25 changes: 20 additions & 5 deletions OMDbApiNet.Test/SearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ public void TestGetSearchListGood()
Assert.Equal("tt0115759", search[1].ImdbId);
Assert.Equal("movie", search[1].Type);

Assert.Equal("Green Arrow", search[5].Title);
Assert.Equal("2010", search[5].Year);
Assert.Equal("tt1663633", search[5].ImdbId);
Assert.Equal("movie", search[5].Type);
Assert.Null(searchList.Error);
Assert.Equal("True", searchList.Response);
}

public void TestGetSearchListGood2()
{
var omdb = new OmdbClient(TestData.apikey);
var searchList = omdb.GetSearchList("Skyrim", OmdbType.Game);

var search = searchList.SearchResults.ToArray();
Assert.Equal("The Elder Scrolls V: Skyrim", search[0].Title);
Assert.Equal("2011", search[0].Year);
Assert.Equal("tt1814884", search[0].ImdbId);
Assert.Equal("game", search[0].Type);

Assert.Equal("The Elder Scrolls V: Skyrim - Dawnguard", search[1].Title);
Assert.Equal("2012", search[1].Year);
Assert.Equal("tt5333506", search[1].ImdbId);
Assert.Equal("game", search[1].Type);

Assert.Equal(null, searchList.Error);
Assert.Null(searchList.Error);
Assert.Equal("True", searchList.Response);
}

Expand Down
1 change: 0 additions & 1 deletion OMDbApiNet/AsyncOmdbClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
Expand Down
98 changes: 98 additions & 0 deletions OMDbApiNet/IAsyncOmdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,133 @@ namespace OMDbApiNet
{
public interface IAsyncOmdbClient
{
/// <summary>
/// Get an Item by its title asynchronously.
/// </summary>
/// <param name="title"></param>
/// <param name="fullPlot"></param>
/// <returns>Item</returns>
Task<Item> GetItemByTitleAsync(string title, bool fullPlot = false);

/// <summary>
/// Get an Item by its title asynchronously.
/// <br/><br/>
/// 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
/// the client side.
/// </summary>
/// <param name="title"></param>
/// <param name="type"></param>
/// <param name="fullPlot"></param>
/// <returns>Item</returns>
Task<Item> GetItemByTitleAsync(string title, OmdbType type, bool fullPlot = false);

/// <summary>
/// Get an Item by its title asynchronously.
/// </summary>
/// <param name="title"></param>
/// <param name="year"></param>
/// <param name="fullPlot"></param>
/// <returns>Item</returns>
Task<Item> GetItemByTitleAsync(string title, int? year, bool fullPlot = false);

/// <summary>
/// Get an Item by its title asynchronously.
/// <br/><br/>
/// 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
/// the client side.
/// </summary>
/// <param name="title"></param>
/// <param name="type"></param>
/// <param name="year"></param>
/// <param name="fullPlot"></param>
/// <returns>Item</returns>
Task<Item> GetItemByTitleAsync(string title, OmdbType type, int? year, bool fullPlot = false);

/// <summary>
/// Get an Item by its IMDb id asynchronously.
/// </summary>
/// <param name="id"></param>
/// <param name="fullPlot"></param>
/// <returns>Item</returns>
Task<Item> GetItemByIdAsync(string id, bool fullPlot = false);


/// <summary>
/// Get a list with search results for the given query asynchronously.
/// </summary>
/// <param name="query"></param>
/// <param name="page"></param>
/// <returns>SearchList</returns>
Task<SearchList> GetSearchListAsync(string query, int page = 1);

/// <summary>
/// Get a list with search results for the given query and type asynchronously.
/// </summary>
/// <param name="query"></param>
/// <param name="type"></param>
/// <param name="page"></param>
/// <returns>SearchList</returns>
Task<SearchList> GetSearchListAsync(string query, OmdbType type, int page = 1);

/// <summary>
/// Get a list with search results for the given year and query asynchronously.
/// </summary>
/// <param name="year"></param>
/// <param name="query"></param>
/// <param name="page"></param>
/// <returns>SearchList</returns>
Task<SearchList> GetSearchListAsync(int? year, string query, int page = 1);

/// <summary>
/// Get a list with search results for the given year, query and type asynchronously.
/// </summary>
/// <param name="year"></param>
/// <param name="query"></param>
/// <param name="type"></param>
/// <param name="page"></param>
Task<SearchList> GetSearchListAsync(int? year, string query, OmdbType type, int page = 1);


/// <summary>
/// Get an Episode by the IMDb id of the series, its season number and its episode number asynchronously.
/// </summary>
/// <param name="seriesId"></param>
/// <param name="seasonNumber"></param>
/// <param name="episodeNumber"></param>
/// <returns>Episode</returns>
Task<Episode> GetEpisodeBySeriesIdAsync(string seriesId, int seasonNumber, int episodeNumber);

/// <summary>
/// Get an Episode by the name of the series, its season number and its episode number asynchronously.
/// </summary>
/// <param name="seriesTitle"></param>
/// <param name="seasonNumber"></param>
/// <param name="episodeNumber"></param>
/// <returns>Episode</returns>
Task<Episode> GetEpisodeBySeriesTitleAsync(string seriesTitle, int seasonNumber, int episodeNumber);

/// <summary>
/// Get an Episode by its IMDb id asynchronously.
/// </summary>
/// <param name="episodeId"></param>
/// <returns>Episode</returns>
Task<Episode> GetEpisodeByEpisodeIdAsync(string episodeId);


/// <summary>
/// Get a Season by the IMDb id of the series and its season number asynchronously.
/// </summary>
/// <param name="seriesId"></param>
/// <param name="seasonNumber"></param>
/// <returns>Season</returns>
Task<Season> GetSeasonBySeriesIdAsync(string seriesId, int seasonNumber);

/// <summary>
/// Get a Season by the name of the series and its season number asynchronously.
/// </summary>
/// <param name="seriesTitle"></param>
/// <param name="seasonNumber"></param>
/// <returns>Season</returns>
Task<Season> GetSeasonBySeriesTitleAsync(string seriesTitle, int seasonNumber);
}
}
Loading

1 comment on commit 5cb4452

@torben-w
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2

Please sign in to comment.