All tests now use base class Mocker

This commit is contained in:
kay.one 2011-12-14 20:15:53 -08:00
parent ab29a114d1
commit 1b45a85f3f
39 changed files with 1002 additions and 1010 deletions

View File

@ -19,15 +19,13 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id() public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id()
{ {
var mocker = new AutoMoqer(); var processMock = Mocker.GetMock<ProcessProvider>();
var processMock = mocker.GetMock<ProcessProvider>();
processMock.Setup(c => c.GetCurrentProcess()) processMock.Setup(c => c.GetCurrentProcess())
.Returns(Builder<ProcessInfo>.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build()); .Returns(Builder<ProcessInfo>.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build());
processMock.Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null); processMock.Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
var subject = mocker.Resolve<MonitoringProvider>(); var subject = Mocker.Resolve<MonitoringProvider>();
//Act //Act

View File

@ -46,13 +46,13 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Route_should_call_install_service_when_application_mode_is_install() public void Route_should_call_install_service_when_application_mode_is_install()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var serviceProviderMock = mocker.GetMock<ServiceProvider>(); var serviceProviderMock = Mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME)); serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false); serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.InstallService); Mocker.Resolve<Router>().Route(ApplicationMode.InstallService);
serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
} }
@ -61,13 +61,13 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall() public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var serviceProviderMock = mocker.GetMock<ServiceProvider>(); var serviceProviderMock = Mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME)); serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true); serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService); Mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
} }
@ -75,14 +75,14 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Route_should_call_console_service_when_application_mode_is_console() public void Route_should_call_console_service_when_application_mode_is_console()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var consoleProvider = mocker.GetMock<ConsoleProvider>(); var consoleProvider = Mocker.GetMock<ConsoleProvider>();
var appServerProvider = mocker.GetMock<ApplicationServer>(); var appServerProvider = Mocker.GetMock<ApplicationServer>();
consoleProvider.Setup(c => c.WaitForClose()); consoleProvider.Setup(c => c.WaitForClose());
appServerProvider.Setup(c => c.Start()); appServerProvider.Setup(c => c.Start());
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.Console); Mocker.Resolve<Router>().Route(ApplicationMode.Console);
consoleProvider.Verify(c => c.WaitForClose(), Times.Once()); consoleProvider.Verify(c => c.WaitForClose(), Times.Once());
appServerProvider.Verify(c => c.Start(), Times.Once()); appServerProvider.Verify(c => c.Start(), Times.Once());
@ -94,15 +94,15 @@ namespace NzbDrone.App.Test
[TestCase(ApplicationMode.Help)] [TestCase(ApplicationMode.Help)]
public void Route_should_call_service_start_when_run_in_service_more(ApplicationMode applicationMode) public void Route_should_call_service_start_when_run_in_service_more(ApplicationMode applicationMode)
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var envMock = mocker.GetMock<EnviromentProvider>(); var envMock = Mocker.GetMock<EnviromentProvider>();
var serviceProvider = mocker.GetMock<ServiceProvider>(); var serviceProvider = Mocker.GetMock<ServiceProvider>();
envMock.SetupGet(c => c.IsUserInteractive).Returns(false); envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>())); serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
mocker.Resolve<Router>().Route(applicationMode); Mocker.Resolve<Router>().Route(applicationMode);
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once()); serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
} }
@ -111,33 +111,33 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void show_error_on_install_if_service_already_exist() public void show_error_on_install_if_service_already_exist()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var consoleMock = mocker.GetMock<ConsoleProvider>(); var consoleMock = Mocker.GetMock<ConsoleProvider>();
var serviceMock = mocker.GetMock<ServiceProvider>(); var serviceMock = Mocker.GetMock<ServiceProvider>();
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceAlreadyExist()); consoleMock.Setup(c => c.PrintServiceAlreadyExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true); serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.InstallService); Mocker.Resolve<Router>().Route(ApplicationMode.InstallService);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void show_error_on_uninstall_if_service_doesnt_exist() public void show_error_on_uninstall_if_service_doesnt_exist()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var consoleMock = mocker.GetMock<ConsoleProvider>(); var consoleMock = Mocker.GetMock<ConsoleProvider>();
var serviceMock = mocker.GetMock<ServiceProvider>(); var serviceMock = Mocker.GetMock<ServiceProvider>();
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoestExist()); consoleMock.Setup(c => c.PrintServiceDoestExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false); serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService); Mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
} }
} }

View File

@ -57,8 +57,6 @@ namespace NzbDrone.Common.Test
const string key = "LaunchBrowser"; const string key = "LaunchBrowser";
const bool value = true; const bool value = true;
var mocker = new AutoMoqer();
//Act //Act
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value); var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
@ -69,8 +67,6 @@ namespace NzbDrone.Common.Test
[Test] [Test]
public void GetLaunchBrowser_Success() public void GetLaunchBrowser_Success()
{ {
var mocker = new AutoMoqer();
//Act //Act
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser; var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;

View File

@ -32,18 +32,18 @@ namespace NzbDrone.Core.Test
[TestCase("nzbmatrix.xml", 2)] [TestCase("nzbmatrix.xml", 2)]
public void parse_feed_xml(string fileName, int warns) public void parse_feed_xml(string fileName, int warns)
{ {
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName)); .Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build(); var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
mocker.GetMock<IndexerProvider>() Mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
var mockIndexer = mocker.Resolve<MockIndexer>(); var mockIndexer = Mocker.Resolve<MockIndexer>();
var parseResults = mockIndexer.FetchRss(); var parseResults = mockIndexer.FetchRss();
foreach (var episodeParseResult in parseResults) foreach (var episodeParseResult in parseResults)
@ -63,15 +63,15 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void newzbin_parses_languae() public void newzbin_parses_languae()
{ {
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\newbin_none_english.xml")); .Returns(File.OpenRead(".\\Files\\Rss\\newbin_none_english.xml"));
var newzbin = mocker.Resolve<Newzbin>(); var newzbin = Mocker.Resolve<Newzbin>();
var parseResults = newzbin.FetchRss(); var parseResults = newzbin.FetchRss();
foreach (var episodeParseResult in parseResults) foreach (var episodeParseResult in parseResults)
@ -88,22 +88,22 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void newzbin_rss_fetch() public void newzbin_rss_fetch()
{ {
var mocker = new AutoMoqer();
mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build(); var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
mocker.GetMock<IndexerProvider>() Mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NewzbinUsername) .SetupGet(c => c.NewzbinUsername)
.Returns("nzbdrone"); .Returns("nzbdrone");
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NewzbinPassword) .SetupGet(c => c.NewzbinPassword)
.Returns("smartar39865"); .Returns("smartar39865");
var newzbinProvider = mocker.Resolve<Newzbin>(); var newzbinProvider = Mocker.Resolve<Newzbin>();
var parseResults = newzbinProvider.FetchRss(); var parseResults = newzbinProvider.FetchRss();
foreach (var episodeParseResult in parseResults) foreach (var episodeParseResult in parseResults)
@ -125,12 +125,12 @@ namespace NzbDrone.Core.Test
[TestCase("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)] [TestCase("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)]
public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality) public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality)
{ {
var mocker = new AutoMoqer();
const string summary = "My fake summary"; const string summary = "My fake summary";
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build(); var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
mocker.GetMock<IndexerProvider>() Mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test
.With(c => c.Summary = new TextSyndicationContent(summary)) .With(c => c.Summary = new TextSyndicationContent(summary))
.Build(); .Build();
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem); var result = Mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNotNull(result); Assert.IsNotNull(result);
Assert.AreEqual(LanguageType.Finnish, result.Language); Assert.AreEqual(LanguageType.Finnish, result.Language);
@ -152,12 +152,12 @@ namespace NzbDrone.Core.Test
[TestCase("Adventure.Inc.DVDRip.XviD-OSiTV")] [TestCase("Adventure.Inc.DVDRip.XviD-OSiTV")]
public void custome_parser_full_parse(string title) public void custome_parser_full_parse(string title)
{ {
var mocker = new AutoMoqer();
const string summary = "My fake summary"; const string summary = "My fake summary";
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build(); var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
mocker.GetMock<IndexerProvider>() Mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
@ -166,7 +166,7 @@ namespace NzbDrone.Core.Test
.With(c => c.Summary = new TextSyndicationContent(summary)) .With(c => c.Summary = new TextSyndicationContent(summary))
.Build(); .Build();
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem); var result = Mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNotNull(result); Assert.IsNotNull(result);
Assert.AreEqual(LanguageType.Finnish, result.Language); Assert.AreEqual(LanguageType.Finnish, result.Language);
@ -176,15 +176,15 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void downloadFeed() public void downloadFeed()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(new HttpProvider()); Mocker.SetConstant(new HttpProvider());
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build(); var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
mocker.GetMock<IndexerProvider>() Mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
mocker.Resolve<TestUrlIndexer>().FetchRss(); Mocker.Resolve<TestUrlIndexer>().FetchRss();
ExceptionVerification.IgnoreWarns(); ExceptionVerification.IgnoreWarns();
} }
@ -194,19 +194,19 @@ namespace NzbDrone.Core.Test
[TestCase("In plain Sight", 1, 4)] [TestCase("In plain Sight", 1, 4)]
public void nzbsorg_search_returns_valid_results(string title, int season, int episode) public void nzbsorg_search_returns_valid_results(string title, int season, int episode)
{ {
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbsOrgUId) .SetupGet(c => c.NzbsOrgUId)
.Returns("43516"); .Returns("43516");
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbsOrgHash) .SetupGet(c => c.NzbsOrgHash)
.Returns("bc8edb4cc49d4ae440775adec5ac001f"); .Returns("bc8edb4cc49d4ae440775adec5ac001f");
mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
var result = mocker.Resolve<NzbsOrg>().FetchEpisode(title, season, episode); var result = Mocker.Resolve<NzbsOrg>().FetchEpisode(title, season, episode);
ExceptionVerification.MarkInconclusive(typeof(WebException)); ExceptionVerification.MarkInconclusive(typeof(WebException));
@ -221,19 +221,19 @@ namespace NzbDrone.Core.Test
[TestCase("In plain Sight", 1, 11, Ignore = true)] [TestCase("In plain Sight", 1, 11, Ignore = true)]
public void newzbin_search_returns_valid_results(string title, int season, int episode) public void newzbin_search_returns_valid_results(string title, int season, int episode)
{ {
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NewzbinUsername) .SetupGet(c => c.NewzbinUsername)
.Returns("nzbdrone"); .Returns("nzbdrone");
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NewzbinPassword) .SetupGet(c => c.NewzbinPassword)
.Returns("smartar39865"); .Returns("smartar39865");
mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
var result = mocker.Resolve<Newzbin>().FetchEpisode(title, season, episode); var result = Mocker.Resolve<Newzbin>().FetchEpisode(title, season, episode);
ExceptionVerification.MarkInconclusive(typeof(WebException)); ExceptionVerification.MarkInconclusive(typeof(WebException));
ExceptionVerification.IgnoreWarns(); ExceptionVerification.IgnoreWarns();
@ -248,19 +248,19 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void nzbmatrix_search_returns_valid_results() public void nzbmatrix_search_returns_valid_results()
{ {
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixUsername) .SetupGet(c => c.NzbMatrixUsername)
.Returns(""); .Returns("");
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixApiKey) .SetupGet(c => c.NzbMatrixApiKey)
.Returns(""); .Returns("");
mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
var result = mocker.Resolve<NzbMatrix>().FetchEpisode("Simpsons", 21, 23); var result = Mocker.Resolve<NzbMatrix>().FetchEpisode("Simpsons", 21, 23);
ExceptionVerification.MarkInconclusive(typeof(WebException)); ExceptionVerification.MarkInconclusive(typeof(WebException));
@ -274,19 +274,19 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void nzbmatrix_multi_word_search_returns_valid_results() public void nzbmatrix_multi_word_search_returns_valid_results()
{ {
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixUsername) .SetupGet(c => c.NzbMatrixUsername)
.Returns(""); .Returns("");
mocker.GetMock<ConfigProvider>() Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixApiKey) .SetupGet(c => c.NzbMatrixApiKey)
.Returns(""); .Returns("");
mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
var result = mocker.Resolve<NzbMatrix>().FetchEpisode("Blue Bloods", 1, 19); var result = Mocker.Resolve<NzbMatrix>().FetchEpisode("Blue Bloods", 1, 19);
ExceptionVerification.MarkInconclusive(typeof(WebException)); ExceptionVerification.MarkInconclusive(typeof(WebException));
@ -311,14 +311,14 @@ namespace NzbDrone.Core.Test
public void size_newzbin() public void size_newzbin()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml")); .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml"));
//Act //Act
var parseResults = mocker.Resolve<Newzbin>().FetchRss(); var parseResults = Mocker.Resolve<Newzbin>().FetchRss();
parseResults.Should().HaveCount(1); parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(1295620506); parseResults[0].Size.Should().Be(1295620506);
@ -328,14 +328,14 @@ namespace NzbDrone.Core.Test
public void size_nzbmatrix() public void size_nzbmatrix()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\nzbmatrix.xml")); .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\nzbmatrix.xml"));
//Act //Act
var parseResults = mocker.Resolve<NzbMatrix>().FetchRss(); var parseResults = Mocker.Resolve<NzbMatrix>().FetchRss();
parseResults.Should().HaveCount(1); parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(1331439862); parseResults[0].Size.Should().Be(1331439862);
@ -345,14 +345,14 @@ namespace NzbDrone.Core.Test
public void size_nzbsorg() public void size_nzbsorg()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\nzbsorg.xml")); .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\nzbsorg.xml"));
//Act //Act
var parseResults = mocker.Resolve<NzbsOrg>().FetchRss(); var parseResults = Mocker.Resolve<NzbsOrg>().FetchRss();
parseResults.Should().HaveCount(1); parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(1793148846); parseResults[0].Size.Should().Be(1793148846);
@ -362,14 +362,14 @@ namespace NzbDrone.Core.Test
public void size_nzbsrus() public void size_nzbsrus()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\nzbsrus.xml")); .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\nzbsrus.xml"));
//Act //Act
var parseResults = mocker.Resolve<NzbsRUs>().FetchRss(); var parseResults = Mocker.Resolve<NzbsRUs>().FetchRss();
parseResults.Should().HaveCount(1); parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(1793148846); parseResults[0].Size.Should().Be(1793148846);

View File

@ -8,12 +8,13 @@ using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq; using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests namespace NzbDrone.Core.Test.JobTests
{ {
[TestFixture] [TestFixture]
public class BacklogSearchJobTest public class BacklogSearchJobTest : CoreTest
{ {
[Test] [Test]
public void no_missing_epsiodes_should_not_trigger_any_search() public void no_missing_epsiodes_should_not_trigger_any_search()
@ -23,19 +24,19 @@ namespace NzbDrone.Core.Test.JobTests
var episodes = new List<Episode>(); var episodes = new List<Episode>();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
//Act //Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0); Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
Times.Never()); Times.Never());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
Times.Never()); Times.Never());
} }
@ -47,22 +48,22 @@ namespace NzbDrone.Core.Test.JobTests
var episodes = Builder<Episode>.CreateListOfSize(1).Build(); var episodes = Builder<Episode>.CreateListOfSize(1).Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
mocker.GetMock<EpisodeSearchJob>() Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable(); .Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
//Act //Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0); Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
Times.Never()); Times.Never());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
Times.Once()); Times.Once());
} }
@ -74,22 +75,22 @@ namespace NzbDrone.Core.Test.JobTests
var episodes = Builder<Episode>.CreateListOfSize(5).Build(); var episodes = Builder<Episode>.CreateListOfSize(5).Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
mocker.GetMock<EpisodeSearchJob>() Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable(); .Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
//Act //Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0); Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
Times.Never()); Times.Never());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
Times.Exactly(episodes.Count)); Times.Exactly(episodes.Count));
} }
@ -105,25 +106,25 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.SeasonNumber = 1) .With(e => e.SeasonNumber = 1)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
mocker.GetMock<EpisodeSearchJob>() Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable(); .Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
//Act //Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0); Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
Times.Never()); Times.Never());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
Times.Exactly(episodes.Count)); Times.Exactly(episodes.Count));
} }
@ -139,25 +140,25 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.SeasonNumber = 1) .With(e => e.SeasonNumber = 1)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
mocker.GetMock<SeasonSearchJob>() Mocker.GetMock<SeasonSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), It.IsAny<int>())).Verifiable(); .Setup(s => s.Start(notification, It.IsAny<int>(), It.IsAny<int>())).Verifiable();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList()); .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList());
//Act //Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0); Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
Times.Once()); Times.Once());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
Times.Never()); Times.Never());
} }
@ -173,28 +174,28 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.SeasonNumber = 1) .With(e => e.SeasonNumber = 1)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
mocker.GetMock<SeasonSearchJob>() Mocker.GetMock<SeasonSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), It.IsAny<int>())).Verifiable(); .Setup(s => s.Start(notification, It.IsAny<int>(), It.IsAny<int>())).Verifiable();
mocker.GetMock<EpisodeSearchJob>() Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable(); .Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5 }); .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5 });
//Act //Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0); Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
Times.Once()); Times.Once());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
Times.Exactly(5)); Times.Exactly(5));
} }
} }

