diff --git a/NzbDrone.Core.Test/LogProviderTest.cs b/NzbDrone.Core.Test/LogProviderTest.cs index ec147eab1..64641d769 100644 --- a/NzbDrone.Core.Test/LogProviderTest.cs +++ b/NzbDrone.Core.Test/LogProviderTest.cs @@ -1,12 +1,17 @@ // ReSharper disable RedundantUsingDirective using System; using System.Linq; +using AutoMoq; +using FizzWare.NBuilder; using FluentAssertions; +using Moq; using NLog; using NLog.Config; using NUnit.Framework; using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test @@ -112,8 +117,6 @@ public void clearLog() provider.GetAllLogs().Should().HaveCount(1); } - - [Test] public void write_log_exception() { @@ -182,10 +185,6 @@ public void write_log_exception_no_message_should_use_exception_message() ExceptionVerification.ExcpectedErrors(1); } - - - - [Test] public void null_string_as_arg_should_not_fail() { @@ -198,5 +197,72 @@ public void null_string_as_arg_should_not_fail() epFile.Path.Should().BeNull(); } + [Test] + public void top_logs() + { + //Setup + var mocker = new AutoMoqer(MockBehavior.Strict); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeLogs = Builder.CreateListOfSize(510) + + .Build(); + + db.InsertMany(fakeLogs); + + //Act + var logs = mocker.Resolve().TopLogs(500); + + //Assert + logs.Should().HaveCount(501); + logs.Last().Message.Should().Be( + "Number of logs currently shown: 500. More may exist, check 'All' to see everything"); + } + + [Test] + public void top_logs_less_than_number_wanted() + { + //Setup + var mocker = new AutoMoqer(MockBehavior.Strict); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeLogs = Builder.CreateListOfSize(100) + + .Build(); + + db.InsertMany(fakeLogs); + + //Act + var logs = mocker.Resolve().TopLogs(500); + + //Assert + logs.Should().HaveCount(101); + logs.Last().Message.Should().Be( + "Number of logs currently shown: 100. More may exist, check 'All' to see everything"); + } + + [Test] + public void pagedLogs() + { + //Setup + var mocker = new AutoMoqer(MockBehavior.Strict); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeLogs = Builder.CreateListOfSize(100) + + .Build(); + + db.InsertMany(fakeLogs); + + //Act + var logs = mocker.Resolve().GetPagedLogs(1, 50); + + //Assert + logs.Items.Should().HaveCount(50); + logs.TotalItems.Should().Be(100); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/LogProvider.cs b/NzbDrone.Core/Instrumentation/LogProvider.cs index 2b36e579b..07fdcab98 100644 --- a/NzbDrone.Core/Instrumentation/LogProvider.cs +++ b/NzbDrone.Core/Instrumentation/LogProvider.cs @@ -22,15 +22,15 @@ public IList GetAllLogs() return _database.Fetch(); } - public IList TopLogs() + public IList TopLogs(int count) { - var logs = _database.Fetch("SELECT TOP 7500 * FROM Logs ORDER BY Time Desc"); + var logs = _database.Fetch("SELECT TOP " + count + " * FROM Logs ORDER BY Time Desc"); logs.Add(new Log { Time = DateTime.Now.AddYears(-100), Level = "Info", - Logger = "NzbDrone.Core.Instrumentation.LogProvider", - Message = String.Format("Number of logs currently shown: 7500. More may exist, check 'All' to see everything") + Logger = "Core.Instrumentation.LogProvider", + Message = String.Format("Number of logs currently shown: {0}. More may exist, check 'All' to see everything", Math.Min(count, logs.Count)) }); return logs; diff --git a/NzbDrone.Web/Controllers/LogController.cs b/NzbDrone.Web/Controllers/LogController.cs index 90d31a021..d4adc66e9 100644 --- a/NzbDrone.Web/Controllers/LogController.cs +++ b/NzbDrone.Web/Controllers/LogController.cs @@ -35,7 +35,7 @@ public JsonResult Clear() [GridAction] public ActionResult _TopAjaxBinding() { - var logs = _logProvider.TopLogs(); + var logs = _logProvider.TopLogs(5000); return View(new GridModel(logs)); }