Make ignoring compliance more explicit

This commit is contained in:
Michael Bisbjerg 2016-08-08 22:05:18 +02:00
parent c343b5f06f
commit 5baadd1f91
9 changed files with 47 additions and 30 deletions

View File

@ -25,7 +25,7 @@ namespace TMDbLibTests
public void TestCollectionsExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / images");
Collection collection = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection).Result;
@ -45,7 +45,7 @@ namespace TMDbLibTests
public void TestCollectionsParts()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / images");
Collection collection = Config.Client.GetCollectionAsync(IdHelper.JamesBondCollection).Result;
@ -62,9 +62,6 @@ namespace TMDbLibTests
[Fact]
public void TestCollectionsExtrasExclusive()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetCollectionAsync(id, extras).Result, IdHelper.JamesBondCollection);
}

View File

@ -26,7 +26,7 @@ namespace TMDbLibTests
public void TestCompaniesExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / movies");
Company company = Config.Client.GetCompanyAsync(IdHelper.TwentiethCenturyFox).Result;
@ -45,9 +45,6 @@ namespace TMDbLibTests
[Fact]
public void TestCompaniesExtrasExclusive()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetCompanyAsync(id, extras).Result, IdHelper.TwentiethCenturyFox);
}
@ -91,7 +88,7 @@ namespace TMDbLibTests
[Fact]
public void TestCompaniesImages()
{
IgnoreMissingJson = true;
IgnoreMissingJson(" / movies");
// Get config
Config.Client.GetConfig();
@ -109,7 +106,7 @@ namespace TMDbLibTests
[Fact]
public void TestCompaniesFull()
{
IgnoreMissingJson = true;
IgnoreMissingJson(" / movies");
Company company = Config.Client.GetCompanyAsync(IdHelper.ColumbiaPictures).Result;

View File

@ -19,7 +19,7 @@ namespace TMDbLibTests
public class ClientMovieTests : TestBase
{
private static Dictionary<MovieMethods, Func<Movie, object>> _methods;
public ClientMovieTests()
{
_methods = new Dictionary<MovieMethods, Func<Movie, object>>
@ -44,7 +44,7 @@ namespace TMDbLibTests
public void TestMoviesExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / account_states", " / alternative_titles", " / changes", " / credits", " / images", " / keywords", " / lists", " / release_dates", " / releases", " / reviews", " / similar", " / translations", " / videos");
Movie movie = Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard).Result;
@ -64,7 +64,7 @@ namespace TMDbLibTests
public void TestMoviesExtrasExclusive()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / account_states", " / alternative_titles", " / changes", " / credits", " / images", " / keywords", " / lists", " / release_dates", " / releases", " / reviews", " / similar", " / translations", " / videos", "alternative_titles / id", "credits / id", "keywords / id", "release_dates / id", "releases / id", "translations / id", "videos / id");
Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);
TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetMovieAsync(id, extras).Result, IdHelper.AGoodDayToDieHard);
@ -342,7 +342,7 @@ namespace TMDbLibTests
[Fact]
public void TestMoviesGetMovieChanges()
{
IgnoreMissingJson = true;
IgnoreMissingJson(" / account_states", " / alternative_titles", " / changes", " / credits", " / images", " / keywords", " / lists", " / release_dates", " / releases", " / reviews", " / similar", " / translations", " / videos");
//GetMovieChangesAsync(int id, DateTime? startDate = null, DateTime? endDate = null)
// FindAsync latest changed title
@ -624,6 +624,9 @@ namespace TMDbLibTests
[Fact]
public void TestMoviesExtrasAccountState()
{
// Ignore certain properties
IgnoreMissingJson(" / id", " / alternative_titles", " / changes", " / credits", " / images", " / keywords", " / lists", " / release_dates", " / releases", " / reviews", " / similar", " / translations", " / videos");
// Test the custom parsing code for Account State rating
Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);

View File

@ -32,7 +32,7 @@ namespace TMDbLibTests
public void TestPersonsExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / changes", " / external_ids", " / images", " / movie_credits", " / tagged_images", " / tv_credits");
Person person = Config.Client.GetPersonAsync(IdHelper.BruceWillis).Result;
@ -51,7 +51,7 @@ namespace TMDbLibTests
public void TestPersonsExtrasExclusive()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / changes", " / external_ids", " / images", " / movie_credits", " / tagged_images", " / tv_credits", "external_ids / id", "images / id", "movie_credits / id", "tv_credits / id");
TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetPersonAsync(id, extras).Result, IdHelper.BruceWillis);
}

View File