View File

@ -27,22 +27,22 @@ namespace NzbDrone.Core.Test.JobTests
.With(s => s.SeriesId = 12) .With(s => s.SeriesId = 12)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetSeries(series.SeriesId)) .Setup(p => p.GetSeries(series.SeriesId))
.Returns(series); .Returns(series);
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(p => p.Scan(series)) .Setup(p => p.Scan(series))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
//Act //Act
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), series.SeriesId, 0); Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), series.SeriesId, 0);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
@ -55,24 +55,24 @@ namespace NzbDrone.Core.Test.JobTests
.TheNext(1).With(s => s.SeriesId = 15) .TheNext(1).With(s => s.SeriesId = 15)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries()) .Setup(p => p.GetAllSeries())
.Returns(series); .Returns(series);
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(s => s.Scan(series[0])) .Setup(s => s.Scan(series[0]))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(s => s.Scan(series[1])) .Setup(s => s.Scan(series[1]))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0); Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
@ -83,24 +83,24 @@ namespace NzbDrone.Core.Test.JobTests
.TheNext(1).With(s => s.SeriesId = 15) .TheNext(1).With(s => s.SeriesId = 15)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries()) .Setup(p => p.GetAllSeries())
.Returns(series); .Returns(series);
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(s => s.Scan(series[0])) .Setup(s => s.Scan(series[0]))
.Throws(new InvalidOperationException("Bad Job")); .Throws(new InvalidOperationException("Bad Job"));
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(s => s.Scan(series[1])) .Setup(s => s.Scan(series[1]))
.Throws(new InvalidOperationException("Bad Job")); .Throws(new InvalidOperationException("Bad Job"));
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0); Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedErrors(2); ExceptionVerification.ExcpectedErrors(2);
} }
@ -112,26 +112,26 @@ namespace NzbDrone.Core.Test.JobTests
.TheNext(1).With(s => s.SeriesId = 15) .TheNext(1).With(s => s.SeriesId = 15)
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries()) .Setup(p => p.GetAllSeries())
.Returns(series); .Returns(series);
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(s => s.Scan(series[0])) .Setup(s => s.Scan(series[0]))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
mocker.GetMock<DiskScanProvider>() Mocker.GetMock<DiskScanProvider>()
.Setup(s => s.Scan(series[1])) .Setup(s => s.Scan(series[1]))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0); Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<DiskScanProvider>().Verify(s => s.Scan(It.IsAny<Series>()), Times.Exactly(2)); Mocker.GetMock<DiskScanProvider>().Verify(s => s.Scan(It.IsAny<Series>()), Times.Exactly(2));
} }
} }

View File

@ -31,53 +31,53 @@ namespace NzbDrone.Core.Test.JobTests
var notification = new ProgressNotification("Test"); var notification = new ProgressNotification("Test");
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries()) .Setup(p => p.GetAllSeries())
.Returns(series); .Returns(series);
mocker.GetMock<DiskScanJob>() Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0)) .Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastDiskSync = DateTime.Now); .Callback(() => series[0].LastDiskSync = DateTime.Now);
mocker.GetMock<DiskScanJob>() Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, series[1].SeriesId, 0)) .Setup(j => j.Start(notification, series[1].SeriesId, 0))
.Callback(() => series[1].LastDiskSync = DateTime.Now); .Callback(() => series[1].LastDiskSync = DateTime.Now);
mocker.GetMock<BannerDownloadJob>() Mocker.GetMock<BannerDownloadJob>()
.Setup(j => j.Start(notification, It.IsAny<int>(), 0)); .Setup(j => j.Start(notification, It.IsAny<int>(), 0));
mocker.GetMock<UpdateInfoJob>() Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0)) .Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastInfoSync = DateTime.Now); .Callback(() => series[0].LastInfoSync = DateTime.Now);
mocker.GetMock<UpdateInfoJob>() Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[1].SeriesId, 0)) .Setup(j => j.Start(notification, series[1].SeriesId, 0))
.Callback(() => series[1].LastInfoSync = DateTime.Now); .Callback(() => series[1].LastInfoSync = DateTime.Now);
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]); .Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(s => s.GetSeries(series[1].SeriesId)).Returns(series[1]); .Setup(s => s.GetSeries(series[1].SeriesId)).Returns(series[1]);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>()); .Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
//Act //Act
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0); Mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once()); Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once()); Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());
} }
@ -96,43 +96,43 @@ namespace NzbDrone.Core.Test.JobTests
var notification = new ProgressNotification("Test"); var notification = new ProgressNotification("Test");
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries()) .Setup(p => p.GetAllSeries())
.Returns(series); .Returns(series);
mocker.GetMock<UpdateInfoJob>() Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0)) .Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastInfoSync = DateTime.Now); .Callback(() => series[0].LastInfoSync = DateTime.Now);
mocker.GetMock<UpdateInfoJob>() Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[1].SeriesId, 0)) .Setup(j => j.Start(notification, series[1].SeriesId, 0))
.Throws(new InvalidOperationException()); .Throws(new InvalidOperationException());
mocker.GetMock<DiskScanJob>() Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0)) .Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastDiskSync = DateTime.Now); .Callback(() => series[0].LastDiskSync = DateTime.Now);
mocker.GetMock<BannerDownloadJob>() Mocker.GetMock<BannerDownloadJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0)); .Setup(j => j.Start(notification, series[0].SeriesId, 0));
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]); .Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>()); .Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
//Act //Act
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0); Mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once()); Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());
mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
ExceptionVerification.ExcpectedErrors(1); ExceptionVerification.ExcpectedErrors(1);
@ -145,19 +145,19 @@ namespace NzbDrone.Core.Test.JobTests
{ {
int seriesId = 12; int seriesId = 12;
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.GetSeriesFiles(seriesId)) .Setup(p => p.GetSeriesFiles(seriesId))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetSeasons(seriesId)) .Setup(p => p.GetSeasons(seriesId))
.Returns(new List<int> { 0, 1, 2, 3, 4 }); .Returns(new List<int> { 0, 1, 2, 3, 4 });
mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId); Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never()); Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never());
} }
[Test] [Test]
@ -172,19 +172,19 @@ namespace NzbDrone.Core.Test.JobTests
episodesFiles[0].SeasonNumber = 0; episodesFiles[0].SeasonNumber = 0;
episodesFiles[1].SeasonNumber = 1; episodesFiles[1].SeasonNumber = 1;
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.GetSeriesFiles(seriesId)) .Setup(p => p.GetSeriesFiles(seriesId))
.Returns(episodesFiles); .Returns(episodesFiles);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetSeasons(seriesId)) .Setup(p => p.GetSeasons(seriesId))
.Returns(new List<int> { 0, 1, 2 }); .Returns(new List<int> { 0, 1, 2 });
mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId); Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never()); Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
} }
[Test] [Test]
@ -198,21 +198,21 @@ namespace NzbDrone.Core.Test.JobTests
episodesFiles[0].SeasonNumber = 1; episodesFiles[0].SeasonNumber = 1;
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.GetSeriesFiles(seriesId)) .Setup(p => p.GetSeriesFiles(seriesId))
.Returns(episodesFiles); .Returns(episodesFiles);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetSeasons(seriesId)) .Setup(p => p.GetSeasons(seriesId))
.Returns(new List<int> { 0, 1, 2 }); .Returns(new List<int> { 0, 1, 2 });
mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId); Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 0, true), Times.Once()); Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 0, true), Times.Once());
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 1, true), Times.Never()); Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 1, true), Times.Never());
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never()); Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
} }
} }

View File

@ -4,12 +4,13 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Jobs; using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq; using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests namespace NzbDrone.Core.Test.JobTests
{ {
[TestFixture] [TestFixture]
public class SearchJobTest public class SearchJobTest:CoreTest
{ {
[TestCase(0)] [TestCase(0)]
[TestCase(-1)] [TestCase(-1)]
@ -17,8 +18,8 @@ namespace NzbDrone.Core.Test.JobTests
[ExpectedException(typeof(ArgumentOutOfRangeException))] [ExpectedException(typeof(ArgumentOutOfRangeException))]
public void start_target_id_less_than_0_throws_exception(int target) public void start_target_id_less_than_0_throws_exception(int target)
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.Resolve<EpisodeSearchJob>().Start(new ProgressNotification("Test"), target, 0); Mocker.Resolve<EpisodeSearchJob>().Start(new ProgressNotification("Test"), target, 0);
} }
[TestCase(0)] [TestCase(0)]
@ -27,8 +28,8 @@ namespace NzbDrone.Core.Test.JobTests
[ExpectedException(typeof(ArgumentOutOfRangeException))] [ExpectedException(typeof(ArgumentOutOfRangeException))]
public void start_secondary_target_id_less_than_0_throws_exception(int target) public void start_secondary_target_id_less_than_0_throws_exception(int target)
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.Resolve<SeasonSearchJob>().Start(new ProgressNotification("Test"), 0, target); Mocker.Resolve<SeasonSearchJob>().Start(new ProgressNotification("Test"), 0, target);
} }
} }
} }

View File

@ -19,25 +19,25 @@ namespace NzbDrone.Core.Test.JobTests
{ {
var seasons = new List<int> { 1, 2, 3, 4, 5 }; var seasons = new List<int> { 1, 2, 3, 4, 5 };
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var notification = new ProgressNotification("Series Search"); var notification = new ProgressNotification("Series Search");
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetSeasons(1)).Returns(seasons); .Setup(c => c.GetSeasons(1)).Returns(seasons);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.IsIgnored(It.IsAny<int>(), It.IsAny<int>())).Returns(false); .Setup(c => c.IsIgnored(It.IsAny<int>(), It.IsAny<int>())).Returns(false);
mocker.GetMock<SeasonSearchJob>() Mocker.GetMock<SeasonSearchJob>()
.Setup(c => c.Start(notification, 1, It.IsAny<int>())).Verifiable(); .Setup(c => c.Start(notification, 1, It.IsAny<int>())).Verifiable();
//Act //Act
mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0); Mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
Times.Exactly(seasons.Count)); Times.Exactly(seasons.Count));
} }
@ -46,19 +46,19 @@ namespace NzbDrone.Core.Test.JobTests
{ {
var seasons = new List<int>(); var seasons = new List<int>();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var notification = new ProgressNotification("Series Search"); var notification = new ProgressNotification("Series Search");
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetSeasons(1)).Returns(seasons); .Setup(c => c.GetSeasons(1)).Returns(seasons);
//Act //Act
mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0); Mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()), Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
Times.Never()); Times.Never());
} }

View File

@ -23,15 +23,15 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "MY_KEY"; const string key = "MY_KEY";
const string value = "MY_VALUE"; const string value = "MY_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
mocker.Resolve<ConfigProvider>().SetValue(key, value); Mocker.Resolve<ConfigProvider>().SetValue(key, value);
//Assert //Assert
mocker.Resolve<ConfigProvider>().GetValue(key, "").Should().Be(value); Mocker.Resolve<ConfigProvider>().GetValue(key, "").Should().Be(value);
} }
[Test] [Test]
@ -40,15 +40,15 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "MY_KEY"; const string key = "MY_KEY";
const string value = "MY_VALUE"; const string value = "MY_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(new Config { Key = key, Value = value }); db.Insert(new Config { Key = key, Value = value });
db.Insert(new Config { Key = "Other Key", Value = "OtherValue" }); db.Insert(new Config { Key = "Other Key", Value = "OtherValue" });
//Act //Act
var result = mocker.Resolve<ConfigProvider>().GetValue(key, ""); var result = Mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert //Assert
result.Should().Be(value); result.Should().Be(value);
@ -61,13 +61,13 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "MY_KEY"; const string key = "MY_KEY";
const string value = "MY_VALUE"; const string value = "MY_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
var result = mocker.Resolve<ConfigProvider>().GetValue(key, value); var result = Mocker.Resolve<ConfigProvider>().GetValue(key, value);
//Assert //Assert
result.Should().Be(value); result.Should().Be(value);
@ -80,15 +80,15 @@ namespace NzbDrone.Core.Test.ProviderTests
const string originalValue = "OLD_VALUE"; const string originalValue = "OLD_VALUE";
const string newValue = "NEW_VALUE"; const string newValue = "NEW_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(new Config { Key = key, Value = originalValue }); db.Insert(new Config { Key = key, Value = originalValue });
//Act //Act
mocker.Resolve<ConfigProvider>().SetValue(key, newValue); Mocker.Resolve<ConfigProvider>().SetValue(key, newValue);
var result = mocker.Resolve<ConfigProvider>().GetValue(key, ""); var result = Mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert //Assert
result.Should().Be(newValue); result.Should().Be(newValue);
@ -102,14 +102,14 @@ namespace NzbDrone.Core.Test.ProviderTests
const string value = "OLD_VALUE"; const string value = "OLD_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
mocker.Resolve<ConfigProvider>().SetValue(key, value); Mocker.Resolve<ConfigProvider>().SetValue(key, value);
mocker.Resolve<ConfigProvider>().SetValue(key, value); Mocker.Resolve<ConfigProvider>().SetValue(key, value);
var result = mocker.Resolve<ConfigProvider>().GetValue(key, ""); var result = Mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert //Assert
result.Should().Be(value); result.Should().Be(value);
@ -121,11 +121,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void config_properties_should_write_and_read_using_same_key() public void config_properties_should_write_and_read_using_same_key()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var configProvider = mocker.Resolve<ConfigProvider>(); var configProvider = Mocker.Resolve<ConfigProvider>();
var allProperties = typeof(ConfigProvider).GetProperties(); var allProperties = typeof(ConfigProvider).GetProperties();

View File

@ -21,11 +21,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
public void FreeDiskSpace() public void FreeDiskSpace()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
//Act //Act
var di = new DirectoryInfo(Directory.GetCurrentDirectory()); var di = new DirectoryInfo(Directory.GetCurrentDirectory());
var result = mocker.Resolve<DiskProvider>().FreeDiskSpace(di); var result = Mocker.Resolve<DiskProvider>().FreeDiskSpace(di);
//Asert //Asert
//Checks to ensure that the free space on the first is greater than 0 (It should be in 99.99999999999999% of cases... I hope) //Checks to ensure that the free space on the first is greater than 0 (It should be in 99.99999999999999% of cases... I hope)

View File

