1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

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 @@ public class MonitoringProviderTest : TestBase
[Test]
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())
.Returns(Builder<ProcessInfo>.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build());
processMock.Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
var subject = mocker.Resolve<MonitoringProvider>();
var subject = Mocker.Resolve<MonitoringProvider>();
//Act

View File

@ -46,13 +46,13 @@ public void GetApplicationMode_two_args(string a, string b, ApplicationMode mode
[Test]
public void Route_should_call_install_service_when_application_mode_is_install()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var serviceProviderMock = mocker.GetMock<ServiceProvider>();
WithStrictMocker();
var serviceProviderMock = Mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
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());
}
@ -61,13 +61,13 @@ public void Route_should_call_install_service_when_application_mode_is_install()
[Test]
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var serviceProviderMock = mocker.GetMock<ServiceProvider>();
WithStrictMocker();
var serviceProviderMock = Mocker.GetMock<ServiceProvider>();
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);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
Mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
}
@ -75,14 +75,14 @@ public void Route_should_call_uninstall_service_when_application_mode_is_uninsta
[Test]
public void Route_should_call_console_service_when_application_mode_is_console()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var consoleProvider = mocker.GetMock<ConsoleProvider>();
var appServerProvider = mocker.GetMock<ApplicationServer>();
WithStrictMocker();
var consoleProvider = Mocker.GetMock<ConsoleProvider>();
var appServerProvider = Mocker.GetMock<ApplicationServer>();
consoleProvider.Setup(c => c.WaitForClose());
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());
appServerProvider.Verify(c => c.Start(), Times.Once());
@ -94,15 +94,15 @@ public void Route_should_call_console_service_when_application_mode_is_console()
[TestCase(ApplicationMode.Help)]
public void Route_should_call_service_start_when_run_in_service_more(ApplicationMode applicationMode)
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var envMock = mocker.GetMock<EnviromentProvider>();
var serviceProvider = mocker.GetMock<ServiceProvider>();
WithStrictMocker();
var envMock = Mocker.GetMock<EnviromentProvider>();
var serviceProvider = Mocker.GetMock<ServiceProvider>();
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
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());
}
@ -111,33 +111,33 @@ public void Route_should_call_service_start_when_run_in_service_more(Application
[Test]
public void show_error_on_install_if_service_already_exist()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var consoleMock = mocker.GetMock<ConsoleProvider>();
var serviceMock = mocker.GetMock<ServiceProvider>();
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
WithStrictMocker();
var consoleMock = Mocker.GetMock<ConsoleProvider>();
var serviceMock = Mocker.GetMock<ServiceProvider>();
Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
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]
public void show_error_on_uninstall_if_service_doesnt_exist()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var consoleMock = mocker.GetMock<ConsoleProvider>();
var serviceMock = mocker.GetMock<ServiceProvider>();
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
WithStrictMocker();
var consoleMock = Mocker.GetMock<ConsoleProvider>();
var serviceMock = Mocker.GetMock<ServiceProvider>();
Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoestExist());
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 @@ public void GetBool_Success()
const string key = "LaunchBrowser";
const bool value = true;
var mocker = new AutoMoqer();
//Act
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
@ -69,8 +67,6 @@ public void GetBool_Success()
[Test]
public void GetLaunchBrowser_Success()
{
var mocker = new AutoMoqer();
//Act
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;

View File

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

View File

@ -8,12 +8,13 @@
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
public class BacklogSearchJobTest
public class BacklogSearchJobTest : CoreTest
{
[Test]
public void no_missing_epsiodes_should_not_trigger_any_search()
@ -23,19 +24,19 @@ public void no_missing_epsiodes_should_not_trigger_any_search()
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);
//Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//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());
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());
}
@ -47,22 +48,22 @@ public void individual_missing_episode()
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);
mocker.GetMock<EpisodeSearchJob>()
Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
//Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//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());
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());
}
@ -74,22 +75,22 @@ public void individual_missing_episodes_only()
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);
mocker.GetMock<EpisodeSearchJob>()
Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
//Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//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());
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));
}
@ -105,25 +106,25 @@ public void series_season_missing_episodes_only_mismatch_count()
.With(e => e.SeasonNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
mocker.GetMock<EpisodeSearchJob>()
Mocker.GetMock<EpisodeSearchJob>()
.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 });
//Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//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());
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));
}
@ -139,25 +140,25 @@ public void series_season_missing_episodes_only()
.With(e => e.SeasonNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.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();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList());
//Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//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());
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());
}
@ -173,28 +174,28 @@ public void multiple_missing_episodes()
.With(e => e.SeasonNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.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();
mocker.GetMock<EpisodeSearchJob>()
Mocker.GetMock<EpisodeSearchJob>()
.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 });
//Act
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
//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());
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));
}
}

View File

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

View File

