2011-05-22 19:53:21 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
using System;
|
2010-10-08 01:17:24 +03:00
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-03 00:06:46 +03:00
|
|
|
using FluentAssertions;
|
2010-10-24 10:46:58 +03:00
|
|
|
using NLog;
|
2011-04-10 05:44:01 +03:00
|
|
|
using NLog.Config;
|
2011-06-03 00:06:46 +03:00
|
|
|
using NUnit.Framework;
|
2010-10-24 10:46:58 +03:00
|
|
|
using NzbDrone.Core.Instrumentation;
|
2010-10-21 04:49:23 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
2011-05-19 06:55:35 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-04-10 05:44:01 +03:00
|
|
|
using LogLevel = NLog.LogLevel;
|
2010-10-08 01:17:24 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 06:55:35 +03:00
|
|
|
public class RepoTest : TestBase
|
2010-10-08 01:17:24 +03:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void to_many__series_to_episode()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(s => s.SeriesId = 69).Build();
|
2010-10-21 04:49:23 +03:00
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew().With(c => c.SeriesId = 69).Build();
|
2010-10-08 01:17:24 +03:00
|
|
|
|
|
|
|
//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);
|
|
|
|
|
2011-06-03 00:06:46 +03:00
|
|
|
|
|
|
|
fetchedSeries.Episodes.Should().HaveCount(1);
|
2010-10-08 01:17:24 +03:00
|
|
|
Assert.AreEqual(fetchedSeries.Episodes[0].EpisodeId, fakeEpisode.EpisodeId);
|
|
|
|
Assert.AreEqual(fetchedSeries.Episodes[0].SeriesId, fakeEpisode.SeriesId);
|
|
|
|
Assert.AreEqual(fetchedSeries.Episodes[0].Title, fakeEpisode.Title);
|
|
|
|
}
|
|
|
|
|
2011-05-28 22:23:35 +03:00
|
|
|
[Test]
|
|
|
|
public void ToString_test_over_castle_proxy()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(s => s.SeriesId = 69).Build();
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew().With(c => c.SeriesId = 69).Build();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var repo = MockLib.GetEmptyRepository(true);
|
|
|
|
repo.Add(fakeSeries);
|
|
|
|
repo.Add(fakeEpisode);
|
|
|
|
Console.WriteLine("Getting single");
|
|
|
|
var fetchedEpisode = repo.Single<Episode>(fakeEpisode.EpisodeId);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Console.WriteLine("Doing assert");
|
|
|
|
Assert.AreEqual(fakeEpisode.EpisodeId, fetchedEpisode.EpisodeId);
|
|
|
|
Console.WriteLine("Doing assert");
|
|
|
|
Assert.AreEqual(fakeEpisode.Title, fetchedEpisode.Title);
|
|
|
|
|
|
|
|
Console.WriteLine("=======================");
|
2011-06-03 00:06:46 +03:00
|
|
|
var ttt = fetchedEpisode.Series;
|
2011-05-28 22:23:35 +03:00
|
|
|
Console.WriteLine("=======================");
|
2011-06-03 00:06:46 +03:00
|
|
|
var tttd = fetchedEpisode.Series;
|
2011-05-28 22:23:35 +03:00
|
|
|
Console.WriteLine("=======================");
|
|
|
|
|
|
|
|
//Assert.Contains(fetchedEpisode.ToString(), fakeSeries.Title);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 01:17:24 +03:00
|
|
|
[Test]
|
2011-04-10 05:44:01 +03:00
|
|
|
[Description(
|
|
|
|
"This test confirms that the tvdb id stored in the db is preserved rather than being replaced by an auto incrementing value"
|
|
|
|
)]
|
2011-06-03 00:06:46 +03:00
|
|
|
public void tvdbid_is_preserved()
|
2010-10-08 01:17:24 +03:00
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
var sonicRepo = MockLib.GetEmptyRepository();
|
2011-06-03 00:06:46 +03:00
|
|
|
var series = Builder<Series>.CreateNew().With(c => c.SeriesId = 18).Build();
|
2010-10-08 01:17:24 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var addId = sonicRepo.Add(series);
|
|
|
|
|
|
|
|
//Assert
|
2011-06-03 00:06:46 +03:00
|
|
|
Assert.AreEqual(18, addId);
|
2010-10-08 01:17:24 +03:00
|
|
|
var allSeries = sonicRepo.All<Series>();
|
2011-06-03 00:06:46 +03:00
|
|
|
allSeries.Should().HaveCount(1);
|
|
|
|
Assert.AreEqual(18, allSeries.First().SeriesId);
|
2010-10-08 01:17:24 +03:00
|
|
|
}
|
2010-10-21 04:49:23 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void enteties_toString()
|
|
|
|
{
|
|
|
|
Console.WriteLine(new Episode().ToString());
|
2011-05-27 05:12:28 +03:00
|
|
|
Console.WriteLine(new Series().ToString());
|
|
|
|
Console.WriteLine(new EpisodeFile().ToString());
|
2010-10-21 04:49:23 +03:00
|
|
|
}
|
2010-10-24 10:46:58 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void write_log()
|
|
|
|
{
|
|
|
|
//setup
|
|
|
|
var message = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
var sonicRepo = MockLib.GetEmptyRepository();
|
|
|
|
|
|
|
|
var sonicTarget = new SubsonicTarget(sonicRepo);
|
2011-04-06 06:14:43 +03:00
|
|
|
|
2010-10-24 10:46:58 +03:00
|
|
|
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
2011-04-10 05:44:01 +03:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
2010-10-24 10:46:58 +03:00
|
|
|
LogManager.Configuration.Reload();
|
|
|
|
|
|
|
|
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
//Act
|
|
|
|
|
|
|
|
Logger.Info(message);
|
|
|
|
|
|
|
|
//Assert
|
2011-06-03 00:06:46 +03:00
|
|
|
sonicRepo.All<Log>().Should().HaveCount(1);
|
2010-10-24 10:46:58 +03:00
|
|
|
|
|
|
|
var logItem = sonicRepo.All<Log>().First();
|
|
|
|
Assert.AreNotEqual(new DateTime(), logItem.Time);
|
|
|
|
Assert.AreEqual(message, logItem.Message);
|
|
|
|
Assert.AreEqual(Logger.Name, logItem.Logger);
|
|
|
|
Assert.AreEqual(Logger.Name, logItem.Logger);
|
2011-04-22 05:23:31 +03:00
|
|
|
Assert.AreEqual(LogLevel.Info.Name, logItem.Level);
|
|
|
|
Assert.AreEqual("write_log", logItem.Method);
|
2011-05-19 06:55:35 +03:00
|
|
|
|
|
|
|
|
2010-10-24 10:46:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void write_log_exception()
|
|
|
|
{
|
|
|
|
//setup
|
|
|
|
var message = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
var sonicRepo = MockLib.GetEmptyRepository();
|
|
|
|
|
|
|
|
var sonicTarget = new SubsonicTarget(sonicRepo);
|
|
|
|
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
2011-04-10 05:44:01 +03:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
2010-10-24 10:46:58 +03:00
|
|
|
LogManager.Configuration.Reload();
|
|
|
|
|
|
|
|
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
var ex = new InvalidOperationException("Fake Exception");
|
|
|
|
//Act
|
|
|
|
|
|
|
|
Logger.ErrorException(message, ex);
|
|
|
|
|
|
|
|
//Assert
|
2011-06-03 00:06:46 +03:00
|
|
|
sonicRepo.All<Log>().Should().HaveCount(1);
|
2010-10-24 10:46:58 +03:00
|
|
|
|
|
|
|
var logItem = sonicRepo.All<Log>().First();
|
|
|
|
Assert.AreNotEqual(new DateTime(), logItem.Time);
|
2011-04-25 20:48:16 +03:00
|
|
|
Assert.AreEqual(message + ": " + ex.Message, logItem.Message);
|
2010-10-24 10:46:58 +03:00
|
|
|
Assert.AreEqual(Logger.Name, logItem.Logger);
|
2011-04-22 05:23:31 +03:00
|
|
|
Assert.AreEqual(LogLevel.Error.Name, logItem.Level);
|
2010-10-24 10:46:58 +03:00
|
|
|
Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType);
|
2011-04-22 05:23:31 +03:00
|
|
|
Assert.AreEqual(ex.ToString(), logItem.Exception);
|
2011-05-19 06:55:35 +03:00
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
2010-10-24 10:46:58 +03:00
|
|
|
}
|
2010-10-24 20:35:58 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void write_log_exception_no_message_should_use_exception_message()
|
|
|
|
{
|
|
|
|
//setup
|
|
|
|
var message = String.Empty;
|
|
|
|
|
|
|
|
var sonicRepo = MockLib.GetEmptyRepository();
|
|
|
|
|
|
|
|
var sonicTarget = new SubsonicTarget(sonicRepo);
|
|
|
|
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
2011-04-10 05:44:01 +03:00
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
2010-10-24 20:35:58 +03:00
|
|
|
LogManager.Configuration.Reload();
|
|
|
|
|
|
|
|
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
var ex = new InvalidOperationException("Fake Exception");
|
|
|
|
//Act
|
|
|
|
|
|
|
|
Logger.ErrorException(message, ex);
|
|
|
|
|
|
|
|
//Assert
|
2011-06-03 00:06:46 +03:00
|
|
|
sonicRepo.All<Log>().Should().HaveCount(1);
|
2010-10-24 20:35:58 +03:00
|
|
|
|
|
|
|
var logItem = sonicRepo.All<Log>().First();
|
|
|
|
Assert.AreNotEqual(new DateTime(), logItem.Time);
|
|
|
|
Assert.AreEqual(ex.Message, logItem.Message);
|
|
|
|
Assert.AreEqual(Logger.Name, logItem.Logger);
|
2011-04-22 05:23:31 +03:00
|
|
|
Assert.AreEqual(LogLevel.Error.Name, logItem.Level);
|
2010-10-24 20:35:58 +03:00
|
|
|
Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType);
|
2011-04-22 05:23:31 +03:00
|
|
|
Assert.AreEqual(ex.ToString(), logItem.Exception);
|
2011-05-19 06:55:35 +03:00
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
2010-10-24 20:35:58 +03:00
|
|
|
}
|
2010-10-08 01:17:24 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|