@ -24,74 +24,74 @@ namespace NzbDrone.Core.Test.ProviderTests
public void scan_series_should_update_the_last_scan_date() public void scan_series_should_update_the_last_scan_date()
{ {
var mocker = new AutoMoqer();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(c => c.UpdateSeries(It.Is<Series>(s => s.LastDiskSync != null))).Verifiable(); .Setup(c => c.UpdateSeries(It.Is<Series>(s => s.LastDiskSync != null))).Verifiable();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodeBySeries(It.IsAny<long>())) .Setup(c => c.GetEpisodeBySeries(It.IsAny<long>()))
.Returns(new List<Episode> { new Episode() }); .Returns(new List<Episode> { new Episode() });
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(It.IsAny<string>())) .Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetSeriesFiles(It.IsAny<int>())) .Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
.Returns(new List<EpisodeFile>()); .Returns(new List<EpisodeFile>());
mocker.Resolve<DiskScanProvider>().Scan(new Series()); Mocker.Resolve<DiskScanProvider>().Scan(new Series());
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void cleanup_should_skip_existing_files() public void cleanup_should_skip_existing_files()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build(); var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>())) .Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(true); .Returns(true);
//Act //Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes); Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void cleanup_should_delete_none_existing_files() public void cleanup_should_delete_none_existing_files()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build(); var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>())) .Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>())) .Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(e => e.Delete(It.IsAny<int>())); .Setup(e => e.Delete(It.IsAny<int>()));
//Act //Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes); Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10)); .Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10)); .Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
} }
@ -99,40 +99,40 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void cleanup_should_delete_none_existing_files_remove_links_to_episodes() public void cleanup_should_delete_none_existing_files_remove_links_to_episodes()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build(); var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>())) .Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>())) .Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
.Returns(new List<Episode> { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } }); .Returns(new List<Episode> { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } });
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>())); .Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(e => e.Delete(It.IsAny<int>())); .Setup(e => e.Delete(It.IsAny<int>()));
//Act //Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes); Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10)); .Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g=>g.EpisodeFileId == 0)), Times.Exactly(20)); .Verify(e => e.UpdateEpisode(It.Is<Episode>(g=>g.EpisodeFileId == 0)), Times.Exactly(20));
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10)); .Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10)); .Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
} }
@ -141,29 +141,29 @@ namespace NzbDrone.Core.Test.ProviderTests
public void scan_series_should_log_warning_if_path_doesnt_exist_on_disk() public void scan_series_should_log_warning_if_path_doesnt_exist_on_disk()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(s => s.Path = @"C:\Test\TV\SeriesName\") .With(s => s.Path = @"C:\Test\TV\SeriesName\")
.Build(); .Build();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.DeleteOrphaned()) .Setup(c => c.DeleteOrphaned())
.Returns(0); .Returns(0);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.RepairLinks()) .Setup(c => c.RepairLinks())
.Returns(0); .Returns(0);
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(series.Path)) .Setup(c => c.FolderExists(series.Path))
.Returns(false); .Returns(false);
//Act //Act
mocker.Resolve<DiskScanProvider>().Scan(series, series.Path); Mocker.Resolve<DiskScanProvider>().Scan(series, series.Path);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }

View File

@ -29,23 +29,23 @@ namespace NzbDrone.Core.Test.ProviderTests
var fakeEpisode = Builder<Episode>.CreateNew().Build(); var fakeEpisode = Builder<Episode>.CreateNew().Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode }); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
//Assert //Assert
VerifyFileImport(result, mocker, fakeEpisode, 12345); VerifyFileImport(result, Mocker, fakeEpisode, 12345);
} }
@ -65,21 +65,21 @@ namespace NzbDrone.Core.Test.ProviderTests
.And(g => g.Proper = currentFileProper).Build() .And(g => g.Proper = currentFileProper).Build()
).Build(); ).Build();
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode }); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
//Assert //Assert
VerifyFileImport(result, mocker, fakeEpisode, size); VerifyFileImport(result, Mocker, fakeEpisode, size);
} }
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
@ -96,23 +96,23 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode }); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifySkipImport(result, mocker); VerifySkipImport(result, Mocker);
} }
[Test] [Test]
@ -124,19 +124,19 @@ namespace NzbDrone.Core.Test.ProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build(); var fakeSeries = Builder<Series>.CreateNew().Build();
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false); .Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifySkipImport(result, mocker); VerifySkipImport(result, Mocker);
ExceptionVerification.ExcpectedWarns(2); ExceptionVerification.ExcpectedWarns(2);
} }
@ -149,19 +149,19 @@ namespace NzbDrone.Core.Test.ProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build(); var fakeSeries = Builder<Series>.CreateNew().Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false); .Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifySkipImport(result, mocker); VerifySkipImport(result, Mocker);
} }
[Test] [Test]
@ -171,16 +171,16 @@ namespace NzbDrone.Core.Test.ProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build(); var fakeSeries = Builder<Series>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(true); .Returns(true);
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifySkipImport(result, mocker); VerifySkipImport(result, Mocker);
} }
[Test] [Test]
@ -193,24 +193,24 @@ namespace NzbDrone.Core.Test.ProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build(); var fakeSeries = Builder<Series>.CreateNew().Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<DiskProvider>(MockBehavior.Strict) Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
.Setup(e => e.GetSize(fileName)).Returns(90000000000); .Setup(e => e.GetSize(fileName)).Returns(90000000000);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)) .Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifySkipImport(result, mocker); VerifySkipImport(result, Mocker);
} }
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
@ -227,24 +227,24 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode }); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifyFileImport(result, mocker, fakeEpisode, 12345); VerifyFileImport(result, Mocker, fakeEpisode, 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once()); Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
} }
[TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")]
@ -263,24 +263,24 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(fakeEpisodes); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(fakeEpisodes);
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifyFileImport(result, mocker, fakeEpisodes[0], 12345); VerifyFileImport(result, Mocker, fakeEpisodes[0], 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once()); Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
} }
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
@ -298,23 +298,23 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(fakeEpisodes); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(fakeEpisodes);
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifySkipImport(result, mocker); VerifySkipImport(result, Mocker);
} }
[Test] [Test]
@ -339,24 +339,24 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode1, fakeEpisode2 }); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode1, fakeEpisode2 });
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifyFileImport(result, mocker, fakeEpisode1, 12345); VerifyFileImport(result, Mocker, fakeEpisode1, 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2)); Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
} }
[Test] [Test]
@ -373,48 +373,48 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Mocks //Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable(); .Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())) .Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode}); .Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode});
//Act //Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName); var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert //Assert
VerifyFileImport(result, mocker, fakeEpisode, 12345); VerifyFileImport(result, Mocker, fakeEpisode, 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never()); Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
} }
private static void VerifyFileImport(EpisodeFile result, AutoMoqer mocker, Episode fakeEpisode, int size) private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episode fakeEpisode, int size)
{ {
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
result.Should().NotBeNull(); result.Should().NotBeNull();
result.SeriesId.Should().Be(fakeEpisode.SeriesId); result.SeriesId.Should().Be(fakeEpisode.SeriesId);
result.Size.Should().Be(size); result.Size.Should().Be(size);
result.DateAdded.Should().HaveDay(DateTime.Now.Day); result.DateAdded.Should().HaveDay(DateTime.Now.Day);
mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once()); Mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
//Get the count of episodes linked //Get the count of episodes linked
var count = mocker.GetMock<EpisodeProvider>().Object.GetEpisodesByParseResult(null, false).Count; var count = Mocker.GetMock<EpisodeProvider>().Object.GetEpisodesByParseResult(null, false).Count;
mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count)); Mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count));
} }
private static void VerifySkipImport(EpisodeFile result, AutoMoqer mocker) private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker)
{ {
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
result.Should().BeNull(); result.Should().BeNull();
mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never()); Mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never()); Mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never()); Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
} }
} }
} }

View File

@ -20,7 +20,7 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed() public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var parseResult = Builder<EpisodeParseResult>.CreateNew() var parseResult = Builder<EpisodeParseResult>.CreateNew()
.With(c => c.Quality = new Quality(QualityTypes.DVD, false)) .With(c => c.Quality = new Quality(QualityTypes.DVD, false))
.Build(); .Build();
@ -33,38 +33,38 @@ namespace NzbDrone.Core.Test.ProviderTests
const string sabTitle = "My fake sab title"; const string sabTitle = "My fake sab title";
mocker.GetMock<SabProvider>() Mocker.GetMock<SabProvider>()
.Setup(s => s.IsInQueue(It.IsAny<String>())) .Setup(s => s.IsInQueue(It.IsAny<String>()))
.Returns(false); .Returns(false);
mocker.GetMock<SabProvider>() Mocker.GetMock<SabProvider>()
.Setup(s => s.AddByUrl(parseResult.NzbUrl, sabTitle)) .Setup(s => s.AddByUrl(parseResult.NzbUrl, sabTitle))
.Returns(true); .Returns(true);
mocker.GetMock<SabProvider>() Mocker.GetMock<SabProvider>()
.Setup(s => s.GetSabTitle(parseResult)) .Setup(s => s.GetSabTitle(parseResult))
.Returns(sabTitle); .Returns(sabTitle);
mocker.GetMock<HistoryProvider>() Mocker.GetMock<HistoryProvider>()
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5))); .Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)));
mocker.GetMock<HistoryProvider>() Mocker.GetMock<HistoryProvider>()
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5))); .Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)));
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(episodes); .Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(episodes);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.MarkEpisodeAsFetched(12)); .Setup(c => c.MarkEpisodeAsFetched(12));
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.MarkEpisodeAsFetched(99)); .Setup(c => c.MarkEpisodeAsFetched(99));
mocker.GetMock<ExternalNotificationProvider>() Mocker.GetMock<ExternalNotificationProvider>()
.Setup(c => c.OnGrab(It.IsAny<string>())); .Setup(c => c.OnGrab(It.IsAny<string>()));
mocker.Resolve<DownloadProvider>().DownloadReport(parseResult); Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
} }
} }

View File

@ -42,16 +42,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.TvDbEpisodeId = tvDbSeries.Episodes.First().Id) .With(e => e.TvDbEpisodeId = tvDbSeries.Episodes.First().Id)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(fakeSeries); db.Insert(fakeSeries);
db.Insert(fakeEpisode); db.Insert(fakeEpisode);
//Act //Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert //Assert
var result = db.Fetch<Episode>(); var result = db.Fetch<Episode>();
@ -82,16 +82,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.TvDbEpisodeId = 0) .With(e => e.TvDbEpisodeId = 0)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(fakeSeries); db.Insert(fakeSeries);
db.Insert(fakeEpisode); db.Insert(fakeEpisode);
//Act //Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert //Assert
var result = db.Fetch<Episode>(); var result = db.Fetch<Episode>();
@ -122,16 +122,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.TvDbEpisodeId = null) .With(e => e.TvDbEpisodeId = null)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(fakeSeries); db.Insert(fakeSeries);
db.Insert(fakeEpisode); db.Insert(fakeEpisode);
//Act //Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert //Assert
var result = db.Fetch<Episode>(); var result = db.Fetch<Episode>();
@ -164,16 +164,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.TvDbEpisodeId = 300) .With(e => e.TvDbEpisodeId = 300)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(fakeSeries); db.Insert(fakeSeries);
db.Insert(fakeEpisode); db.Insert(fakeEpisode);
//Act //Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert //Assert
var result = db.Fetch<Episode>(); var result = db.Fetch<Episode>();
@ -219,10 +219,10 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.TvDbEpisodeId = 300) .With(e => e.TvDbEpisodeId = 300)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(fakeSeries); db.Insert(fakeSeries);
db.Insert(fakeEpisode); db.Insert(fakeEpisode);
@ -230,7 +230,7 @@ namespace NzbDrone.Core.Test.ProviderTests
db.Insert(otherFakeEpisode); db.Insert(otherFakeEpisode);
//Act //Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert //Assert
var result = db.Fetch<Episode>(); var result = db.Fetch<Episode>();

View File

@ -20,17 +20,17 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_true() public void SendNotification_true()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var header = "NzbDrone Test"; var header = "NzbDrone Test";
var message = "Test Message!"; var message = "Test Message!";
var address = "localhost"; var address = "localhost";
var fakeUdp = mocker.GetMock<UdpProvider>(); var fakeUdp = Mocker.GetMock<UdpProvider>();
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Notification, It.IsAny<byte[]>())).Returns(true); fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Notification, It.IsAny<byte[]>())).Returns(true);
//Act //Act
var result = mocker.Resolve<EventClientProvider>().SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", address); var result = Mocker.Resolve<EventClientProvider>().SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", address);
//Assert //Assert
Assert.AreEqual(true, result); Assert.AreEqual(true, result);
@ -40,17 +40,17 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_false() public void SendNotification_false()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var header = "NzbDrone Test"; var header = "NzbDrone Test";
var message = "Test Message!"; var message = "Test Message!";
var address = "localhost"; var address = "localhost";
var fakeUdp = mocker.GetMock<UdpProvider>(); var fakeUdp = Mocker.GetMock<UdpProvider>();
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Notification, It.IsAny<byte[]>())).Returns(false); fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Notification, It.IsAny<byte[]>())).Returns(false);
//Act //Act
var result = mocker.Resolve<EventClientProvider>().SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", address); var result = Mocker.Resolve<EventClientProvider>().SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", address);
//Assert //Assert
Assert.AreEqual(false, result); Assert.AreEqual(false, result);
@ -60,17 +60,17 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendAction_Update_true() public void SendAction_Update_true()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var path = @"C:\Test\TV\30 Rock"; var path = @"C:\Test\TV\30 Rock";
var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path); var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path);
var address = "localhost"; var address = "localhost";
var fakeUdp = mocker.GetMock<UdpProvider>(); var fakeUdp = Mocker.GetMock<UdpProvider>();
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Action, It.IsAny<byte[]>())).Returns(true); fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Action, It.IsAny<byte[]>())).Returns(true);
//Act //Act
var result = mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command); var result = Mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
//Assert //Assert
Assert.AreEqual(true, result); Assert.AreEqual(true, result);
@ -80,17 +80,17 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendAction_Update_false() public void SendAction_Update_false()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var path = @"C:\Test\TV\30 Rock"; var path = @"C:\Test\TV\30 Rock";
var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path); var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path);
var address = "localhost"; var address = "localhost";
var fakeUdp = mocker.GetMock<UdpProvider>(); var fakeUdp = Mocker.GetMock<UdpProvider>();
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Action, It.IsAny<byte[]>())).Returns(false); fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Action, It.IsAny<byte[]>())).Returns(false);
//Act //Act
var result = mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command); var result = Mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
//Assert //Assert
Assert.AreEqual(false, result); Assert.AreEqual(false, result);

View File

@ -23,52 +23,52 @@ namespace NzbDrone.Core.Test.ProviderTests
public void Register_should_add_new_application_to_local_growl_instance() public void Register_should_add_new_application_to_local_growl_instance()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
mocker.Resolve<GrowlProvider>().Register("localhost", 23053, ""); Mocker.Resolve<GrowlProvider>().Register("localhost", 23053, "");
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void TestNotification_should_send_a_message_to_local_growl_instance() public void TestNotification_should_send_a_message_to_local_growl_instance()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
mocker.Resolve<GrowlProvider>().TestNotification("localhost", 23053, ""); Mocker.Resolve<GrowlProvider>().TestNotification("localhost", 23053, "");
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void OnGrab_should_send_a_message_to_local_growl_instance() public void OnGrab_should_send_a_message_to_local_growl_instance()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
mocker.Resolve<GrowlProvider>().SendNotification("Episode Grabbed", "Series Title - 1x05 - Episode Title", "GRAB", "localhost", 23053, ""); Mocker.Resolve<GrowlProvider>().SendNotification("Episode Grabbed", "Series Title - 1x05 - Episode Title", "GRAB", "localhost", 23053, "");
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void OnDownload_should_send_a_message_to_local_growl_instance() public void OnDownload_should_send_a_message_to_local_growl_instance()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
mocker.Resolve<GrowlProvider>().SendNotification("Episode Downloaded", "Series Title - 1x05 - Episode Title", "DOWNLOAD", "localhost", 23053, ""); Mocker.Resolve<GrowlProvider>().SendNotification("Episode Downloaded", "Series Title - 1x05 - Episode Title", "DOWNLOAD", "localhost", 23053, "");
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
} }
} }

View File