@ -31,53 +31,53 @@ public void import_new_series_succesfull()
var notification = new ProgressNotification("Test");
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series);
mocker.GetMock<DiskScanJob>()
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastDiskSync = DateTime.Now);
mocker.GetMock<DiskScanJob>()
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, series[1].SeriesId, 0))
.Callback(() => series[1].LastDiskSync = DateTime.Now);
mocker.GetMock<BannerDownloadJob>()
Mocker.GetMock<BannerDownloadJob>()
.Setup(j => j.Start(notification, It.IsAny<int>(), 0));
mocker.GetMock<UpdateInfoJob>()
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastInfoSync = DateTime.Now);
mocker.GetMock<UpdateInfoJob>()
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[1].SeriesId, 0))
.Callback(() => series[1].LastInfoSync = DateTime.Now);
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.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]);
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
//Act
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
//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[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[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[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[1].SeriesId, 0), Times.Once());
}
@ -96,43 +96,43 @@ public void failed_import_should_not_be_stuck_in_loop()
var notification = new ProgressNotification("Test");
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetAllSeries())
.Returns(series);
mocker.GetMock<UpdateInfoJob>()
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastInfoSync = DateTime.Now);
mocker.GetMock<UpdateInfoJob>()
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, series[1].SeriesId, 0))
.Throws(new InvalidOperationException());
mocker.GetMock<DiskScanJob>()
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
.Callback(() => series[0].LastDiskSync = DateTime.Now);
mocker.GetMock<BannerDownloadJob>()
Mocker.GetMock<BannerDownloadJob>()
.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]);
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
//Act
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
//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[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[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);
@ -145,19 +145,19 @@ public void AutoIgnoreSeason_new_series_should_not_ignore_any()
{
int seriesId = 12;
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<MediaFileProvider>()
WithStrictMocker();
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.GetSeriesFiles(seriesId))
.Returns(new List<EpisodeFile>());
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetSeasons(seriesId))
.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]
@ -172,19 +172,19 @@ public void AutoIgnoreSeason_existing_should_not_ignore_currentseason()
episodesFiles[0].SeasonNumber = 0;
episodesFiles[1].SeasonNumber = 1;
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.GetSeriesFiles(seriesId))
.Returns(episodesFiles);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetSeasons(seriesId))
.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]
@ -198,21 +198,21 @@ public void AutoIgnoreSeason_existing_should_ignore_seasons_with_no_file()
episodesFiles[0].SeasonNumber = 1;
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.GetSeriesFiles(seriesId))
.Returns(episodesFiles);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetSeasons(seriesId))
.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, 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, 0, true), Times.Once());
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());
}
}

View File

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

View File

@ -19,25 +19,25 @@ public void SeriesSearch_success()
{
var seasons = new List<int> { 1, 2, 3, 4, 5 };
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
var notification = new ProgressNotification("Series Search");
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.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);
mocker.GetMock<SeasonSearchJob>()
Mocker.GetMock<SeasonSearchJob>()
.Setup(c => c.Start(notification, 1, It.IsAny<int>())).Verifiable();
//Act
mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);
Mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
Times.Exactly(seasons.Count));
}
@ -46,19 +46,19 @@ public void SeriesSearch_no_seasons()
{
var seasons = new List<int>();
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
var notification = new ProgressNotification("Series Search");
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetSeasons(1)).Returns(seasons);
//Act
mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);
Mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
Times.Never());
}

View File

@ -23,15 +23,15 @@ public void Add_new_value_to_database()
const string key = "MY_KEY";
const string value = "MY_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, value);
Mocker.Resolve<ConfigProvider>().SetValue(key, value);
//Assert
mocker.Resolve<ConfigProvider>().GetValue(key, "").Should().Be(value);
Mocker.Resolve<ConfigProvider>().GetValue(key, "").Should().Be(value);
}
[Test]
@ -40,15 +40,15 @@ public void Get_value_from_database()
const string key = "MY_KEY";
const string value = "MY_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(new Config { Key = key, Value = value });
db.Insert(new Config { Key = "Other Key", Value = "OtherValue" });
//Act
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
var result = Mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert
result.Should().Be(value);
@ -61,13 +61,13 @@ public void Get_value_should_return_default_when_no_value()
const string key = "MY_KEY";
const string value = "MY_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
//Act
var result = mocker.Resolve<ConfigProvider>().GetValue(key, value);
var result = Mocker.Resolve<ConfigProvider>().GetValue(key, value);
//Assert
result.Should().Be(value);
@ -80,15 +80,15 @@ public void New_value_should_update_old_value_new_value()
const string originalValue = "OLD_VALUE";
const string newValue = "NEW_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(new Config { Key = key, Value = originalValue });
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, newValue);
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
Mocker.Resolve<ConfigProvider>().SetValue(key, newValue);
var result = Mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert
result.Should().Be(newValue);
@ -102,14 +102,14 @@ public void New_value_should_update_old_value_same_value()
const string value = "OLD_VALUE";
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, value);
mocker.Resolve<ConfigProvider>().SetValue(key, value);
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
Mocker.Resolve<ConfigProvider>().SetValue(key, value);
Mocker.Resolve<ConfigProvider>().SetValue(key, value);
var result = Mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert
result.Should().Be(value);
@ -121,11 +121,11 @@ public void New_value_should_update_old_value_same_value()
public void config_properties_should_write_and_read_using_same_key()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
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();

