diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..ba4a7e3d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed +dotnet_diagnostic.CS4014.severity = error diff --git a/TMDbLib.sln b/TMDbLib.sln index 498cd577..a33e9e6c 100644 --- a/TMDbLib.sln +++ b/TMDbLib.sln @@ -11,6 +11,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{26BF5A0A-354A-46F5-A20C-0BEB5D45783A}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props + .editorconfig = .editorconfig Readme.md = Readme.md EndProjectSection EndProject diff --git a/TMDbLib/Client/TMDbClient.cs b/TMDbLib/Client/TMDbClient.cs index 7b3cf4ea..a346ce20 100644 --- a/TMDbLib/Client/TMDbClient.cs +++ b/TMDbLib/Client/TMDbClient.cs @@ -243,7 +243,7 @@ public void SetConfig(TMDbConfig config) /// - Use the 'AuthenticationGetUserSessionAsync' and 'AuthenticationCreateGuestSessionAsync' methods to optain the respective session ids. /// - User sessions have access to far for methods than guest sessions, these can currently only be used to rate media. /// - public void SetSessionInformation(string sessionId, SessionType sessionType) + public async Task SetSessionInformationAsync(string sessionId, SessionType sessionType) { ActiveAccount = null; SessionId = sessionId; @@ -259,7 +259,7 @@ public void SetSessionInformation(string sessionId, SessionType sessionType) { try { - ActiveAccount = AccountGetDetailsAsync().Result; + ActiveAccount = await AccountGetDetailsAsync().ConfigureAwait(false); } catch (Exception) { diff --git a/TMDbLib/Rest/RestResponse.cs b/TMDbLib/Rest/RestResponse.cs index 6b555af2..ed23d214 100644 --- a/TMDbLib/Rest/RestResponse.cs +++ b/TMDbLib/Rest/RestResponse.cs @@ -51,6 +51,7 @@ public async Task GetDataObject() return _client.Serializer.Deserialize(tr); } + [Obsolete("Remove this, uses .Result")] public static implicit operator T(RestResponse response) { try diff --git a/TMDbLibTests/ClientAccountTests.cs b/TMDbLibTests/ClientAccountTests.cs index 24de433f..533d2470 100644 --- a/TMDbLibTests/ClientAccountTests.cs +++ b/TMDbLibTests/ClientAccountTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Account; using TMDbLib.Objects.Authentication; @@ -22,18 +23,18 @@ public ClientAccountTests() : base() } [Fact] - public void TestAccountGetDetailsGuestAccount() + public async Task TestAccountGetDetailsGuestAccount() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); - Assert.Throws(() => Config.Client.AccountGetDetailsAsync().Sync()); + await Assert.ThrowsAsync(() => Config.Client.AccountGetDetailsAsync()); } [Fact] - public void TestAccountGetDetailsUserAccount() + public async Task TestAccountGetDetailsUserAccount() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - AccountDetails account = Config.Client.AccountGetDetailsAsync().Sync(); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + AccountDetails account = await Config.Client.AccountGetDetailsAsync(); // Naturally the specified account must have these values populated for the test to pass Assert.NotNull(account); @@ -49,26 +50,25 @@ public void TestAccountGetDetailsUserAccount() } [Fact] - public void TestAccountAccountGetLists() + public async Task TestAccountAccountGetLists() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetListsAsync(i).Result); - AccountList list = Config.Client.AccountGetListsAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetListsAsync(i)); + AccountList list = (await Config.Client.AccountGetListsAsync()).Results[0]; Assert.NotNull(list.Id); Assert.NotNull(list.Name); Assert.Null(list.PosterPath); Assert.NotNull(list.Description); - Assert.NotNull(list.ListType); Assert.NotNull(list.Iso_639_1); } [Fact] - public void TestAccountGetFavoriteMovies() + public async Task TestAccountGetFavoriteMovies() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetFavoriteMoviesAsync(i).Result); - SearchMovie movie = Config.Client.AccountGetFavoriteMoviesAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetFavoriteMoviesAsync(i)); + SearchMovie movie = (await Config.Client.AccountGetFavoriteMoviesAsync()).Results[0]; // Requires that you have marked at least one movie as favorite else this test will fail Assert.True(movie.Id > 0); @@ -88,11 +88,11 @@ public void TestAccountGetFavoriteMovies() } [Fact] - public void TestAccountGetFavoriteTv() + public async Task TestAccountGetFavoriteTv() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetFavoriteTvAsync(i).Result); - SearchTv tvShow = Config.Client.AccountGetFavoriteTvAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetFavoriteTvAsync(i)); + SearchTv tvShow = (await Config.Client.AccountGetFavoriteTvAsync()).Results[0]; // Requires that you have marked at least one movie as favorite else this test will fail Assert.True(tvShow.Id > 0); @@ -112,11 +112,11 @@ public void TestAccountGetFavoriteTv() } [Fact] - public void TestAccountGetMovieWatchlist() + public async Task TestAccountGetMovieWatchlist() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetFavoriteMoviesAsync(i).Result); - SearchMovie movie = Config.Client.AccountGetFavoriteMoviesAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetFavoriteMoviesAsync(i)); + SearchMovie movie = (await Config.Client.AccountGetFavoriteMoviesAsync()).Results[0]; // Requires that you have added at least one movie to your watchlist else this test will fail Assert.True(movie.Id > 0); @@ -136,11 +136,11 @@ public void TestAccountGetMovieWatchlist() } [Fact] - public void TestAccountGetTvWatchlist() + public async Task TestAccountGetTvWatchlist() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetTvWatchlistAsync(i).Result); - SearchTv tvShow = Config.Client.AccountGetTvWatchlistAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetTvWatchlistAsync(i)); + SearchTv tvShow = (await Config.Client.AccountGetTvWatchlistAsync()).Results[0]; // Requires that you have added at least one movie to your watchlist else this test will fail Assert.True(tvShow.Id > 0); @@ -160,11 +160,11 @@ public void TestAccountGetTvWatchlist() } [Fact] - public void TestAccountGetRatedMovies() + public async Task TestAccountGetRatedMovies() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetFavoriteMoviesAsync(i).Result); - SearchMovie movie = Config.Client.AccountGetFavoriteMoviesAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetFavoriteMoviesAsync(i)); + SearchMovie movie = (await Config.Client.AccountGetFavoriteMoviesAsync()).Results[0]; // Requires that you have rated at least one movie else this test will fail Assert.True(movie.Id > 0); @@ -184,11 +184,11 @@ public void TestAccountGetRatedMovies() } [Fact] - public void TestAccountGetRatedTv() + public async Task TestAccountGetRatedTv() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetRatedTvShowsAsync(i).Result); - AccountSearchTv tvShow = Config.Client.AccountGetRatedTvShowsAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetRatedTvShowsAsync(i)); + AccountSearchTv tvShow = (await Config.Client.AccountGetRatedTvShowsAsync()).Results[0]; // Requires that you have rated at least one movie else this test will fail Assert.True(tvShow.Id > 0); @@ -208,12 +208,12 @@ public void TestAccountGetRatedTv() } [Fact] - public void TestAccountGetRatedTvEpisodes() + public async Task TestAccountGetRatedTvEpisodes() { // TODO: Error in TMDb: https://www.themoviedb.org/talk/557f1af49251410a2c002480 - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestHelpers.SearchPages(i => Config.Client.AccountGetRatedTvShowEpisodesAsync(i).Result); - AccountSearchTvEpisode tvEpisode = Config.Client.AccountGetRatedTvShowEpisodesAsync().Sync().Results[0]; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestHelpers.SearchPagesAsync(i => Config.Client.AccountGetRatedTvShowEpisodesAsync(i)); + AccountSearchTvEpisode tvEpisode = (await Config.Client.AccountGetRatedTvShowEpisodesAsync()).Results[0]; // Requires that you have rated at least one movie else this test will fail Assert.True(tvEpisode.Id > 0); @@ -229,129 +229,129 @@ public void TestAccountGetRatedTvEpisodes() } [Fact] - public void TestAccountChangeTvFavoriteStatus() + public async Task TestAccountChangeTvFavoriteStatusAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Ensure that the test movie is not marked as favorite before we start the test - if (DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)) - Assert.True(Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false).Result); + if (await DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)) + Assert.True(await Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false)); - if (DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)) + if (await DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)) throw new Exception($"Test tv show '{IdHelper.DoctorWho}' was already marked as favorite. Unable to perform test correctly"); // Try to mark is as a favorite - Assert.True(Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Tv, IdHelper.DoctorWho, true).Result); + Assert.True(await Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Tv, IdHelper.DoctorWho, true)); // Check if it worked - Assert.True(DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)); + Assert.True(await DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)); // Try to un-mark is as a favorite - Assert.True(Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false).Result); + Assert.True(await Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false)); // Check if it worked - Assert.False(DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)); + Assert.False(await DoesFavoriteListContainSpecificTvShow(IdHelper.DoctorWho)); } [Fact] - public void TestAccountChangeMovieFavoriteStatus() + public async Task TestAccountChangeMovieFavoriteStatusAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Ensure that the test movie is not marked as favorite before we start the test - if (DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)) - Assert.True(Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Movie, IdHelper.Terminator, false).Result); + if (await DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)) + Assert.True(await Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Movie, IdHelper.Terminator, false)); - if (DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)) + if (await DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)) throw new Exception($"Test movie '{IdHelper.Terminator}' was already marked as favorite. Unable to perform test correctly"); // Try to mark is as a favorite - Assert.True(Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Movie, IdHelper.Terminator, true).Result); + Assert.True(await Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Movie, IdHelper.Terminator, true)); // Check if it worked - Assert.True(DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)); + Assert.True(await DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)); // Try to un-mark is as a favorite - Assert.True(Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Movie, IdHelper.Terminator, false).Result); + Assert.True(await Config.Client.AccountChangeFavoriteStatusAsync(MediaType.Movie, IdHelper.Terminator, false)); // Check if it worked - Assert.False(DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)); + Assert.False(await DoesFavoriteListContainSpecificMovie(IdHelper.Terminator)); } [Fact] - public void TestAccountChangeTvWatchlistStatus() + public async Task TestAccountChangeTvWatchlistStatusAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Ensure that the test movie is not marked as favorite before we start the test - if (DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)) - Assert.True(Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false).Result); + if (await DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)) + Assert.True(await Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false)); - if (DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)) + if (await DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)) throw new Exception($"Test tv show '{IdHelper.DoctorWho}' was already on watchlist. Unable to perform test correctly"); // Try to add an item to the watchlist - Assert.True(Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Tv, IdHelper.DoctorWho, true).Result); + Assert.True(await Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Tv, IdHelper.DoctorWho, true)); // Check if it worked - Assert.True(DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)); + Assert.True(await DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)); // Try to remove item from watchlist - Assert.True(Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false).Result); + Assert.True(await Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Tv, IdHelper.DoctorWho, false)); // Check if it worked - Assert.False(DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)); + Assert.False(await DoesWatchListContainSpecificTvShow(IdHelper.DoctorWho)); } [Fact] - public void TestAccountChangeMovieWatchlistStatus() + public async Task TestAccountChangeMovieWatchlistStatusAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Ensure that the test movie is not marked as favorite before we start the test - if (DoesWatchListContainSpecificMovie(IdHelper.Terminator)) - Assert.True(Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Movie, IdHelper.Terminator, false).Result); + if (await DoesWatchListContainSpecificMovie(IdHelper.Terminator)) + Assert.True(await Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Movie, IdHelper.Terminator, false)); - if (DoesWatchListContainSpecificMovie(IdHelper.Terminator)) + if (await DoesWatchListContainSpecificMovie(IdHelper.Terminator)) throw new Exception($"Test movie '{IdHelper.Terminator}' was already on watchlist. Unable to perform test correctly"); // Try to add an item to the watchlist - Assert.True(Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Movie, IdHelper.Terminator, true).Result); + Assert.True(await Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Movie, IdHelper.Terminator, true)); // Check if it worked - Assert.True(DoesWatchListContainSpecificMovie(IdHelper.Terminator)); + Assert.True(await DoesWatchListContainSpecificMovie(IdHelper.Terminator)); // Try to remove item from watchlist - Assert.True(Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Movie, IdHelper.Terminator, false).Result); + Assert.True(await Config.Client.AccountChangeWatchlistStatusAsync(MediaType.Movie, IdHelper.Terminator, false)); // Check if it worked - Assert.False(DoesWatchListContainSpecificMovie(IdHelper.Terminator)); + Assert.False(await DoesWatchListContainSpecificMovie(IdHelper.Terminator)); } - private bool DoesFavoriteListContainSpecificTvShow(int tvId) + private async Task DoesFavoriteListContainSpecificTvShow(int tvId) { - return DoesListContainSpecificMovie(tvId, page => Config.Client.AccountGetFavoriteTvAsync(page).Result.Results.Select(s => s.Id)); + return await DoesListContainSpecificMovie(tvId, async page => (await Config.Client.AccountGetFavoriteTvAsync(page)).Results.Select(s => s.Id)); } - private bool DoesWatchListContainSpecificTvShow(int tvId) + private async Task DoesWatchListContainSpecificTvShow(int tvId) { - return DoesListContainSpecificMovie(tvId, page => Config.Client.AccountGetTvWatchlistAsync(page).Result.Results.Select(s => s.Id)); + return await DoesListContainSpecificMovie(tvId, async page => (await Config.Client.AccountGetTvWatchlistAsync(page)).Results.Select(s => s.Id)); } - private bool DoesFavoriteListContainSpecificMovie(int movieId) + private async Task DoesFavoriteListContainSpecificMovie(int movieId) { - return DoesListContainSpecificMovie(movieId, page => Config.Client.AccountGetFavoriteMoviesAsync(page).Result.Results.Select(s => s.Id)); + return await DoesListContainSpecificMovie(movieId, async page => (await Config.Client.AccountGetFavoriteMoviesAsync(page)).Results.Select(s => s.Id)); } - private bool DoesWatchListContainSpecificMovie(int movieId) + private async Task DoesWatchListContainSpecificMovie(int movieId) { - return DoesListContainSpecificMovie(movieId, page => Config.Client.AccountGetMovieWatchlistAsync(page).Result.Results.Select(s => s.Id)); + return await DoesListContainSpecificMovie(movieId, async page => (await Config.Client.AccountGetMovieWatchlistAsync(page)).Results.Select(s => s.Id)); } - private bool DoesListContainSpecificMovie(int movieId, Func> listGetter) + private async Task DoesListContainSpecificMovie(int movieId, Func>> listGetter) { int page = 1; - List originalList = listGetter(1).ToList(); + List originalList = (await listGetter(1)).ToList(); while (originalList != null && originalList.Any()) { // Check if the current result page contains the relevant movie @@ -359,7 +359,7 @@ private bool DoesListContainSpecificMovie(int movieId, Func(() => Config.Client.AuthenticationGetUserSessionAsync(requestToken).Sync()); + await Assert.ThrowsAsync(() => Config.Client.AuthenticationGetUserSessionAsync(requestToken)); } /// /// Requires a valid test user to be assigned /// [Fact] - public void TestAuthenticationGetUserSessionApiUserValidationSuccess() + public async Task TestAuthenticationGetUserSessionApiUserValidationSuccessAsync() { - Token token = Config.Client.AuthenticationRequestAutenticationTokenAsync().Sync(); + Token token = await Config.Client.AuthenticationRequestAutenticationTokenAsync(); - Config.Client.AuthenticationValidateUserTokenAsync(token.RequestToken, Config.Username, Config.Password).Sync(); + await Config.Client.AuthenticationValidateUserTokenAsync(token.RequestToken, Config.Username, Config.Password); } [Fact] - public void TestAuthenticationGetUserSessionApiUserValidationInvalidLogin() + public async Task TestAuthenticationGetUserSessionApiUserValidationInvalidLoginAsync() { - Token token = Config.Client.AuthenticationRequestAutenticationTokenAsync().Sync(); + Token token = await Config.Client.AuthenticationRequestAutenticationTokenAsync(); - Assert.Throws(() => Config.Client.AuthenticationValidateUserTokenAsync(token.RequestToken, "bla", "bla").Sync()); + await Assert.ThrowsAsync(() => Config.Client.AuthenticationValidateUserTokenAsync(token.RequestToken, "bla", "bla")); } /// /// Requires a valid test user to be assigned /// [Fact] - public void AuthenticationGetUserSessionWithLoginSuccess() + public async Task AuthenticationGetUserSessionWithLoginSuccess() { - UserSession session = Config.Client.AuthenticationGetUserSessionAsync(Config.Username, Config.Password).Result; + UserSession session = await Config.Client.AuthenticationGetUserSessionAsync(Config.Username, Config.Password); Assert.NotNull(session); Assert.True(session.Success); @@ -89,21 +88,20 @@ public void AuthenticationGetUserSessionWithLoginSuccess() } [Fact] - public void TestAuthenticationUserAuthenticatedSessionOldToken() + public async Task TestAuthenticationUserAuthenticatedSessionOldTokenAsync() { const string requestToken = "5f3a62c0d7977319e3d14adf1a2064c0c0938bcf"; - Assert.Throws(() => Config.Client.AuthenticationGetUserSessionAsync(requestToken).Sync()); + await Assert.ThrowsAsync(() => Config.Client.AuthenticationGetUserSessionAsync(requestToken)); } [Fact] - public void TestAuthenticationCreateGuestSession() + public async Task TestAuthenticationCreateGuestSessionAsync() { - GuestSession guestSession = Config.Client.AuthenticationCreateGuestSessionAsync().Sync(); + GuestSession guestSession = await Config.Client.AuthenticationCreateGuestSessionAsync(); Assert.NotNull(guestSession); Assert.True(guestSession.Success); - Assert.NotNull(guestSession.ExpiresAt); Assert.NotNull(guestSession.GuestSessionId); } } diff --git a/TMDbLibTests/ClientCertificationsTests.cs b/TMDbLibTests/ClientCertificationsTests.cs index ffccfc2d..50d61147 100644 --- a/TMDbLibTests/ClientCertificationsTests.cs +++ b/TMDbLibTests/ClientCertificationsTests.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Certifications; -using TMDbLibTests.Helpers; using TMDbLibTests.JsonHelpers; namespace TMDbLibTests @@ -10,9 +10,9 @@ namespace TMDbLibTests public class ClientCertificationsTests : TestBase { [Fact] - public void TestCertificationsListMovie() + public async Task TestCertificationsListMovieAsync() { - CertificationsContainer result = Config.Client.GetMovieCertificationsAsync().Sync(); + CertificationsContainer result = await Config.Client.GetMovieCertificationsAsync(); Assert.NotNull(result); Assert.NotNull(result.Certifications); Assert.True(result.Certifications.Count > 1); @@ -30,9 +30,9 @@ public void TestCertificationsListMovie() } [Fact] - public void TestCertificationsListTv() + public async Task TestCertificationsListTvAsync() { - CertificationsContainer result = Config.Client.GetTvCertificationsAsync().Sync(); + CertificationsContainer result = await Config.Client.GetTvCertificationsAsync(); Assert.NotNull(result); Assert.NotNull(result.Certifications); Assert.True(result.Certifications.Count > 1); diff --git a/TMDbLibTests/ClientChangesTests.cs b/TMDbLibTests/ClientChangesTests.cs index e5e2d360..4edd7b31 100644 --- a/TMDbLibTests/ClientChangesTests.cs +++ b/TMDbLibTests/ClientChangesTests.cs @@ -1,9 +1,9 @@ using System; using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Changes; using TMDbLib.Objects.General; -using TMDbLibTests.Helpers; using TMDbLibTests.JsonHelpers; namespace TMDbLibTests @@ -11,10 +11,10 @@ namespace TMDbLibTests public class ClientChangesTests : TestBase { [Fact] - public void TestChangesMovies() + public async Task TestChangesMoviesAsync() { // Basic check - SearchContainer changesPage1 = Config.Client.GetChangesMoviesAsync().Sync(); + SearchContainer changesPage1 = await Config.Client.GetChangesMoviesAsync(); Assert.NotNull(changesPage1); Assert.True(changesPage1.Results.Count > 0); @@ -22,14 +22,14 @@ public void TestChangesMovies() Assert.Equal(1, changesPage1.Page); // Page 2 - SearchContainer changesPage2 = Config.Client.GetChangesMoviesAsync(2).Result; + SearchContainer changesPage2 = await Config.Client.GetChangesMoviesAsync(2); Assert.NotNull(changesPage2); Assert.Equal(2, changesPage2.Page); // Check date range (max) DateTime higher = DateTime.UtcNow.AddDays(-7); - SearchContainer changesMaxDate = Config.Client.GetChangesMoviesAsync(endDate: higher).Result; + SearchContainer changesMaxDate = await Config.Client.GetChangesMoviesAsync(endDate: higher); Assert.NotNull(changesMaxDate); Assert.Equal(1, changesMaxDate.Page); @@ -37,7 +37,7 @@ public void TestChangesMovies() // Check date range (lower) DateTime lower = DateTime.UtcNow.AddDays(-6); // Use 6 days to avoid clashes with the 'higher' - SearchContainer changesLowDate = Config.Client.GetChangesMoviesAsync(startDate: lower).Result; + SearchContainer changesLowDate = await Config.Client.GetChangesMoviesAsync(startDate: lower); Assert.NotNull(changesLowDate); Assert.Equal(1, changesLowDate.Page); @@ -45,10 +45,10 @@ public void TestChangesMovies() } [Fact] - public void TestChangesPeople() + public async Task TestChangesPeopleAsync() { // Basic check - SearchContainer changesPage1 = Config.Client.GetChangesPeopleAsync().Sync(); + SearchContainer changesPage1 = await Config.Client.GetChangesPeopleAsync(); Assert.NotNull(changesPage1); Assert.True(changesPage1.Results.Count > 0); @@ -56,14 +56,14 @@ public void TestChangesPeople() Assert.Equal(1, changesPage1.Page); // Page 2 - SearchContainer changesPage2 = Config.Client.GetChangesPeopleAsync(2).Result; + SearchContainer changesPage2 = await Config.Client.GetChangesPeopleAsync(2); Assert.NotNull(changesPage2); Assert.Equal(2, changesPage2.Page); // Check date range (max) DateTime higher = DateTime.UtcNow.AddDays(-7); - SearchContainer changesMaxDate = Config.Client.GetChangesPeopleAsync(endDate: higher).Result; + SearchContainer changesMaxDate = await Config.Client.GetChangesPeopleAsync(endDate: higher); Assert.NotNull(changesMaxDate); Assert.Equal(1, changesMaxDate.Page); @@ -71,7 +71,7 @@ public void TestChangesPeople() // Check date range (lower) DateTime lower = DateTime.UtcNow.AddDays(-6); // Use 6 days to avoid clashes with the 'higher' - SearchContainer changesLowDate = Config.Client.GetChangesPeopleAsync(startDate: lower).Result; + SearchContainer changesLowDate = await Config.Client.GetChangesPeopleAsync(startDate: lower); Assert.NotNull(changesLowDate); Assert.Equal(1, changesLowDate.Page); @@ -84,10 +84,10 @@ public void TestChangesPeople() [Fact] - public void TestChangesTvShows() + public async Task TestChangesTvShowsAsync() { // Basic check - SearchContainer changesPage1 = Config.Client.GetChangesTvAsync().Sync(); + SearchContainer changesPage1 = await Config.Client.GetChangesTvAsync(); Assert.NotNull(changesPage1); Assert.NotNull(changesPage1.Results); @@ -99,7 +99,7 @@ public void TestChangesTvShows() { Assert.True(changesPage1.TotalResults > changesPage1.Results.Count); // Page 2 - SearchContainer changesPage2 = Config.Client.GetChangesTvAsync(2).Result; + SearchContainer changesPage2 = await Config.Client.GetChangesTvAsync(2); Assert.NotNull(changesPage2); Assert.Equal(2, changesPage2.Page); @@ -107,7 +107,7 @@ public void TestChangesTvShows() // Check date range (max) DateTime higher = DateTime.UtcNow.AddDays(-8); - SearchContainer changesMaxDate = Config.Client.GetChangesTvAsync(endDate: higher).Result; + SearchContainer changesMaxDate = await Config.Client.GetChangesTvAsync(endDate: higher); Assert.NotNull(changesMaxDate); Assert.Equal(1, changesMaxDate.Page); @@ -115,7 +115,7 @@ public void TestChangesTvShows() // Check date range (lower) DateTime lower = DateTime.UtcNow.AddDays(-6); // Use 6 days to avoid clashes with the 'higher' - SearchContainer changesLowDate = Config.Client.GetChangesTvAsync(startDate: lower).Result; + SearchContainer changesLowDate = await Config.Client.GetChangesTvAsync(startDate: lower); Assert.NotNull(changesLowDate); Assert.Equal(1, changesLowDate.Page); diff --git a/TMDbLibTests/ClientCollectionTests.cs b/TMDbLibTests/ClientCollectionTests.cs index 04df33d3..0bd6f8a4 100644 --- a/TMDbLibTests/ClientCollectionTests.cs +++ b/TMDbLibTests/ClientCollectionTests.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Collections; using TMDbLib.Objects.General; @@ -22,9 +22,9 @@ public ClientCollectionTests() } [Fact] - public void TestCollectionsExtrasNone() + public async Task TestCollectionsExtrasNone() { - Collection collection = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection).Result; + Collection collection = await Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection); Assert.NotNull(collection); Assert.Equal("James Bond Collection", collection.Name); @@ -39,17 +39,17 @@ public void TestCollectionsExtrasNone() } [Fact] - public void TestCollectionMissing() + public async Task TestCollectionMissing() { - Collection collection = Config.Client.GetCollectionAsync(IdHelper.MissingID).Result; + Collection collection = await Config.Client.GetCollectionAsync(IdHelper.MissingID); Assert.Null(collection); } [Fact] - public void TestCollectionsParts() + public async Task TestCollectionsParts() { - Collection collection = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection).Result; + Collection collection = await Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection); Assert.NotNull(collection); Assert.Equal("James Bond Collection", collection.Name); @@ -62,31 +62,28 @@ public void TestCollectionsParts() } [Fact] - public void TestCollectionsExtrasExclusive() + public async Task TestCollectionsExtrasExclusive() { - TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetCollectionAsync(id, extras).Result, IdHelper.JamesBondCollection); + await TestMethodsHelper.TestGetExclusive(_methods, extras => Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection, extras)); } [Fact] - public void TestCollectionsExtrasAll() + public async Task TestCollectionsExtrasAll() { - CollectionMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); - Collection item = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection, combinedEnum).Result; - - TestMethodsHelper.TestAllNotNull(_methods, item); + await TestMethodsHelper.TestGetAll(_methods, combined => Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection, combined)); } [Fact] - public void TestCollectionsImages() + public async Task TestCollectionsImagesAsync() { // Get config - Config.Client.GetConfigAsync().Sync(); + await Config.Client.GetConfigAsync(); // Test image url generator - ImagesWithId images = Config.Client.GetCollectionImagesAsync(IdHelper.JamesBondCollection).Result; + ImagesWithId images = await Config.Client.GetCollectionImagesAsync(IdHelper.JamesBondCollection); Assert.Equal(IdHelper.JamesBondCollection, images.Id); - TestImagesHelpers.TestImages(Config, images); + await TestImagesHelpers.TestImagesAsync(Config, images); } } } \ No newline at end of file diff --git a/TMDbLibTests/ClientCompanyTests.cs b/TMDbLibTests/ClientCompanyTests.cs index 27da1fef..524af0ea 100644 --- a/TMDbLibTests/ClientCompanyTests.cs +++ b/TMDbLibTests/ClientCompanyTests.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Companies; using TMDbLib.Objects.General; @@ -23,9 +23,9 @@ public ClientCompanyTests() } [Fact] - public void TestCompaniesExtrasNone() + public async Task TestCompaniesExtrasNoneAsync() { - Company company = Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox).Result; + Company company = await Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox); Assert.NotNull(company); @@ -40,35 +40,32 @@ public void TestCompaniesExtrasNone() } [Fact] - public void TestCompaniesExtrasExclusive() + public async Task TestCompaniesExtrasExclusive() { - TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetCompanyAsync(id, extras).Result, IdHelper.TwentiethCenturyFox); + await TestMethodsHelper.TestGetExclusive(_methods, extras => Config.Client.GetCompanyAsync( IdHelper.TwentiethCenturyFox, extras)); } [Fact] - public void TestCompaniesExtrasAll() + public async Task TestCompaniesExtrasAllAsync() { - CompanyMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); - Company item = Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox, combinedEnum).Result; - - TestMethodsHelper.TestAllNotNull(_methods, item); + await TestMethodsHelper.TestGetAll(_methods, combined => Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox, combined)); } [Fact] - public void TestCompanyMissing() + public async Task TestCompanyMissingAsync() { - Company company = Config.Client.GetCompanyAsync(IdHelper.MissingID).Result; + Company company = await Config.Client.GetCompanyAsync(IdHelper.MissingID); Assert.Null(company); } [Fact] - public void TestCompaniesGetters() + public async Task TestCompaniesGettersAsync() { //GetCompanyMoviesAsync(int id, string language, int page = -1) - SearchContainerWithId resp = Config.Client.GetCompanyMoviesAsync(IdHelper.TwentiethCenturyFox).Result; - SearchContainerWithId respPage2 = Config.Client.GetCompanyMoviesAsync(IdHelper.TwentiethCenturyFox, 2).Result; - SearchContainerWithId respItalian = Config.Client.GetCompanyMoviesAsync(IdHelper.TwentiethCenturyFox, "it").Result; + SearchContainerWithId resp = await Config.Client.GetCompanyMoviesAsync(IdHelper.TwentiethCenturyFox); + SearchContainerWithId respPage2 = await Config.Client.GetCompanyMoviesAsync(IdHelper.TwentiethCenturyFox, 2); + SearchContainerWithId respItalian = await Config.Client.GetCompanyMoviesAsync(IdHelper.TwentiethCenturyFox, "it"); Assert.NotNull(resp); Assert.NotNull(respPage2); @@ -91,25 +88,25 @@ public void TestCompaniesGetters() } [Fact] - public void TestCompaniesImages() + public async Task TestCompaniesImagesAsync() { // Get config - Config.Client.GetConfigAsync().Sync(); + await Config.Client.GetConfigAsync(); // Test image url generator - Company company = Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox).Result; + Company company = await Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox); Uri url = Config.Client.GetImageUrl("original", company.LogoPath); Uri urlSecure = Config.Client.GetImageUrl("original", company.LogoPath, true); - Assert.True(TestHelpers.InternetUriExists(url)); - Assert.True(TestHelpers.InternetUriExists(urlSecure)); + Assert.True(await TestHelpers.InternetUriExistsAsync(url)); + Assert.True(await TestHelpers.InternetUriExistsAsync(urlSecure)); } [Fact] - public void TestCompaniesFull() + public async Task TestCompaniesFullAsync() { - Company company = Config.Client.GetCompanyAsync(IdHelper.ColumbiaPictures).Result; + Company company = await Config.Client.GetCompanyAsync(IdHelper.ColumbiaPictures); Assert.NotNull(company); diff --git a/TMDbLibTests/ClientConfigurationTests.cs b/TMDbLibTests/ClientConfigurationTests.cs index a7bc8c40..c7efbb7f 100644 --- a/TMDbLibTests/ClientConfigurationTests.cs +++ b/TMDbLibTests/ClientConfigurationTests.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using TMDbLib.Objects.Configuration; using Xunit; using TMDbLib.Objects.Timezones; -using TMDbLibTests.Helpers; using TMDbLibTests.JsonHelpers; using TMDbLib.Objects.Countries; using TMDbLib.Objects.General; @@ -14,9 +14,9 @@ namespace TMDbLibTests public class ClientConfigurationTests : TestBase { [Fact] - public void TestConfiguration() + public async Task TestConfigurationAsync() { - APIConfiguration result = Config.Client.GetAPIConfiguration().Sync(); + APIConfiguration result = await Config.Client.GetAPIConfiguration(); Assert.NotNull(result); @@ -24,9 +24,9 @@ public void TestConfiguration() } [Fact] - public void TestPrimaryTranslations() + public async Task TestPrimaryTranslationsAsync() { - List result = Config.Client.GetPrimaryTranslationsAsync().Sync(); + List result = await Config.Client.GetPrimaryTranslationsAsync(); Assert.NotNull(result); @@ -34,9 +34,9 @@ public void TestPrimaryTranslations() } [Fact] - public void TestCountryList() + public async Task TestCountryListAsync() { - List result = Config.Client.GetCountriesAsync().Sync(); + List result = await Config.Client.GetCountriesAsync(); Assert.NotNull(result); Assert.True(result.Count > 200); @@ -45,9 +45,9 @@ public void TestCountryList() } [Fact] - public void TestLanguageList() + public async Task TestLanguageListAsync() { - List result = Config.Client.GetLanguagesAsync().Sync(); + List result = await Config.Client.GetLanguagesAsync(); Assert.NotNull(result); Assert.True(result.Count > 180); @@ -56,23 +56,23 @@ public void TestLanguageList() } [Fact] - public void TestTimezonesList() + public async Task TestTimezonesListAsync() { - Timezones result = Config.Client.GetTimezonesAsync().Sync(); + Timezones result = await Config.Client.GetTimezonesAsync(); Assert.NotNull(result); Assert.True(result.List.Count > 200); List item = result.List["DK"]; Assert.NotNull(item); - Assert.Equal(1, item.Count); + Assert.Single(item); Assert.Equal("Europe/Copenhagen", item[0]); } [Fact] - public void TestJobList() + public async Task TestJobListAsync() { - List jobs = Config.Client.GetJobsAsync().Sync(); + List jobs = await Config.Client.GetJobsAsync(); Assert.NotNull(jobs); Assert.True(jobs.Count > 0); diff --git a/TMDbLibTests/ClientCreditTests.cs b/TMDbLibTests/ClientCreditTests.cs index dcad9707..231ab379 100644 --- a/TMDbLibTests/ClientCreditTests.cs +++ b/TMDbLibTests/ClientCreditTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Credit; using TMDbLib.Objects.General; @@ -11,9 +12,9 @@ namespace TMDbLibTests public class ClientCreditTests : TestBase { [Fact] - public void TestGetCreditTv() + public async Task TestGetCreditTv() { - Credit result = Config.Client.GetCreditsAsync(IdHelper.BruceWillisMiamiVice).Result; + Credit result = await Config.Client.GetCreditsAsync(IdHelper.BruceWillisMiamiVice); Assert.NotNull(result); Assert.Equal(CreditType.Cast, result.CreditType); @@ -34,17 +35,17 @@ public void TestGetCreditTv() } [Fact] - public void TestMissingCredit() + public async Task TestMissingCredit() { - Credit result = Config.Client.GetCreditsAsync(IdHelper.MissingID.ToString()).Result; + Credit result = await Config.Client.GetCreditsAsync(IdHelper.MissingID.ToString()); Assert.Null(result); } [Fact] - public void TestGetCreditEpisode() + public async Task TestGetCreditEpisode() { - Credit result = Config.Client.GetCreditsAsync(IdHelper.BruceWillisMiamiVice).Result; + Credit result = await Config.Client.GetCreditsAsync(IdHelper.BruceWillisMiamiVice); Assert.NotNull(result); Assert.NotNull(result.Media); @@ -62,9 +63,9 @@ public void TestGetCreditEpisode() } [Fact] - public void TestGetCreditSeasons() + public async Task TestGetCreditSeasons() { - Credit result = Config.Client.GetCreditsAsync(IdHelper.HughLaurieHouse).Result; + Credit result = await Config.Client.GetCreditsAsync(IdHelper.HughLaurieHouse); Assert.NotNull(result); Assert.NotNull(result.Media); diff --git a/TMDbLibTests/ClientDiscoverTests.cs b/TMDbLibTests/ClientDiscoverTests.cs index 5812f024..b2581104 100644 --- a/TMDbLibTests/ClientDiscoverTests.cs +++ b/TMDbLibTests/ClientDiscoverTests.cs @@ -7,17 +7,18 @@ using TMDbLibTests.JsonHelpers; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace TMDbLibTests { public class ClientDiscoverTests : TestBase { [Fact] - public void TestDiscoverTvShowsNoParams() + public async Task TestDiscoverTvShowsNoParamsAsync() { - TestHelpers.SearchPages(i => Config.Client.DiscoverTvShowsAsync().Query(i).Result); + await TestHelpers.SearchPagesAsync(i => Config.Client.DiscoverTvShowsAsync().Query(i)); - SearchContainer result = Config.Client.DiscoverTvShowsAsync().Query().Result; + SearchContainer result = await Config.Client.DiscoverTvShowsAsync().Query(); Assert.NotNull(result); Assert.Equal(1, result.Page); @@ -26,21 +27,21 @@ public void TestDiscoverTvShowsNoParams() } [Fact] - public void TestDiscoverTvShows() + public async Task TestDiscoverTvShowsAsync() { DiscoverTv query = Config.Client.DiscoverTvShowsAsync() .WhereVoteCountIsAtLeast(100) .WhereVoteAverageIsAtLeast(2); - TestHelpers.SearchPages(i => query.Query(i).Result); + await TestHelpers.SearchPagesAsync(i => query.Query(i)); } [Fact] - public void TestDiscoverMoviesNoParams() + public async Task TestDiscoverMoviesNoParamsAsync() { - TestHelpers.SearchPages(i => Config.Client.DiscoverMoviesAsync().Query(i).Result); + await TestHelpers.SearchPagesAsync(i => Config.Client.DiscoverMoviesAsync().Query(i)); - SearchContainer result = Config.Client.DiscoverMoviesAsync().Query().Result; + SearchContainer result = await Config.Client.DiscoverMoviesAsync().Query(); Assert.NotNull(result); Assert.Equal(1, result.Page); @@ -49,40 +50,40 @@ public void TestDiscoverMoviesNoParams() } [Fact] - public void TestDiscoverMovies() + public async Task TestDiscoverMoviesAsync() { DiscoverMovie query = Config.Client.DiscoverMoviesAsync() .WhereVoteCountIsAtLeast(1000) .WhereVoteAverageIsAtLeast(2); - TestHelpers.SearchPages(i => query.Query(i).Result); + await TestHelpers.SearchPagesAsync(i => query.Query(i)); } [Fact] - public void TestDiscoverMoviesRegion() + public async Task TestDiscoverMoviesRegionAsync() { DiscoverMovie query = Config.Client.DiscoverMoviesAsync().WhereReleaseDateIsInRegion("BR").WherePrimaryReleaseDateIsAfter(new DateTime(2017, 01, 01)); - TestHelpers.SearchPages(i => query.Query(i).Result); + await TestHelpers.SearchPagesAsync(i => query.Query(i)); } [Fact] - public void TestDiscoverMoviesLanguage() + public async Task TestDiscoverMoviesLanguageAsync() { DiscoverMovie query = Config.Client.DiscoverMoviesAsync().WhereLanguageIs("da-DK").WherePrimaryReleaseDateIsAfter(new DateTime(2017, 01, 01)); - Assert.Equal("Skønheden og Udyret", query.Query(0).Result.Results[11].Title); + Assert.Equal("Skønheden og Udyret", (await query.Query(0)).Results[11].Title); - TestHelpers.SearchPages(i => query.Query(i).Result); + await TestHelpers.SearchPagesAsync(i => query.Query(i)); } [Theory] [InlineData("ko")] [InlineData("zh")] - public void TestDiscoverMoviesOriginalLanguage(string language) + public async Task TestDiscoverMoviesOriginalLanguage(string language) { DiscoverMovie query = Config.Client.DiscoverMoviesAsync().WhereOriginalLanguageIs(language); - List results = query.Query(0).Result.Results; + List results = (await query.Query(0)).Results; Assert.NotEmpty(results); Assert.All(results, item => Assert.Contains(language, item.OriginalLanguage)); diff --git a/TMDbLibTests/ClientFindTests.cs b/TMDbLibTests/ClientFindTests.cs index 3d8162ae..ba4d0de1 100644 --- a/TMDbLibTests/ClientFindTests.cs +++ b/TMDbLibTests/ClientFindTests.cs @@ -12,7 +12,7 @@ public class ClientFindTests : TestBase public void TestFindImdbMovie() { Task result = Config.Client.FindAsync(FindExternalSource.Imdb, IdHelper.ImdbTerminatorId); - Assert.Equal(1, result.Result.MovieResults.Count); + Assert.Single(result.Result.MovieResults); Assert.Equal(IdHelper.TmdbTerminatorId, result.Result.MovieResults[0].Id); } @@ -20,7 +20,7 @@ public void TestFindImdbMovie() public void TestFindImdbPerson() { Task result = Config.Client.FindAsync(FindExternalSource.Imdb, IdHelper.ImdbBruceWillis); - Assert.Equal(1, result.Result.PersonResults.Count); + Assert.Single(result.Result.PersonResults); Assert.Equal(IdHelper.BruceWillis, result.Result.PersonResults[0].Id); } @@ -28,7 +28,7 @@ public void TestFindImdbPerson() public void TestFindImdbTvShowEpisode() { Task result = Config.Client.FindAsync(FindExternalSource.Imdb, IdHelper.ImdbBreakingBadSeason1Episode1Id); - Assert.Equal(1, result.Result.TvEpisode.Count); + Assert.Single(result.Result.TvEpisode); Assert.Equal(IdHelper.BreakingBadSeason1Episode1Id, result.Result.TvEpisode[0].Id); } @@ -36,9 +36,9 @@ public void TestFindImdbTvShowEpisode() public void TestFindImdbTvShowSeason() { Task result = Config.Client.FindAsync(FindExternalSource.TvDb, IdHelper.TvdbBreakingBadSeason1Id); - Assert.Equal(1, result.Result.TvEpisode.Count); + Assert.Single(result.Result.TvEpisode); - Assert.Equal(1, result.Result.TvSeason.Count); + Assert.Single(result.Result.TvSeason); Assert.Equal(IdHelper.BreakingBadSeason1Id, result.Result.TvSeason[0].Id); } @@ -46,7 +46,7 @@ public void TestFindImdbTvShowSeason() public void TestFindTvdbTvShow() { Task result = Config.Client.FindAsync(FindExternalSource.TvDb, IdHelper.TvdbBreakingBadId); - Assert.Equal(1, result.Result.TvResults.Count); + Assert.Single(result.Result.TvResults); Assert.Equal(IdHelper.TmdbBreakingBadId, result.Result.TvResults[0].Id); } @@ -54,7 +54,7 @@ public void TestFindTvdbTvShow() public void TestFindImdbTvShow() { Task result = Config.Client.FindAsync(FindExternalSource.Imdb, IdHelper.ImdbBreakingBadId); - Assert.Equal(1, result.Result.TvResults.Count); + Assert.Single(result.Result.TvResults); Assert.Equal(IdHelper.TmdbBreakingBadId, result.Result.TvResults[0].Id); } } diff --git a/TMDbLibTests/ClientGenreTests.cs b/TMDbLibTests/ClientGenreTests.cs index 3ce231da..cb1bb7bb 100644 --- a/TMDbLibTests/ClientGenreTests.cs +++ b/TMDbLibTests/ClientGenreTests.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.General; using TMDbLib.Objects.Search; -using TMDbLibTests.Helpers; using TMDbLibTests.JsonHelpers; namespace TMDbLibTests @@ -11,16 +11,16 @@ namespace TMDbLibTests public class ClientGenreTests : TestBase { [Fact] - public void TestGenreTvList() + public async Task TestGenreTvListAsync() { // Default language - List genres = Config.Client.GetTvGenresAsync().Sync(); + List genres = await Config.Client.GetTvGenresAsync(); Assert.NotNull(genres); Assert.True(genres.Count > 0); // Another language - List genresDanish = Config.Client.GetTvGenresAsync("da").Result; + List genresDanish = await Config.Client.GetTvGenresAsync("da"); Assert.NotNull(genresDanish); Assert.True(genresDanish.Count > 0); @@ -28,20 +28,20 @@ public void TestGenreTvList() Assert.Equal(genres.Count, genresDanish.Count); // At least one should be different - Assert.True(genres.Any(genre => genresDanish.First(danishGenre => danishGenre.Id == genre.Id).Name != genre.Name)); + Assert.Contains(genres, genre => genresDanish.First(danishGenre => danishGenre.Id == genre.Id).Name != genre.Name); } [Fact] - public void TestGenreMovieList() + public async Task TestGenreMovieListAsync() { // Default language - List genres = Config.Client.GetMovieGenresAsync().Sync(); + List genres = await Config.Client.GetMovieGenresAsync(); Assert.NotNull(genres); Assert.True(genres.Count > 0); // Another language - List genresDanish = Config.Client.GetMovieGenresAsync("da").Result; + List genresDanish = await Config.Client.GetMovieGenresAsync("da"); Assert.NotNull(genresDanish); Assert.True(genresDanish.Count > 0); @@ -49,19 +49,19 @@ public void TestGenreMovieList() Assert.Equal(genres.Count, genresDanish.Count); // At least one should be different - Assert.True(genres.Any(genre => genresDanish.First(danishGenre => danishGenre.Id == genre.Id).Name != genre.Name)); + Assert.Contains(genres, genre => genresDanish.First(danishGenre => danishGenre.Id == genre.Id).Name != genre.Name); } [Fact] - public void TestGenreMovies() + public async Task TestGenreMoviesAsync() { // Get first genre - Genre genre = Config.Client.GetMovieGenresAsync().Sync().First(); + Genre genre = (await Config.Client.GetMovieGenresAsync()).First(); // Get movies - SearchContainerWithId movies = Config.Client.GetGenreMoviesAsync(genre.Id).Result; - SearchContainerWithId moviesPage2 = Config.Client.GetGenreMoviesAsync(genre.Id, "it", 2, includeAllMovies: false).Result; - SearchContainerWithId moviesAll = Config.Client.GetGenreMoviesAsync(genre.Id, includeAllMovies: true).Result; + SearchContainerWithId movies = await Config.Client.GetGenreMoviesAsync(genre.Id); + SearchContainerWithId moviesPage2 = await Config.Client.GetGenreMoviesAsync(genre.Id, "it", 2, includeAllMovies: false); + SearchContainerWithId moviesAll = await Config.Client.GetGenreMoviesAsync(genre.Id, includeAllMovies: true); Assert.Equal(1, movies.Page); Assert.Equal(2, moviesPage2.Page); diff --git a/TMDbLibTests/ClientGuestSessionTests.cs b/TMDbLibTests/ClientGuestSessionTests.cs index 37390152..40f7d6b5 100644 --- a/TMDbLibTests/ClientGuestSessionTests.cs +++ b/TMDbLibTests/ClientGuestSessionTests.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.General; @@ -14,17 +15,17 @@ namespace TMDbLibTests public class ClientGuestSessionTests : TestBase { [Fact] - public void TestTvEpisodeSetRatingGuestSession() + public async Task TestTvEpisodeSetRatingGuestSessionAsync() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); // Try changing the rating - Assert.True(Config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 7.5).Result); + Assert.True(await Config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 7.5)); // Allow TMDb to cache our changes Thread.Sleep(2000); - SearchContainer ratings = Config.Client.GetGuestSessionRatedTvEpisodesAsync().Sync(); + SearchContainer ratings = await Config.Client.GetGuestSessionRatedTvEpisodesAsync(); Assert.False(true, "This test has been failing for some time - TMDb has been made aware, but have not responded"); @@ -33,7 +34,7 @@ public void TestTvEpisodeSetRatingGuestSession() //Assert.True(Math.Abs(7.5 - tmpRating) < float.Epsilon); //// Try changing it back to the previous rating - //Assert.True(Config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 8).Result); + //Assert.True(Config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 8)); //// Allow TMDb to cache our changes //Thread.Sleep(2000); @@ -45,7 +46,7 @@ public void TestTvEpisodeSetRatingGuestSession() //Assert.True(Math.Abs(8 - tmpRating) < float.Epsilon); //// Try removing the rating - //Assert.True(Config.Client.TvEpisodeRemoveRatingAsync(IdHelper.BreakingBad, 1, 1).Result); + //Assert.True(Config.Client.TvEpisodeRemoveRatingAsync(IdHelper.BreakingBad, 1, 1)); //// Allow TMDb to cache our changes //Thread.Sleep(2000); @@ -56,134 +57,134 @@ public void TestTvEpisodeSetRatingGuestSession() } [Fact] - public void TestTvSetRatingGuestSession() + public async Task TestTvSetRatingGuestSessionAsync() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); // Try changing the rating - Assert.True(Config.Client.TvShowSetRatingAsync(IdHelper.House, 7.5).Result); + Assert.True(await Config.Client.TvShowSetRatingAsync(IdHelper.House, 7.5)); // Allow TMDb to cache our changes Thread.Sleep(2000); - SearchContainer ratings = Config.Client.GetGuestSessionRatedTvAsync().Sync(); + SearchContainer ratings = await Config.Client.GetGuestSessionRatedTvAsync(); double tmpRating = ratings.Results.Single(s => s.Id == IdHelper.House).Rating; - Assert.True(ratings.Results.Any(s => s.Id == IdHelper.House)); + Assert.Contains(ratings.Results, s => s.Id == IdHelper.House); Assert.True(Math.Abs(7.5 - tmpRating) < float.Epsilon); // Try changing it back to the previous rating - Assert.True(Config.Client.TvShowSetRatingAsync(IdHelper.House, 8).Result); + Assert.True(await Config.Client.TvShowSetRatingAsync(IdHelper.House, 8)); // Allow TMDb to cache our changes Thread.Sleep(2000); - ratings = Config.Client.GetGuestSessionRatedTvAsync().Sync(); + ratings = await Config.Client.GetGuestSessionRatedTvAsync(); tmpRating = ratings.Results.Single(s => s.Id == IdHelper.House).Rating; - Assert.True(ratings.Results.Any(s => s.Id == IdHelper.House)); + Assert.Contains(ratings.Results, s => s.Id == IdHelper.House); Assert.True(Math.Abs(8 - tmpRating) < float.Epsilon); // Try removing the rating - Assert.True(Config.Client.TvShowRemoveRatingAsync(IdHelper.House).Result); + Assert.True(await Config.Client.TvShowRemoveRatingAsync(IdHelper.House)); // Allow TMDb to cache our changes Thread.Sleep(2000); - ratings = Config.Client.GetGuestSessionRatedTvAsync().Sync(); + ratings = await Config.Client.GetGuestSessionRatedTvAsync(); - Assert.False(ratings.Results.Any(s => s.Id == IdHelper.House)); + Assert.DoesNotContain(ratings.Results, s => s.Id == IdHelper.House); } [Fact] - public void TestMoviesSetRatingGuestSession() + public async Task TestMoviesSetRatingGuestSessionAsync() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); // Try changing the rating - Assert.True(Config.Client.MovieSetRatingAsync(IdHelper.Terminator, 7.5).Result); + Assert.True(await Config.Client.MovieSetRatingAsync(IdHelper.Terminator, 7.5)); // Allow TMDb to cache our changes Thread.Sleep(2000); - SearchContainer ratings = Config.Client.GetGuestSessionRatedMoviesAsync().Sync(); + SearchContainer ratings = await Config.Client.GetGuestSessionRatedMoviesAsync(); double tmpRating = ratings.Results.Single(s => s.Id == IdHelper.Terminator).Rating; - Assert.True(ratings.Results.Any(s => s.Id == IdHelper.Terminator)); + Assert.Contains(ratings.Results, s => s.Id == IdHelper.Terminator); Assert.True(Math.Abs(7.5 - tmpRating) < float.Epsilon); // Try changing it back to the previous rating - Assert.True(Config.Client.MovieSetRatingAsync(IdHelper.Terminator, 8).Result); + Assert.True(await Config.Client.MovieSetRatingAsync(IdHelper.Terminator, 8)); // Allow TMDb to cache our changes Thread.Sleep(2000); - ratings = Config.Client.GetGuestSessionRatedMoviesAsync().Sync(); + ratings = await Config.Client.GetGuestSessionRatedMoviesAsync(); tmpRating = ratings.Results.Single(s => s.Id == IdHelper.Terminator).Rating; - Assert.True(ratings.Results.Any(s => s.Id == IdHelper.Terminator)); + Assert.Contains(ratings.Results, s => s.Id == IdHelper.Terminator); Assert.True(Math.Abs(8 - tmpRating) < float.Epsilon); // Try removing the rating - Assert.True(Config.Client.MovieRemoveRatingAsync(IdHelper.Terminator).Result); + Assert.True(await Config.Client.MovieRemoveRatingAsync(IdHelper.Terminator)); // Allow TMDb to cache our changes Thread.Sleep(2000); - ratings = Config.Client.GetGuestSessionRatedMoviesAsync().Sync(); + ratings = await Config.Client.GetGuestSessionRatedMoviesAsync(); - Assert.False(ratings.Results.Any(s => s.Id == IdHelper.Terminator)); + Assert.DoesNotContain(ratings.Results, s => s.Id == IdHelper.Terminator); } [Fact] - public void TestGuestSessionGetRatedTvEpisodes() + public async Task TestGuestSessionGetRatedTvEpisodesAsync() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); // Ensure we have a rating - Assert.True(Config.Client.TvEpisodeSetRatingAsync(IdHelper.BigBangTheory, 1, 1, 7.5).Result); + Assert.True(await Config.Client.TvEpisodeSetRatingAsync(IdHelper.BigBangTheory, 1, 1, 7.5)); // Test paging - TestHelpers.SearchPages(i => Config.Client.GetGuestSessionRatedTvEpisodesAsync(i).Result); + await TestHelpers.SearchPagesAsync(i => Config.Client.GetGuestSessionRatedTvEpisodesAsync(i)); // Fetch ratings - SearchContainer result = Config.Client.GetGuestSessionRatedTvEpisodesAsync().Sync(); + SearchContainer result = await Config.Client.GetGuestSessionRatedTvEpisodesAsync(); Assert.NotNull(result); Assert.NotNull(result.Results); } [Fact] - public void TestGuestSessionGetRatedTv() + public async Task TestGuestSessionGetRatedTvAsync() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); // Ensure we have a rating - Assert.True(Config.Client.TvShowSetRatingAsync(IdHelper.BigBangTheory, 7.5).Result); + Assert.True(await Config.Client.TvShowSetRatingAsync(IdHelper.BigBangTheory, 7.5)); // Test paging - TestHelpers.SearchPages(i => Config.Client.GetGuestSessionRatedTvAsync(i).Result); + await TestHelpers.SearchPagesAsync(i => Config.Client.GetGuestSessionRatedTvAsync(i)); // Fetch ratings - SearchContainer result = Config.Client.GetGuestSessionRatedTvAsync().Sync(); + SearchContainer result = await Config.Client.GetGuestSessionRatedTvAsync(); Assert.NotNull(result); Assert.NotNull(result.Results); } [Fact] - public void TestGuestSessionGetRatedMovies() + public async Task TestGuestSessionGetRatedMoviesAsync() { - Config.Client.SetSessionInformation(Config.GuestTestSessionId, SessionType.GuestSession); + await Config.Client.SetSessionInformationAsync(Config.GuestTestSessionId, SessionType.GuestSession); // Ensure we have a rating - Assert.True(Config.Client.MovieSetRatingAsync(IdHelper.Terminator, 7.5).Result); + Assert.True(await Config.Client.MovieSetRatingAsync(IdHelper.Terminator, 7.5)); // Test paging - TestHelpers.SearchPages(i => Config.Client.GetGuestSessionRatedMoviesAsync(i).Result); + await TestHelpers.SearchPagesAsync(i => Config.Client.GetGuestSessionRatedMoviesAsync(i)); // Fetch ratings - SearchContainer result = Config.Client.GetGuestSessionRatedMoviesAsync().Sync(); + SearchContainer result = await Config.Client.GetGuestSessionRatedMoviesAsync(); Assert.NotNull(result); Assert.NotNull(result.Results); diff --git a/TMDbLibTests/ClientKeywordTests.cs b/TMDbLibTests/ClientKeywordTests.cs index 1736f562..dcf7e03a 100644 --- a/TMDbLibTests/ClientKeywordTests.cs +++ b/TMDbLibTests/ClientKeywordTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.General; using TMDbLib.Objects.Movies; @@ -11,9 +12,9 @@ namespace TMDbLibTests public class ClientKeywordTests : TestBase { [Fact] - public void TestKeywordGet() + public async Task TestKeywordGet() { - KeywordsContainer keywords = Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard).Result; + KeywordsContainer keywords = await Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(keywords); Assert.NotNull(keywords.Keywords); @@ -22,7 +23,7 @@ public void TestKeywordGet() // Try to get all keywords foreach (Keyword testKeyword in keywords.Keywords) { - Keyword getKeyword = Config.Client.GetKeywordAsync(testKeyword.Id).Result; + Keyword getKeyword = await Config.Client.GetKeywordAsync(testKeyword.Id); Assert.NotNull(getKeyword); @@ -32,17 +33,17 @@ public void TestKeywordGet() } [Fact] - public void TestKeywordsMissing() + public async Task TestKeywordsMissing() { - KeywordsContainer keywords = Config.Client.GetMovieKeywordsAsync(IdHelper.MissingID).Result; + KeywordsContainer keywords = await Config.Client.GetMovieKeywordsAsync(IdHelper.MissingID); Assert.Null(keywords); } [Fact] - public void TestKeywordMovies() + public async Task TestKeywordMovies() { - KeywordsContainer keywords = Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard).Result; + KeywordsContainer keywords = await Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(keywords); Assert.NotNull(keywords.Keywords); @@ -52,9 +53,9 @@ public void TestKeywordMovies() Keyword testKeyword = keywords.Keywords.First(); // Get movies - SearchContainerWithId movies = Config.Client.GetKeywordMoviesAsync(testKeyword.Id).Result; - SearchContainerWithId moviesItalian = Config.Client.GetKeywordMoviesAsync(testKeyword.Id, "it").Result; - SearchContainerWithId moviesPage2 = Config.Client.GetKeywordMoviesAsync(testKeyword.Id, 2).Result; + SearchContainerWithId movies = await Config.Client.GetKeywordMoviesAsync(testKeyword.Id); + SearchContainerWithId moviesItalian = await Config.Client.GetKeywordMoviesAsync(testKeyword.Id, "it"); + SearchContainerWithId moviesPage2 = await Config.Client.GetKeywordMoviesAsync(testKeyword.Id, 2); Assert.NotNull(movies); Assert.NotNull(moviesItalian); @@ -70,7 +71,7 @@ public void TestKeywordMovies() if (movies.TotalResults > movies.Results.Count) Assert.True(moviesPage2.Results.Count > 0); else - Assert.Equal(0, moviesPage2.Results.Count); + Assert.Empty(moviesPage2.Results); Assert.Equal(1, movies.Page); Assert.Equal(1, moviesItalian.Page); diff --git a/TMDbLibTests/ClientListsTests.cs b/TMDbLibTests/ClientListsTests.cs index 5d02a8c7..21a8ea33 100644 --- a/TMDbLibTests/ClientListsTests.cs +++ b/TMDbLibTests/ClientListsTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.General; @@ -16,10 +17,10 @@ public class ClientListsTests : TestBase private const string TestListId = "528349d419c2954bd21ca0a8"; [Fact] - public void TestList() + public async Task TestListAsync() { // Get list - GenericList list = Config.Client.GetListAsync(TestListId).Result; + GenericList list = await Config.Client.GetListAsync(TestListId); Assert.NotNull(list); Assert.Equal(TestListId, list.Id); @@ -31,7 +32,7 @@ public void TestList() // Ensure all movies point to this list int page = 1; - SearchContainer movieLists = Config.Client.GetMovieListsAsync(movieResult.Id).Result; + SearchContainer movieLists = await Config.Client.GetMovieListsAsync(movieResult.Id); while (movieLists != null) { // Check if the current result page contains the relevant list @@ -43,7 +44,7 @@ public void TestList() // See if there is an other page we could try, if not the test fails if (movieLists.Page < movieLists.TotalPages) - movieLists = Config.Client.GetMovieListsAsync(movieResult.Id, ++page).Result; + movieLists = await Config.Client.GetMovieListsAsync(movieResult.Id, ++page); else throw new Exception($"Movie '{movieResult.Title}' was not linked to the test list"); } @@ -51,103 +52,103 @@ public void TestList() } [Fact] - public void TestListMissing() + public async Task TestListMissingAsync() { - GenericList list = Config.Client.GetListAsync(IdHelper.MissingID.ToString()).Result; + GenericList list = await Config.Client.GetListAsync(IdHelper.MissingID.ToString()); Assert.Null(list); } [Fact] - public void TestListIsMoviePresentFailure() + public async Task TestListIsMoviePresentFailureAsync() { - Assert.False(Config.Client.GetListIsMoviePresentAsync(TestListId, IdHelper.Terminator).Result); - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + Assert.False(await Config.Client.GetListIsMoviePresentAsync(TestListId, IdHelper.Terminator)); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Clear list - Assert.True(Config.Client.ListClearAsync(TestListId).Result); + Assert.True(await Config.Client.ListClearAsync(TestListId)); // Verify Avatar is not present - Assert.False(Config.Client.GetListIsMoviePresentAsync(TestListId, IdHelper.Avatar).Result); + Assert.False(await Config.Client.GetListIsMoviePresentAsync(TestListId, IdHelper.Avatar)); // Add Avatar - Assert.True(Config.Client.ListAddMovieAsync(TestListId, IdHelper.Avatar).Result); + Assert.True(await Config.Client.ListAddMovieAsync(TestListId, IdHelper.Avatar)); // Verify Avatar is present - Assert.True(Config.Client.GetListIsMoviePresentAsync(TestListId, IdHelper.Avatar).Result); + Assert.True(await Config.Client.GetListIsMoviePresentAsync(TestListId, IdHelper.Avatar)); } [Fact] - public void TestListCreateAndDelete() + public async Task TestListCreateAndDeleteAsync() { const string listName = "Test List 123"; - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - string newListId = Config.Client.ListCreateAsync(listName).Result; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + string newListId = await Config.Client.ListCreateAsync(listName); Assert.False(string.IsNullOrWhiteSpace(newListId)); - GenericList newlyAddedList = Config.Client.GetListAsync(newListId).Result; + GenericList newlyAddedList = await Config.Client.GetListAsync(newListId); Assert.NotNull(newlyAddedList); Assert.Equal(listName, newlyAddedList.Name); Assert.Equal("", newlyAddedList.Description); // "" is the default value Assert.Equal("en", newlyAddedList.Iso_639_1); // en is the default value Assert.Equal(0, newlyAddedList.ItemCount); - Assert.Equal(0, newlyAddedList.Items.Count); + Assert.Empty(newlyAddedList.Items); Assert.False(string.IsNullOrWhiteSpace(newlyAddedList.CreatedBy)); - Assert.True(Config.Client.ListDeleteAsync(newListId).Result); + Assert.True(await Config.Client.ListDeleteAsync(newListId)); } [Fact] - public void TestListDeleteFailure() + public async Task TestListDeleteFailureAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Try removing a list with an incorrect id - Assert.False(Config.Client.ListDeleteAsync("bla").Result); + Assert.False(await Config.Client.ListDeleteAsync("bla")); } [Fact] - public void TestListAddAndRemoveMovie() + public async Task TestListAddAndRemoveMovieAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Add a new movie to the list - Assert.True(Config.Client.ListAddMovieAsync(TestListId, IdHelper.EvanAlmighty).Result); + Assert.True(await Config.Client.ListAddMovieAsync(TestListId, IdHelper.EvanAlmighty)); // Try again, this time it should fail since the list already contains this movie - Assert.False(Config.Client.ListAddMovieAsync(TestListId, IdHelper.EvanAlmighty).Result); + Assert.False(await Config.Client.ListAddMovieAsync(TestListId, IdHelper.EvanAlmighty)); // Get list and check if the item was added - GenericList listAfterAdd = Config.Client.GetListAsync(TestListId).Result; - Assert.True(listAfterAdd.Items.Any(m => m.Id == IdHelper.EvanAlmighty)); + GenericList listAfterAdd = await Config.Client.GetListAsync(TestListId); + Assert.Contains(listAfterAdd.Items, m => m.Id == IdHelper.EvanAlmighty); // Remove the previously added movie from the list - Assert.True(Config.Client.ListRemoveMovieAsync(TestListId, IdHelper.EvanAlmighty).Result); + Assert.True(await Config.Client.ListRemoveMovieAsync(TestListId, IdHelper.EvanAlmighty)); // Get list and check if the item was removed - GenericList listAfterRemove = Config.Client.GetListAsync(TestListId).Result; - Assert.False(listAfterRemove.Items.Any(m => m.Id == IdHelper.EvanAlmighty)); + GenericList listAfterRemove = await Config.Client.GetListAsync(TestListId); + Assert.DoesNotContain(listAfterRemove.Items, m => m.Id == IdHelper.EvanAlmighty); } [Fact] - public void TestListClear() + public async Task TestListClearAsync() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Add a new movie to the list - Assert.True(Config.Client.ListAddMovieAsync(TestListId, IdHelper.MadMaxFuryRoad).Result); + Assert.True(await Config.Client.ListAddMovieAsync(TestListId, IdHelper.MadMaxFuryRoad)); // Get list and check if the item was added - GenericList listAfterAdd = Config.Client.GetListAsync(TestListId).Result; - Assert.True(listAfterAdd.Items.Any(m => m.Id == IdHelper.MadMaxFuryRoad)); + GenericList listAfterAdd = await Config.Client.GetListAsync(TestListId); + Assert.Contains(listAfterAdd.Items, m => m.Id == IdHelper.MadMaxFuryRoad); // Clear the list - Assert.True(Config.Client.ListClearAsync(TestListId).Result); + Assert.True(await Config.Client.ListClearAsync(TestListId)); // Get list and check that all items were removed - GenericList listAfterRemove = Config.Client.GetListAsync(TestListId).Result; + GenericList listAfterRemove = await Config.Client.GetListAsync(TestListId); Assert.False(listAfterRemove.Items.Any()); } } diff --git a/TMDbLibTests/ClientMovieTests.cs b/TMDbLibTests/ClientMovieTests.cs index 26716203..c69f62ce 100644 --- a/TMDbLibTests/ClientMovieTests.cs +++ b/TMDbLibTests/ClientMovieTests.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Xunit; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.Changes; @@ -45,9 +45,9 @@ public ClientMovieTests() } [Fact] - public void TestMoviesExtrasNone() + public async void TestMoviesExtrasNone() { - Movie movie = Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard).Result; + Movie movie = await Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(movie); @@ -62,44 +62,39 @@ public void TestMoviesExtrasNone() } [Fact] - public void TestMoviesExtrasExclusive() + public async void TestMoviesExtrasExclusive() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetMovieAsync(id, extras).Result, IdHelper.AGoodDayToDieHard); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); + await TestMethodsHelper.TestGetExclusive(_methods, extras => Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard, extras)); } [Fact] - public void TestMoviesImdbExtrasAll() + public async Task TestMoviesImdbExtrasAllAsync() { Dictionary> tmpMethods = new Dictionary>(_methods); tmpMethods.Remove(MovieMethods.Videos); - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); // Account states will only show up if we've done something - Config.Client.MovieSetRatingAsync(IdHelper.TheDarkKnightRises, 5).Sync(); + await Config.Client.MovieSetRatingAsync(IdHelper.TheDarkKnightRises, 5); - MovieMethods combinedEnum = tmpMethods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); - Movie item = Config.Client.GetMovieAsync(IdHelper.TheDarkKnightRisesImdb, combinedEnum).Result; - - TestMethodsHelper.TestAllNotNull(tmpMethods, item); + await TestMethodsHelper.TestGetAll(tmpMethods, combined => Config.Client.GetMovieAsync(IdHelper.TheDarkKnightRisesImdb, combined)); } [Fact] - public void TestMoviesExtrasAll() + public async void TestMoviesExtrasAll() { - Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); - MovieMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); - Movie item = Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard, combinedEnum).Result; + await Config.Client.SetSessionInformationAsync(Config.UserSessionId, SessionType.UserSession); - TestMethodsHelper.TestAllNotNull(_methods, item); + await TestMethodsHelper.TestGetAll(_methods, combined => Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard, combined)); } [Fact] - public void TestMoviesLanguage() + public async void TestMoviesLanguage() { - Movie movie = Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard).Result; - Movie movieItalian = Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard, "it").Result; + Movie movie = await Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard); + Movie movieItalian = await Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard, "it"); Assert.NotNull(movie); Assert.NotNull(movieItalian); @@ -116,30 +111,30 @@ public void TestMoviesLanguage() } [Fact] - public void TestMoviesGetMovieAlternativeTitles() + public async void TestMoviesGetMovieAlternativeTitles() { - AlternativeTitles respUs = Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard, "US").Result; + AlternativeTitles respUs = await Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard, "US"); Assert.NotNull(respUs); - AlternativeTitles respFrench = Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard, "FR").Result; + AlternativeTitles respFrench = await Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard, "FR"); Assert.NotNull(respFrench); - Assert.False(respUs.Titles.Any(s => s.Title == "Duro de matar 5")); - Assert.True(respFrench.Titles.Any(s => s.Title == "Die Hard 5 - Belle Journée Pour mourir")); + Assert.DoesNotContain(respUs.Titles, s => s.Title == "Duro de matar 5"); + Assert.Contains(respFrench.Titles, s => s.Title == "Die Hard 5 - Belle Journée Pour mourir"); Assert.True(respUs.Titles.All(s => s.Iso_3166_1 == "US")); Assert.True(respFrench.Titles.All(s => s.Iso_3166_1 == "FR")); } [Fact] - public void TestMoviesGetMovieReleaseDates() + public async void TestMoviesGetMovieReleaseDates() { - ResultContainer resp = Config.Client.GetMovieReleaseDatesAsync(IdHelper.AGoodDayToDieHard).Result; + ResultContainer resp = await Config.Client.GetMovieReleaseDatesAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(resp); ReleaseDatesContainer releasesUs = resp.Results.SingleOrDefault(s => s.Iso_3166_1 == "US"); Assert.NotNull(releasesUs); - Assert.Equal(1, releasesUs.ReleaseDates.Count); + Assert.Single(releasesUs.ReleaseDates); ReleaseDateItem singleRelease = releasesUs.ReleaseDates.First(); @@ -151,23 +146,23 @@ public void TestMoviesGetMovieReleaseDates() } [Fact] - public void TestMoviesGetMovieAlternativeTitlesCountry() + public async void TestMoviesGetMovieAlternativeTitlesCountry() { - AlternativeTitles respUs = Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard, "US").Result; + AlternativeTitles respUs = await Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard, "US"); Assert.NotNull(respUs); Config.Client.DefaultCountry = "US"; - AlternativeTitles respUs2 = Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard).Result; + AlternativeTitles respUs2 = await Config.Client.GetMovieAlternativeTitlesAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(respUs2); Assert.Equal(respUs.Titles.Count, respUs2.Titles.Count); } [Fact] - public void TestMoviesGetMovieCasts() + public async void TestMoviesGetMovieCasts() { - Credits resp = Config.Client.GetMovieCreditsAsync(IdHelper.AGoodDayToDieHard).Result; + Credits resp = await Config.Client.GetMovieCreditsAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(resp); Cast cast = resp.Cast.SingleOrDefault(s => s.Name == "Bruce Willis"); @@ -196,9 +191,9 @@ public void TestMoviesGetMovieCasts() } [Fact] - public void TestMoviesGetExternalIds() + public async void TestMoviesGetExternalIds() { - ExternalIdsMovie externalIds = Config.Client.GetMovieExternalIdsAsync(IdHelper.BladeRunner2049).Result; + ExternalIdsMovie externalIds = await Config.Client.GetMovieExternalIdsAsync(IdHelper.BladeRunner2049); Assert.NotNull(externalIds); Assert.Equal(335984, externalIds.Id); @@ -209,9 +204,9 @@ public void TestMoviesGetExternalIds() } [Fact] - public void TestMoviesGetMovieImages() + public async void TestMoviesGetMovieImages() { - ImagesWithId resp = Config.Client.GetMovieImagesAsync(IdHelper.AGoodDayToDieHard).Result; + ImagesWithId resp = await Config.Client.GetMovieImagesAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(resp); ImageData backdrop = resp.Backdrops.SingleOrDefault(s => s.FilePath == "/17zArExB7ztm6fjUXZwQWgGMC9f.jpg"); @@ -238,18 +233,18 @@ public void TestMoviesGetMovieImages() } [Fact] - public void TestMoviesGetMovieImagesWithImageLanguage() + public async void TestMoviesGetMovieImagesWithImageLanguage() { - ImagesWithId resp = Config.Client.GetMovieImagesAsync(IdHelper.AGoodDayToDieHard, language: "en-US", includeImageLanguage: "en").Result; + ImagesWithId resp = await Config.Client.GetMovieImagesAsync(IdHelper.AGoodDayToDieHard, language: "en-US", includeImageLanguage: "en"); Assert.True(resp.Backdrops.Count > 0); Assert.True(resp.Posters.Count > 0); } [Fact] - public void TestMoviesGetMovieWithImageLanguage() + public async void TestMoviesGetMovieWithImageLanguage() { - Movie resp = Config.Client.GetMovieAsync(IdHelper.Avatar, language: "en-US", includeImageLanguage: "en", extraMethods: MovieMethods.Images).Result; + Movie resp = await Config.Client.GetMovieAsync(IdHelper.Avatar, language: "en-US", includeImageLanguage: "en", extraMethods: MovieMethods.Images); Assert.True(resp.Images.Backdrops.Count > 0); Assert.True(resp.Images.Backdrops.All(b => b.Iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase))); @@ -258,9 +253,9 @@ public void TestMoviesGetMovieWithImageLanguage() } [Fact] - public void TestMoviesGetMovieKeywords() + public async void TestMoviesGetMovieKeywords() { - KeywordsContainer resp = Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard).Result; + KeywordsContainer resp = await Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(resp); Keyword keyword = resp.Keywords.SingleOrDefault(s => s.Id == 186447); @@ -271,9 +266,9 @@ public void TestMoviesGetMovieKeywords() } [Fact] - public void TestMoviesGetMovieReleases() + public async void TestMoviesGetMovieReleases() { - Releases resp = Config.Client.GetMovieReleasesAsync(IdHelper.AGoodDayToDieHard).Result; + Releases resp = await Config.Client.GetMovieReleasesAsync(IdHelper.AGoodDayToDieHard); Assert.NotNull(resp); Country country = resp.Countries.SingleOrDefault(s => s.Iso_3166_1 == "US"); @@ -281,14 +276,15 @@ public void TestMoviesGetMovieReleases() Assert.Equal("R", country.Certification); Assert.Equal("US", country.Iso_3166_1); - Assert.Equal(false, country.Primary); + Assert.False(country.Primary); Assert.Equal(new DateTime(2013, 2, 14), country.ReleaseDate); } [Fact] - public void TestMoviesGetMovieVideos() + public async void TestMoviesGetMovieVideos() { - ResultContainer