TopLogs will now return the count pass in, reduced to 5000 from 7500 to prevent JsonSerialization issues when being sent to the grid.

Added tests for TopLogs and GetPagedLogs.
This commit is contained in:
Mark McDowall 2011-09-07 17:01:51 -07:00
parent 73fadac397
commit 070115a59a
3 changed files with 77 additions and 11 deletions

View File

@ -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 @@ namespace NzbDrone.Core.Test
provider.GetAllLogs().Should().HaveCount(1);
}
[Test]
public void write_log_exception()
{
@ -182,10 +185,6 @@ namespace NzbDrone.Core.Test
ExceptionVerification.ExcpectedErrors(1);
}
[Test]
public void null_string_as_arg_should_not_fail()
{
@ -198,5 +197,72 @@ namespace NzbDrone.Core.Test
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<Log>.CreateListOfSize(510)
.Build();
db.InsertMany(fakeLogs);
//Act
var logs = mocker.Resolve<LogProvider>().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<Log>.CreateListOfSize(100)
.Build();
db.InsertMany(fakeLogs);
//Act
var logs = mocker.Resolve<LogProvider>().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<Log>.CreateListOfSize(100)
.Build();
db.InsertMany(fakeLogs);
//Act
var logs = mocker.Resolve<LogProvider>().GetPagedLogs(1, 50);
//Assert
logs.Items.Should().HaveCount(50);
logs.TotalItems.Should().Be(100);
}
}
}

View File

@ -22,15 +22,15 @@ namespace NzbDrone.Core.Instrumentation
return _database.Fetch<Log>();
}
public IList<Log> TopLogs()
public IList<Log> TopLogs(int count)
{
var logs = _database.Fetch<Log>("SELECT TOP 7500 * FROM Logs ORDER BY Time Desc");
var logs = _database.Fetch<Log>("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;

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Web.Controllers
[GridAction]
public ActionResult _TopAjaxBinding()
{
var logs = _logProvider.TopLogs();
var logs = _logProvider.TopLogs(5000);
return View(new GridModel(logs));
}