View File

@ -21,11 +21,11 @@ public class FreeDiskSpaceTest : CoreTest
public void FreeDiskSpace()
{
//Setup
var mocker = new AutoMoqer();
//Act
var di = new DirectoryInfo(Directory.GetCurrentDirectory());
var result = mocker.Resolve<DiskProvider>().FreeDiskSpace(di);
var result = Mocker.Resolve<DiskProvider>().FreeDiskSpace(di);
//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)

View File

@ -24,74 +24,74 @@ public class DiskScanProviderTest : CoreTest
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();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodeBySeries(It.IsAny<long>()))
.Returns(new List<Episode> { new Episode() });
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
.Returns(new List<EpisodeFile>());
mocker.Resolve<DiskScanProvider>().Scan(new Series());
Mocker.Resolve<DiskScanProvider>().Scan(new Series());
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
[Test]
public void cleanup_should_skip_existing_files()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(true);
//Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
//Assert
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
[Test]
public void cleanup_should_delete_none_existing_files()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
.Returns(new List<Episode>());
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(e => e.Delete(It.IsAny<int>()));
//Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
//Assert
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.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));
}
@ -99,40 +99,40 @@ public void cleanup_should_delete_none_existing_files()
[Test]
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();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
.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>()));
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(e => e.Delete(It.IsAny<int>()));
//Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
//Assert
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.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));
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.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));
}
@ -141,29 +141,29 @@ public void cleanup_should_delete_none_existing_files_remove_links_to_episodes()
public void scan_series_should_log_warning_if_path_doesnt_exist_on_disk()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
var series = Builder<Series>.CreateNew()
.With(s => s.Path = @"C:\Test\TV\SeriesName\")
.Build();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.DeleteOrphaned())
.Returns(0);
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.RepairLinks())
.Returns(0);
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(series.Path))
.Returns(false);
//Act
mocker.Resolve<DiskScanProvider>().Scan(series, series.Path);
Mocker.Resolve<DiskScanProvider>().Scan(series, series.Path);
//Assert
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1);
}

View File

@ -29,23 +29,23 @@ public void import_new_file_should_succeed()
var fakeEpisode = Builder<Episode>.CreateNew().Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
//Assert
VerifyFileImport(result, mocker, fakeEpisode, 12345);
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
}
@ -65,21 +65,21 @@ public void import_new_file_with_better_same_quality_should_succeed(QualityTypes
.And(g => g.Proper = currentFileProper).Build()
).Build();
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.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 });
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
//Assert
VerifyFileImport(result, mocker, fakeEpisode, size);
VerifyFileImport(result, Mocker, fakeEpisode, size);
}
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
@ -96,23 +96,23 @@ public void import_new_file_episode_has_same_or_better_quality_should_skip(strin
.Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, mocker);
VerifySkipImport(result, Mocker);
}
[Test]
@ -124,19 +124,19 @@ public void import_unparsable_file_should_skip()
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);
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, mocker);
VerifySkipImport(result, Mocker);
ExceptionVerification.ExcpectedWarns(2);
}
@ -149,19 +149,19 @@ public void import_sample_file_should_skip()
var fakeSeries = Builder<Series>.CreateNew().Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, mocker);
VerifySkipImport(result, Mocker);
}
[Test]
@ -171,16 +171,16 @@ public void import_existing_file_should_skip()
var fakeSeries = Builder<Series>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<MediaFileProvider>()
WithStrictMocker();
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(true);
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, mocker);
VerifySkipImport(result, Mocker);
}
[Test]
@ -193,24 +193,24 @@ public void import_file_with_no_episode_in_db_should_skip()
var fakeSeries = Builder<Series>.CreateNew().Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<DiskProvider>(MockBehavior.Strict)
Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
.Setup(e => e.GetSize(fileName)).Returns(90000000000);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false))
.Returns(new List<Episode>());
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, mocker);
VerifySkipImport(result, Mocker);
}
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
@ -227,24 +227,24 @@ public void import_new_file_episode_has_better_quality_than_existing(string file
.Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifyFileImport(result, mocker, fakeEpisode, 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
}
[TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")]
@ -263,24 +263,24 @@ public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_
.Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(fakeEpisodes);
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifyFileImport(result, mocker, fakeEpisodes[0], 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
VerifyFileImport(result, Mocker, fakeEpisodes[0], 12345);
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
}
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
@ -298,23 +298,23 @@ public void skip_import_new_multi_part_file_episode_existing_has_better_quality(
.Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(fakeEpisodes);
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, mocker);
VerifySkipImport(result, Mocker);
}
[Test]
@ -339,24 +339,24 @@ public void import_new_multi_part_file_episode_replace_two_files()
.Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode1, fakeEpisode2 });
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifyFileImport(result, mocker, fakeEpisode1, 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
VerifyFileImport(result, Mocker, fakeEpisode1, 12345);
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
}
[Test]
@ -373,48 +373,48 @@ public void import_new_episode_no_existing_episode_file()
.Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
mocker.GetMock<MediaFileProvider>()
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode});
//Act
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifyFileImport(result, mocker, fakeEpisode, 12345);
mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
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.SeriesId.Should().Be(fakeEpisode.SeriesId);
result.Size.Should().Be(size);
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
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();
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<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), 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<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
}
}
}