@ -83,9 +83,6 @@ namespace TMDbLibTests
[Fact]
public void ClientRateLimitTest()
{
IgnoreMissingJson = true;
IgnoreMissingProperties = true;
const int id = IdHelper.AGoodDayToDieHard;
TMDbClient client = new TMDbClient(TestConfig.APIKey);

View File

@ -35,7 +35,7 @@ namespace TMDbLibTests
public void TestTvEpisodeExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / account_states", " / credits", " / external_ids", " / images", " / videos");
TvEpisode tvEpisode = Config.Client.GetTvEpisodeAsync(IdHelper.BreakingBad, 1, 1).Result;
@ -52,7 +52,7 @@ namespace TMDbLibTests
public void TestTvEpisodeExtrasAccountState()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / credits", " / external_ids", " / images", " / videos");
// Test the custom parsing code for Account State rating
Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);
@ -135,7 +135,7 @@ namespace TMDbLibTests
public void TestTvEpisodeSeparateExtrasExternalIds()
{
ExternalIdsTvEpisode externalIds = Config.Client.GetTvEpisodeExternalIdsAsync(IdHelper.BreakingBad, 1, 1).Result;
Assert.NotNull(externalIds);
Assert.True(string.IsNullOrEmpty(externalIds.FreebaseId));
Assert.Equal(62085, externalIds.Id);

View File

@ -35,7 +35,7 @@ namespace TMDbLibTests
public void TestTvSeasonExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / account_states", " / credits", " / episode_count", " / external_ids", " / images", " / videos");
TvSeason tvSeason = Config.Client.GetTvSeasonAsync(IdHelper.BreakingBad, 1).Result;
@ -52,7 +52,7 @@ namespace TMDbLibTests
public void TestTvSeasonExtrasAccountState()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / credits", " / external_ids", " / images", " / videos", "account_states / id");
// Test the custom parsing code for Account State rating
Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);
@ -93,7 +93,7 @@ namespace TMDbLibTests
public void TestTvSeasonExtrasExclusive()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / account_states", " / episode_count", " / external_ids", " / images", " / videos", " / credits", "external_ids / id", "videos / id", "credits / id", "account_states / id");
Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);
TestMethodsHelper.TestGetExclusive(_methods, (id, extras) => Config.Client.GetTvSeasonAsync(id, 1, extras).Result, IdHelper.BreakingBad);
@ -126,7 +126,7 @@ namespace TMDbLibTests
public void TestTvSeasonSeparateExtrasExternalIds()
{
ExternalIdsTvSeason externalIds = Config.Client.GetTvSeasonExternalIdsAsync(IdHelper.BreakingBad, 1).Result;
Assert.NotNull(externalIds);
Assert.Equal(3572, externalIds.Id);
Assert.Equal("/en/breaking_bad_season_1", externalIds.FreebaseId);

View File

@ -38,7 +38,7 @@ namespace TMDbLibTests
public void TestTvShowExtrasNone()
{
// We will intentionally ignore errors reg. missing JSON as we do not request it
IgnoreMissingJson = true;
IgnoreMissingJson(" / adult", " / known_for", " / popularity", " / account_states", " / alternative_titles", " / changes", " / content_ratings", " / credits", " / external_ids", " / images", " / keywords", " / similar", " / translations", " / videos", " / genre_ids");
TvShow tvShow = Config.Client.GetTvShowAsync(IdHelper.BreakingBad).Result;

View File

@ -23,10 +23,18 @@ namespace TMDbLibTests.JsonHelpers
/// <summary>
/// Ignores errors about missing JSON properties (Where C# properties are not set)
/// </summary>
protected bool IgnoreMissingJson = false;
private readonly List<string> _ignoreMissingJsonProperties;
protected void IgnoreMissingJson(params string[] keys)
{
_ignoreMissingJsonProperties.AddRange(keys);
}
public TestBase()
{
// Always ignore certain properties, as TMDb shouldn't be serving those
_ignoreMissingJsonProperties = new List<string> { " / _id" };
JsonSerializerSettings sett = new JsonSerializerSettings();
//sett.MissingMemberHandling = MissingMemberHandling.Error;
@ -68,7 +76,7 @@ namespace TMDbLibTests.JsonHelpers
else if (errorMessage.StartsWith("Required property"))
{
// Field in C# is missing in JSON
if (!IgnoreMissingJson && !missingPropertyInJson.ContainsKey(key))
if (!_ignoreMissingJsonProperties.Contains(key) && !missingPropertyInJson.ContainsKey(key))
missingPropertyInJson.Add(key, error);
}
else
@ -86,6 +94,8 @@ namespace TMDbLibTests.JsonHelpers
sb.AppendLine("Fields missing in C# (Present in JSON)");
foreach (KeyValuePair<string, ErrorEventArgs> pair in missingFieldInCSharp)
sb.AppendLine($"{pair.Key}: {pair.Value.ErrorContext.Error.Message}");
sb.AppendLine();
}
if (missingPropertyInJson.Any())
@ -93,6 +103,8 @@ namespace TMDbLibTests.JsonHelpers
sb.AppendLine("Fields missing in JSON (Present in C#)");
foreach (KeyValuePair<string, ErrorEventArgs> pair in missingPropertyInJson)
sb.AppendLine($"{pair.Key}: {pair.Value.ErrorContext.Error.Message}");
sb.AppendLine();
}
if (other.Any())
@ -100,6 +112,17 @@ namespace TMDbLibTests.JsonHelpers
sb.AppendLine("Other errors");
foreach (KeyValuePair<string, ErrorEventArgs> pair in other)
sb.AppendLine($"{pair.Key}: {pair.Value.ErrorContext.Error.Message}");
sb.AppendLine();
}
if (missingPropertyInJson.Any())
{
// Helper line of properties that can be ignored
sb.AppendLine("Ignore C# props missing from JSON:");
sb.AppendLine(string.Join(", ", missingPropertyInJson.OrderBy(s => s.Key).Select(s => $"\"{s.Key}\"")));
sb.AppendLine();
}
if (missingFieldInCSharp.Any() || missingPropertyInJson.Any() || other.Any())