sonarr-repo-only/NzbDrone.Core.Test/ProviderTests/InventoryProviderTests/IsMonitoredFixture.cs

272 lines
9.1 KiB
C#
Raw Normal View History

2011-05-28 19:23:35 +00:00
// ReSharper disable RedundantUsingDirective
2011-05-28 19:23:35 +00:00
using System;
using System.Collections.Generic;
2011-05-28 19:23:35 +00:00
using FizzWare.NBuilder;
2011-06-02 21:06:46 +00:00
using FluentAssertions;
2011-05-28 19:23:35 +00:00
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
2011-05-28 19:23:35 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
2011-05-28 19:23:35 +00:00
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
2011-05-28 19:23:35 +00:00
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class IsMonitoredFixture : CoreTest
2011-05-28 19:23:35 +00:00
{
private EpisodeParseResult parseResultMulti;
private Series series;
private Episode episode;
private Episode episode2;
private EpisodeParseResult parseResultSingle;
private EpisodeParseResult parseResultDaily;
2011-05-28 19:23:35 +00:00
[SetUp]
2011-11-08 20:12:54 +00:00
public void Setup()
2011-05-28 19:23:35 +00:00
{
parseResultMulti = new EpisodeParseResult()
{
CleanTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.Bluray720p, true),
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date,
};
parseResultSingle = new EpisodeParseResult()
{
CleanTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.Bluray720p, true),
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date,
};
parseResultDaily = new EpisodeParseResult()
{
CleanTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.Bluray720p, true),
AirDate = DateTime.Now.AddDays(-12).Date,
};
2011-05-28 19:23:35 +00:00
episode = Builder<Episode>.CreateNew()
.With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[0])
.With(c => c.SeasonNumber = parseResultMulti.SeasonNumber)
.With(c => c.AirDate = parseResultMulti.AirDate)
.With(c => c.Title = "EpisodeTitle1")
.Build();
episode2 = Builder<Episode>.CreateNew()
.With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[1])
.With(c => c.SeasonNumber = parseResultMulti.SeasonNumber)
.With(c => c.AirDate = parseResultMulti.AirDate)
.With(c => c.Title = "EpisodeTitle2")
.Build();
series = Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(d => d.CleanTitle = parseResultMulti.CleanTitle)
.Build();
}
[Test]
public void not_monitored_series_should_be_skipped()
{
series.Monitored = false;
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
//Act
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
2011-05-28 19:23:35 +00:00
//Assert
Assert.IsFalse(result);
Assert.AreSame(series, parseResultMulti.Series);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
[Test]
public void not_in_db_should_be_skipped()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns<Series>(null);
//Act
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
2011-05-28 19:23:35 +00:00
//Assert
Assert.IsFalse(result);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
2011-06-22 01:12:20 +00:00
2011-05-28 19:23:35 +00:00
[Test]
2011-06-22 01:12:20 +00:00
public void IsMonitored_should_return_true()
2011-05-28 19:23:35 +00:00
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode });
parseResultSingle.Series.Should().BeNull();
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultSingle);
2011-06-22 01:12:20 +00:00
//Assert
result.Should().BeTrue();
parseResultSingle.Series.Should().Be(series);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-06-22 01:12:20 +00:00
}
[Test]
public void IsMonitored_ignored_single_episode_should_return_false()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-06-22 01:12:20 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode });
episode.Ignored = true;
parseResultSingle.Series.Should().BeNull();
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultSingle);
2011-05-28 19:23:35 +00:00
//Assert
2011-06-22 01:12:20 +00:00
result.Should().BeFalse();
parseResultSingle.Series.Should().Be(series);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
[Test]
2011-06-22 01:12:20 +00:00
public void IsMonitored_multi_some_episodes_ignored_should_return_true()
2011-05-28 19:23:35 +00:00
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode, episode2 });
episode.Ignored = true;
episode2.Ignored = false;
parseResultMulti.Series.Should().BeNull();
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
2011-06-22 01:12:20 +00:00
//Assert
result.Should().BeTrue();
parseResultMulti.Series.Should().Be(series);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-06-22 01:12:20 +00:00
}
[Test]
public void IsMonitored_multi_all_episodes_ignored_should_return_false()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-06-22 01:12:20 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode, episode2 });
episode.Ignored = true;
episode2.Ignored = true;
parseResultSingle.Series.Should().BeNull();
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
2011-06-22 01:12:20 +00:00
//Assert
result.Should().BeFalse();
parseResultMulti.Series.Should().Be(series);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-06-22 01:12:20 +00:00
}
[Test]
public void IsMonitored_multi_no_episodes_ignored_should_return_true()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-06-22 01:12:20 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
2011-05-28 19:23:35 +00:00
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode, episode2 });
2011-05-28 19:23:35 +00:00
2011-06-22 01:12:20 +00:00
episode.Ignored = false;
episode2.Ignored = false;
parseResultSingle.Series.Should().BeNull();
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultMulti);
2011-05-28 19:23:35 +00:00
//Assert
2011-06-22 01:12:20 +00:00
result.Should().BeTrue();
parseResultMulti.Series.Should().Be(series);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
2011-06-22 01:12:20 +00:00
[Test]
public void IsMonitored_daily_not_ignored_should_return_true()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-12-15 04:15:53 +00:00
Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode });
episode.Ignored = false;
2011-12-15 04:15:53 +00:00
var result = Mocker.Resolve<InventoryProvider>().IsMonitored(parseResultDaily);
2011-06-22 01:12:20 +00:00
//Assert
result.Should().BeTrue();
}
2011-05-28 19:23:35 +00:00
}
}