1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 09:49:00 +00:00
Radarr/NzbDrone.Core.Test/SeriesProviderTest.cs
2011-05-23 10:20:43 -07:00

198 lines
No EOL
7.5 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMoq;
using FizzWare.NBuilder;
using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
using TvdbLib.Data;
// ReSharper disable InconsistentNaming
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SeriesProviderTest : TestBase
{
[Test]
public void Map_path_to_series()
{
//Arrange
var fakeSeries = Builder<TvdbSeries>.CreateNew()
.With(f => f.SeriesName = "The Simpsons")
.Build();
var fakeSearch = Builder<TvdbSearchResult>.CreateNew()
.With(s => s.Id = fakeSeries.Id)
.With(s => s.SeriesName = fakeSeries.SeriesName)
.Build();
var mocker = new AutoMoqer();
mocker.GetMock<IRepository>()
.Setup(f => f.Exists<Series>(c => c.SeriesId == It.IsAny<int>()))
.Returns(false);
mocker.GetMock<TvDbProvider>()
.Setup(f => f.GetSeries(It.IsAny<String>()))
.Returns(fakeSearch);
mocker.GetMock<TvDbProvider>()
.Setup(f => f.GetSeries(fakeSeries.Id, false))
.Returns(fakeSeries)
.Verifiable();
//Act
var mappedSeries = mocker.Resolve<SeriesProvider>().MapPathToSeries(@"D:\TV Shows\The Simpsons");
//Assert
mocker.GetMock<TvDbProvider>().VerifyAll();
Assert.AreEqual(fakeSeries, mappedSeries);
}
[Test]
public void Add_new_series()
{
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
const string path = "C:\\Test\\";
const int tvDbId = 1234;
const int qualityProfileId = 2;
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
seriesProvider.AddSeries(path, tvDbId, qualityProfileId);
//Assert
var series = seriesProvider.GetAllSeries();
Assert.IsNotEmpty(series);
Assert.Count(1, series);
Assert.AreEqual(path, series.First().Path);
Assert.AreEqual(tvDbId, series.First().SeriesId);
Assert.AreEqual(qualityProfileId, series.First().QualityProfileId);
}
[Test]
public void find_series_empty_repo()
{
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
var series = seriesProvider.FindSeries("My Title");
//Assert
Assert.IsNull(series);
}
[Test]
public void find_series_empty_match()
{
var mocker = new AutoMoqer();
var emptyRepository = MockLib.GetEmptyRepository();
mocker.SetConstant(emptyRepository);
emptyRepository.Add(MockLib.GetFakeSeries(1, "MyTitle"));
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
var series = seriesProvider.FindSeries("WrongTitle");
//Assert
Assert.IsNull(series);
}
[Test]
[Row("The Test", "Test")]
[Row("Through the Wormhole", "Through.the.Wormhole")]
public void find_series_match(string title, string searchTitle)
{
var mocker = new AutoMoqer();
var emptyRepository = MockLib.GetEmptyRepository();
mocker.SetConstant(emptyRepository);
emptyRepository.Add(MockLib.GetFakeSeries(1, title));
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
var series = seriesProvider.FindSeries(searchTitle);
//Assert
Assert.IsNotNull(series);
Assert.AreEqual(title, series.Title);
}
[Test]
public void is_monitored()
{
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
mocker.Resolve<IRepository>().Add(Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(c => c.SeriesId = 12)
.Build());
mocker.Resolve<IRepository>().Add(Builder<Series>.CreateNew()
.With(c => c.Monitored = false)
.With(c => c.SeriesId = 11)
.Build());
//Act, Assert
var provider = mocker.Resolve<SeriesProvider>();
Assert.IsTrue(provider.IsMonitored(12));
Assert.IsFalse(provider.IsMonitored(11));
Assert.IsFalse(provider.IsMonitored(1));
}
[Test]
[Row(QualityTypes.SDTV, true)]
[Row(QualityTypes.Unknown, false)]
[Row(QualityTypes.Bluray1080, false)]
[Row(QualityTypes.Bluray720, false)]
[Row(QualityTypes.HDTV, false)]
[Row(QualityTypes.WEBDL, false)]
public void QualityWanted(QualityTypes qualityTypes, Boolean result)
{
var quality = Builder<QualityProfile>.CreateNew()
.With(q => q.Allowed = new List<QualityTypes> { QualityTypes.DVD, QualityTypes.SDTV })
.With(q => q.Cutoff = QualityTypes.DVD)
.Build();
var series = Builder<Series>.CreateNew()
.With(c => c.SeriesId = 12)
.With(c => c.QualityProfileId = quality.QualityProfileId)
.Build();
var mocker = new AutoMoqer();
var emptyRepository = MockLib.GetEmptyRepository();
mocker.SetConstant(emptyRepository);
mocker.GetMock<QualityProvider>()
.Setup(c => c.Find(quality.QualityProfileId)).Returns(quality);
emptyRepository.Add(series);
emptyRepository.Add(quality);
//Act
var needed = mocker.Resolve<SeriesProvider>().QualityWanted(12, qualityTypes);
Assert.AreEqual(result, needed);
}
}
}