@ -23,14 +23,14 @@ namespace NzbDrone.Core.Test.ProviderTests
//Setup //Setup
var historyItem = Builder<History>.CreateListOfSize(10).Build(); var historyItem = Builder<History>.CreateListOfSize(10).Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(historyItem); db.InsertMany(historyItem);
//Act //Act
var result = mocker.Resolve<HistoryProvider>().AllItems(); var result = Mocker.Resolve<HistoryProvider>().AllItems();
//Assert //Assert
result.Should().HaveSameCount(historyItem); result.Should().HaveSameCount(historyItem);
@ -47,9 +47,9 @@ namespace NzbDrone.Core.Test.ProviderTests
var historyItems = Builder<History>.CreateListOfSize(10).TheFirst(5).With(h => h.SeriesId = seriesOne.SeriesId).TheLast(5).With(h => h.SeriesId = seriesTwo.SeriesId).Build(); var historyItems = Builder<History>.CreateListOfSize(10).TheFirst(5).With(h => h.SeriesId = seriesOne.SeriesId).TheLast(5).With(h => h.SeriesId = seriesTwo.SeriesId).Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(historyItems); db.InsertMany(historyItems);
db.InsertMany(episodes); db.InsertMany(episodes);
@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.ProviderTests
db.Insert(seriesTwo); db.Insert(seriesTwo);
//Act //Act
var result = mocker.Resolve<HistoryProvider>().AllItemsWithRelationships(); var result = Mocker.Resolve<HistoryProvider>().AllItemsWithRelationships();
//Assert //Assert
result.Should().HaveSameCount(historyItems); result.Should().HaveSameCount(historyItems);
@ -75,16 +75,16 @@ namespace NzbDrone.Core.Test.ProviderTests
//Setup //Setup
var historyItem = Builder<History>.CreateListOfSize(10).Build(); var historyItem = Builder<History>.CreateListOfSize(10).Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(historyItem); db.InsertMany(historyItem);
//Act //Act
db.Fetch<History>().Should().HaveCount(10); db.Fetch<History>().Should().HaveCount(10);
mocker.Resolve<HistoryProvider>().Purge(); Mocker.Resolve<HistoryProvider>().Purge();
//Assert //Assert
db.Fetch<History>().Should().HaveCount(0); db.Fetch<History>().Should().HaveCount(0);
@ -99,16 +99,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.TheNext(20).With(c => c.Date = DateTime.Now.AddDays(-31)) .TheNext(20).With(c => c.Date = DateTime.Now.AddDays(-31))
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(historyItem); db.InsertMany(historyItem);
//Act //Act
db.Fetch<History>().Should().HaveCount(30); db.Fetch<History>().Should().HaveCount(30);
mocker.Resolve<HistoryProvider>().Trim(); Mocker.Resolve<HistoryProvider>().Trim();
//Assert //Assert
var result = db.Fetch<History>(); var result = db.Fetch<History>();
@ -120,12 +120,12 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void GetBestQualityInHistory_no_result() public void GetBestQualityInHistory_no_result()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act //Act
var result = mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(12); var result = Mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(12);
//Assert //Assert
Assert.IsNull(result); Assert.IsNull(result);
@ -134,17 +134,17 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void GetBestQualityInHistory_single_result() public void GetBestQualityInHistory_single_result()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
var history = Builder<History>.CreateNew() var history = Builder<History>.CreateNew()
.With(h => h.Quality = QualityTypes.Bluray720p).Build(); .With(h => h.Quality = QualityTypes.Bluray720p).Build();
db.Insert(history); db.Insert(history);
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
var result = mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(history.EpisodeId); var result = Mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(history.EpisodeId);
//Assert //Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
@ -154,10 +154,10 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void add_item() public void add_item()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var episode = Builder<Episode>.CreateNew().Build(); var episode = Builder<Episode>.CreateNew().Build();
@ -176,7 +176,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}; };
//Act //Act
mocker.Resolve<HistoryProvider>().Add(history); Mocker.Resolve<HistoryProvider>().Add(history);
//Assert //Assert
var storedHistory = db.Fetch<History>(); var storedHistory = db.Fetch<History>();

View File

@ -23,13 +23,13 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void Init_indexer_test() public void Init_indexer_test()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act //Act
var indexerProvider = mocker.Resolve<IndexerProvider>(); var indexerProvider = Mocker.Resolve<IndexerProvider>();
indexerProvider.InitializeIndexers(new List<IndexerBase> { mocker.Resolve<MockIndexer>() }); indexerProvider.InitializeIndexers(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
var settings = indexerProvider.GetSettings(typeof(MockIndexer)); var settings = indexerProvider.GetSettings(typeof(MockIndexer));
settings.Enable = true; settings.Enable = true;
indexerProvider.SaveSettings(settings); indexerProvider.SaveSettings(settings);
@ -45,13 +45,13 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void Init_indexer_with_disabled_job() public void Init_indexer_with_disabled_job()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act //Act
var indexerProvider = mocker.Resolve<IndexerProvider>(); var indexerProvider = Mocker.Resolve<IndexerProvider>();
indexerProvider.InitializeIndexers(new List<IndexerBase> { mocker.Resolve<MockIndexer>() }); indexerProvider.InitializeIndexers(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
var settings = indexerProvider.GetSettings(typeof(MockIndexer)); var settings = indexerProvider.GetSettings(typeof(MockIndexer));
settings.Enable = false; settings.Enable = false;
indexerProvider.SaveSettings(settings); indexerProvider.SaveSettings(settings);

View File

@ -72,19 +72,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute() public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series30minutes; parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 184572800; parseResultSingle.Size = 184572800;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -93,19 +93,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute() public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series60minutes; parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 368572800; parseResultSingle.Size = 368572800;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -114,19 +114,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute() public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series30minutes; parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 1.Gigabytes(); parseResultSingle.Size = 1.Gigabytes();
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
@ -135,19 +135,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute() public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series60minutes; parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 1.Gigabytes(); parseResultSingle.Size = 1.Gigabytes();
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
@ -156,19 +156,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute() public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultMulti.Series = series30minutes; parseResultMulti.Series = series30minutes;
parseResultMulti.Size = 184572800; parseResultMulti.Size = 184572800;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -177,19 +177,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute() public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultMulti.Series = series60minutes; parseResultMulti.Series = series60minutes;
parseResultMulti.Size = 368572800; parseResultMulti.Size = 368572800;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -198,19 +198,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute() public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultMulti.Series = series30minutes; parseResultMulti.Series = series30minutes;
parseResultMulti.Size = 1.Gigabytes(); parseResultMulti.Size = 1.Gigabytes();
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
@ -219,19 +219,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute() public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultMulti.Series = series60minutes; parseResultMulti.Series = series60minutes;
parseResultMulti.Size = 10.Gigabytes(); parseResultMulti.Size = 10.Gigabytes();
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
@ -240,19 +240,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_single_episode_first_30_minute() public void IsAcceptableSize_true_single_episode_first_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series30minutes; parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 184572800; parseResultSingle.Size = 184572800;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true); .Returns(true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -261,19 +261,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_single_episode_first_60_minute() public void IsAcceptableSize_true_single_episode_first_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series60minutes; parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 368572800; parseResultSingle.Size = 368572800;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true); .Returns(true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -282,19 +282,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_false_single_episode_first_30_minute() public void IsAcceptableSize_false_single_episode_first_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series30minutes; parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 1.Gigabytes(); parseResultSingle.Size = 1.Gigabytes();
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true); .Returns(true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
@ -303,19 +303,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_false_single_episode_first_60_minute() public void IsAcceptableSize_false_single_episode_first_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series60minutes; parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 10.Gigabytes(); parseResultSingle.Size = 10.Gigabytes();
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true); .Returns(true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
@ -324,20 +324,20 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_unlimited_30_minute() public void IsAcceptableSize_true_unlimited_30_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series30minutes; parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 18457280000; parseResultSingle.Size = 18457280000;
qualityType.MaxSize = 0; qualityType.MaxSize = 0;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true); .Returns(true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -346,20 +346,20 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsAcceptableSize_true_unlimited_60_minute() public void IsAcceptableSize_true_unlimited_60_minute()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series = series60minutes; parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 36857280000; parseResultSingle.Size = 36857280000;
qualityType.MaxSize = 0; qualityType.MaxSize = 0;
mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType); Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup( Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true); .Returns(true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();

View File

@ -86,74 +86,74 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
series.Monitored = false; series.Monitored = false;
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
//Act //Act
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
//Assert //Assert
Assert.IsFalse(result); Assert.IsFalse(result);
Assert.AreSame(series, parseResultMulti.Series); Assert.AreSame(series, parseResultMulti.Series);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void not_in_db_should_be_skipped() public void not_in_db_should_be_skipped()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns<Series>(null); .Returns<Series>(null);
//Act //Act
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
//Assert //Assert
Assert.IsFalse(result); Assert.IsFalse(result);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsMonitored_should_return_true() public void IsMonitored_should_return_true()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true)) .Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode }); .Returns(new List<Episode> { episode });
parseResultSingle.Series.Should().BeNull(); parseResultSingle.Series.Should().BeNull();
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultSingle); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
parseResultSingle.Series.Should().Be(series); parseResultSingle.Series.Should().Be(series);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsMonitored_ignored_single_episode_should_return_false() public void IsMonitored_ignored_single_episode_should_return_false()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true)) .Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode }); .Returns(new List<Episode> { episode });
@ -161,24 +161,24 @@ namespace NzbDrone.Core.Test.ProviderTests
parseResultSingle.Series.Should().BeNull(); parseResultSingle.Series.Should().BeNull();
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultSingle); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultSingle);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
parseResultSingle.Series.Should().Be(series); parseResultSingle.Series.Should().Be(series);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsMonitored_multi_some_episodes_ignored_should_return_true() public void IsMonitored_multi_some_episodes_ignored_should_return_true()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true)) .Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode, episode2 }); .Returns(new List<Episode> { episode, episode2 });
@ -187,24 +187,24 @@ namespace NzbDrone.Core.Test.ProviderTests
parseResultMulti.Series.Should().BeNull(); parseResultMulti.Series.Should().BeNull();
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
parseResultMulti.Series.Should().Be(series); parseResultMulti.Series.Should().Be(series);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsMonitored_multi_all_episodes_ignored_should_return_false() public void IsMonitored_multi_all_episodes_ignored_should_return_false()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true)) .Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode, episode2 }); .Returns(new List<Episode> { episode, episode2 });
@ -213,25 +213,25 @@ namespace NzbDrone.Core.Test.ProviderTests
parseResultSingle.Series.Should().BeNull(); parseResultSingle.Series.Should().BeNull();
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
//Assert //Assert
result.Should().BeFalse(); result.Should().BeFalse();
parseResultMulti.Series.Should().Be(series); parseResultMulti.Series.Should().Be(series);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsMonitored_multi_no_episodes_ignored_should_return_true() public void IsMonitored_multi_no_episodes_ignored_should_return_true()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true)) .Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode, episode2 }); .Returns(new List<Episode> { episode, episode2 });
@ -240,30 +240,30 @@ namespace NzbDrone.Core.Test.ProviderTests
parseResultSingle.Series.Should().BeNull(); parseResultSingle.Series.Should().BeNull();
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
parseResultMulti.Series.Should().Be(series); parseResultMulti.Series.Should().Be(series);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsMonitored_daily_not_ignored_should_return_true() public void IsMonitored_daily_not_ignored_should_return_true()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<SeriesProvider>() Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>())) .Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series); .Returns(series);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true)) .Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode }); .Returns(new List<Episode> { episode });
episode.Ignored = false; episode.Ignored = false;
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultDaily); var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultDaily);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();

View File

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.ProviderTests
private Series series; private Series series;
[SetUp] [SetUp]
public new void Setup() public void Setup()
{ {
parseResultMulti = new EpisodeParseResult parseResultMulti = new EpisodeParseResult
{ {
@ -108,145 +108,145 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void IsQualityNeeded_report_not_in_quality_profile_should_be_skipped() public void IsQualityNeeded_report_not_in_quality_profile_should_be_skipped()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultMulti.Series.QualityProfile = sdProfile; parseResultMulti.Series.QualityProfile = sdProfile;
parseResultMulti.Quality = new Quality(QualityTypes.HDTV, true); parseResultMulti.Quality = new Quality(QualityTypes.HDTV, true);
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultMulti); bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultMulti);
//Assert //Assert
Assert.IsFalse(result); Assert.IsFalse(result);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsQualityNeeded_file_already_at_cut_off_should_be_skipped() public void IsQualityNeeded_file_already_at_cut_off_should_be_skipped()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultMulti.Series.QualityProfile = hdProfile; parseResultMulti.Series.QualityProfile = hdProfile;
parseResultMulti.Quality = new Quality(QualityTypes.HDTV, true); parseResultMulti.Quality = new Quality(QualityTypes.HDTV, true);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(parseResultMulti, true)) .Setup(p => p.GetEpisodesByParseResult(parseResultMulti, true))
.Returns(new List<Episode> { episode, episode2 }); .Returns(new List<Episode> { episode, episode2 });
mocker.GetMock<QualityTypeProvider>() Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>())) .Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 }); .Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.Bluray720p; episode.EpisodeFile.Quality = QualityTypes.Bluray720p;
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultMulti); bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultMulti);
//Assert //Assert
Assert.IsFalse(result); Assert.IsFalse(result);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsQualityNeeded_file_in_history_should_be_skipped() public void IsQualityNeeded_file_in_history_should_be_skipped()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series.QualityProfile = sdProfile; parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD; parseResultSingle.Quality.QualityType = QualityTypes.DVD;
mocker.GetMock<HistoryProvider>() Mocker.GetMock<HistoryProvider>()
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId)) .Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns(new Quality(QualityTypes.DVD, true)); .Returns(new Quality(QualityTypes.DVD, true));
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true)) .Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode }); .Returns(new List<Episode> { episode });
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) .Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
mocker.GetMock<QualityTypeProvider>() Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>())) .Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 }); .Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.SDTV; episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle);
//Assert //Assert
Assert.IsFalse(result); Assert.IsFalse(result);
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsQualityNeeded_lesser_file_in_history_should_be_downloaded() public void IsQualityNeeded_lesser_file_in_history_should_be_downloaded()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series.QualityProfile = sdProfile; parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD; parseResultSingle.Quality.QualityType = QualityTypes.DVD;
mocker.GetMock<HistoryProvider>() Mocker.GetMock<HistoryProvider>()
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId)) .Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns(new Quality(QualityTypes.SDTV, true)); .Returns(new Quality(QualityTypes.SDTV, true));
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true)) .Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode }); .Returns(new List<Episode> { episode });
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) .Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
mocker.GetMock<QualityTypeProvider>() Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>())) .Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 }); .Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.SDTV; episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void IsQualityNeeded_file_not_in_history_should_be_downloaded() public void IsQualityNeeded_file_not_in_history_should_be_downloaded()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
parseResultSingle.Series.QualityProfile = sdProfile; parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD; parseResultSingle.Quality.QualityType = QualityTypes.DVD;
mocker.GetMock<HistoryProvider>() Mocker.GetMock<HistoryProvider>()
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId)) .Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns<Quality>(null); .Returns<Quality>(null);
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true)) .Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode }); .Returns(new List<Episode> { episode });
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) .Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false); .Returns(false);
mocker.GetMock<QualityTypeProvider>() Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>())) .Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 }); .Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.SDTV; episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act //Act
bool result = mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle); bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
//Should Download //Should Download

View File

