diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs index 2fd0f4803..79572153c 100644 --- a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -55,7 +55,7 @@ namespace PlexRequests.Services.Tests var plexMock = new Mock(); Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - Assert.Throws(() => Checker.IsAvailable("title", "2013"), "We should be throwing an exception since we cannot talk to the services."); + Assert.Throws(() => Checker.IsAvailable("title", "2013", null, PlexType.TvShow), "We should be throwing an exception since we cannot talk to the services."); } [Test] @@ -74,20 +74,20 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", "2011"); + var result = Checker.IsAvailable("title", "2011", null, PlexType.Movie); Assert.That(result, Is.True); } [Test] - public void IsAvailableDirectoryTitleTest() + public void IsAvailableMusicDirectoryTitleTest() { var settingsMock = new Mock>(); var authMock = new Mock>(); var requestMock = new Mock(); var plexMock = new Mock(); - var searchResult = new PlexSearch { Directory = new Directory1 { Title = "title", Year = "2013" } }; + var searchResult = new PlexSearch { Directory = new List { new Directory1 { Title = "title", Year = "2013", ParentTitle = "dIzZy"} } }; settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" }); authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" }); @@ -95,11 +95,32 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", "2013"); + var result = Checker.IsAvailable("title", "2013", "dIzZy", PlexType.Music); Assert.That(result, Is.True); } + [Test] + public void IsNotAvailableMusicDirectoryTitleTest() + { + var settingsMock = new Mock>(); + var authMock = new Mock>(); + var requestMock = new Mock(); + var plexMock = new Mock(); + + var searchResult = new PlexSearch { Directory = new List { new Directory1 { Title = "title2", Year = "1992", ParentTitle = "dIzZy" } } }; + + settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" }); + authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" }); + plexMock.Setup(x => x.SearchContent(It.IsAny(), It.IsAny(), It.IsAny())).Returns(searchResult); + + Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); + + var result = Checker.IsAvailable("title", "2013", "dIzZy", PlexType.Music); + + Assert.That(result, Is.False); + } + [Test] public void IsAvailableDirectoryTitleWithoutYearTest() { @@ -108,7 +129,7 @@ namespace PlexRequests.Services.Tests var requestMock = new Mock(); var plexMock = new Mock(); - var searchResult = new PlexSearch { Directory = new Directory1 { Title = "title", } }; + var searchResult = new PlexSearch { Directory = new List { new Directory1 { Title = "title", } } }; settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" }); authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" }); @@ -116,7 +137,7 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", null); + var result = Checker.IsAvailable("title", null, null, PlexType.Movie); Assert.That(result, Is.True); } @@ -137,7 +158,7 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", "2011"); + var result = Checker.IsAvailable("title", "2011", null, PlexType.Movie); Assert.That(result, Is.False); } @@ -158,7 +179,7 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", null); + var result = Checker.IsAvailable("title", null, null, PlexType.Movie); Assert.That(result, Is.False); } @@ -179,7 +200,7 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", "2011"); + var result = Checker.IsAvailable("title", "2011", null, PlexType.Movie); Assert.That(result, Is.False); } @@ -200,7 +221,7 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", "2019"); + var result = Checker.IsAvailable("title", "2019", null, PlexType.Movie); Assert.That(result, Is.False); } @@ -221,7 +242,7 @@ namespace PlexRequests.Services.Tests Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - var result = Checker.IsAvailable("title", null); + var result = Checker.IsAvailable("title", null, null, PlexType.Movie); Assert.That(result, Is.False); } @@ -328,11 +349,11 @@ namespace PlexRequests.Services.Tests Title = "Title2", } }, - Directory = new Directory1 + Directory = new List { new Directory1 { Title = "Title9", Year = "1978" - } + }} }; var settingsMock = new Mock>(); @@ -402,10 +423,107 @@ namespace PlexRequests.Services.Tests Title = "Hi", } }, - Directory = new Directory1 + Directory = new List { new Directory1 { Title = "missingTitle", Year = "1978" + }} + }; + + var settingsMock = new Mock>(); + var authMock = new Mock>(); + var requestMock = new Mock(); + var plexMock = new Mock(); + settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "192.168.1.1" }); + authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" }); + requestMock.Setup(x => x.GetAll()).Returns(requests); + plexMock.Setup(x => x.SearchContent(It.IsAny(), It.IsAny(), It.IsAny())).Returns(search); + Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); + + Checker.CheckAndUpdateAll(1); + + requestMock.Verify(x => x.BatchUpdate(It.IsAny>()), Times.Once); + requestMock.Verify(x => x.Get(It.IsAny()), Times.Never); + plexMock.Verify(x => x.SearchContent(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(4)); + } + + + [Test] + public void CheckAndUpdateAllMusicRequestsTest() + { + + var requests = new List { + new RequestedModel + { + Id = 123, + Title = "title1", + Available = false, + ArtistName = "dizzy", + Type = RequestType.Album, + ReleaseDate = new DateTime(2010,1,1) + }, + new RequestedModel + { + Id=222, + Title = "title3", + Available = false, + ArtistName = "a", + Type = RequestType.Album, + ReleaseDate = new DateTime(2006,1,1) + }, + new RequestedModel + { + Id = 333, + Title= "missingTitle", + Available = false, + ArtistName = "b", + Type = RequestType.Album, + ReleaseDate = new DateTime(1992,1,1) + }, + new RequestedModel + { + Id= 444, + Title = "Hi", + Available = false, + ArtistName = "c", + Type = RequestType.Album, + ReleaseDate = new DateTime(2017,1,1) + } + }; + + var search = new PlexSearch + { + Directory = new List { + new Directory1 + { + Title = "missingTitle", + Year = "1978", + ParentTitle = "c" + }, + new Directory1 + { + Title = "Hi", + Year = "1978", + ParentTitle = "c" + }, + new Directory1 + { + Title = "Hi", + Year = "2017", + ParentTitle = "c" + }, + new Directory1 + { + Title = "missingTitle", + Year = "1992", + ParentTitle = "b" + }, + new Directory1 + { + Title = "title1", + Year = "2010", + ParentTitle = "DiZzY" + }, } }; diff --git a/PlexRequests.Services/PlexAvailabilityChecker.cs b/PlexRequests.Services/PlexAvailabilityChecker.cs index ab897c843..aedc954ac 100644 --- a/PlexRequests.Services/PlexAvailabilityChecker.cs +++ b/PlexRequests.Services/PlexAvailabilityChecker.cs @@ -102,13 +102,14 @@ namespace PlexRequests.Services Log.Trace("Search results from Plex for the following request: {0}", r.Title); Log.Trace(results.DumpJson()); bool matchResult; + var releaseDate = r.ReleaseDate == DateTime.MinValue ? string.Empty : r.ReleaseDate.ToString("yyyy"); switch (r.Type) { case RequestType.Movie: - matchResult = MovieTvSearch(results, r.Title, r.ReleaseDate.ToString("yyyy")); + matchResult = MovieTvSearch(results, r.Title, releaseDate); break; case RequestType.TvShow: - matchResult = MovieTvSearch(results, r.Title, r.ReleaseDate.ToString("yyyy")); + matchResult = MovieTvSearch(results, r.Title, releaseDate); break; case RequestType.Album: matchResult = MusicSearch(results, r.Title, r.ArtistName); diff --git a/PlexRequests.sln b/PlexRequests.sln index 8bd25df43..e3feb5b1d 100644 --- a/PlexRequests.sln +++ b/PlexRequests.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.UI", "PlexRequests.UI\PlexRequests.UI.csproj", "{68F5F5F3-B8BB-4911-875F-6F00AAE04EA6}" EndProject @@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Services", "Pl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Api.Models", "PlexRequests.Api.Models\PlexRequests.Api.Models.csproj", "{CB37A5F8-6DFC-4554-99D3-A42B502E4591}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Services.Tests", "PlexRequests.Services.Tests\PlexRequests.Services.Tests.csproj", "{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,6 +79,10 @@ Global {CB37A5F8-6DFC-4554-99D3-A42B502E4591}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB37A5F8-6DFC-4554-99D3-A42B502E4591}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB37A5F8-6DFC-4554-99D3-A42B502E4591}.Release|Any CPU.Build.0 = Release|Any CPU + {EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE