diff --git a/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/GetSeriesPathFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/GetSeriesPathFixture.cs index c375d4f7a..00cdeac85 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/GetSeriesPathFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/GetSeriesPathFixture.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json [TestFixture] public class GetSeriesPathFixture : CoreTest { + private const int TVDB_ID = 5; private XbmcSettings _settings; private Series _series; private string _response; @@ -25,24 +26,28 @@ public void Setup() .Build(); _xbmcSeries = Builder.CreateListOfSize(3) - .Build() - .ToList(); + .All() + .With(s => s.ImdbNumber = "0") + .TheFirst(1) + .With(s => s.ImdbNumber = TVDB_ID.ToString()) + .Build() + .ToList(); Mocker.GetMock() .Setup(s => s.GetSeries(_settings)) .Returns(_xbmcSeries); } - private void WithMatchingTvdbId() + private void GivenMatchingTvdbId() { _series = new Series { - TvdbId = _xbmcSeries.First().ImdbNumber, + TvdbId = TVDB_ID, Title = "TV Show" }; } - private void WithMatchingTitle() + private void GivenMatchingTitle() { _series = new Series { @@ -51,7 +56,7 @@ private void WithMatchingTitle() }; } - private void WithoutMatchingSeries() + private void GivenMatchingSeries() { _series = new Series { @@ -63,7 +68,7 @@ private void WithoutMatchingSeries() [Test] public void should_return_null_when_series_is_not_found() { - WithoutMatchingSeries(); + GivenMatchingSeries(); Subject.GetSeriesPath(_settings, _series).Should().BeNull(); } @@ -71,7 +76,7 @@ public void should_return_null_when_series_is_not_found() [Test] public void should_return_path_when_tvdbId_matches() { - WithMatchingTvdbId(); + GivenMatchingTvdbId(); Subject.GetSeriesPath(_settings, _series).Should().Be(_xbmcSeries.First().File); } @@ -79,9 +84,24 @@ public void should_return_path_when_tvdbId_matches() [Test] public void should_return_path_when_title_matches() { - WithMatchingTitle(); + GivenMatchingTitle(); Subject.GetSeriesPath(_settings, _series).Should().Be(_xbmcSeries.First().File); } + + [Test] + public void should_not_throw_when_imdb_number_is_not_a_number() + { + GivenMatchingTvdbId(); + + _xbmcSeries.ForEach(s => s.ImdbNumber = "tt12345"); + _xbmcSeries.Last().ImdbNumber = TVDB_ID.ToString(); + + Mocker.GetMock() + .Setup(s => s.GetSeries(_settings)) + .Returns(_xbmcSeries); + + Subject.GetSeriesPath(_settings, _series).Should().NotBeNull(); + } } } diff --git a/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/UpdateFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/UpdateFixture.cs index 9cfb3a457..8258c566d 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/UpdateFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/Xbmc/Json/UpdateFixture.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json [TestFixture] public class UpdateFixture : CoreTest { + private const int TVDB_ID = 5; private XbmcSettings _settings; private Series _series; private List _xbmcSeries; @@ -25,8 +26,10 @@ public void Setup() .Build(); _xbmcSeries = Builder.CreateListOfSize(3) - .Build() - .ToList(); + .TheFirst(1) + .With(s => s.ImdbNumber = TVDB_ID.ToString()) + .Build() + .ToList(); Mocker.GetMock() .Setup(s => s.GetSeries(_settings)) @@ -41,7 +44,7 @@ public void Setup() public void should_update_using_series_path() { var series = Builder.CreateNew() - .With(s => s.TvdbId = _xbmcSeries.First().ImdbNumber) + .With(s => s.TvdbId = TVDB_ID) .Build(); Subject.Update(_settings, series); diff --git a/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs b/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs index aa3954e41..077eed962 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs @@ -65,7 +65,13 @@ public String GetSeriesPath(XbmcSettings settings, Series series) return null; } - var matchingSeries = allSeries.FirstOrDefault(s => s.ImdbNumber == series.TvdbId || s.Label == series.Title); + var matchingSeries = allSeries.FirstOrDefault(s => + { + var tvdbId = 0; + Int32.TryParse(s.ImdbNumber, out tvdbId); + + return tvdbId == series.TvdbId || s.Label == series.Title; + }); if (matchingSeries != null) return matchingSeries.File; diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Model/TvShow.cs b/src/NzbDrone.Core/Notifications/Xbmc/Model/TvShow.cs index 318167d37..437285107 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/Model/TvShow.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/Model/TvShow.cs @@ -4,7 +4,7 @@ public class TvShow { public int TvShowId { get; set; } public string Label { get; set; } - public int ImdbNumber { get; set; } + public string ImdbNumber { get; set; } public string File { get; set; } } }