Cleaned up some tests

This commit is contained in:
Keivan 2010-10-07 15:17:24 -07:00
parent 81e155ae42
commit 9c7355f3fb
14 changed files with 156 additions and 62 deletions

View File

@ -8,6 +8,7 @@ using MbUnit.Framework.ContractVerifiers;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class EpisodeProviderTest
{

View File

@ -74,6 +74,7 @@
<Compile Include="Ninject.Moq\MockProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QualityProfileTest.cs" />
<Compile Include="RepoTest.cs" />
<Compile Include="SabControllerTest.cs" />
<Compile Include="SeriesProviderTest.cs" />
<Compile Include="TvDbControllerTest.cs" />

View File

@ -7,6 +7,8 @@ using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class QualityProfileTest
{
/// <summary>

View File

@ -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<Series>.CreateNew().With(s => s.SeriesId = 69).Build();
var fakeEpisode = Builder<EpisodeInfo>.CreateNew().With(c => c.SeriesId = 69).Build();
//Act
var repo = MockLib.GetEmptyRepository();
repo.Add(fakeSeries);
repo.Add(fakeEpisode);
var fetchedSeries = repo.Single<Series>(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<Series>.CreateNew().With(c => c.SeriesId = tvdbId).Build();
//Act
var addId = sonicRepo.Add(series);
//Assert
Assert.AreEqual(tvdbId, addId);
var allSeries = sonicRepo.All<Series>();
Assert.IsNotEmpty(allSeries);
Assert.AreEqual(tvdbId, allSeries.First().SeriesId);
}
}
}

View File

@ -14,6 +14,7 @@ using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SabControllerTest
{
[Test]

View File

@ -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<Series>.CreateNew().With(c => c.SeriesId = tvdbId).Build();
//Act
var addId = sonicRepo.Add(series);
//Assert
Assert.AreEqual(tvdbId, addId);
var allSeries = sonicRepo.All<Series>();
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<Series>.CreateNew().Build();
var fakeEpisode = Builder<EpisodeInfo>.CreateNew().With(c => c.SeriesId).Build();
Console.WriteLine("test");
var repo = MockLib.GetEmptyRepository();
repo.Add(fakeSeries);
repo.Add(fakeEpisode);
var fetchedSeries = repo.Single<Series>(fakeSeries.SeriesId);
Assert.IsNotEmpty(fetchedSeries.Episodes);
}
}
}

View File

@ -9,6 +9,7 @@ using NzbDrone.Core.Providers;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class TvDbControllerTest
{
[Test]

View File

@ -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<ISeriesProvider>().To<SeriesProvider>();
kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
@ -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<Series>(0, 1);
repository.GetPaged<EpisodeInfo>(0, 1);
repository.GetPaged<Series>(0, 1);
}
}
}

View File

@ -146,6 +146,7 @@
<Reference Include="TvdbLib, Version=0.8.8.0, Culture=neutral, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="SonicTrace.cs" />
<Compile Include="Providers\ConfigProvider.cs" />
<Compile Include="Providers\EpisodeProvider.cs" />
<Compile Include="Providers\HttpProvider.cs" />

View File

@ -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)

View File

@ -31,7 +31,7 @@ namespace NzbDrone.Core.Providers
if (_sonicRepo.Exists<Season>(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()
{

View File

@ -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; }
}
}
}

View File

@ -34,6 +34,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\NzbDrone.Core\Libraries\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />

View File

@ -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();
}