@ -28,7 +28,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10) var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
.All().With(s => s.SeriesId = 20).Build(); .All().With(s => s.SeriesId = 20).Build();
var mocker = new AutoMoqer();
var database = TestDbHelper.GetEmptyDatabase(true); var database = TestDbHelper.GetEmptyDatabase(true);
@ -36,9 +36,9 @@ namespace NzbDrone.Core.Test.ProviderTests
database.InsertMany(firstSeriesFiles); database.InsertMany(firstSeriesFiles);
database.InsertMany(secondSeriesFiles); database.InsertMany(secondSeriesFiles);
mocker.SetConstant(database); Mocker.SetConstant(database);
var result = mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12); var result = Mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
result.Should().HaveSameCount(firstSeriesFiles); result.Should().HaveSameCount(firstSeriesFiles);
@ -59,16 +59,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.SeasonNumber = 2) .With(s => s.SeasonNumber = 2)
.Build(); .Build();
var mocker = new AutoMoqer();
var database = TestDbHelper.GetEmptyDatabase(true); var database = TestDbHelper.GetEmptyDatabase(true);
database.InsertMany(firstSeriesFiles); database.InsertMany(firstSeriesFiles);
database.InsertMany(secondSeriesFiles); database.InsertMany(secondSeriesFiles);
mocker.SetConstant(database); Mocker.SetConstant(database);
var result = mocker.Resolve<MediaFileProvider>().GetSeasonFiles(12, 1); var result = Mocker.Resolve<MediaFileProvider>().GetSeasonFiles(12, 1);
result.Should().HaveSameCount(firstSeriesFiles); result.Should().HaveSameCount(firstSeriesFiles);
} }
@ -76,19 +76,19 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void Scan_series_should_skip_series_with_no_episodes() public void Scan_series_should_skip_series_with_no_episodes()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodeBySeries(12)) .Setup(c => c.GetEpisodeBySeries(12))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(e => e.RepairLinks()).Returns(0); .Setup(e => e.RepairLinks()).Returns(0);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(e => e.DeleteOrphaned()).Returns(0); .Setup(e => e.DeleteOrphaned()).Returns(0);
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(It.IsAny<string>())) .Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
@ -96,10 +96,10 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.SeriesId = 12).Build(); .With(s => s.SeriesId = 12).Build();
//Act //Act
mocker.Resolve<DiskScanProvider>().Scan(series); Mocker.Resolve<DiskScanProvider>().Scan(series);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
@ -120,13 +120,13 @@ namespace NzbDrone.Core.Test.ProviderTests
//Setup //Setup
var episodes = Builder<Episode>.CreateListOfSize(10).Build(); var episodes = Builder<Episode>.CreateListOfSize(10).Build();
var mocker = new AutoMoqer();
var database = TestDbHelper.GetEmptyDatabase(true); var database = TestDbHelper.GetEmptyDatabase(true);
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodes); database.InsertMany(episodes);
//Act //Act
var removedLinks = mocker.Resolve<MediaFileProvider>().RepairLinks(); var removedLinks = Mocker.Resolve<MediaFileProvider>().RepairLinks();
var result = database.Fetch<Episode>(); var result = database.Fetch<Episode>();
//Assert //Assert
@ -142,14 +142,14 @@ namespace NzbDrone.Core.Test.ProviderTests
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10).Build(); var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10).Build();
var episodes = Builder<Episode>.CreateListOfSize(5).Build(); var episodes = Builder<Episode>.CreateListOfSize(5).Build();
var mocker = new AutoMoqer();
var database = TestDbHelper.GetEmptyDatabase(true); var database = TestDbHelper.GetEmptyDatabase(true);
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodes); database.InsertMany(episodes);
database.InsertMany(episodeFiles); database.InsertMany(episodeFiles);
//Act //Act
mocker.Resolve<MediaFileProvider>().DeleteOrphaned(); Mocker.Resolve<MediaFileProvider>().DeleteOrphaned();
var result = database.Fetch<EpisodeFile>(); var result = database.Fetch<EpisodeFile>();
//Assert //Assert
@ -172,11 +172,11 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.SeasonFolder = useSeasonFolder) .With(s => s.SeasonFolder = useSeasonFolder)
.Build(); .Build();
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat); Mocker.GetMock<ConfigProvider>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat);
//Act //Act
var result = mocker.Resolve<MediaFileProvider>().CalculateFilePath(fakeSeries, 1, filename, ".mkv"); var result = Mocker.Resolve<MediaFileProvider>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
//Assert //Assert
Assert.AreEqual(expectedPath, result.FullName); Assert.AreEqual(expectedPath, result.FullName);
@ -188,13 +188,13 @@ namespace NzbDrone.Core.Test.ProviderTests
//Setup //Setup
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10).Build(); var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10).Build();
var mocker = new AutoMoqer();
var database = TestDbHelper.GetEmptyDatabase(true); var database = TestDbHelper.GetEmptyDatabase(true);
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodeFiles); database.InsertMany(episodeFiles);
//Act //Act
mocker.Resolve<MediaFileProvider>().Delete(1); Mocker.Resolve<MediaFileProvider>().Delete(1);
var result = database.Fetch<EpisodeFile>(); var result = database.Fetch<EpisodeFile>();
//Assert //Assert

View File

@ -21,9 +21,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() public void GetNewFilename_Series_Episode_Quality_S01E05_Dash()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV]", result); Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV]", result);
@ -48,9 +48,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_Episode_Quality_1x05_Dash() public void GetNewFilename_Episode_Quality_1x05_Dash()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -65,7 +65,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("15x06 - City Sushi [HDTV]", result); Assert.AreEqual("15x06 - City Sushi [HDTV]", result);
@ -75,9 +75,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_Series_Quality_01x05_Space() public void GetNewFilename_Series_Quality_01x05_Space()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("South Park 05x06 [HDTV]", result); Assert.AreEqual("South Park 05x06 [HDTV]", result);
@ -102,9 +102,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_Series_s01e05_Space() public void GetNewFilename_Series_s01e05_Space()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -120,7 +120,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("South Park s05e06", result); Assert.AreEqual("South Park s05e06", result);
@ -130,9 +130,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_Series_Episode_s01e05_Periods() public void GetNewFilename_Series_Episode_s01e05_Periods()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -147,7 +147,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("South.Park.s05e06.City.Sushi", result); Assert.AreEqual("South.Park.s05e06.City.Sushi", result);
@ -157,9 +157,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -174,7 +174,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV]", result); Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV]", result);
@ -184,9 +184,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_S01E05_Dash() public void GetNewFilename_S01E05_Dash()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -202,7 +202,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode }, "South Park", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("S15E06", result); Assert.AreEqual("S15E06", result);
@ -212,9 +212,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -236,7 +236,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
@ -246,9 +246,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -270,7 +270,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("3x23x24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); Assert.AreEqual("3x23x24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
@ -280,9 +280,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -304,7 +304,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("3x23x24 Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); Assert.AreEqual("3x23x24 Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
@ -314,9 +314,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -338,7 +338,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream.(1).+.Strawberries.and.Cream.(2)", result); Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream.(1).+.Strawberries.and.Cream.(2)", result);
@ -348,9 +348,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -372,7 +372,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("The.Mentalist.-.S03E23-24", result); Assert.AreEqual("The.Mentalist.-.S03E23-24", result);
@ -382,9 +382,9 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetNewFilename_multi_1x05_Repeat_Dash_Period() public void GetNewFilename_multi_1x05_Repeat_Dash_Period()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -406,7 +406,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Build(); .Build();
//Act //Act
string result = mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV);
//Assert //Assert
Assert.AreEqual("3x23x24", result); Assert.AreEqual("3x23x24", result);

View File

@ -7,12 +7,13 @@ using NUnit.Framework;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq; using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests namespace NzbDrone.Core.Test.ProviderTests
{ {
[TestFixture] [TestFixture]
public class MisnamedProviderTest public class MisnamedProviderTest : CoreTest
{ {
[Test] [Test]
public void no_misnamed_files() public void no_misnamed_files()
@ -42,22 +43,22 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> {episodes[0]}, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title1"); .Returns("Title1");
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> {episodes[1]}, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2"); .Returns("Title2");
//Act //Act
var totalItems = 0; var totalItems = 0;
var misnamedEpisodes = mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems); var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert //Assert
misnamedEpisodes.Should().HaveCount(0); misnamedEpisodes.Should().HaveCount(0);
@ -91,22 +92,22 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 1"); .Returns("New Title 1");
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 2"); .Returns("New Title 2");
//Act //Act
var totalItems = 0; var totalItems = 0;
var misnamedEpisodes = mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems); var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert //Assert
misnamedEpisodes.Should().HaveCount(2); misnamedEpisodes.Should().HaveCount(2);
@ -140,22 +141,22 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 1"); .Returns("New Title 1");
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2"); .Returns("Title2");
//Act //Act
var totalItems = 0; var totalItems = 0;
var misnamedEpisodes = mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems); var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert //Assert
misnamedEpisodes.Should().HaveCount(1); misnamedEpisodes.Should().HaveCount(1);
@ -191,22 +192,22 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 1"); .Returns("New Title 1");
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2"); .Returns("Title2");
//Act //Act
var totalItems = 0; var totalItems = 0;
var misnamedEpisodes = mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems); var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert //Assert
misnamedEpisodes.Should().HaveCount(1); misnamedEpisodes.Should().HaveCount(1);
@ -242,22 +243,22 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.EpisodeFile = episodeFiles[1]) .With(e => e.EpisodeFile = episodeFiles[1])
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes); .Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title1"); .Returns("Title1");
mocker.GetMock<MediaFileProvider>() Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>())) .Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2"); .Returns("Title2");
//Act //Act
var totalItems = 0; var totalItems = 0;
var misnamedEpisodes = mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems); var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert //Assert
misnamedEpisodes.Should().HaveCount(0); misnamedEpisodes.Should().HaveCount(0);

View File

@ -23,12 +23,12 @@ namespace NzbDrone.Core.Test.ProviderTests
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" }; var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" };
var expectedUrl = "http://www.nzbdrone.com"; var expectedUrl = "http://www.nzbdrone.com";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
var result = mocker.Resolve<NewznabProvider>().Save(newznab); var result = Mocker.Resolve<NewznabProvider>().Save(newznab);
//Assert //Assert
db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl);
@ -42,15 +42,15 @@ namespace NzbDrone.Core.Test.ProviderTests
var expectedUrl = "http://www.nzbdrone.com"; var expectedUrl = "http://www.nzbdrone.com";
var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world"; var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
newznab.Id = Convert.ToInt32(db.Insert(newznab)); newznab.Id = Convert.ToInt32(db.Insert(newznab));
newznab.Url = newUrl; newznab.Url = newUrl;
//Act //Act
var result = mocker.Resolve<NewznabProvider>().Save(newznab); var result = Mocker.Resolve<NewznabProvider>().Save(newznab);
//Assert //Assert
db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl);
@ -63,12 +63,12 @@ namespace NzbDrone.Core.Test.ProviderTests
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" }; var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" };
var expectedUrl = ""; var expectedUrl = "";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
var result = mocker.Resolve<NewznabProvider>().Save(newznab); var result = Mocker.Resolve<NewznabProvider>().Save(newznab);
//Assert //Assert
db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl);
@ -82,15 +82,15 @@ namespace NzbDrone.Core.Test.ProviderTests
var expectedUrl = ""; var expectedUrl = "";
var newUrl = ""; var newUrl = "";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
newznab.Id = Convert.ToInt32(db.Insert(newznab)); newznab.Id = Convert.ToInt32(db.Insert(newznab));
newznab.Url = newUrl; newznab.Url = newUrl;
//Act //Act
var result = mocker.Resolve<NewznabProvider>().Save(newznab); var result = Mocker.Resolve<NewznabProvider>().Save(newznab);
//Assert //Assert
db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl);
@ -107,16 +107,16 @@ namespace NzbDrone.Core.Test.ProviderTests
var expectedUrl = "http://www.nzbdrone.com"; var expectedUrl = "http://www.nzbdrone.com";
var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world"; var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(definitions); db.InsertMany(definitions);
definitions.ToList().ForEach(d => d.Url = newUrl); definitions.ToList().ForEach(d => d.Url = newUrl);
//Act //Act
mocker.Resolve<NewznabProvider>().SaveAll(definitions); Mocker.Resolve<NewznabProvider>().SaveAll(definitions);
//Assert //Assert
db.Fetch<NewznabDefinition>().Where(d => d.Url == expectedUrl).Should().HaveCount(5); db.Fetch<NewznabDefinition>().Where(d => d.Url == expectedUrl).Should().HaveCount(5);
@ -133,14 +133,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(d => d.Enable = true) .With(d => d.Enable = true)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(definitions); db.InsertMany(definitions);
//Act //Act
var result = mocker.Resolve<NewznabProvider>().Enabled(); var result = Mocker.Resolve<NewznabProvider>().Enabled();
//Assert //Assert
result.Should().HaveCount(3); result.Should().HaveCount(3);
@ -158,14 +158,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(d => d.Enable = true) .With(d => d.Enable = true)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(definitions); db.InsertMany(definitions);
//Act //Act
var result = mocker.Resolve<NewznabProvider>().All(); var result = Mocker.Resolve<NewznabProvider>().All();
//Assert //Assert
result.Should().HaveCount(5); result.Should().HaveCount(5);
@ -182,14 +182,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(d => d.Enable = true) .With(d => d.Enable = true)
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.InsertMany(definitions); db.InsertMany(definitions);
//Act //Act
mocker.Resolve<NewznabProvider>().Delete(1); Mocker.Resolve<NewznabProvider>().Delete(1);
//Assert //Assert
var result = db.Fetch<NewznabDefinition>(); var result = db.Fetch<NewznabDefinition>();
@ -206,12 +206,12 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(d => d.Url = "http://www.nzbdrone.com") .With(d => d.Url = "http://www.nzbdrone.com")
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
mocker.Resolve<NewznabProvider>().InitializeNewznabIndexers(definitions); Mocker.Resolve<NewznabProvider>().InitializeNewznabIndexers(definitions);
//Assert //Assert
var result = db.Fetch<NewznabDefinition>(); var result = db.Fetch<NewznabDefinition>();
@ -231,15 +231,15 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(d => d.Url = "http://www.nzbdrone.com") .With(d => d.Url = "http://www.nzbdrone.com")
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(definitions[0]); db.Insert(definitions[0]);
db.Insert(definitions[1]); db.Insert(definitions[1]);
//Act //Act
mocker.Resolve<NewznabProvider>().InitializeNewznabIndexers(definitions); Mocker.Resolve<NewznabProvider>().InitializeNewznabIndexers(definitions);
//Assert //Assert
var result = db.Fetch<NewznabDefinition>(); var result = db.Fetch<NewznabDefinition>();

View File

@ -23,30 +23,28 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
[Test] [Test]
public void should_skip_if_folder_is_tagged_and_too_fresh() public void should_skip_if_folder_is_tagged_and_too_fresh()
{ {
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\"); var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
droppedFolder.Create(); droppedFolder.Create();
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
} }
[Test] [Test]
public void should_continue_processing_if_folder_is_tagged_and_not_fresh() public void should_continue_processing_if_folder_is_tagged_and_not_fresh()
{ {
var mocker = new AutoMoqer(MockBehavior.Loose);
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\"); var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
droppedFolder.Create(); droppedFolder.Create();
droppedFolder.LastWriteTime = DateTime.Now.AddMinutes(-2); droppedFolder.LastWriteTime = DateTime.Now.AddMinutes(-2);
//Act //Act
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null).Verifiable(); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null).Verifiable();
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -54,17 +52,15 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
[Test] [Test]
public void should_search_for_series_using_title_without_status() public void should_search_for_series_using_title_without_status()
{ {
//Setup
var mocker = new AutoMoqer(MockBehavior.Loose);
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\_unpack_The Office - S01E01 - Episode Title"); var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\_unpack_The Office - S01E01 - Episode Title");
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null).Verifiable(); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null).Verifiable();
//Act //Act
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -72,19 +68,19 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void when_series_isnt_found_folder_should_be_tagged_as_unknown_series() public void when_series_isnt_found_folder_should_be_tagged_as_unknown_series()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title"); var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title"; var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title";
//Act //Act
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null);
mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -92,7 +88,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void when_no_files_are_imported_folder_should_be_tagged_with_parse_error() public void when_no_files_are_imported_folder_should_be_tagged_with_parse_error()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title"); var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
var taggedFolder = @"C:\Test\Unsorted TV\_ParseError_The Office - S01E01 - Episode Title"; var taggedFolder = @"C:\Test\Unsorted TV\_ParseError_The Office - S01E01 - Episode Title";
@ -102,16 +98,16 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Build(); .Build();
//Act //Act
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(new List<EpisodeFile>()); Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(new List<EpisodeFile>());
mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes()); Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -120,7 +116,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void when_no_file_are_imported_and_folder_size_isnt_small_enought_folder_should_be_tagged_unknown() public void when_no_file_are_imported_and_folder_size_isnt_small_enought_folder_should_be_tagged_unknown()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01"); var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown); var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown);
@ -135,16 +131,16 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Build().ToList(); .Build().ToList();
//Act //Act
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes()); Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true); Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true);
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -155,39 +151,39 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void folder_shouldnt_be_tagged_with_same_tag_again(string path) public void folder_shouldnt_be_tagged_with_same_tag_again(string path)
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var droppedFolder = new DirectoryInfo(TempFolder + path); var droppedFolder = new DirectoryInfo(TempFolder + path);
droppedFolder.Create(); droppedFolder.Create();
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1); droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
//Act //Act
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null);
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never()); Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
} }
[Test] [Test]
public void folder_should_be_tagged_if_existing_tag_is_diffrent() public void folder_should_be_tagged_if_existing_tag_is_diffrent()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title"); var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title");
droppedFolder.Create(); droppedFolder.Create();
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1); droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title"; var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title";
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null);
//Act //Act
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(droppedFolder.FullName, taggedFolder), Times.Once()); Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(droppedFolder.FullName, taggedFolder), Times.Once());
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -195,7 +191,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
public void when_files_are_imported_and_folder_is_small_enought_dir_should_be_deleted() public void when_files_are_imported_and_folder_is_small_enought_dir_should_be_deleted()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01"); var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
var fakeSeries = Builder<Series>.CreateNew() var fakeSeries = Builder<Series>.CreateNew()
@ -207,24 +203,22 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.With(f => f.SeriesId = fakeSeries.SeriesId) .With(f => f.SeriesId = fakeSeries.SeriesId)
.Build().ToList(); .Build().ToList();
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true); Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true);
mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes()); Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true)); Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true));
//Act //Act
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void all_imported_files_should_be_moved() public void all_imported_files_should_be_moved()
{ {
//Setup
var mocker = new AutoMoqer(MockBehavior.Loose);
var droppedFolder = new DirectoryInfo(TempFolder); var droppedFolder = new DirectoryInfo(TempFolder);
var fakeSeries = Builder<Series>.CreateNew() var fakeSeries = Builder<Series>.CreateNew()
@ -233,16 +227,16 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2) var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.Build().ToList(); .Build().ToList();
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<string>())).Returns(fakeSeries); Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<string>())).Returns(fakeSeries);
mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
//Act //Act
mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder); Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
//Assert //Assert
mocker.GetMock<DiskScanProvider>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true), Mocker.GetMock<DiskScanProvider>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true),
Times.Exactly(fakeEpisodeFiles.Count)); Times.Exactly(fakeEpisodeFiles.Count));
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }

