diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index eb5cc93dd..ef3eaa129 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -112,6 +112,7 @@ + diff --git a/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs new file mode 100644 index 000000000..7f6a80c2e --- /dev/null +++ b/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs @@ -0,0 +1,267 @@ +using System; +using System.IO; +using System.Linq; +using System.Net; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.Model; +using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Repository.Search; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common.AutoMoq; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.ProviderTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class SearchHistoryProviderTest : CoreTest + { + private SearchHistory _searchHistory; + private Series _series; + private Episode _episode; + + [SetUp] + public void Setup() + { + _series = Builder.CreateNew() + .Build(); + + _episode = Builder.CreateNew() + .Build(); + + var items = Builder.CreateListOfSize(10) + .Build().ToList(); + + _searchHistory = Builder.CreateNew() + .With(h => h.EpisodeId = _episode.EpisodeId) + .With(h => h.SeriesId - _series.SeriesId) + .With(h => h.SearchHistoryItems = items) + .Build(); + } + + private void WithUnsuccessfulSearch() + { + foreach(var item in _searchHistory.SearchHistoryItems) + { + item.Success = false; + } + } + + private void WithSuccessfulSearch() + { + foreach(var item in _searchHistory.SearchHistoryItems) + { + item.Success = false; + } + + var i = _searchHistory.SearchHistoryItems.Last(); + i.Success = true; + i.SearchError = ReportRejectionType.None; + } + + [Test] + public void Add_should_add_history_and_history_items() + { + WithRealDb(); + + Mocker.Resolve().Add(_searchHistory); + + Db.Fetch().Should().HaveCount(1); + Db.Fetch().Should().HaveCount(10); + } + + [Test] + public void Add_should_add_return_id() + { + WithRealDb(); + + var result = Mocker.Resolve().Add(_searchHistory); + + result.Should().NotBe(0); + } + + [Test] + public void Delete_should_delete_history_and_history_items() + { + WithRealDb(); + + Mocker.Resolve().Add(_searchHistory); + + var history = Db.Fetch(); + + Mocker.Resolve().Delete(history.First().Id); + + Db.Fetch().Should().HaveCount(0); + Db.Fetch().Should().HaveCount(0); + } + + [Test] + public void AllSearchHistory_should_return_all_items() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().AllSearchHistory(); + + result.Count.Should().Be(1); + } + + [Test] + public void AllSearchHistory_should_have_series_title() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().AllSearchHistory(); + + result.Count.Should().Be(1); + result.First().SeriesTitle.Should().Be(_series.Title); + } + + [Test] + public void AllSearchHistory_should_have_episode_information() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().AllSearchHistory(); + + result.Count.Should().Be(1); + result.First().EpisodeTitle.Should().Be(_episode.Title); + result.First().EpisodeNumber.Should().Be(_episode.EpisodeNumber); + result.First().SeasonNumber.Should().Be(_episode.SeasonNumber); + } + + [Test] + public void AllSearchHistory_should_have_totalItems_count() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().AllSearchHistory(); + + result.Count.Should().Be(1); + result.First().TotalItems.Should().Be(_searchHistory.SearchHistoryItems.Count); + } + + [Test] + public void AllSearchHistory_should_have_successfulCount_equal_zero_when_all_failed() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + WithUnsuccessfulSearch(); + + Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().AllSearchHistory(); + + result.Count.Should().Be(1); + result.First().SuccessfulCount.Should().Be(0); + } + + [Test] + public void AllSearchHistory_should_have_successfulCount_equal_one_when_one_was_downloaded() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + WithSuccessfulSearch(); + + Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().AllSearchHistory(); + + result.Count.Should().Be(1); + result.First().SuccessfulCount.Should().Be(1); + } + + [Test] + public void GetSearchHistory_should_return_searchHistory_with_items() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + WithSuccessfulSearch(); + var id = Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().GetSearchHistory(id); + + result.SearchHistoryItems.Should().HaveCount(_searchHistory.SearchHistoryItems.Count); + } + + [Test] + public void GetSearchHistory_should_have_episodeDetails() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + WithSuccessfulSearch(); + var id = Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().GetSearchHistory(id); + + result.EpisodeNumber.Should().Be(_episode.EpisodeNumber); + result.SeasonNumber.Should().Be(_episode.SeasonNumber); + result.EpisodeTitle.Should().Be(_episode.Title); + result.AirDate.Should().Be(_episode.AirDate.Value); + } + + [Test] + public void GetSearchHistory_should_not_have_episode_info_if_it_was_a_full_season_search() + { + WithRealDb(); + Db.Insert(_series); + + _searchHistory.EpisodeId = 0; + var id = Mocker.Resolve().Add(_searchHistory); + + var result = Mocker.Resolve().GetSearchHistory(id); + + result.EpisodeNumber.Should().Be(null); + result.SeasonNumber.Should().Be(_searchHistory.SeasonNumber); + result.EpisodeTitle.Should().Be(null); + } + + [Test] + public void ForceDownload_should_download_report() + { + WithRealDb(); + Db.Insert(_series); + Db.Insert(_episode); + + var reportTitle = String.Format("{0} - S{1:00}E{2:00}", _series.Title, _episode.SeasonNumber, _episode.EpisodeNumber); + _searchHistory.SearchHistoryItems.First().ReportTitle = reportTitle; + + Mocker.Resolve().Add(_searchHistory); + var items = Db.Fetch(); + + Mocker.Resolve().ForceDownload(items.First().Id); + + Mocker.GetMock().Verify(v => v.DownloadReport(It.IsAny()), Times.Once()); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/SearchHistoryProvider.cs b/NzbDrone.Core/Providers/SearchHistoryProvider.cs index 3432cf273..b262302ac 100644 --- a/NzbDrone.Core/Providers/SearchHistoryProvider.cs +++ b/NzbDrone.Core/Providers/SearchHistoryProvider.cs @@ -34,15 +34,17 @@ public SearchHistoryProvider() } - public virtual void Add(SearchHistory searchResult) + public virtual int Add(SearchHistory searchHistory) { logger.Trace("Adding new search result"); - searchResult.SuccessfulDownload = searchResult.SearchHistoryItems.Any(s => s.Success); - var id = Convert.ToInt32(_database.Insert(searchResult)); + searchHistory.SuccessfulDownload = searchHistory.SearchHistoryItems.Any(s => s.Success); + var id = Convert.ToInt32(_database.Insert(searchHistory)); - searchResult.SearchHistoryItems.ForEach(s => s.SearchHistoryId = id); + searchHistory.SearchHistoryItems.ForEach(s => s.SearchHistoryId = id); logger.Trace("Adding search result items"); - _database.InsertMany(searchResult.SearchHistoryItems); + _database.InsertMany(searchHistory.SearchHistoryItems); + + return id; } public virtual void Delete(int id) @@ -102,6 +104,7 @@ LEFT JOIN Episodes public virtual void ForceDownload(int itemId) { var item = _database.Single(itemId); + logger.Info("Starting Force Download of: {0}", item.ReportTitle); var searchResult = _database.Single(item.SearchHistoryId); var series = _seriesProvider.GetSeries(searchResult.SeriesId); @@ -111,6 +114,7 @@ public virtual void ForceDownload(int itemId) parseResult.Indexer = item.Indexer; var episodes = _episodeProvider.GetEpisodesByParseResult(parseResult); + logger.Info("Forcing Download of: {0}", item.ReportTitle); _downloadProvider.DownloadReport(parseResult); } } diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index e64985d2d..a9241eb1d 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -51,9 +51,9 @@ x86 - - ..\packages\DataTables.Mvc.0.1.0.67\lib\DataTables.Mvc.Core.dll - True + + False + ..\packages\DataTables.Mvc.0.1.0.68\lib\DataTables.Mvc.Core.dll ..\packages\DynamicQuery.1.0\lib\35\Dynamic.dll diff --git a/NzbDrone.Web/Views/SearchHistory/Details.cshtml b/NzbDrone.Web/Views/SearchHistory/Details.cshtml index 0546caba1..93ef288fd 100644 --- a/NzbDrone.Web/Views/SearchHistory/Details.cshtml +++ b/NzbDrone.Web/Views/SearchHistory/Details.cshtml @@ -20,7 +20,7 @@ .AddColumn(new Column().DataProperty("Success").Title("Successful").Width("120px")) .AddColumn(new Column().DisplayAndSort("Quality", "QualityInt").Title("Quality").Width("80px")) .AddColumn(new Column().DataProperty("SearchError").Title("Error")) - .AddColumn(new Column().DataProperty("return actionColumn(source, type, val);", true)) + .AddColumn(new Column().DataProperty("return actionColumn(source, type, val);", true).Sortable(false).Searchable(false)) .AddColumn(new Column().DataProperty("Details").RenderFunction("return getDetails(row, val);").Visible(false)) .AddSorting(3, SortDirection.Desc)) diff --git a/NzbDrone.Web/packages.config b/NzbDrone.Web/packages.config index f1a80c99a..d435e4f26 100644 --- a/NzbDrone.Web/packages.config +++ b/NzbDrone.Web/packages.config @@ -1,6 +1,6 @@  - + diff --git a/packages/DataTables.Mvc.0.1.0.67/DataTables.Mvc.0.1.0.67.nupkg b/packages/DataTables.Mvc.0.1.0.67/DataTables.Mvc.0.1.0.67.nupkg deleted file mode 100644 index a3bc6861c..000000000 Binary files a/packages/DataTables.Mvc.0.1.0.67/DataTables.Mvc.0.1.0.67.nupkg and /dev/null differ diff --git a/packages/DataTables.Mvc.0.1.0.67/lib/DataTables.Mvc.Core.dll b/packages/DataTables.Mvc.0.1.0.67/lib/DataTables.Mvc.Core.dll deleted file mode 100644 index a18c8bf2c..000000000 Binary files a/packages/DataTables.Mvc.0.1.0.67/lib/DataTables.Mvc.Core.dll and /dev/null differ diff --git a/packages/DataTables.Mvc.0.1.0.68/Content/App_Start/DataTablesMvc.cs.pp b/packages/DataTables.Mvc.0.1.0.68/Content/App_Start/DataTablesMvc.cs.pp new file mode 100644 index 000000000..abaaa76f4 --- /dev/null +++ b/packages/DataTables.Mvc.0.1.0.68/Content/App_Start/DataTablesMvc.cs.pp @@ -0,0 +1,17 @@ +using DataTables.Mvc.Core.Helpers; +using DataTables.Mvc.Core.Models; +using System.Web.Mvc; + +[assembly: WebActivator.PreApplicationStartMethod(typeof($rootnamespace$.App_Start.DataTablesModelBinderActivator), "Start")] + +namespace $rootnamespace$.App_Start +{ + public static class DataTablesModelBinderActivator + { + public static void Start() + { + if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesParams))) + ModelBinders.Binders.Add(typeof(DataTablesParams), new DataTablesModelBinder()); + } + } +} \ No newline at end of file diff --git a/packages/DataTables.Mvc.0.1.0.68/DataTables.Mvc.0.1.0.68.nupkg b/packages/DataTables.Mvc.0.1.0.68/DataTables.Mvc.0.1.0.68.nupkg new file mode 100644 index 000000000..04747a362 Binary files /dev/null and b/packages/DataTables.Mvc.0.1.0.68/DataTables.Mvc.0.1.0.68.nupkg differ diff --git a/packages/DataTables.Mvc.0.1.0.68/lib/DataTables.Mvc.Core.dll b/packages/DataTables.Mvc.0.1.0.68/lib/DataTables.Mvc.Core.dll new file mode 100644 index 000000000..abe1a56e1 Binary files /dev/null and b/packages/DataTables.Mvc.0.1.0.68/lib/DataTables.Mvc.Core.dll differ diff --git a/packages/DataTables.Mvc.0.1.0.68/tools/install.ps1 b/packages/DataTables.Mvc.0.1.0.68/tools/install.ps1 new file mode 100644 index 000000000..7e1f5357f --- /dev/null +++ b/packages/DataTables.Mvc.0.1.0.68/tools/install.ps1 @@ -0,0 +1,5 @@ +param($installPath, $toolsPath, $package, $project) + +$path = [System.IO.Path] +$appstart = $path::Combine($path::GetDirectoryName($project.FileName), "App_Start\DataTablesMvc.cs") +$DTE.ItemOperations.OpenFile($appstart) \ No newline at end of file