From 6d085d534043c5aea339a70661ac171b76707f4c Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 18 May 2011 20:55:35 -0700 Subject: [PATCH] Added support to Error/Warning/Fatal verification in text projects --- ...ontrollerTest.cs => ConfigProviderTest.cs} | 3 +- NzbDrone.Core.Test/EpisodeProviderTest.cs | Bin 8192 -> 8242 bytes NzbDrone.Core.Test/Fixtures.cs | 6 + .../{ => Framework}/AutoMoq/AutoMoqer.cs | 0 .../{ => Framework}/AutoMoq/AutoMoqerTest.cs | 0 .../{ => Framework}/AutoMoq/License.txt | 0 .../Unity/AutoMockingBuilderStrategy.cs | 22 ++-- .../Unity/AutoMockingContainerExtension.cs | 0 .../Framework/ExceptionVerification.cs | 87 +++++++++++++++ NzbDrone.Core.Test/{ => Framework}/MockLib.cs | 2 +- NzbDrone.Core.Test/Framework/TestBase.cs | 21 ++++ NzbDrone.Core.Test/HistoryProviderTest.cs | 103 +++++++----------- NzbDrone.Core.Test/IndexerProviderTest.cs | 10 +- NzbDrone.Core.Test/JobProviderTest.cs | 31 ++---- NzbDrone.Core.Test/MediaFileProviderTests.cs | 13 +-- .../Ninject.Moq/ExtensionsForBindingSyntax.cs | 36 ------ .../Ninject.Moq/MockProvider.cs | 80 -------------- .../Ninject.Moq/MockingKernel.cs | 41 ------- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 23 ++-- NzbDrone.Core.Test/ParserTest.cs | 8 +- NzbDrone.Core.Test/QualityProfileTest.cs | 15 +-- NzbDrone.Core.Test/RepoTest.cs | 7 +- NzbDrone.Core.Test/RootDirProviderTest.cs | 16 +-- ...abControllerTest.cs => SabProviderTest.cs} | 19 ++-- NzbDrone.Core.Test/SeriesProviderTest.cs | Bin 8234 -> 8286 bytes NzbDrone.Core.Test/SyncProviderTest.cs | 5 +- ...bControllerTest.cs => TvDbProviderTest.cs} | 3 +- NzbDrone.Core.Test/log.config | 2 +- 28 files changed, 240 insertions(+), 313 deletions(-) rename NzbDrone.Core.Test/{DbConfigControllerTest.cs => ConfigProviderTest.cs} (95%) rename NzbDrone.Core.Test/{ => Framework}/AutoMoq/AutoMoqer.cs (100%) rename NzbDrone.Core.Test/{ => Framework}/AutoMoq/AutoMoqerTest.cs (100%) rename NzbDrone.Core.Test/{ => Framework}/AutoMoq/License.txt (100%) rename NzbDrone.Core.Test/{ => Framework}/AutoMoq/Unity/AutoMockingBuilderStrategy.cs (73%) rename NzbDrone.Core.Test/{ => Framework}/AutoMoq/Unity/AutoMockingContainerExtension.cs (100%) create mode 100644 NzbDrone.Core.Test/Framework/ExceptionVerification.cs rename NzbDrone.Core.Test/{ => Framework}/MockLib.cs (98%) create mode 100644 NzbDrone.Core.Test/Framework/TestBase.cs delete mode 100644 NzbDrone.Core.Test/Ninject.Moq/ExtensionsForBindingSyntax.cs delete mode 100644 NzbDrone.Core.Test/Ninject.Moq/MockProvider.cs delete mode 100644 NzbDrone.Core.Test/Ninject.Moq/MockingKernel.cs rename NzbDrone.Core.Test/{SabControllerTest.cs => SabProviderTest.cs} (94%) rename NzbDrone.Core.Test/{TvDbControllerTest.cs => TvDbProviderTest.cs} (96%) diff --git a/NzbDrone.Core.Test/DbConfigControllerTest.cs b/NzbDrone.Core.Test/ConfigProviderTest.cs similarity index 95% rename from NzbDrone.Core.Test/DbConfigControllerTest.cs rename to NzbDrone.Core.Test/ConfigProviderTest.cs index e70d613c4..74690899e 100644 --- a/NzbDrone.Core.Test/DbConfigControllerTest.cs +++ b/NzbDrone.Core.Test/ConfigProviderTest.cs @@ -3,13 +3,14 @@ using MbUnit.Framework; using Moq; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; +using NzbDrone.Core.Test.Framework; using SubSonic.Repository; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class DbConfigControllerTest + public class ConfigProviderTest : TestBase { [Test] public void Overwrite_existing_value() diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 68147abe1ca6b714e9bf36c41ea6d6ac69e282b8..80f5c3c9b6f0e31d34e37d7eb26501f2f1993353 100644 GIT binary patch delta 73 zcmZp0*yOOmn^BFItF$;XFI~Z}D#@iNKQC3!Ilm}XFC?|NM9-}#F*mh5zbM<9cd|EQ aFC*{d8;q*l3RVgrS*OI})XjexndJbNXBc__ delta 20 bcmdnw(BQDan{jd>WAEhujH;XUnV97OR4fMm diff --git a/NzbDrone.Core.Test/Fixtures.cs b/NzbDrone.Core.Test/Fixtures.cs index bf56c0a01..e413f01f7 100644 --- a/NzbDrone.Core.Test/Fixtures.cs +++ b/NzbDrone.Core.Test/Fixtures.cs @@ -3,6 +3,7 @@ using System.IO; using MbUnit.Framework; using NLog; using NLog.Config; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { @@ -50,6 +51,11 @@ namespace NzbDrone.Core.Test LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); LogManager.ThrowExceptions = true; + + var exceptionVerification = new ExceptionVerification(); + LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, exceptionVerification)); + LogManager.Configuration.Reload(); } catch (Exception e) { diff --git a/NzbDrone.Core.Test/AutoMoq/AutoMoqer.cs b/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqer.cs similarity index 100% rename from NzbDrone.Core.Test/AutoMoq/AutoMoqer.cs rename to NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqer.cs diff --git a/NzbDrone.Core.Test/AutoMoq/AutoMoqerTest.cs b/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs similarity index 100% rename from NzbDrone.Core.Test/AutoMoq/AutoMoqerTest.cs rename to NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs diff --git a/NzbDrone.Core.Test/AutoMoq/License.txt b/NzbDrone.Core.Test/Framework/AutoMoq/License.txt similarity index 100% rename from NzbDrone.Core.Test/AutoMoq/License.txt rename to NzbDrone.Core.Test/Framework/AutoMoq/License.txt diff --git a/NzbDrone.Core.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs b/NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingBuilderStrategy.cs similarity index 73% rename from NzbDrone.Core.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs rename to NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingBuilderStrategy.cs index c89ab8491..0f1877b3d 100644 --- a/NzbDrone.Core.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs +++ b/NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingBuilderStrategy.cs @@ -10,21 +10,21 @@ namespace AutoMoq.Unity { internal class AutoMockingBuilderStrategy : BuilderStrategy { - private readonly IUnityContainer container; - private readonly MockFactory mockFactory; - private readonly IEnumerable registeredTypes; + private readonly IUnityContainer _container; + private readonly MockRepository _mockFactory; + private readonly IEnumerable _registeredTypes; public AutoMockingBuilderStrategy(IEnumerable registeredTypes, IUnityContainer container) { var autoMoqer = container.Resolve(); - mockFactory = new MockFactory(autoMoqer.DefaultBehavior); - this.registeredTypes = registeredTypes; - this.container = container; + _mockFactory = new MockRepository(autoMoqer.DefaultBehavior); + _registeredTypes = registeredTypes; + _container = container; } public override void PreBuildUp(IBuilderContext context) { - var autoMoqer = container.Resolve(); + var autoMoqer = _container.Resolve(); var type = GetTheTypeFromTheBuilderContext(context); if (AMockObjectShouldBeCreatedForThisType(type)) @@ -39,7 +39,7 @@ namespace AutoMoq.Unity private bool AMockObjectShouldBeCreatedForThisType(Type type) { - var mocker = container.Resolve(); + var mocker = _container.Resolve(); return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type); //return TypeIsNotRegistered(type) && type.IsInterface; } @@ -51,7 +51,7 @@ namespace AutoMoq.Unity private bool TypeIsNotRegistered(Type type) { - return registeredTypes.Any(x => x.Equals(type)) == false; + return _registeredTypes.Any(x => x.Equals(type)) == false; } private Mock CreateAMockObject(Type type) @@ -63,12 +63,12 @@ namespace AutoMoq.Unity private Mock InvokeTheMockCreationMethod(MethodInfo createMethod) { - return (Mock)createMethod.Invoke(mockFactory, new object[] { new List().ToArray() }); + return (Mock)createMethod.Invoke(_mockFactory, new object[] { new List().ToArray() }); } private MethodInfo GenerateAnInterfaceMockCreationMethod(Type type) { - var createMethodWithNoParameters = mockFactory.GetType().GetMethod("Create", EmptyArgumentList()); + var createMethodWithNoParameters = _mockFactory.GetType().GetMethod("Create", EmptyArgumentList()); return createMethodWithNoParameters.MakeGenericMethod(new[] { type }); } diff --git a/NzbDrone.Core.Test/AutoMoq/Unity/AutoMockingContainerExtension.cs b/NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingContainerExtension.cs similarity index 100% rename from NzbDrone.Core.Test/AutoMoq/Unity/AutoMockingContainerExtension.cs rename to NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingContainerExtension.cs diff --git a/NzbDrone.Core.Test/Framework/ExceptionVerification.cs b/NzbDrone.Core.Test/Framework/ExceptionVerification.cs new file mode 100644 index 000000000..6f6f27331 --- /dev/null +++ b/NzbDrone.Core.Test/Framework/ExceptionVerification.cs @@ -0,0 +1,87 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using NLog; +using NLog.Targets; +using MbUnit.Framework; + +namespace NzbDrone.Core.Test.Framework +{ + public class ExceptionVerification : Target + { + private static List _logs = new List(); + + protected override void Write(LogEventInfo logEvent) + { + if (logEvent.Level >= LogLevel.Warn) + { + _logs.Add(logEvent); + } + } + + internal static void Reset() + { + _logs = new List(); + } + + internal static void AssertNoError() + { + if (_logs.Count != 0) + { + string errors = GetLogsString(_logs); + + var message = String.Format("{0} unexpected Fatal/Error/Warning were logged during execution.\n\r Use ExceptionVerification.Excpected methods if errors are excepted for this test.{1}{2}", + _logs.Count, + Environment.NewLine, + errors); + + Assert.Fail(message); + } + } + + private static string GetLogsString(IEnumerable logs) + { + string errors = ""; + foreach (var log in logs) + { + string exception = ""; + if (log.Exception != null) + { + exception = log.Exception.ToString(); + } + errors += Environment.NewLine + String.Format("[{0}] {1}: {2} {3}", log.Level, log.LoggerName, log.FormattedMessage, exception); + } + return errors; + } + + internal static void ExcpectedErrors(int count) + { + Excpected(LogLevel.Error, count); + } + + internal static void ExcpectedFatals(int count) + { + Excpected(LogLevel.Fatal, count); + } + + internal static void ExcpectedWarns(int count) + { + Excpected(LogLevel.Warn, count); + } + + private static void Excpected(LogLevel level, int count) + { + var levelLogs = _logs.Where(l => l.Level == level).ToList(); + + if (levelLogs.Count != count) + { + var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}", + count, level, _logs.Count, GetLogsString(levelLogs)); + + Assert.Fail(message); + } + + levelLogs.ForEach(c => _logs.Remove(c)); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs similarity index 98% rename from NzbDrone.Core.Test/MockLib.cs rename to NzbDrone.Core.Test/Framework/MockLib.cs index 2945d2580..dc58de9c2 100644 --- a/NzbDrone.Core.Test/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -11,7 +11,7 @@ using NzbDrone.Core.Repository.Quality; using SubSonic.DataProviders; using SubSonic.Repository; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.Framework { /// /// Provides the standard Mocks needed for a typical test diff --git a/NzbDrone.Core.Test/Framework/TestBase.cs b/NzbDrone.Core.Test/Framework/TestBase.cs new file mode 100644 index 000000000..f17e9bf26 --- /dev/null +++ b/NzbDrone.Core.Test/Framework/TestBase.cs @@ -0,0 +1,21 @@ +using MbUnit.Framework; + +namespace NzbDrone.Core.Test.Framework +{ + public class TestBase + { + + [SetUp] + public void Setup() + { + ExceptionVerification.Reset(); + } + + [TearDown] + public void TearDown() + { + if (!Assert.IsFailurePending) ExceptionVerification.AssertNoError(); + } + + } +} diff --git a/NzbDrone.Core.Test/HistoryProviderTest.cs b/NzbDrone.Core.Test/HistoryProviderTest.cs index 71828312b..edbfb2d94 100644 --- a/NzbDrone.Core.Test/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/HistoryProviderTest.cs @@ -7,28 +7,20 @@ using Moq; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; using SubSonic.Repository; namespace NzbDrone.Core.Test { [TestFixture] - public class HistoryProviderTest + // ReSharper disable InconsistentNaming + public class HistoryProviderTest : TestBase { [Test] public void AllItems() { //Setup - var series = new Series - { - SeriesId = 5656, - CleanTitle = "rock", - Monitored = true, - Overview = "Series Overview", - QualityProfileId = 1, - Title = "30 Rock", - Path = @"C:\Test\TV\30 Rock" - }; - var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; + Season season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { AirDate = DateTime.Today.AddDays(-1), @@ -42,15 +34,17 @@ namespace NzbDrone.Core.Test SeriesId = 5656 }; - var list = new List(); - list.Add(new History - { - HistoryId = new int(), - Date = DateTime.Now, - IsProper = false, - Quality = QualityTypes.TV, - EpisodeId = episode.EpisodeId - }); + var list = new List + { + new History + { + HistoryId = new int(), + Date = DateTime.Now, + IsProper = false, + Quality = QualityTypes.TV, + EpisodeId = episode.EpisodeId + } + }; var repo = new Mock(); repo.Setup(r => r.All()).Returns(list.AsQueryable()); @@ -68,6 +62,7 @@ namespace NzbDrone.Core.Test [Test] public void add_item() { + //Arange var mocker = new AutoMoqer(); var repo = MockLib.GetEmptyRepository(); @@ -82,10 +77,22 @@ namespace NzbDrone.Core.Test { Date = DateTime.Now, EpisodeId = episode.EpisodeId, - NzbTitle = "my title" + NzbTitle = "my title", + Indexer = "Fake Indexer" }; + //Act mocker.Resolve().Add(history); + + //Assert + var storedHistory = repo.All(); + var newHistiory = repo.All().First(); + + Assert.Count(1, storedHistory); + Assert.AreEqual(history.Date, newHistiory.Date); + Assert.AreEqual(history.EpisodeId, newHistiory.EpisodeId); + Assert.AreEqual(history.NzbTitle, newHistiory.NzbTitle); + Assert.AreEqual(history.Indexer, newHistiory.Indexer); } [Test] @@ -94,16 +101,6 @@ namespace NzbDrone.Core.Test { //Todo: This test fails... Moq Setup doesn't return the expected value //Setup - var series = new Series - { - SeriesId = 5656, - CleanTitle = "rock", - Monitored = true, - Overview = "Series Overview", - QualityProfileId = 1, - Title = "30 Rock", - Path = @"C:\Test\TV\30 Rock" - }; var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { @@ -118,16 +115,6 @@ namespace NzbDrone.Core.Test SeriesId = 5656 }; - var list = new List(); - list.Add(new History - { - HistoryId = new int(), - Date = DateTime.Now, - IsProper = false, - Quality = QualityTypes.TV, - EpisodeId = episode.EpisodeId - }); - var proper = false; var repo = new Mock(); @@ -150,17 +137,7 @@ namespace NzbDrone.Core.Test //Todo: This test fails... Moq Setup doesn't return the expected value //Setup - var series = new Series - { - SeriesId = 5656, - CleanTitle = "rock", - Monitored = true, - Overview = "Series Overview", - QualityProfileId = 1, - Title = "30 Rock", - Path = @"C:\Test\TV\30 Rock" - }; - var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { AirDate = DateTime.Today.AddDays(-1), @@ -174,15 +151,17 @@ namespace NzbDrone.Core.Test SeriesId = 5656 }; - var list = new List(); - list.Add(new History - { - HistoryId = new int(), - Date = DateTime.Now, - IsProper = false, - Quality = QualityTypes.TV, - EpisodeId = episode.EpisodeId - }); + var list = new List + { + new History + { + HistoryId = new int(), + Date = DateTime.Now, + IsProper = false, + Quality = QualityTypes.TV, + EpisodeId = episode.EpisodeId + } + }; var repo = new Mock(); repo.Setup(r => r.Exists(h => h.Episode == episode && h.IsProper == list[0].IsProper)).Returns( diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index 886bd4cdc..6eeadec26 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Net; using System.ServiceModel.Syndication; -using System.Xml; using AutoMoq; using FizzWare.NBuilder; using MbUnit.Framework; @@ -14,13 +13,13 @@ using NzbDrone.Core.Providers.ExternalNotification; using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; -using SubSonic.Repository; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] - public class IndexerProviderTest // ReSharper disable InconsistentNaming + public class IndexerProviderTest : TestBase { [Test] [Row("nzbsorg.xml")] @@ -58,7 +57,7 @@ namespace NzbDrone.Core.Test { var mocker = new AutoMoqer(); - var summary = "My fake summary"; + const string summary = "My fake summary"; var fakeSettings = Builder.CreateNew().Build(); mocker.GetMock() @@ -104,6 +103,7 @@ namespace NzbDrone.Core.Test var result = mocker.Resolve().ParseFeed(fakeRssItem); Assert.IsNull(result); + ExceptionVerification.ExcpectedWarns(1); } @@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test //Act var indexerProvider = mocker.Resolve(); - indexerProvider.InitializeIndexers(new List() { mocker.Resolve() }); + indexerProvider.InitializeIndexers(new List { mocker.Resolve() }); var indexers = indexerProvider.All(); //Assert diff --git a/NzbDrone.Core.Test/JobProviderTest.cs b/NzbDrone.Core.Test/JobProviderTest.cs index d33e531bb..380eaa461 100644 --- a/NzbDrone.Core.Test/JobProviderTest.cs +++ b/NzbDrone.Core.Test/JobProviderTest.cs @@ -5,12 +5,13 @@ using AutoMoq; using MbUnit.Framework; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers.Jobs; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class JobProviderTest + public class JobProviderTest : TestBase { [Test] public void Run_Jobs_Updates_Last_Execution() @@ -53,6 +54,7 @@ namespace NzbDrone.Core.Test Assert.IsNotEmpty(settings); Assert.AreNotEqual(DateTime.MinValue, settings[0].LastExecution); Assert.IsFalse(settings[0].Success); + ExceptionVerification.ExcpectedErrors(1); } [Test] @@ -76,27 +78,6 @@ namespace NzbDrone.Core.Test } - [Test] - //This test will confirm that the concurrency checks are rest - //after execution so the job can successfully run. - public void can_run_broken_job_again() - { - IEnumerable fakeJobs = new List { new BrokenJob() }; - var mocker = new AutoMoqer(); - - mocker.SetConstant(MockLib.GetEmptyRepository()); - mocker.SetConstant(fakeJobs); - - var timerProvider = mocker.Resolve(); - timerProvider.Initialize(); - var firstRun = timerProvider.RunScheduled(); - Thread.Sleep(2000); - var secondRun = timerProvider.RunScheduled(); - - Assert.IsTrue(firstRun); - Assert.IsTrue(secondRun); - } - [Test] //This test will confirm that the concurrency checks are rest //after execution so the job can successfully run. @@ -132,12 +113,14 @@ namespace NzbDrone.Core.Test var timerProvider = mocker.Resolve(); timerProvider.Initialize(); - var firstRun = timerProvider.QueueJob(typeof(FakeJob)); + var firstRun = timerProvider.QueueJob(typeof(BrokenJob)); Thread.Sleep(2000); - var secondRun = timerProvider.QueueJob(typeof(FakeJob)); + var secondRun = timerProvider.QueueJob(typeof(BrokenJob)); Assert.IsTrue(firstRun); Assert.IsTrue(secondRun); + Thread.Sleep(2000); + ExceptionVerification.ExcpectedErrors(2); } [Test] diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index dbb363255..6fe658c41 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -1,26 +1,25 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq.Expressions; using System.Linq; using AutoMoq; using FizzWare.NBuilder; using MbUnit.Framework; using Moq; -using Moq.Linq; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; using SubSonic.Repository; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class MediaFileProviderTests + public class MediaFileProviderTests : TestBase { [Test] [Description("Verifies that a new file imported properly")] @@ -86,7 +85,7 @@ namespace NzbDrone.Core.Test //Constants const string fileName = @"2011.01.10 - Denis Leary - HD TV.mkv"; - DateTime airDate = new DateTime(2011, 01, 10); + var airDate = new DateTime(2011, 01, 10); const int size = 12345; //Fakes var fakeSeries = Builder.CreateNew().Build(); @@ -144,9 +143,6 @@ namespace NzbDrone.Core.Test //Fakes var fakeSeries = Builder.CreateNew().Build(); - var fakeEpisode = Builder.CreateNew() - .With(c => c.SeriesId = fakeSeries.SeriesId) - .With(c => c.EpisodeFileId = 12).Build(); //Mocks var mocker = new AutoMoqer(); @@ -179,7 +175,7 @@ namespace NzbDrone.Core.Test //Constants const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv"; - DateTime airDate = new DateTime(2011, 01, 10); + var airDate = new DateTime(2011, 01, 10); const int size = 12345; //Fakes var fakeSeries = Builder.CreateNew().Build(); @@ -275,6 +271,7 @@ namespace NzbDrone.Core.Test mocker.VerifyAllMocks(); Assert.IsNull(result); mocker.GetMock().Verify(r => r.Add(result), Times.Never()); + ExceptionVerification.ExcpectedWarns(1); } [Test] diff --git a/NzbDrone.Core.Test/Ninject.Moq/ExtensionsForBindingSyntax.cs b/NzbDrone.Core.Test/Ninject.Moq/ExtensionsForBindingSyntax.cs deleted file mode 100644 index 6ae16b6d8..000000000 --- a/NzbDrone.Core.Test/Ninject.Moq/ExtensionsForBindingSyntax.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Ninject.Infrastructure; -using Ninject.Injection; -using Ninject.Planning.Bindings; -using Ninject.Syntax; - -namespace Ninject.Moq -{ - /// - /// Extensions for the fluent binding syntax API. - /// - public static class ExtensionsForBindingSyntax - { - /// - /// Indicates that the service should be bound to a mocked instance of the specified type. - /// - /// The service that is being mocked. - /// The builder that is building the binding. - public static IBindingWhenInNamedWithOrOnSyntax ToMock(this IBindingToSyntax builder) - { - var haveBinding = builder as IHaveBinding; - - if (haveBinding == null) - throw new NotSupportedException( - String.Format( - "The binding builder for {0} is of type {1}, which does not implement IHaveBinding and is therefore not extensible.", - typeof (T), builder.GetType())); - - IBinding binding = haveBinding.Binding; - - binding.ProviderCallback = ctx => new MockProvider(ctx.Kernel.Components.Get()); - - return builder as IBindingWhenInNamedWithOrOnSyntax; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/Ninject.Moq/MockProvider.cs b/NzbDrone.Core.Test/Ninject.Moq/MockProvider.cs deleted file mode 100644 index 04a744601..000000000 --- a/NzbDrone.Core.Test/Ninject.Moq/MockProvider.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using Moq; -using Ninject.Activation; -using Ninject.Injection; - -namespace Ninject.Moq -{ - /// - /// Creates mocked instances via Moq. - /// - public class MockProvider : IProvider - { - private static readonly Dictionary _injectors = - new Dictionary(); - - /// - /// Initializes a new instance of the class. - /// - /// The injector factory component. - public MockProvider(IInjectorFactory injectorFactory) - { - InjectorFactory = injectorFactory; - } - - /// - /// Gets the injector factory component. - /// - public IInjectorFactory InjectorFactory { get; private set; } - - #region IProvider Members - - /// - /// Gets the type (or prototype) of instances the provider creates. - /// - public Type Type - { - get { return typeof (Mock<>); } - } - - /// - /// Creates an instance within the specified context. - /// - /// The context. - /// The created instance. - public object Create(IContext context) - { - ConstructorInjector injector = GetInjector(context.Request.Service); - var mock = injector.Invoke() as Mock; - return mock.Object; - } - - #endregion - - private ConstructorInjector GetInjector(Type service) - { - lock (_injectors) - { - Type mockType = typeof (Mock<>).MakeGenericType(service); - - if (_injectors.ContainsKey(mockType)) - return _injectors[mockType]; - - ConstructorInjector injector = InjectorFactory.Create(mockType.GetConstructor(Type.EmptyTypes)); - _injectors[mockType] = injector; - - return injector; - } - } - - /// - /// Gets a callback that creates an instance of the . - /// - /// The created callback. - public static Func GetCreationCallback() - { - return ctx => new MockProvider(ctx.Kernel.Components.Get()); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/Ninject.Moq/MockingKernel.cs b/NzbDrone.Core.Test/Ninject.Moq/MockingKernel.cs deleted file mode 100644 index f391dc549..000000000 --- a/NzbDrone.Core.Test/Ninject.Moq/MockingKernel.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Ninject.Activation.Caching; -using Ninject.Planning.Bindings; - -namespace Ninject.Moq -{ - /// - /// A kernel that will create mocked instances (via Moq) for any service that is - /// requested for which no binding is registered. - /// - public class MockingKernel : StandardKernel - { - /// - /// Clears the kernel's cache, immediately deactivating all activated instances regardless of scope. - /// This does not remove any modules, extensions, or bindings. - /// - public void Reset() - { - Components.Get().Clear(); - } - - /// - /// Attempts to handle a missing binding for a service. - /// - /// The service. - /// True if the missing binding can be handled; otherwise false. - protected override bool HandleMissingBinding(Type service) - { - var binding = new Binding(service) - { - ProviderCallback = MockProvider.GetCreationCallback(), - ScopeCallback = ctx => null, - IsImplicit = true - }; - - AddBinding(binding); - - return true; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index eba28a08a..a15bb3b77 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -85,34 +85,33 @@ - - - + + + Code - + Code + + - + - - - - + - + - + @@ -121,7 +120,7 @@ - + Always diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 262429f03..ad584cd51 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -1,13 +1,13 @@ using System; -using System.Threading; using MbUnit.Framework; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class ParserTest + public class ParserTest : TestBase { /*Fucked-up hall of shame, * WWE.Wrestlemania.27.PPV.HDTV.XviD-KYR @@ -15,6 +15,10 @@ namespace NzbDrone.Core.Test * Unreported.World.Chinas.Lost.Sons.WS.PDTV.XviD-FTP */ + + + + [Test] [Row("Sonny.With.a.Chance.S02E15", "Sonny.With.a.Chance", 2, 15)] [Row("Two.and.a.Half.Me.103.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 1, 3)] diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index 4f7ce0a95..484326cec 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -5,12 +5,13 @@ using FizzWare.NBuilder; using MbUnit.Framework; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class QualityProfileTest + public class QualityProfileTest : TestBase { /// /// Test_s the storage. @@ -24,11 +25,11 @@ namespace NzbDrone.Core.Test { Name = Guid.NewGuid().ToString(), Cutoff = QualityTypes.TV, - Allowed = new List {QualityTypes.HDTV, QualityTypes.DVD}, + Allowed = new List { QualityTypes.HDTV, QualityTypes.DVD }, }; //Act - var id = (int) repo.Add(testProfile); + var id = (int)repo.Add(testProfile); var fetch = repo.Single(c => c.QualityProfileId == id); //Assert @@ -48,20 +49,16 @@ namespace NzbDrone.Core.Test { Name = Guid.NewGuid().ToString(), Cutoff = QualityTypes.TV, - Allowed = new List {QualityTypes.HDTV, QualityTypes.DVD}, + Allowed = new List { QualityTypes.HDTV, QualityTypes.DVD }, }; - var profileId = (int) repo.Add(testProfile); + var profileId = (int)repo.Add(testProfile); var series = Builder.CreateNew().Build(); series.QualityProfileId = profileId; - var seriesID = (int) repo.Add(series); - - var result = repo.All(); - var quality = repo.All(); Assert.Count(1, result); Assert.AreEqual(result.ToList()[0].QualityProfile.Name, testProfile.Name); diff --git a/NzbDrone.Core.Test/RepoTest.cs b/NzbDrone.Core.Test/RepoTest.cs index 59388f241..4cc73e07b 100644 --- a/NzbDrone.Core.Test/RepoTest.cs +++ b/NzbDrone.Core.Test/RepoTest.cs @@ -6,13 +6,14 @@ using NLog; using NLog.Config; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Repository; +using NzbDrone.Core.Test.Framework; using LogLevel = NLog.LogLevel; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class RepoTest + public class RepoTest : TestBase { [Test] public void to_many__series_to_episode() @@ -93,6 +94,8 @@ namespace NzbDrone.Core.Test Assert.AreEqual(Logger.Name, logItem.Logger); Assert.AreEqual(LogLevel.Info.Name, logItem.Level); Assert.AreEqual("write_log", logItem.Method); + + } [Test] @@ -126,6 +129,7 @@ namespace NzbDrone.Core.Test Assert.AreEqual(LogLevel.Error.Name, logItem.Level); Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType); Assert.AreEqual(ex.ToString(), logItem.Exception); + ExceptionVerification.ExcpectedErrors(1); } [Test] @@ -159,6 +163,7 @@ namespace NzbDrone.Core.Test Assert.AreEqual(LogLevel.Error.Name, logItem.Level); Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType); Assert.AreEqual(ex.ToString(), logItem.Exception); + ExceptionVerification.ExcpectedErrors(1); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/RootDirProviderTest.cs b/NzbDrone.Core.Test/RootDirProviderTest.cs index b931ee1df..a74373b56 100644 --- a/NzbDrone.Core.Test/RootDirProviderTest.cs +++ b/NzbDrone.Core.Test/RootDirProviderTest.cs @@ -3,13 +3,17 @@ using AutoMoq; using MbUnit.Framework; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; +using NzbDrone.Core.Test.Framework; using SubSonic.Repository; namespace NzbDrone.Core.Test { [TestFixture] - public class RootDirProviderTest + // ReSharper disable InconsistentNaming + public class RootDirProviderTest : TestBase { + + [Test] public void GetRootDirs() { @@ -38,7 +42,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); mocker.SetConstant(MockLib.GetEmptyRepository()); - string path = @"C:\TV\"; + const string path = @"C:\TV\"; //Act var rootDirProvider = mocker.Resolve(); @@ -59,7 +63,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); mocker.SetConstant(MockLib.GetEmptyRepository()); - string path = @"C:\TV2"; + const string path = @"C:\TV2"; //Act var rootDirProvider = mocker.Resolve(); @@ -80,8 +84,6 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); mocker.SetConstant(MockLib.GetEmptyRepository()); - string path = @"C:\TV2"; - //Act var rootDirProvider = mocker.Resolve(); rootDirProvider.Add(new RootDir {Path = @"C:\TV"}); @@ -99,8 +101,8 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); mocker.SetConstant(MockLib.GetEmptyRepository()); - int id = 1; - string path = @"C:\TV"; + const int id = 1; + const string path = @"C:\TV"; //Act var rootDirProvider = mocker.Resolve(); diff --git a/NzbDrone.Core.Test/SabControllerTest.cs b/NzbDrone.Core.Test/SabProviderTest.cs similarity index 94% rename from NzbDrone.Core.Test/SabControllerTest.cs rename to NzbDrone.Core.Test/SabProviderTest.cs index 68e92c855..229d2564e 100644 --- a/NzbDrone.Core.Test/SabControllerTest.cs +++ b/NzbDrone.Core.Test/SabProviderTest.cs @@ -7,26 +7,26 @@ using Moq; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class SabControllerTest + public class SabProviderTest : TestBase { [Test] public void AddByUrlSuccess() { //Setup - string sabHost = "192.168.5.55"; - int sabPort = 2222; - string apikey = "5c770e3197e4fe763423ee7c392c25d1"; - string username = "admin"; - string password = "pass"; - var priority = SabnzbdPriorityType.Normal; - string category = "tv"; + const string sabHost = "192.168.5.55"; + const int sabPort = 2222; + const string apikey = "5c770e3197e4fe763423ee7c392c25d1"; + const string username = "admin"; + const string password = "pass"; + const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal; + const string category = "tv"; var mocker = new AutoMoqer(); @@ -101,6 +101,7 @@ namespace NzbDrone.Core.Test //Assert Assert.IsFalse(result); + ExceptionVerification.ExcpectedWarns(1); } [Test] diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index 7a88771e61d4196d746fd3779707e2cb5dcb6113..bcf0579db9be724d582c30c12a429ed5f81f3ebf 100644 GIT binary patch delta 99 zcmZ4GaL-}FcShcc6GR0!&Q_J&oO&=PM*rHA(xp~qEJ%ilH{49V5?wg nWNcy$Rs~WC1e>3;uVvw|2~I7_Of9zCJcXx@3BeQM_YnjD3eX*> diff --git a/NzbDrone.Core.Test/SyncProviderTest.cs b/NzbDrone.Core.Test/SyncProviderTest.cs index b0422ed68..11c451224 100644 --- a/NzbDrone.Core.Test/SyncProviderTest.cs +++ b/NzbDrone.Core.Test/SyncProviderTest.cs @@ -4,17 +4,18 @@ using MbUnit.Framework; using Moq; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class SyncProviderTest + public class SyncProviderTest : TestBase { [Test] public void None_existing_folder_returns_empty_list() { - string path = "d:\\bad folder"; + const string path = "d:\\bad folder"; var mocker = new AutoMoqer(); mocker.GetMock(MockBehavior.Strict) diff --git a/NzbDrone.Core.Test/TvDbControllerTest.cs b/NzbDrone.Core.Test/TvDbProviderTest.cs similarity index 96% rename from NzbDrone.Core.Test/TvDbControllerTest.cs rename to NzbDrone.Core.Test/TvDbProviderTest.cs index eec987004..812fa8a9a 100644 --- a/NzbDrone.Core.Test/TvDbControllerTest.cs +++ b/NzbDrone.Core.Test/TvDbProviderTest.cs @@ -1,12 +1,13 @@ using System; using MbUnit.Framework; using NzbDrone.Core.Providers; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class TvDbControllerTest + public class TvDbProviderTest : TestBase { [Test] [Row("The Simpsons")] diff --git a/NzbDrone.Core.Test/log.config b/NzbDrone.Core.Test/log.config index 1eddaa214..bce2d6d0c 100644 --- a/NzbDrone.Core.Test/log.config +++ b/NzbDrone.Core.Test/log.config @@ -1,6 +1,6 @@  - +