View File

@ -30,10 +30,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void Verify_should_return_true_for_a_valid_apiKey() public void Verify_should_return_true_for_a_valid_apiKey()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().Verify(_apiKey); var result = Mocker.Resolve<ProwlProvider>().Verify(_apiKey);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -43,10 +43,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void Verify_should_return_false_for_an_invalid_apiKey() public void Verify_should_return_false_for_an_invalid_apiKey()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().Verify(_badApiKey); var result = Mocker.Resolve<ProwlProvider>().Verify(_badApiKey);
//Assert //Assert
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
@ -57,10 +57,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_return_true_for_a_valid_apiKey() public void SendNotification_should_return_true_for_a_valid_apiKey()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -70,10 +70,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_return_false_for_an_invalid_apiKey() public void SendNotification_should_return_false_for_an_invalid_apiKey()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _badApiKey); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _badApiKey);
//Assert //Assert
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
@ -84,10 +84,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_alert_with_high_priority() public void SendNotification_should_alert_with_high_priority()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (High)", _apiKey, NotificationPriority.High); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (High)", _apiKey, NotificationPriority.High);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -97,10 +97,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_alert_with_VeryLow_priority() public void SendNotification_should_alert_with_VeryLow_priority()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (VeryLow)", _apiKey, NotificationPriority.VeryLow); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (VeryLow)", _apiKey, NotificationPriority.VeryLow);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -110,10 +110,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_have_a_call_back_url() public void SendNotification_should_have_a_call_back_url()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey, NotificationPriority.Normal, "http://www.nzbdrone.com"); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey, NotificationPriority.Normal, "http://www.nzbdrone.com");
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -123,10 +123,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_return_true_for_two_valid_apiKey() public void SendNotification_should_return_true_for_two_valid_apiKey()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _apiKey2); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _apiKey2);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -136,10 +136,10 @@ namespace NzbDrone.Core.Test.ProviderTests
public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey() public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
//Act //Act
var result = mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _badApiKey); var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _badApiKey);
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();

View File

@ -19,15 +19,15 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void SetupDefault_should_add_six_profiles() public void SetupDefault_should_add_six_profiles()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
mocker.Resolve<QualityTypeProvider>().SetupDefault(); Mocker.Resolve<QualityTypeProvider>().SetupDefault();
//Assert //Assert
var types = mocker.Resolve<QualityTypeProvider>().All(); var types = Mocker.Resolve<QualityTypeProvider>().All();
types.Should().HaveCount(6); types.Should().HaveCount(6);
types.Should().Contain(e => e.Name == "SDTV" && e.QualityTypeId == 1); types.Should().Contain(e => e.Name == "SDTV" && e.QualityTypeId == 1);
@ -41,9 +41,9 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void SetupDefault_already_exists() public void SetupDefault_already_exists()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var fakeQualityType = Builder<QualityType>.CreateNew() var fakeQualityType = Builder<QualityType>.CreateNew()
.Build(); .Build();
@ -51,10 +51,10 @@ namespace NzbDrone.Core.Test.ProviderTests
db.Insert(fakeQualityType); db.Insert(fakeQualityType);
//Act //Act
mocker.Resolve<QualityTypeProvider>().SetupDefault(); Mocker.Resolve<QualityTypeProvider>().SetupDefault();
//Assert //Assert
var types = mocker.Resolve<QualityTypeProvider>().All(); var types = Mocker.Resolve<QualityTypeProvider>().All();
types.Should().HaveCount(1); types.Should().HaveCount(1);
} }
@ -62,9 +62,9 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void GetList_single_quality_type() public void GetList_single_quality_type()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var fakeQualityTypes = Builder<QualityType>.CreateListOfSize(6) var fakeQualityTypes = Builder<QualityType>.CreateListOfSize(6)
.Build(); .Build();
@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.ProviderTests
db.InsertMany(fakeQualityTypes); db.InsertMany(fakeQualityTypes);
//Act //Act
var result = mocker.Resolve<QualityTypeProvider>().GetList(ids); var result = Mocker.Resolve<QualityTypeProvider>().GetList(ids);
//Assert //Assert
result.Should().HaveCount(ids.Count); result.Should().HaveCount(ids.Count);
@ -83,9 +83,9 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test] [Test]
public void GetList_multiple_quality_type() public void GetList_multiple_quality_type()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var fakeQualityTypes = Builder<QualityType>.CreateListOfSize(6) var fakeQualityTypes = Builder<QualityType>.CreateListOfSize(6)
.Build(); .Build();
@ -95,7 +95,7 @@ namespace NzbDrone.Core.Test.ProviderTests
db.InsertMany(fakeQualityTypes); db.InsertMany(fakeQualityTypes);
//Act //Act
var result = mocker.Resolve<QualityTypeProvider>().GetList(ids); var result = Mocker.Resolve<QualityTypeProvider>().GetList(ids);
//Assert //Assert
result.Should().HaveCount(ids.Count); result.Should().HaveCount(ids.Count);

View File

@ -24,19 +24,19 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetRootDirs() public void GetRootDirs()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var emptyDatabase = TestDbHelper.GetEmptyDatabase(); var emptyDatabase = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(emptyDatabase); Mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(new RootDir { Path = @"C:\TV" }); emptyDatabase.Insert(new RootDir { Path = @"C:\TV" });
emptyDatabase.Insert(new RootDir { Path = @"C:\TV2" }); emptyDatabase.Insert(new RootDir { Path = @"C:\TV2" });
//mocker.GetMock<IRepository>() //Mocker.GetMock<IRepository>()
// .Setup(f => f.All<RootDir>()) // .Setup(f => f.All<RootDir>())
// .Returns(sonicRepo.All<RootDir>); // .Returns(sonicRepo.All<RootDir>);
//Act //Act
var result = mocker.Resolve<RootDirProvider>().GetAll(); var result = Mocker.Resolve<RootDirProvider>().GetAll();
//Assert //Assert
Assert.AreEqual(result.Count, 2); Assert.AreEqual(result.Count, 2);
@ -47,11 +47,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void AddRootDir(string path) public void AddRootDir(string path)
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act //Act
var rootDirProvider = mocker.Resolve<RootDirProvider>(); var rootDirProvider = Mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir { Path = path }); rootDirProvider.Add(new RootDir { Path = path });
@ -67,11 +67,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void RemoveRootDir() public void RemoveRootDir()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act //Act
var rootDirProvider = mocker.Resolve<RootDirProvider>(); var rootDirProvider = Mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir { Path = @"C:\TV" }); rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
rootDirProvider.Remove(1); rootDirProvider.Remove(1);
@ -84,14 +84,14 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetRootDir() public void GetRootDir()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
const int id = 1; const int id = 1;
const string path = @"C:\TV"; const string path = @"C:\TV";
//Act //Act
var rootDirProvider = mocker.Resolve<RootDirProvider>(); var rootDirProvider = Mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir { Id = id, Path = path }); rootDirProvider.Add(new RootDir { Id = id, Path = path });
//Assert //Assert
@ -105,24 +105,24 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
const string path = "d:\\bad folder"; const string path = "d:\\bad folder";
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>(MockBehavior.Strict) Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
.Setup(m => m.FolderExists(path)).Returns(false); .Setup(m => m.FolderExists(path)).Returns(false);
var result = mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path); var result = Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
result.Should().NotBeNull(); result.Should().NotBeNull();
result.Should().BeEmpty(); result.Should().BeEmpty();
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException))]
public void empty_folder_path_throws() public void empty_folder_path_throws()
{ {
var mocker = new AutoMoqer();
mocker.Resolve<RootDirProvider>().GetUnmappedFolders(""); Mocker.Resolve<RootDirProvider>().GetUnmappedFolders("");
} }
[TestCase("")] [TestCase("")]
@ -131,8 +131,8 @@ namespace NzbDrone.Core.Test.ProviderTests
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException))]
public void invalid_folder_path_throws_on_add(string path) public void invalid_folder_path_throws_on_add(string path)
{ {
var mocker = new AutoMoqer();
mocker.Resolve<RootDirProvider>().Add(new RootDir { Id = 0, Path = path }); Mocker.Resolve<RootDirProvider>().Add(new RootDir { Id = 0, Path = path });
} }
} }

View File

@ -36,9 +36,9 @@ namespace NzbDrone.Core.Test.ProviderTests
const string category = "tv"; const string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeConfig.SetupGet(c => c.SabTvCategory) fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category); .Returns(category);
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup( .Setup(
s => s =>
s.DownloadString( s.DownloadString(
@ -62,7 +62,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Returns("ok"); .Returns("ok");
//Act //Act
bool result = mocker.Resolve<SabProvider>().AddByUrl( bool result = Mocker.Resolve<SabProvider>().AddByUrl(
"http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb"); "http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb");
//Assert //Assert
@ -83,9 +83,9 @@ namespace NzbDrone.Core.Test.ProviderTests
const string category = "tv"; const string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeConfig.SetupGet(c => c.SabTvCategory) fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category); .Returns(category);
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup( .Setup(
s => s =>
s.DownloadString( s.DownloadString(
@ -109,7 +109,7 @@ namespace NzbDrone.Core.Test.ProviderTests
.Returns("ok"); .Returns("ok");
//Act //Act
bool result = mocker.Resolve<SabProvider>().AddByUrl( bool result = Mocker.Resolve<SabProvider>().AddByUrl(
"http://www.newzbin.com/browse/post/6107863/nzb", "This is an Nzb"); "http://www.newzbin.com/browse/post/6107863/nzb", "This is an Nzb");
//Assert //Assert
@ -128,9 +128,9 @@ namespace NzbDrone.Core.Test.ProviderTests
var priority = SabnzbdPriorityType.Normal; var priority = SabnzbdPriorityType.Normal;
string category = "tv"; string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -145,12 +145,12 @@ namespace NzbDrone.Core.Test.ProviderTests
.Returns(priority); .Returns(priority);
fakeConfig.SetupGet(c => c.SabTvCategory) fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category); .Returns(category);
mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(It.IsAny<String>())) .Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns("error"); .Returns("error");
//Act //Act
var sabProvider = mocker.Resolve<SabProvider>(); var sabProvider = Mocker.Resolve<SabProvider>();
var result = sabProvider.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an nzb"); var result = sabProvider.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an nzb");
//Assert //Assert
@ -168,9 +168,9 @@ namespace NzbDrone.Core.Test.ProviderTests
string username = "admin"; string username = "admin";
string password = "pass"; string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -182,12 +182,12 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeConfig.SetupGet(c => c.SabPassword) fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password); .Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Queue.xml")); .Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act //Act
bool result = mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test"); bool result = Mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
//Assert //Assert
result.Should().BeTrue(); result.Should().BeTrue();
@ -203,9 +203,9 @@ namespace NzbDrone.Core.Test.ProviderTests
string username = "admin"; string username = "admin";
string password = "pass"; string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -217,12 +217,12 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeConfig.SetupGet(c => c.SabPassword) fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password); .Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml")); .Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
//Act //Act
bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty); bool result = Mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert //Assert
Assert.IsFalse(result); Assert.IsFalse(result);
@ -239,9 +239,9 @@ namespace NzbDrone.Core.Test.ProviderTests
string username = "admin"; string username = "admin";
string password = "pass"; string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -253,13 +253,13 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeConfig.SetupGet(c => c.SabPassword) fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password); .Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueError.xml")); .Returns(File.ReadAllText(@".\Files\QueueError.xml"));
//Act //Act
mocker.Resolve<SabProvider>().IsInQueue(String.Empty); Mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
} }
[Test] [Test]
@ -271,7 +271,7 @@ namespace NzbDrone.Core.Test.ProviderTests
[TestCase(1, new[] { 2, 4 }, "", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - [HDTV] [Proper]")] [TestCase(1, new[] { 2, 4 }, "", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - [HDTV] [Proper]")]
public void sab_title(int seasons, int[] episodes, string title, QualityTypes quality, bool proper, string expected) public void sab_title(int seasons, int[] episodes, string title, QualityTypes quality, bool proper, string expected)
{ {
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name") .With(c => c.Path = @"d:\tv shows\My Series Name")
@ -288,7 +288,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}; };
//Act //Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult); var actual = Mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert //Assert
Assert.AreEqual(expected, actual); Assert.AreEqual(expected, actual);
@ -298,7 +298,7 @@ namespace NzbDrone.Core.Test.ProviderTests
[TestCase(false, "My Series Name - Season 1 [Bluray720p]")] [TestCase(false, "My Series Name - Season 1 [Bluray720p]")]
public void sab_season_title(bool proper, string expected) public void sab_season_title(bool proper, string expected)
{ {
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name") .With(c => c.Path = @"d:\tv shows\My Series Name")
@ -315,7 +315,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}; };
//Act //Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult); var actual = Mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert //Assert
Assert.AreEqual(expected, actual); Assert.AreEqual(expected, actual);
@ -325,7 +325,7 @@ namespace NzbDrone.Core.Test.ProviderTests
[TestCase(false, "My Series Name - 2011-12-01 - My Episode Title [Bluray720p]")] [TestCase(false, "My Series Name - 2011-12-01 - My Episode Title [Bluray720p]")]
public void sab_daily_series_title(bool proper, string expected) public void sab_daily_series_title(bool proper, string expected)
{ {
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew() var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name") .With(c => c.Path = @"d:\tv shows\My Series Name")
@ -341,7 +341,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}; };
//Act //Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult); var actual = Mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert //Assert
Assert.AreEqual(expected, actual); Assert.AreEqual(expected, actual);
@ -361,9 +361,9 @@ namespace NzbDrone.Core.Test.ProviderTests
const string category = "tv"; const string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -380,10 +380,10 @@ namespace NzbDrone.Core.Test.ProviderTests
.Returns(category); .Returns(category);
mocker.SetConstant(new HttpProvider()); Mocker.SetConstant(new HttpProvider());
//Act //Act
bool result = mocker.Resolve<SabProvider>().AddByUrl( bool result = Mocker.Resolve<SabProvider>().AddByUrl(
"http://www.newzbin.com/browse/post/6107863/nzb", "Added by unit tests."); "http://www.newzbin.com/browse/post/6107863/nzb", "Added by unit tests.");
//Assert //Assert
@ -400,14 +400,14 @@ namespace NzbDrone.Core.Test.ProviderTests
const string username = "admin"; const string username = "admin";
const string password = "pass"; const string password = "pass";
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Categories_json.txt")); .Returns(File.ReadAllText(@".\Files\Categories_json.txt"));
//Act //Act
var result = mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password); var result = Mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password);
//Assert //Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
@ -425,9 +425,9 @@ namespace NzbDrone.Core.Test.ProviderTests
const string username = "admin"; const string username = "admin";
const string password = "pass"; const string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(host); .Returns(host);
fakeConfig.SetupGet(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
@ -439,12 +439,12 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeConfig.SetupGet(c => c.SabPassword) fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password); .Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Categories_json.txt")); .Returns(File.ReadAllText(@".\Files\Categories_json.txt"));
//Act //Act
var result = mocker.Resolve<SabProvider>().GetCategories(); var result = Mocker.Resolve<SabProvider>().GetCategories();
//Assert //Assert
result.Should().NotBeNull(); result.Should().NotBeNull();

