Skip to content
2 changes: 1 addition & 1 deletion src/OpenMovieDatabase.Client/BasicResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OpenMovieDatabase.Client
public class BasicResponse
{
public string Title { get; }
public int Year { get; }
public int?[] Year { get; }
public string ImdbID { get; }
public ItemType Type { get; }
public Uri Poster { get; }
Expand Down
3 changes: 2 additions & 1 deletion src/OpenMovieDatabase.Client/Internal/InternalSearchItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ internal class InternalSearchItem
internal string Title { get; set; }

[JsonProperty]
internal int Year { get; set; }
[JsonConverter(typeof(YearJsonConverter))]
internal int?[] Year { get; set; }

[JsonProperty]
internal string Rated { get; set; }
Expand Down
46 changes: 46 additions & 0 deletions src/OpenMovieDatabase.Client/Internal/YearJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Newtonsoft.Json;
using System;
using System.Linq;

namespace OpenMovieDatabase.Client.Internal
{
internal class YearJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(int[]);
}

public override bool CanRead => true;
public override bool CanWrite => false;

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var value = (string)reader.Value;

if (string.IsNullOrEmpty(value))
return null;

var values = value.Split('-', '–');
if (values.Length > 2)
return null;

return values.Select(ParseValue).ToArray();
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
}

private static int? ParseValue(string value)
{
if (string.IsNullOrEmpty(value))
return null;

if (int.TryParse(value, out int parsedValue))
return parsedValue;

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public OpenMovieDatabaseClientIntegrationTest()
var httpClient = new HttpClient(handler);

//I'm using the same api key that http://www.omdbapi.com this could be stop working any moment
_sut = new OpenMovieDatabaseClient("PlzBanMe", httpClient);
_sut = new OpenMovieDatabaseClient("BanMePlz", httpClient);
}

[Fact]
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task SearchAsyncThrowsError()
}

[Fact]
//[Fact(Skip = "Integration test")]
[Trait("Category", "Integration")]
public async Task GetByIdOrTitleAsync()
{
var request = new GetByIdOrTitleRequest
Expand All @@ -85,7 +85,7 @@ public async Task GetByIdOrTitleAsync()
}

[Fact]
//[Fact(Skip = "Integration test")]
[Trait("Category", "Integration")]
public async Task GetByIdOrTitleAsyncThrowsError()
{
var request = new GetByIdOrTitleRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void ShouldThrowWhenApiKeyIsNullOrEmptyString(string apiKey)
Assert.Throws<ArgumentNullException>(() => new OpenMovieDatabaseClient(apiKey, null));
}

[Fact]
public void ShouldThrowWhenHttpClientIsNull()
{
Assert.Throws<ArgumentNullException>(() => new OpenMovieDatabaseClient("api-key", null));
Expand Down