View File

@ -20,7 +20,7 @@ public class DownloadProviderTest : CoreTest
[Test]
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()
.With(c => c.Quality = new Quality(QualityTypes.DVD, false))
.Build();
@ -33,38 +33,38 @@ public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed()
const string sabTitle = "My fake sab title";
mocker.GetMock<SabProvider>()
Mocker.GetMock<SabProvider>()
.Setup(s => s.IsInQueue(It.IsAny<String>()))
.Returns(false);
mocker.GetMock<SabProvider>()
Mocker.GetMock<SabProvider>()
.Setup(s => s.AddByUrl(parseResult.NzbUrl, sabTitle))
.Returns(true);
mocker.GetMock<SabProvider>()
Mocker.GetMock<SabProvider>()
.Setup(s => s.GetSabTitle(parseResult))
.Returns(sabTitle);
mocker.GetMock<HistoryProvider>()
Mocker.GetMock<HistoryProvider>()
.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)));
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(episodes);
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.MarkEpisodeAsFetched(12));
mocker.GetMock<EpisodeProvider>()
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.MarkEpisodeAsFetched(99));
mocker.GetMock<ExternalNotificationProvider>()
Mocker.GetMock<ExternalNotificationProvider>()
.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 @@ public void Delete_None_Valid_TvDbEpisodeId()
.With(e => e.TvDbEpisodeId = tvDbSeries.Episodes.First().Id)
.Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(fakeSeries);
db.Insert(fakeEpisode);
//Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert
var result = db.Fetch<Episode>();
@ -82,16 +82,16 @@ public void Delete_None_TvDbEpisodeId_is_zero()
.With(e => e.TvDbEpisodeId = 0)
.Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(fakeSeries);
db.Insert(fakeEpisode);
//Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert
var result = db.Fetch<Episode>();
@ -122,16 +122,16 @@ public void Delete_None_TvDbEpisodeId_is_null()
.With(e => e.TvDbEpisodeId = null)
.Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(fakeSeries);
db.Insert(fakeEpisode);
//Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert
var result = db.Fetch<Episode>();
@ -164,16 +164,16 @@ public void Delete_TvDbId()
.With(e => e.TvDbEpisodeId = 300)
.Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(fakeSeries);
db.Insert(fakeEpisode);
//Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert
var result = db.Fetch<Episode>();
@ -219,10 +219,10 @@ public void Delete_TvDbId_multiple_series()
.With(e => e.TvDbEpisodeId = 300)
.Build();
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
db.Insert(fakeSeries);
db.Insert(fakeEpisode);
@ -230,7 +230,7 @@ public void Delete_TvDbId_multiple_series()
db.Insert(otherFakeEpisode);
//Act
mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
//Assert
var result = db.Fetch<Episode>();

View File

@ -20,17 +20,17 @@ public class EventClientProviderTest : CoreTest
public void SendNotification_true()
{
//Setup
var mocker = new AutoMoqer();
var header = "NzbDrone Test";
var message = "Test Message!";
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);
//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.AreEqual(true, result);
@ -40,17 +40,17 @@ public void SendNotification_true()
public void SendNotification_false()
{
//Setup
var mocker = new AutoMoqer();
var header = "NzbDrone Test";
var message = "Test Message!";
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);
//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.AreEqual(false, result);
@ -60,17 +60,17 @@ public void SendNotification_false()
public void SendAction_Update_true()
{
//Setup
var mocker = new AutoMoqer();
var path = @"C:\Test\TV\30 Rock";
var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path);
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);
//Act
var result = mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
var result = Mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
//Assert
Assert.AreEqual(true, result);
@ -80,17 +80,17 @@ public void SendAction_Update_true()
public void SendAction_Update_false()
{
//Setup
var mocker = new AutoMoqer();
var path = @"C:\Test\TV\30 Rock";
var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path);
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);
//Act
var result = mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
var result = Mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
//Assert
Assert.AreEqual(false, result);