View File

@ -43,14 +43,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "Law and Order")
.Build(); .Build();
var mocker = new AutoMoqer();
var emptyDatabase = TestDbHelper.GetEmptyDatabase(); var emptyDatabase = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(emptyDatabase); Mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(fakeMap); emptyDatabase.Insert(fakeMap);
//Act //Act
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId); var sceneName = Mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId);
//Assert //Assert
Assert.AreEqual(fakeMap.SceneName, sceneName); Assert.AreEqual(fakeMap.SceneName, sceneName);
@ -66,14 +66,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(f => f.SceneName = "laworder") .With(f => f.SceneName = "laworder")
.Build(); .Build();
var mocker = new AutoMoqer();
var emptyDatabase = TestDbHelper.GetEmptyDatabase(); var emptyDatabase = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(emptyDatabase); Mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(fakeMap); emptyDatabase.Insert(fakeMap);
//Act //Act
var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId(fakeMap.CleanTitle); var seriesId = Mocker.Resolve<SceneMappingProvider>().GetSeriesId(fakeMap.CleanTitle);
//Assert //Assert
Assert.AreEqual(fakeMap.SeriesId, seriesId); Assert.AreEqual(fakeMap.SeriesId, seriesId);
@ -89,14 +89,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(f => f.SceneName = "laworder") .With(f => f.SceneName = "laworder")
.Build(); .Build();
var mocker = new AutoMoqer();
var emptyDatabase = TestDbHelper.GetEmptyDatabase(); var emptyDatabase = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(emptyDatabase); Mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(fakeMap); emptyDatabase.Insert(fakeMap);
//Act //Act
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(54321); var sceneName = Mocker.Resolve<SceneMappingProvider>().GetSceneName(54321);
//Assert //Assert
Assert.AreEqual(null, sceneName); Assert.AreEqual(null, sceneName);
@ -112,14 +112,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(f => f.CleanTitle = "laworder") .With(f => f.CleanTitle = "laworder")
.Build(); .Build();
var mocker = new AutoMoqer();
var emptyDatabase = TestDbHelper.GetEmptyDatabase(); var emptyDatabase = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(emptyDatabase); Mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(fakeMap); emptyDatabase.Insert(fakeMap);
//Act //Act
var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId("notlaworder"); var seriesId = Mocker.Resolve<SceneMappingProvider>().GetSeriesId("notlaworder");
//Assert //Assert
Assert.AreEqual(null, seriesId); Assert.AreEqual(null, seriesId);
@ -143,16 +143,16 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(f => f.SceneName = "The Office") .With(f => f.SceneName = "The Office")
.Build(); .Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
db.Insert(fakeMap); db.Insert(fakeMap);
db.Insert(fakeMap2); db.Insert(fakeMap2);
//Act //Act
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId); var sceneName = Mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId);
//Assert //Assert
Assert.AreEqual(fakeMap.SceneName, sceneName); Assert.AreEqual(fakeMap.SceneName, sceneName);

View File

@ -50,14 +50,14 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodes); database.InsertMany(episodes);
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert //Assert
result.Should().HaveCount(1); result.Should().HaveCount(1);
@ -71,14 +71,14 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodes); database.InsertMany(episodes);
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert //Assert
result.Should().HaveCount(1); result.Should().HaveCount(1);
@ -92,14 +92,14 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodes); database.InsertMany(episodes);
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert //Assert
result.Should().HaveCount(1); result.Should().HaveCount(1);
@ -113,14 +113,14 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
database.InsertMany(episodes); database.InsertMany(episodes);
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert //Assert
result.Should().HaveCount(2); result.Should().HaveCount(2);
@ -135,8 +135,8 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).Single().Ignored = true; episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).Single().Ignored = true;
@ -144,7 +144,7 @@ namespace NzbDrone.Core.Test.ProviderTests
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert //Assert
result.Should().BeEmpty(); result.Should().BeEmpty();
@ -155,8 +155,8 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today).Single().Ignored = true; episodes.Where(e => e.AirDate == DateTime.Today).Single().Ignored = true;
@ -164,7 +164,7 @@ namespace NzbDrone.Core.Test.ProviderTests
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert //Assert
result.Should().BeEmpty(); result.Should().BeEmpty();
@ -175,8 +175,8 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).Single().Ignored = true; episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).Single().Ignored = true;
@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test.ProviderTests
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert //Assert
result.Should().BeEmpty(); result.Should().BeEmpty();
@ -195,8 +195,8 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
//Setup //Setup
var database = TestDbHelper.GetEmptyDatabase(); var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database); Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(2)).Single().Ignored = true; episodes.Where(e => e.AirDate == DateTime.Today.AddDays(2)).Single().Ignored = true;
@ -204,7 +204,7 @@ namespace NzbDrone.Core.Test.ProviderTests
database.Insert(series); database.Insert(series);
//Act //Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week(); var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert //Assert
result.Should().HaveCount(1); result.Should().HaveCount(1);

View File

@ -13,8 +13,6 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
{ {
class GetAvilableUpdateFixture : CoreTest class GetAvilableUpdateFixture : CoreTest
{ {
private AutoMoqer _mocker = null;
private static Version _latestsTestVersion = new Version("0.6.0.3"); private static Version _latestsTestVersion = new Version("0.6.0.3");
private static string _latestsTestUrl = "http://update.nzbdrone.com/_test/NzbDrone.master.0.6.0.3.zip"; private static string _latestsTestUrl = "http://update.nzbdrone.com/_test/NzbDrone.master.0.6.0.3.zip";
private static string _latestsTestFileName = "NzbDrone.master.0.6.0.3.zip"; private static string _latestsTestFileName = "NzbDrone.master.0.6.0.3.zip";
@ -22,10 +20,10 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
[SetUp] [SetUp]
public void setup() public void setup()
{ {
_mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
_mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/_test/"); Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/_test/");
_mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
} }
[TestCase("0.6.0.9")] [TestCase("0.6.0.9")]
@ -33,9 +31,9 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
[TestCase("1.0.0.0")] [TestCase("1.0.0.0")]
public void should_return_null_if_latests_is_lower_than_current_version(string currentVersion) public void should_return_null_if_latests_is_lower_than_current_version(string currentVersion)
{ {
_mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(new Version(currentVersion)); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(new Version(currentVersion));
var updatePackage = _mocker.Resolve<UpdateProvider>().GetAvilableUpdate(); var updatePackage = Mocker.Resolve<UpdateProvider>().GetAvilableUpdate();
updatePackage.Should().BeNull(); updatePackage.Should().BeNull();
} }
@ -43,9 +41,9 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
[Test] [Test]
public void should_return_null_if_latests_is_equal_to_current_version() public void should_return_null_if_latests_is_equal_to_current_version()
{ {
_mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(_latestsTestVersion); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(_latestsTestVersion);
var updatePackage = _mocker.Resolve<UpdateProvider>().GetAvilableUpdate(); var updatePackage = Mocker.Resolve<UpdateProvider>().GetAvilableUpdate();
updatePackage.Should().BeNull(); updatePackage.Should().BeNull();
} }
@ -55,9 +53,9 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
[TestCase("0.0.10.10")] [TestCase("0.0.10.10")]
public void should_return_update_if_latests_is_higher_than_current_version(string currentVersion) public void should_return_update_if_latests_is_higher_than_current_version(string currentVersion)
{ {
_mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(new Version(currentVersion)); Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(new Version(currentVersion));
var updatePackage = _mocker.Resolve<UpdateProvider>().GetAvilableUpdate(); var updatePackage = Mocker.Resolve<UpdateProvider>().GetAvilableUpdate();
updatePackage.Should().NotBeNull(); updatePackage.Should().NotBeNull();
updatePackage.Version.Should().Be(_latestsTestVersion); updatePackage.Version.Should().Be(_latestsTestVersion);

View File

@ -24,11 +24,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void JsonError_true() public void JsonError_true()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var response = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}"; var response = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}";
//Act //Act
var result = mocker.Resolve<XbmcProvider>().CheckForJsonError(response); var result = Mocker.Resolve<XbmcProvider>().CheckForJsonError(response);
//Assert //Assert
Assert.AreEqual(true, result); Assert.AreEqual(true, result);
@ -38,11 +38,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void JsonError_true_empty_response() public void JsonError_true_empty_response()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var response = String.Empty; var response = String.Empty;
//Act //Act
var result = mocker.Resolve<XbmcProvider>().CheckForJsonError(response); var result = Mocker.Resolve<XbmcProvider>().CheckForJsonError(response);
//Assert //Assert
Assert.AreEqual(true, result); Assert.AreEqual(true, result);
@ -52,11 +52,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void JsonError_false() public void JsonError_false()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var reposnse = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":3}}"; var reposnse = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":3}}";
//Act //Act
var result = mocker.Resolve<XbmcProvider>().CheckForJsonError(reposnse); var result = Mocker.Resolve<XbmcProvider>().CheckForJsonError(reposnse);
//Assert //Assert
Assert.AreEqual(false, result); Assert.AreEqual(false, result);
@ -68,16 +68,16 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetJsonVersion(int number) public void GetJsonVersion(int number)
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":" + number + "}}"; var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":" + number + "}}";
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>())) fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
.Returns(message); .Returns(message);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetJsonVersion("localhost:8080", "xbmc", "xbmc"); var result = Mocker.Resolve<XbmcProvider>().GetJsonVersion("localhost:8080", "xbmc", "xbmc");
//Assert //Assert
Assert.AreEqual(number, result); Assert.AreEqual(number, result);
@ -87,16 +87,16 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetJsonVersion_error() public void GetJsonVersion_error()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var message = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}"; var message = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}";
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>())) fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
.Returns(message); .Returns(message);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetJsonVersion("localhost:8080", "xbmc", "xbmc"); var result = Mocker.Resolve<XbmcProvider>().GetJsonVersion("localhost:8080", "xbmc", "xbmc");
//Assert //Assert
Assert.AreEqual(0, result); Assert.AreEqual(0, result);
@ -113,7 +113,7 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetActivePlayers(bool audio, bool picture, bool video) public void GetActivePlayers(bool audio, bool picture, bool video)
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"audio\":" var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"audio\":"
+ audio.ToString().ToLower() + audio.ToString().ToLower()
@ -123,12 +123,12 @@ namespace NzbDrone.Core.Test.ProviderTests
+ video.ToString().ToLower() + video.ToString().ToLower()
+ "}}"; + "}}";
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>())) fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
.Returns(message); .Returns(message);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetActivePlayers("localhost:8080", "xbmc", "xbmc"); var result = Mocker.Resolve<XbmcProvider>().GetActivePlayers("localhost:8080", "xbmc", "xbmc");
//Assert //Assert
Assert.AreEqual(audio, result["audio"]); Assert.AreEqual(audio, result["audio"]);
@ -140,16 +140,16 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetTvShowsJson() public void GetTvShowsJson()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"limits\":{\"end\":5,\"start\":0,\"total\":5},\"tvshows\":[{\"file\":\"smb://HOMESERVER/TV/7th Heaven/\",\"imdbnumber\":\"73928\",\"label\":\"7th Heaven\",\"tvshowid\":3},{\"file\":\"smb://HOMESERVER/TV/8 Simple Rules/\",\"imdbnumber\":\"78461\",\"label\":\"8 Simple Rules\",\"tvshowid\":4},{\"file\":\"smb://HOMESERVER/TV/24-7 Penguins-Capitals- Road to the NHL Winter Classic/\",\"imdbnumber\":\"213041\",\"label\":\"24/7 Penguins/Capitals: Road to the NHL Winter Classic\",\"tvshowid\":1},{\"file\":\"smb://HOMESERVER/TV/30 Rock/\",\"imdbnumber\":\"79488\",\"label\":\"30 Rock\",\"tvshowid\":2},{\"file\":\"smb://HOMESERVER/TV/90210/\",\"imdbnumber\":\"82716\",\"label\":\"90210\",\"tvshowid\":5}]}}"; var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"limits\":{\"end\":5,\"start\":0,\"total\":5},\"tvshows\":[{\"file\":\"smb://HOMESERVER/TV/7th Heaven/\",\"imdbnumber\":\"73928\",\"label\":\"7th Heaven\",\"tvshowid\":3},{\"file\":\"smb://HOMESERVER/TV/8 Simple Rules/\",\"imdbnumber\":\"78461\",\"label\":\"8 Simple Rules\",\"tvshowid\":4},{\"file\":\"smb://HOMESERVER/TV/24-7 Penguins-Capitals- Road to the NHL Winter Classic/\",\"imdbnumber\":\"213041\",\"label\":\"24/7 Penguins/Capitals: Road to the NHL Winter Classic\",\"tvshowid\":1},{\"file\":\"smb://HOMESERVER/TV/30 Rock/\",\"imdbnumber\":\"79488\",\"label\":\"30 Rock\",\"tvshowid\":2},{\"file\":\"smb://HOMESERVER/TV/90210/\",\"imdbnumber\":\"82716\",\"label\":\"90210\",\"tvshowid\":5}]}}";
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>())) fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
.Returns(message); .Returns(message);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetTvShowsJson("localhost:8080", "xbmc", "xbmc"); var result = Mocker.Resolve<XbmcProvider>().GetTvShowsJson("localhost:8080", "xbmc", "xbmc");
//Assert //Assert
Assert.AreEqual(5, result.Count); Assert.AreEqual(5, result.Count);
@ -160,30 +160,30 @@ namespace NzbDrone.Core.Test.ProviderTests
public void Notify_true() public void Notify_true()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var header = "NzbDrone Test"; var header = "NzbDrone Test";
var message = "Test Message!"; var message = "Test Message!";
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(s => s.XbmcHosts).Returns("localhost:8080"); fakeConfig.SetupGet(s => s.XbmcHosts).Returns("localhost:8080");
//var fakeUdpProvider = mocker.GetMock<EventClient>(); //var fakeUdpProvider = Mocker.GetMock<EventClient>();
var fakeEventClient = mocker.GetMock<EventClientProvider>(); var fakeEventClient = Mocker.GetMock<EventClientProvider>();
fakeEventClient.Setup(s => s.SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", "localhost")).Returns(true); fakeEventClient.Setup(s => s.SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", "localhost")).Returns(true);
//Act //Act
mocker.Resolve<XbmcProvider>().Notify(header, message); Mocker.Resolve<XbmcProvider>().Notify(header, message);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void SendCommand() public void SendCommand()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var host = "localhost:8080"; var host = "localhost:8080";
var command = "ExecBuiltIn(CleanLibrary(video))"; var command = "ExecBuiltIn(CleanLibrary(video))";
@ -192,15 +192,15 @@ namespace NzbDrone.Core.Test.ProviderTests
var url = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(CleanLibrary(video))"); var url = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(CleanLibrary(video))");
//var fakeUdpProvider = mocker.GetMock<EventClient>(); //var fakeUdpProvider = Mocker.GetMock<EventClient>();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(url, username, password)).Returns("Ok\n"); fakeHttp.Setup(s => s.DownloadString(url, username, password)).Returns("Ok\n");
//Act //Act
var result = mocker.Resolve<XbmcProvider>().SendCommand(host, command, username, username); var result = Mocker.Resolve<XbmcProvider>().SendCommand(host, command, username, username);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
Assert.AreEqual("Ok\n", result); Assert.AreEqual("Ok\n", result);
} }
@ -208,7 +208,7 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetXbmcSeriesPath_true() public void GetXbmcSeriesPath_true()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>"; var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>";
@ -221,8 +221,8 @@ namespace NzbDrone.Core.Test.ProviderTests
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)"); var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
//var fakeUdpProvider = mocker.GetMock<EventClient>(); //var fakeUdpProvider = Mocker.GetMock<EventClient>();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>"); fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>");
fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html> fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html>
<li>OK <li>OK
@ -230,10 +230,10 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult); fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username); var result = Mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
Assert.AreEqual("smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/", result); Assert.AreEqual("smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/", result);
} }
@ -241,7 +241,7 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetXbmcSeriesPath_false() public void GetXbmcSeriesPath_false()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var queryResult = @"<xml></xml>"; var queryResult = @"<xml></xml>";
@ -254,8 +254,8 @@ namespace NzbDrone.Core.Test.ProviderTests
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)"); var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
//var fakeUdpProvider = mocker.GetMock<EventClient>(); //var fakeUdpProvider = Mocker.GetMock<EventClient>();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>"); fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>");
fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html> fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html>
<li>OK <li>OK
@ -263,10 +263,10 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult); fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username); var result = Mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
Assert.AreEqual("", result); Assert.AreEqual("", result);
} }
@ -274,7 +274,7 @@ namespace NzbDrone.Core.Test.ProviderTests
public void GetXbmcSeriesPath_special_characters() public void GetXbmcSeriesPath_special_characters()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/</field></record></xml>"; var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/</field></record></xml>";
@ -287,8 +287,8 @@ namespace NzbDrone.Core.Test.ProviderTests
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)"); var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
//var fakeUdpProvider = mocker.GetMock<EventClient>(); //var fakeUdpProvider = Mocker.GetMock<EventClient>();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>"); fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>");
fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html> fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html>
<li>OK <li>OK
@ -296,10 +296,10 @@ namespace NzbDrone.Core.Test.ProviderTests
fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult); fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult);
//Act //Act
var result = mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username); var result = Mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
result.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/"); result.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/");
} }
@ -307,27 +307,24 @@ namespace NzbDrone.Core.Test.ProviderTests
public void Clean() public void Clean()
{ {
//Setup //Setup
var mocker = new AutoMoqer(MockBehavior.Strict); WithStrictMocker();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(s => s.XbmcHosts).Returns("localhost:8080"); fakeConfig.SetupGet(s => s.XbmcHosts).Returns("localhost:8080");
var fakeEventClient = mocker.GetMock<EventClientProvider>(); var fakeEventClient = Mocker.GetMock<EventClientProvider>();
fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(CleanLibrary(video))")).Returns(true); fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(CleanLibrary(video))")).Returns(true);
//Act //Act
mocker.Resolve<XbmcProvider>().Clean(); Mocker.Resolve<XbmcProvider>().Clean();
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void UpdateWithHttp_Single() public void UpdateWithHttp_Single()
{ {
//Setup
var mocker = new AutoMoqer(MockBehavior.Default);
var host = "localhost:8080"; var host = "localhost:8080";
var username = "xbmc"; var username = "xbmc";
var password = "xbmc"; var password = "xbmc";
@ -340,23 +337,20 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.Title = "30 Rock") .With(s => s.Title = "30 Rock")
.Build(); .Build();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(queryUrl, username, password)).Returns(queryResult); fakeHttp.Setup(s => s.DownloadString(queryUrl, username, password)).Returns(queryResult);
fakeHttp.Setup(s => s.DownloadString(url, username, password)); fakeHttp.Setup(s => s.DownloadString(url, username, password));
//Act //Act
mocker.Resolve<XbmcProvider>().UpdateWithHttp(fakeSeries, host, username, password); Mocker.Resolve<XbmcProvider>().UpdateWithHttp(fakeSeries, host, username, password);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void UpdateWithHttp_All() public void UpdateWithHttp_All()
{ {
//Setup
var mocker = new AutoMoqer(MockBehavior.Default);
var host = "localhost:8080"; var host = "localhost:8080";
var username = "xbmc"; var username = "xbmc";
var password = "xbmc"; var password = "xbmc";
@ -369,22 +363,22 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.Title = "30 Rock") .With(s => s.Title = "30 Rock")
.Build(); .Build();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(queryUrl, username, password)).Returns(queryResult); fakeHttp.Setup(s => s.DownloadString(queryUrl, username, password)).Returns(queryResult);
fakeHttp.Setup(s => s.DownloadString(url, username, password)); fakeHttp.Setup(s => s.DownloadString(url, username, password));
//Act //Act
mocker.Resolve<XbmcProvider>().UpdateWithHttp(fakeSeries, host, username, password); Mocker.Resolve<XbmcProvider>().UpdateWithHttp(fakeSeries, host, username, password);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void UpdateWithJson_Single() public void UpdateWithJson_Single()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var host = "localhost:8080"; var host = "localhost:8080";
var username = "xbmc"; var username = "xbmc";
@ -397,25 +391,25 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.Title = "30 Rock") .With(s => s.Title = "30 Rock")
.Build(); .Build();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.PostCommand(host, username, password, serializedQuery)) fakeHttp.Setup(s => s.PostCommand(host, username, password, serializedQuery))
.Returns(tvshows); .Returns(tvshows);
var fakeEventClient = mocker.GetMock<EventClientProvider>(); var fakeEventClient = Mocker.GetMock<EventClientProvider>();
fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(UpdateLibrary(video,smb://HOMESERVER/TV/30 Rock/))")); fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(UpdateLibrary(video,smb://HOMESERVER/TV/30 Rock/))"));
//Act //Act
mocker.Resolve<XbmcProvider>().UpdateWithJson(fakeSeries, host, username, password); Mocker.Resolve<XbmcProvider>().UpdateWithJson(fakeSeries, host, username, password);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
[Test] [Test]
public void UpdateWithJson_All() public void UpdateWithJson_All()
{ {
//Setup //Setup
var mocker = new AutoMoqer();
var host = "localhost:8080"; var host = "localhost:8080";
var username = "xbmc"; var username = "xbmc";
@ -428,18 +422,18 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.Title = "30 Rock") .With(s => s.Title = "30 Rock")
.Build(); .Build();
var fakeHttp = mocker.GetMock<HttpProvider>(); var fakeHttp = Mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.PostCommand(host, username, password, serializedQuery)) fakeHttp.Setup(s => s.PostCommand(host, username, password, serializedQuery))
.Returns(tvshows); .Returns(tvshows);
var fakeEventClient = mocker.GetMock<EventClientProvider>(); var fakeEventClient = Mocker.GetMock<EventClientProvider>();
fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(UpdateLibrary(video))")); fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(UpdateLibrary(video))"));
//Act //Act
mocker.Resolve<XbmcProvider>().UpdateWithJson(fakeSeries, host, username, password); Mocker.Resolve<XbmcProvider>().UpdateWithJson(fakeSeries, host, username, password);
//Assert //Assert
mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
} }
} }

