diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 91caa7b55..d4fa50f60 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -8,6 +8,7 @@ using MbUnit.Framework.ContractVerifiers; namespace NzbDrone.Core.Test { [TestFixture] + // ReSharper disable InconsistentNaming public class EpisodeProviderTest { diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 39440695a..357ecb3b9 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -74,6 +74,7 @@ + diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index 9e3d0e47f..921162da2 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -7,6 +7,8 @@ using NzbDrone.Core.Repository.Quality; namespace NzbDrone.Core.Test { [TestFixture] + // ReSharper disable InconsistentNaming + public class QualityProfileTest { /// diff --git a/NzbDrone.Core.Test/RepoTest.cs b/NzbDrone.Core.Test/RepoTest.cs new file mode 100644 index 000000000..f5a0d742c --- /dev/null +++ b/NzbDrone.Core.Test/RepoTest.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FizzWare.NBuilder; +using Gallio.Framework; +using MbUnit.Framework; +using MbUnit.Framework.ContractVerifiers; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Episode; + +namespace NzbDrone.Core.Test +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class RepoTest + { + [Test] + public void to_many__series_to_episode() + { + //Arrange + var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 69).Build(); + var fakeEpisode = Builder.CreateNew().With(c => c.SeriesId = 69).Build(); + + //Act + var repo = MockLib.GetEmptyRepository(); + repo.Add(fakeSeries); + repo.Add(fakeEpisode); + var fetchedSeries = repo.Single(fakeSeries.SeriesId); + + //Assert + Assert.AreEqual(fakeSeries.SeriesId, fetchedSeries.SeriesId); + Assert.AreEqual(fakeSeries.Title, fetchedSeries.Title); + + Assert.IsNotEmpty(fetchedSeries.Episodes); + Assert.AreEqual(fetchedSeries.Episodes[0].EpisodeId, fakeEpisode.EpisodeId); + Assert.AreEqual(fetchedSeries.Episodes[0].SeriesId, fakeEpisode.SeriesId); + Assert.AreEqual(fetchedSeries.Episodes[0].Title, fakeEpisode.Title); + } + + [Test] + [Description("This test confirms that the tvdb id stored in the db is preserved rather than being replaced by an auto incrementing value")] + public void tvdbid_is_preserved([RandomNumbers(Minimum = 100, Maximum = 999, Count = 1)] int tvdbId) + { + //Arrange + var sonicRepo = MockLib.GetEmptyRepository(); + var series = Builder.CreateNew().With(c => c.SeriesId = tvdbId).Build(); + + //Act + var addId = sonicRepo.Add(series); + + //Assert + Assert.AreEqual(tvdbId, addId); + var allSeries = sonicRepo.All(); + Assert.IsNotEmpty(allSeries); + Assert.AreEqual(tvdbId, allSeries.First().SeriesId); + } + } +} diff --git a/NzbDrone.Core.Test/SabControllerTest.cs b/NzbDrone.Core.Test/SabControllerTest.cs index 62bf4e57d..f7525eac8 100644 --- a/NzbDrone.Core.Test/SabControllerTest.cs +++ b/NzbDrone.Core.Test/SabControllerTest.cs @@ -14,6 +14,7 @@ using SubSonic.Repository; namespace NzbDrone.Core.Test { [TestFixture] + // ReSharper disable InconsistentNaming public class SabControllerTest { [Test] diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index 19a91ebf2..1249e75ba 100644 --- a/NzbDrone.Core.Test/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/SeriesProviderTest.cs @@ -21,6 +21,7 @@ using System.Linq; namespace NzbDrone.Core.Test { [TestFixture] + // ReSharper disable InconsistentNaming public class SeriesProviderTest { [Test] @@ -65,26 +66,6 @@ namespace NzbDrone.Core.Test Assert.AreEqual(title, result, postTitle); } - - - [Test] - [Description("This test confirms that the tvdb id stored in the db is preserved rather than being replaced by an auto incrementing value")] - public void tvdbid_is_preserved([RandomNumbers(Minimum = 100, Maximum = 999, Count = 1)] int tvdbId) - { - //Arrange - var sonicRepo = MockLib.GetEmptyRepository(); - var series = Builder.CreateNew().With(c => c.SeriesId = tvdbId).Build(); - - //Act - var addId = sonicRepo.Add(series); - - //Assert - Assert.AreEqual(tvdbId, addId); - var allSeries = sonicRepo.All(); - Assert.IsNotEmpty(allSeries); - Assert.AreEqual(tvdbId, allSeries.First().SeriesId); - } - [Test] public void get_unmapped() { @@ -104,21 +85,6 @@ namespace NzbDrone.Core.Test Assert.AreElementsEqualIgnoringOrder(MockLib.StandardSeries, unmappedFolder); } - [Test] - public void get_episode_test() - { - var fakeSeries = Builder.CreateNew().Build(); - var fakeEpisode = Builder.CreateNew().With(c => c.SeriesId).Build(); - - Console.WriteLine("test"); - - var repo = MockLib.GetEmptyRepository(); - repo.Add(fakeSeries); - repo.Add(fakeEpisode); - - var fetchedSeries = repo.Single(fakeSeries.SeriesId); - - Assert.IsNotEmpty(fetchedSeries.Episodes); - } + } } diff --git a/NzbDrone.Core.Test/TvDbControllerTest.cs b/NzbDrone.Core.Test/TvDbControllerTest.cs index 82447975c..bfd85912f 100644 --- a/NzbDrone.Core.Test/TvDbControllerTest.cs +++ b/NzbDrone.Core.Test/TvDbControllerTest.cs @@ -9,6 +9,7 @@ using NzbDrone.Core.Providers; namespace NzbDrone.Core.Test { [TestFixture] + // ReSharper disable InconsistentNaming public class TvDbControllerTest { [Test] diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 8bd4ae1f5..c5e63cc3e 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -3,6 +3,7 @@ using System.IO; using System.Web; using Ninject; using NLog.Config; +using NLog.Layouts; using NLog.Targets; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; @@ -15,11 +16,13 @@ namespace NzbDrone.Core { public static class CentralDispatch { + private static readonly Logger Logger = LogManager.GetLogger("DB"); + public static void BindKernel(IKernel kernel) { string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db")); var provider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite"); - + provider.Log = new SonicTrace(); kernel.Bind().To(); kernel.Bind().To(); kernel.Bind().To(); @@ -50,42 +53,52 @@ namespace NzbDrone.Core // Step 1. Create configuration object var config = new LoggingConfiguration(); - // Step 2. Create targets and add them to the configuration - var consoleTarget = new DebuggerTarget(); - config.AddTarget("console", consoleTarget); + string callSight = "${callsite:className=false:fileName=true:includeSourcePath=false:methodName=true}"; - FileTarget fileTarget = new FileTarget(); - config.AddTarget("file", fileTarget); + // Step 2. Create targets and add them to the configuration + var debuggerTarget = new DebuggerTarget + { + Layout = callSight + "- ${logger}: ${message}" + }; + + + var consoleTarget = new ColoredConsoleTarget + { + Layout = callSight + ": ${message}" + }; + + + var fileTarget = new FileTarget + { + FileName = "${basedir}/test.log", + Layout = "${message}" + }; + + config.AddTarget("debugger", debuggerTarget); + config.AddTarget("console", consoleTarget); + //config.AddTarget("file", fileTarget); // Step 3. Set target properties - consoleTarget.Layout = "${logger} ${message}"; - fileTarget.FileName = "${basedir}/test.log"; - fileTarget.Layout = "${message}"; + + // Step 4. Define rules - LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget); - config.LoggingRules.Add(rule1); + LoggingRule debugRule = new LoggingRule("*", LogLevel.Trace, debuggerTarget); + LoggingRule fileRule = new LoggingRule("*", LogLevel.Trace, fileTarget); + LoggingRule consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget); - LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget); - config.LoggingRules.Add(rule2); + //config.LoggingRules.Add(fileRule); + config.LoggingRules.Add(debugRule); + config.LoggingRules.Add(consoleRule); // Step 5. Activate the configuration - NLog.LogManager.Configuration = config; - - Logger logger = LogManager.GetCurrentClassLogger(); - logger.Trace("trace log message"); - logger.Debug("debug log message"); - logger.Info("info log message"); - logger.Warn("warn log message"); - logger.Error("error log message"); - logger.Fatal("fatal log message"); + LogManager.Configuration = config; } private static void ForceMigration(IRepository repository) { repository.GetPaged(0, 1); repository.GetPaged(0, 1); - repository.GetPaged(0, 1); } } } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index e6616b95b..8a951de46 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -146,6 +146,7 @@ + diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 13a63a227..05a18a409 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Core.Providers private readonly ISeriesProvider _series; private readonly ISeasonProvider _seasons; private readonly ITvDbProvider _tvDb; - private static readonly Logger Logger = NLog.LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); public EpisodeProvider(IRepository sonicRepo, ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, ITvDbProvider tvDbProvider) diff --git a/NzbDrone.Core/Providers/SeasonProvider.cs b/NzbDrone.Core/Providers/SeasonProvider.cs index 481207758..a48c440f8 100644 --- a/NzbDrone.Core/Providers/SeasonProvider.cs +++ b/NzbDrone.Core/Providers/SeasonProvider.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Providers if (_sonicRepo.Exists(s => s.SeasonId == seasonId)) return; //TODO: Calculate Season Folder - Logger.Debug("Creating Season. SeriesID:{0} SeasonID:{1} SeasonNumber:{2} Folder:{3}", seriesId, seasonId, seasonNumber, string.Empty); + Logger.Debug("Adding Season To DB. [SeriesID:{0} SeasonID:{1} SeasonNumber:{2} Folder:{3}]", seriesId, seasonId, seasonNumber, "????"); var newSeason = new Season() { diff --git a/NzbDrone.Core/SonicTrace.cs b/NzbDrone.Core/SonicTrace.cs new file mode 100644 index 000000000..74fdf78d0 --- /dev/null +++ b/NzbDrone.Core/SonicTrace.cs @@ -0,0 +1,39 @@ +/* + *Source:http://stackoverflow.com/questions/1520945/nlog-to-output-db-out + *DamienG + */ + +using System; +using System.IO; +using System.Text; +using NLog; + +namespace NzbDrone.Core +{ + class SonicTrace : TextWriter + { + private static readonly Logger Logger = LogManager.GetLogger("DB"); + + + public override void Write(char[] buffer, int index, int count) + { + Write(new string(buffer, index, count)); + } + + public override void Write(string value) + { + DbAction(value); + } + + private static void DbAction(string value) + { + Logger.Trace(value); + } + + public override Encoding Encoding + { + get { return Encoding.Default; } + } + } + +} \ No newline at end of file diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 4ecfd9d0c..1aad08cd6 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -34,6 +34,10 @@ 4 + + False + ..\NzbDrone.Core\Libraries\NLog.dll + diff --git a/NzbDrone/Program.cs b/NzbDrone/Program.cs index 57e5c987d..986ce9016 100644 --- a/NzbDrone/Program.cs +++ b/NzbDrone/Program.cs @@ -3,18 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; +using NLog; +using NzbDrone.Core; namespace NzbDrone.Console { class Program { + + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); static void Main(string[] args) { + CentralDispatch.ConfigureNlog(); + Logger.Info("Starting NZBDrone WebUI"); var server = new CassiniDev.Server(@"D:\My Dropbox\Git\NzbDrone\NzbDrone.Web"); server.Start(); System.Diagnostics.Process.Start(server.RootUrl); - System.Console.WriteLine(server.RootUrl); + Logger.Info("Server available at: " + server.RootUrl); System.Console.ReadLine(); }