View File

@ -23,52 +23,52 @@ public class GrowlProviderTest : CoreTest
public void Register_should_add_new_application_to_local_growl_instance()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//Act
mocker.Resolve<GrowlProvider>().Register("localhost", 23053, "");
Mocker.Resolve<GrowlProvider>().Register("localhost", 23053, "");
//Assert
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
[Test]
public void TestNotification_should_send_a_message_to_local_growl_instance()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//Act
mocker.Resolve<GrowlProvider>().TestNotification("localhost", 23053, "");
Mocker.Resolve<GrowlProvider>().TestNotification("localhost", 23053, "");
//Assert
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
[Test]
public void OnGrab_should_send_a_message_to_local_growl_instance()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
[Test]
public void OnDownload_should_send_a_message_to_local_growl_instance()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
}
}

View File

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

View File

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

View File

@ -72,19 +72,19 @@ public void Setup()
[Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series30minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
@ -93,19 +93,19 @@ public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute()
[Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series60minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
@ -114,19 +114,19 @@ public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute()
[Test]
public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series30minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeFalse();
@ -135,19 +135,19 @@ public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute()
[Test]
public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series60minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeFalse();
@ -156,19 +156,19 @@ public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute()
[Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultMulti.Series = series30minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert
result.Should().BeTrue();
@ -177,19 +177,19 @@ public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute()
[Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultMulti.Series = series60minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert
result.Should().BeTrue();
@ -198,19 +198,19 @@ public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute()
[Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultMulti.Series = series30minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert
result.Should().BeFalse();
@ -219,19 +219,19 @@ public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute()
[Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultMulti.Series = series60minutes;
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>()))
.Returns(false);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultMulti);
//Assert
result.Should().BeFalse();
@ -240,19 +240,19 @@ public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute()
[Test]
public void IsAcceptableSize_true_single_episode_first_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series30minutes;
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>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
@ -261,19 +261,19 @@ public void IsAcceptableSize_true_single_episode_first_30_minute()
[Test]
public void IsAcceptableSize_true_single_episode_first_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series60minutes;
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>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
@ -282,19 +282,19 @@ public void IsAcceptableSize_true_single_episode_first_60_minute()
[Test]
public void IsAcceptableSize_false_single_episode_first_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series30minutes;
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>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeFalse();
@ -303,19 +303,19 @@ public void IsAcceptableSize_false_single_episode_first_30_minute()
[Test]
public void IsAcceptableSize_false_single_episode_first_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series60minutes;
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>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeFalse();
@ -324,20 +324,20 @@ public void IsAcceptableSize_false_single_episode_first_60_minute()
[Test]
public void IsAcceptableSize_true_unlimited_30_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 18457280000;
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>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
@ -346,20 +346,20 @@ public void IsAcceptableSize_true_unlimited_30_minute()
[Test]
public void IsAcceptableSize_true_unlimited_60_minute()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 36857280000;
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>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
bool result = Mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();

View File

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

View File

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

View File

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

View File

@ -21,9 +21,9 @@ public class MediaFileProvider_GetNewFilenameTest : CoreTest
public void GetNewFilename_Series_Episode_Quality_S01E05_Dash()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -38,7 +38,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash()
.Build();
//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.AreEqual("South Park - S15E06 - City Sushi [HDTV]", result);
@ -48,9 +48,9 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash()
public void GetNewFilename_Episode_Quality_1x05_Dash()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -65,7 +65,7 @@ public void GetNewFilename_Episode_Quality_1x05_Dash()
.Build();
//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.AreEqual("15x06 - City Sushi [HDTV]", result);
@ -75,9 +75,9 @@ public void GetNewFilename_Episode_Quality_1x05_Dash()
public void GetNewFilename_Series_Quality_01x05_Space()
{
//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.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -92,7 +92,7 @@ public void GetNewFilename_Series_Quality_01x05_Space()
.Build();
//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.AreEqual("South Park 05x06 [HDTV]", result);
@ -102,9 +102,9 @@ public void GetNewFilename_Series_Quality_01x05_Space()
public void GetNewFilename_Series_s01e05_Space()
{
//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.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -120,7 +120,7 @@ public void GetNewFilename_Series_s01e05_Space()
.Build();
//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.AreEqual("South Park s05e06", result);
@ -130,9 +130,9 @@ public void GetNewFilename_Series_s01e05_Space()
public void GetNewFilename_Series_Episode_s01e05_Periods()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -147,7 +147,7 @@ public void GetNewFilename_Series_Episode_s01e05_Periods()
.Build();
//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.AreEqual("South.Park.s05e06.City.Sushi", result);
@ -157,9 +157,9 @@ public void GetNewFilename_Series_Episode_s01e05_Periods()
public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -174,7 +174,7 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality()
.Build();
//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.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV]", result);
@ -184,9 +184,9 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality()
public void GetNewFilename_S01E05_Dash()
{
//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.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -202,7 +202,7 @@ public void GetNewFilename_S01E05_Dash()
.Build();
//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.AreEqual("S15E06", result);
@ -212,9 +212,9 @@ public void GetNewFilename_S01E05_Dash()
public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -236,7 +236,7 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
.Build();
//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.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
@ -246,9 +246,9 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -270,7 +270,7 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
.Build();
//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.AreEqual("3x23x24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
@ -280,9 +280,9 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true);
@ -304,7 +304,7 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
.Build();
//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.AreEqual("3x23x24 Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
@ -314,9 +314,9 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
{
//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.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -338,7 +338,7 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
.Build();
//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.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream.(1).+.Strawberries.and.Cream.(2)", result);
@ -348,9 +348,9 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period()
{
//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.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -372,7 +372,7 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period()
.Build();
//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.AreEqual("The.Mentalist.-.S03E23-24", result);
@ -382,9 +382,9 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period()
public void GetNewFilename_multi_1x05_Repeat_Dash_Period()
{
//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.SortingIncludeEpisodeTitle).Returns(false);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
@ -406,7 +406,7 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period()
.Build();
//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.AreEqual("3x23x24", result);

View File

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

View File

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

View File

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

View File

@ -30,10 +30,10 @@ public class ProwlProviderTest : CoreTest
public void Verify_should_return_true_for_a_valid_apiKey()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//Act
var result = mocker.Resolve<ProwlProvider>().Verify(_apiKey);
var result = Mocker.Resolve<ProwlProvider>().Verify(_apiKey);
//Assert
result.Should().BeTrue();
@ -43,10 +43,10 @@ public void Verify_should_return_true_for_a_valid_apiKey()
public void Verify_should_return_false_for_an_invalid_apiKey()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//Act
var result = mocker.Resolve<ProwlProvider>().Verify(_badApiKey);
var result = Mocker.Resolve<ProwlProvider>().Verify(_badApiKey);
//Assert
ExceptionVerification.ExcpectedWarns(1);
@ -57,10 +57,10 @@ public void Verify_should_return_false_for_an_invalid_apiKey()
public void SendNotification_should_return_true_for_a_valid_apiKey()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
result.Should().BeTrue();
@ -70,10 +70,10 @@ public void SendNotification_should_return_true_for_a_valid_apiKey()
public void SendNotification_should_return_false_for_an_invalid_apiKey()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
ExceptionVerification.ExcpectedWarns(1);
@ -84,10 +84,10 @@ public void SendNotification_should_return_false_for_an_invalid_apiKey()
public void SendNotification_should_alert_with_high_priority()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
result.Should().BeTrue();
@ -97,10 +97,10 @@ public void SendNotification_should_alert_with_high_priority()
public void SendNotification_should_alert_with_VeryLow_priority()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
result.Should().BeTrue();
@ -110,10 +110,10 @@ public void SendNotification_should_alert_with_VeryLow_priority()
public void SendNotification_should_have_a_call_back_url()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
result.Should().BeTrue();
@ -123,10 +123,10 @@ public void SendNotification_should_have_a_call_back_url()
public void SendNotification_should_return_true_for_two_valid_apiKey()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
result.Should().BeTrue();
@ -136,10 +136,10 @@ public void SendNotification_should_return_true_for_two_valid_apiKey()
public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
WithStrictMocker();
//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
result.Should().BeTrue();

View File

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

View File

@ -24,19 +24,19 @@ public class RootDirProviderTest : CoreTest
public void GetRootDirs()
{
//Setup
var mocker = new AutoMoqer();
var emptyDatabase = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(emptyDatabase);
Mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(new RootDir { Path = @"C:\TV" });
emptyDatabase.Insert(new RootDir { Path = @"C:\TV2" });
//mocker.GetMock<IRepository>()
//Mocker.GetMock<IRepository>()
// .Setup(f => f.All<RootDir>())
// .Returns(sonicRepo.All<RootDir>);
//Act
var result = mocker.Resolve<RootDirProvider>().GetAll();
var result = Mocker.Resolve<RootDirProvider>().GetAll();
//Assert
Assert.AreEqual(result.Count, 2);
@ -47,11 +47,11 @@ public void GetRootDirs()
public void AddRootDir(string path)
{
//Setup
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir { Path = path });
@ -67,11 +67,11 @@ public void AddRootDir(string path)
public void RemoveRootDir()
{
//Setup
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
rootDirProvider.Remove(1);
@ -84,14 +84,14 @@ public void RemoveRootDir()
public void GetRootDir()
{
//Setup
var mocker = new AutoMoqer();
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
const int id = 1;
const string path = @"C:\TV";
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir { Id = id, Path = path });
//Assert
@ -105,24 +105,24 @@ public void None_existing_folder_returns_empty_list()
{
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);
var result = mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
var result = Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
result.Should().NotBeNull();
result.Should().BeEmpty();
mocker.VerifyAllMocks();
Mocker.VerifyAllMocks();
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void empty_folder_path_throws()
{
var mocker = new AutoMoqer();
mocker.Resolve<RootDirProvider>().GetUnmappedFolders("");
Mocker.Resolve<RootDirProvider>().GetUnmappedFolders("");
}
[TestCase("")]
@ -131,8 +131,8 @@ public void empty_folder_path_throws()
[ExpectedException(typeof(ArgumentException))]
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 @@ public void AddByUrlSuccess()
const string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -54,7 +54,7 @@ public void AddByUrlSuccess()
fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(
s =>
s.DownloadString(
@ -62,7 +62,7 @@ public void AddByUrlSuccess()
.Returns("ok");
//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");
//Assert
@ -83,9 +83,9 @@ public void AddByUrlNewzbin()
const string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -101,7 +101,7 @@ public void AddByUrlNewzbin()
fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(
s =>
s.DownloadString(
@ -109,7 +109,7 @@ public void AddByUrlNewzbin()
.Returns("ok");
//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");
//Assert
@ -128,9 +128,9 @@ public void AddByUrlError()
var priority = SabnzbdPriorityType.Normal;
string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -145,12 +145,12 @@ public void AddByUrlError()
.Returns(priority);
fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns("error");
//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");
//Assert
@ -168,9 +168,9 @@ public void IsInQueue_True()
string username = "admin";
string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -182,12 +182,12 @@ public void IsInQueue_True()
fakeConfig.SetupGet(c => c.SabPassword)
.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"))
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act
bool result = mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
bool result = Mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
//Assert
result.Should().BeTrue();
@ -203,9 +203,9 @@ public void IsInQueue_False_Empty()
string username = "admin";
string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -217,12 +217,12 @@ public void IsInQueue_False_Empty()
fakeConfig.SetupGet(c => c.SabPassword)
.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"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
//Act
bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
bool result = Mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert
Assert.IsFalse(result);
@ -239,9 +239,9 @@ public void IsInQueue_False_Error()
string username = "admin";
string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -253,13 +253,13 @@ public void IsInQueue_False_Error()
fakeConfig.SetupGet(c => c.SabPassword)
.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"))
.Returns(File.ReadAllText(@".\Files\QueueError.xml"));
//Act
mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
Mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
}
[Test]
@ -271,7 +271,7 @@ public void IsInQueue_False_Error()
[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)
{
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name")
@ -288,7 +288,7 @@ public void sab_title(int seasons, int[] episodes, string title, QualityTypes qu
};
//Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
var actual = Mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert
Assert.AreEqual(expected, actual);
@ -298,7 +298,7 @@ public void sab_title(int seasons, int[] episodes, string title, QualityTypes qu
[TestCase(false, "My Series Name - Season 1 [Bluray720p]")]
public void sab_season_title(bool proper, string expected)
{
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name")
@ -315,7 +315,7 @@ public void sab_season_title(bool proper, string expected)
};
//Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
var actual = Mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert
Assert.AreEqual(expected, actual);
@ -325,7 +325,7 @@ public void sab_season_title(bool proper, string expected)
[TestCase(false, "My Series Name - 2011-12-01 - My Episode Title [Bluray720p]")]
public void sab_daily_series_title(bool proper, string expected)
{
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name")
@ -341,7 +341,7 @@ public void sab_daily_series_title(bool proper, string expected)
};
//Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
var actual = Mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert
Assert.AreEqual(expected, actual);
@ -361,9 +361,9 @@ public void AddNewzbingByUrlSuccess()
const string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
@ -380,10 +380,10 @@ public void AddNewzbingByUrlSuccess()
.Returns(category);
mocker.SetConstant(new HttpProvider());
Mocker.SetConstant(new HttpProvider());
//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.");
//Assert
@ -400,14 +400,14 @@ public void Get_Categories_Success_Passed_Values()
const string username = "admin";
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"))
.Returns(File.ReadAllText(@".\Files\Categories_json.txt"));
//Act
var result = mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password);
var result = Mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password);
//Assert
result.Should().NotBeNull();
@ -425,9 +425,9 @@ public void Get_Categories_Success_Config_Values()
const string username = "admin";
const string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(host);
fakeConfig.SetupGet(c => c.SabPort)
@ -439,12 +439,12 @@ public void Get_Categories_Success_Config_Values()
fakeConfig.SetupGet(c => c.SabPassword)
.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"))
.Returns(File.ReadAllText(@".\Files\Categories_json.txt"));
//Act
var result = mocker.Resolve<SabProvider>().GetCategories();
var result = Mocker.Resolve<SabProvider>().GetCategories();
//Assert
result.Should().NotBeNull();

View File

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

View File

@ -50,14 +50,14 @@ public void Get_Yesterday()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database);
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert
result.Should().HaveCount(1);
@ -71,14 +71,14 @@ public void Get_Today()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database);
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert
result.Should().HaveCount(1);
@ -92,14 +92,14 @@ public void Get_Tomorrow()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database);
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert
result.Should().HaveCount(1);
@ -113,14 +113,14 @@ public void Get_Week()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database);
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert
result.Should().HaveCount(2);
@ -135,8 +135,8 @@ public void Get_Yesterday_skip_ingored()
{
//Setup
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;
@ -144,7 +144,7 @@ public void Get_Yesterday_skip_ingored()
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert
result.Should().BeEmpty();
@ -155,8 +155,8 @@ public void Get_Today_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
var mocker = new AutoMoqer();
mocker.SetConstant(database);
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today).Single().Ignored = true;
@ -164,7 +164,7 @@ public void Get_Today_skip_ingored()
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert
result.Should().BeEmpty();
@ -175,8 +175,8 @@ public void Get_Tomorrow_skip_ingored()
{
//Setup
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;
@ -184,7 +184,7 @@ public void Get_Tomorrow_skip_ingored()
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert
result.Should().BeEmpty();
@ -195,8 +195,8 @@ public void Get_Week_skip_ingored()
{
//Setup
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;
@ -204,7 +204,7 @@ public void Get_Week_skip_ingored()
database.Insert(series);
//Act
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week();
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert
result.Should().HaveCount(1);

View File

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

View File

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

View File

@ -68,9 +68,9 @@ public void Test_Storage_no_allowed()
public void Update_Success()
{
//Arrange
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
var testProfile = new QualityProfile
{
@ -85,9 +85,9 @@ public void Update_Success()
//Update
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
updated.Name.Should().Be(currentProfile.Name);
@ -130,15 +130,15 @@ public void Test_Series_Quality()
[Test]
public void SetupInitial_should_add_two_profiles()
{
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
//Act
mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
Mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
//Assert
var profiles = mocker.Resolve<QualityProvider>().All();
var profiles = Mocker.Resolve<QualityProvider>().All();
profiles.Should().HaveCount(2);
@ -152,17 +152,17 @@ public void SetupInitial_should_add_two_profiles()
//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()
{
var mocker = new AutoMoqer();
var db = TestDbHelper.GetEmptyDatabase();
mocker.SetConstant(db);
Mocker.SetConstant(db);
var fakeProfile = Builder<QualityProfile>.CreateNew().Build();
//Act
mocker.Resolve<QualityProvider>().Add(fakeProfile);
mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
Mocker.Resolve<QualityProvider>().Add(fakeProfile);
Mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
//Assert
var profiles = mocker.Resolve<QualityProvider>().All();
var profiles = Mocker.Resolve<QualityProvider>().All();
profiles.Should().HaveCount(1);

View File

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

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.IO;
using Moq;
using NUnit.Framework;
@ -12,7 +13,19 @@ public class TestBase : LoggingTest
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
{
@ -34,19 +47,20 @@ public void TestBaseSetup()
}
Directory.CreateDirectory(TempFolder);
Mocker = new AutoMoqer();
}
[TearDown]
public void TestBaseTearDown()
{
_mocker = null;
}
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.IO;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
using NzbDrone.Update.Providers;
namespace NzbDrone.Update.Test
@ -16,17 +14,14 @@ namespace NzbDrone.Update.Test
class UpdateProviderVerifyFixture : TestBase
{
AutoMoqer mocker = new AutoMoqer();
[SetUp]
public void Setup()
{
mocker = new AutoMoqer();
mocker.GetMock<EnviromentProvider>()
Mocker.GetMock<EnviromentProvider>()
.Setup(c => c.StartUpPath).Returns(@"C:\Temp\NzbDrone_update\");
mocker.GetMock<EnviromentProvider>()
Mocker.GetMock<EnviromentProvider>()
.Setup(c => c.SystemTemp).Returns(@"C:\Temp\");
}
@ -35,7 +30,7 @@ public void Setup()
[TestCase(" ")]
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");
}
@ -44,7 +39,7 @@ public void update_should_throw_if_target_folder_doesnt_exist()
{
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");
}
@ -54,15 +49,15 @@ public void update_should_throw_if_update_folder_doesnt_exist()
const string sandboxFolder = @"C:\Temp\NzbDrone_update\nzbdrone";
const string targetFolder = "c:\\NzbDrone\\";
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(targetFolder))
.Returns(true);
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(sandboxFolder))
.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");
}
}