View File

@ -68,9 +68,9 @@ namespace NzbDrone.Core.Test
public void Update_Success() public void Update_Success()
{ {
//Arrange //Arrange
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var testProfile = new QualityProfile var testProfile = new QualityProfile
{ {
@ -85,9 +85,9 @@ namespace NzbDrone.Core.Test
//Update //Update
currentProfile.Cutoff = QualityTypes.Bluray720p; currentProfile.Cutoff = QualityTypes.Bluray720p;
mocker.Resolve<QualityProvider>().Update(currentProfile); Mocker.Resolve<QualityProvider>().Update(currentProfile);
var updated = mocker.Resolve<QualityProvider>().Get(currentProfile.QualityProfileId); var updated = Mocker.Resolve<QualityProvider>().Get(currentProfile.QualityProfileId);
//Assert //Assert
updated.Name.Should().Be(currentProfile.Name); updated.Name.Should().Be(currentProfile.Name);
@ -130,15 +130,15 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void SetupInitial_should_add_two_profiles() public void SetupInitial_should_add_two_profiles()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
//Act //Act
mocker.Resolve<QualityProvider>().SetupDefaultProfiles(); Mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
//Assert //Assert
var profiles = mocker.Resolve<QualityProvider>().All(); var profiles = Mocker.Resolve<QualityProvider>().All();
profiles.Should().HaveCount(2); profiles.Should().HaveCount(2);
@ -152,17 +152,17 @@ namespace NzbDrone.Core.Test
//We don't want to keep adding them back if a user deleted them on purpose. //We don't want to keep adding them back if a user deleted them on purpose.
public void SetupInitial_should_skip_if_any_profile_exists() public void SetupInitial_should_skip_if_any_profile_exists()
{ {
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase(); var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db); Mocker.SetConstant(db);
var fakeProfile = Builder<QualityProfile>.CreateNew().Build(); var fakeProfile = Builder<QualityProfile>.CreateNew().Build();
//Act //Act
mocker.Resolve<QualityProvider>().Add(fakeProfile); Mocker.Resolve<QualityProvider>().Add(fakeProfile);
mocker.Resolve<QualityProvider>().SetupDefaultProfiles(); Mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
//Assert //Assert
var profiles = mocker.Resolve<QualityProvider>().All(); var profiles = Mocker.Resolve<QualityProvider>().All();
profiles.Should().HaveCount(1); profiles.Should().HaveCount(1);

View File

@ -102,11 +102,11 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_episode_by_series_seasons_episode_x5000() public void get_episode_by_series_seasons_episode_x5000()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(db); Mocker.SetConstant(db);
mocker.Resolve<SeriesProvider>(); Mocker.Resolve<SeriesProvider>();
var epProvider = mocker.Resolve<EpisodeProvider>(); var epProvider = Mocker.Resolve<EpisodeProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -128,11 +128,11 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_episode_by_series_seasons_x1000() public void get_episode_by_series_seasons_x1000()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(db); Mocker.SetConstant(db);
mocker.Resolve<SeriesProvider>(); Mocker.Resolve<SeriesProvider>();
var epProvider = mocker.Resolve<EpisodeProvider>(); var epProvider = Mocker.Resolve<EpisodeProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -156,11 +156,11 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_episode_file_count_x100() public void get_episode_file_count_x100()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(db); Mocker.SetConstant(db);
mocker.Resolve<SeriesProvider>(); Mocker.Resolve<SeriesProvider>();
mocker.Resolve<EpisodeProvider>(); Mocker.Resolve<EpisodeProvider>();
var mediaProvider = mocker.Resolve<MediaFileProvider>(); var mediaProvider = Mocker.Resolve<MediaFileProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -184,11 +184,11 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_episode_file_count_x1000() public void get_episode_file_count_x1000()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(db); Mocker.SetConstant(db);
mocker.Resolve<SeriesProvider>(); Mocker.Resolve<SeriesProvider>();
mocker.Resolve<EpisodeProvider>(); Mocker.Resolve<EpisodeProvider>();
var mediaProvider = mocker.Resolve<MediaFileProvider>(); var mediaProvider = Mocker.Resolve<MediaFileProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -213,9 +213,9 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_season_count_x500() public void get_season_count_x500()
{ {
var mocker = new AutoMoqer();
mocker.SetConstant(db); Mocker.SetConstant(db);
var provider = mocker.Resolve<EpisodeProvider>(); var provider = Mocker.Resolve<EpisodeProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);

View File

@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using System.IO; using System.IO;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -12,7 +13,19 @@ namespace NzbDrone.Test.Common
protected const string INTEGRATION_TEST = "Integration Test"; protected const string INTEGRATION_TEST = "Integration Test";
protected AutoMoqer Mocker { get; private set; } private AutoMoqer _mocker;
protected AutoMoqer Mocker
{
get
{
if (_mocker == null)
{
_mocker = new AutoMoqer();
}
return _mocker;
}
}
protected string VirtualPath protected string VirtualPath
{ {
@ -34,19 +47,20 @@ namespace NzbDrone.Test.Common
} }
Directory.CreateDirectory(TempFolder); Directory.CreateDirectory(TempFolder);
Mocker = new AutoMoqer();
} }
[TearDown] [TearDown]
public void TestBaseTearDown() public void TestBaseTearDown()
{ {
_mocker = null;
} }
protected void WithStrictMocker() protected void WithStrictMocker()
{ {
Mocker = new AutoMoqer(MockBehavior.Strict); if (_mocker != null)
throw new InvalidOperationException("Can not switch to a strict container after container has been used. make sure this is the first call in your test.");
_mocker = new AutoMoqer(MockBehavior.Strict);
} }

View File

@ -3,11 +3,9 @@ using System;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
using NzbDrone.Update.Providers; using NzbDrone.Update.Providers;
namespace NzbDrone.Update.Test namespace NzbDrone.Update.Test
@ -16,17 +14,14 @@ namespace NzbDrone.Update.Test
class UpdateProviderVerifyFixture : TestBase class UpdateProviderVerifyFixture : TestBase
{ {
AutoMoqer mocker = new AutoMoqer();
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
mocker = new AutoMoqer(); Mocker.GetMock<EnviromentProvider>()
mocker.GetMock<EnviromentProvider>()
.Setup(c => c.StartUpPath).Returns(@"C:\Temp\NzbDrone_update\"); .Setup(c => c.StartUpPath).Returns(@"C:\Temp\NzbDrone_update\");
mocker.GetMock<EnviromentProvider>() Mocker.GetMock<EnviromentProvider>()
.Setup(c => c.SystemTemp).Returns(@"C:\Temp\"); .Setup(c => c.SystemTemp).Returns(@"C:\Temp\");
} }
@ -35,7 +30,7 @@ namespace NzbDrone.Update.Test
[TestCase(" ")] [TestCase(" ")]
public void update_should_throw_target_folder_is_blank(string target) public void update_should_throw_target_folder_is_blank(string target)
{ {
Assert.Throws<ArgumentException>(() => mocker.Resolve<UpdateProvider>().Start(target)) Assert.Throws<ArgumentException>(() => Mocker.Resolve<UpdateProvider>().Start(target))
.Message.Should().StartWith("Target folder can not be null or empty"); .Message.Should().StartWith("Target folder can not be null or empty");
} }
@ -44,7 +39,7 @@ namespace NzbDrone.Update.Test
{ {
string targetFolder = "c:\\NzbDrone\\"; string targetFolder = "c:\\NzbDrone\\";
Assert.Throws<DirectoryNotFoundException>(() => mocker.Resolve<UpdateProvider>().Start(targetFolder)) Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<UpdateProvider>().Start(targetFolder))
.Message.Should().StartWith("Target folder doesn't exist"); .Message.Should().StartWith("Target folder doesn't exist");
} }
@ -54,15 +49,15 @@ namespace NzbDrone.Update.Test
const string sandboxFolder = @"C:\Temp\NzbDrone_update\nzbdrone"; const string sandboxFolder = @"C:\Temp\NzbDrone_update\nzbdrone";
const string targetFolder = "c:\\NzbDrone\\"; const string targetFolder = "c:\\NzbDrone\\";
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(targetFolder)) .Setup(c => c.FolderExists(targetFolder))
.Returns(true); .Returns(true);
mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(sandboxFolder)) .Setup(c => c.FolderExists(sandboxFolder))
.Returns(false); .Returns(false);
Assert.Throws<DirectoryNotFoundException>(() => mocker.Resolve<UpdateProvider>().Start(targetFolder)) Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<UpdateProvider>().Start(targetFolder))
.Message.Should().StartWith("Update folder doesn't exist"); .Message.Should().StartWith("Update folder doesn't exist");
} }
} }