1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-11 12:02:35 +02:00

fixed few more broken tests.

This commit is contained in:
kay.one 2013-03-27 23:49:38 -07:00
parent eaff6dc18f
commit 2008b54f5d
12 changed files with 64 additions and 105 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.ServiceModel.Syndication; using System.ServiceModel.Syndication;
@ -13,12 +12,10 @@
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Test.Indexers; using NzbDrone.Core.Test.Indexers;
using NzbDrone.Core.Test.ProviderTests;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.IndexerTests namespace NzbDrone.Core.Test.IndexerTests

View File

@ -4,6 +4,7 @@
using FluentAssertions; using FluentAssertions;
using NLog; using NLog;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;

View File

@ -9,6 +9,8 @@
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.ReferenceData; using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Test.TvTests;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests namespace NzbDrone.Core.Test.ProviderTests
{ {
@ -50,7 +52,7 @@ public void GetSceneName_exists()
.With(f => f.TvdbId = 12345) .With(f => f.TvdbId = 12345)
.With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "Law and Order")
.With(f => f.SeasonNumber = -1) .With(f => f.SeasonNumber = -1)
.Build(); .BuildNew<SceneMapping>();
Db.Insert(fakeMap); Db.Insert(fakeMap);

View File

@ -1,138 +1,61 @@
// ReSharper disable RedundantUsingDirective // ReSharper disable RedundantUsingDirective
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.TvTests namespace NzbDrone.Core.Test.TvTests
{ {
[TestFixture] public class SeasonProviderTest : DbTest<SeasonRepository, Season>
// ReSharper disable InconsistentNaming
public class SeasonProviderTest : DbTest
{ {
[SetUp]
public void Setup()
{
}
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void IsIgnored_should_return_ignored_status_of_season(bool ignoreFlag) public void IsIgnored_should_return_ignored_status_of_season(bool ignoreFlag)
{ {
//Setup
var fakeSeason = Builder<Season>.CreateNew() var fakeSeason = Builder<Season>.CreateNew()
.With(s => s.Ignored = ignoreFlag) .With(s => s.Ignored = ignoreFlag)
.Build(); .BuildNew<Season>();
Db.Insert(fakeSeason); Db.Insert(fakeSeason);
//Act var result = Subject.IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
var result = Mocker.Resolve<SeasonRepository>().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
//Assert
result.Should().Be(ignoreFlag); result.Should().Be(ignoreFlag);
} }
[Test] [Test]
public void IsIgnored_should_throw_an_exception_if_not_in_db() public void IsIgnored_should_return_false_if_not_in_db()
{ {
Assert.Throws<InvalidOperationException>(() => Mocker.Resolve<SeasonRepository>().IsIgnored(10, 0)); Subject.IsIgnored(10, 0).Should().BeFalse();
} }
[Test]
public void All_should_return_seasons_with_episodes()
{
const int seriesId = 10;
var season = Builder<Season>.CreateNew()
.With(s => s.SeriesId = seriesId)
.With(s => s.SeasonNumber = 4)
.With(s => s.Ignored = true)
.Build();
var episodes = Builder<Episode>.CreateListOfSize(10)
.All()
.With(e => e.SeriesId = seriesId)
.With(e => e.SeasonNumber = season.SeasonNumber)
.Build();
Db.Insert(season);
Db.InsertMany(episodes);
//Act
var result = Mocker.Resolve<SeasonRepository>().GetSeasonBySeries(seriesId);
//Assert
result.Should().HaveCount(1);
result.First().Episodes.Should().HaveCount(episodes.Count);
}
[Test]
public void All_should_return_all_seasons_with_episodes()
{
const int seriesId = 10;
//Setup
var seasons = Builder<Season>.CreateListOfSize(5)
.All()
.With(s => s.SeriesId = seriesId)
.Build();
var episodes = new List<Episode>();
for (int i = 0; i < seasons.Count; i++)
{
var newEps = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.SeriesId = seriesId)
.With(e => e.SeasonNumber = i + 1)
.Build();
episodes.AddRange(newEps);
}
Db.InsertMany(seasons);
Db.InsertMany(episodes);
//Act
var result = Mocker.Resolve<SeasonRepository>().GetSeasonBySeries(seriesId);
//Assert
result.Should().HaveCount(5);
foreach (var season in result)
{
season.Episodes.Count.Should().Be(2);
season.Episodes.Should().OnlyContain(c => c.SeasonNumber == season.SeasonNumber);
}
}
[Test] [Test]
public void GetSeason_should_return_seasons_for_specified_series_only() public void GetSeason_should_return_seasons_for_specified_series_only()
{ {
var seriesA = new[] { 1, 2, 3 }; var seriesA = new[] { 1, 2, 3 };
var seriesB = new[] { 4, 5, 6 }; var seriesB = new[] { 4, 5, 6 };
Mocker.Resolve<SeasonRepository>().GetSeasonNumbers(1).Should().Equal(seriesA); var seasonsA = seriesA.Select(c => new Season {SeasonNumber = c, SeriesId = 1}).ToList();
Mocker.Resolve<SeasonRepository>().GetSeasonNumbers(2).Should().Equal(seriesB); var seasonsB = seriesB.Select(c => new Season {SeasonNumber = c, SeriesId = 2}).ToList();
Subject.InsertMany(seasonsA);
Subject.InsertMany(seasonsB);
Subject.GetSeasonNumbers(1).Should().Equal(seriesA);
Subject.GetSeasonNumbers(2).Should().Equal(seriesB);
} }
[Test] [Test]
public void GetSeason_should_return_emptylist_if_series_doesnt_exist() public void GetSeason_should_return_emptylist_if_series_doesnt_exist()
{ {
Mocker.Resolve<SeasonRepository>().GetSeasonNumbers(1).Should().BeEmpty(); Subject.GetSeasonNumbers(1).Should().BeEmpty();
} }
} }

View File

@ -15,7 +15,6 @@ public class Log : ModelBase
public string Method { get; set; } public string Method { get; set; }
public string Exception { get; set; } public string Exception { get; set; }
public string ExceptionType { get; set; } public string ExceptionType { get; set; }

View File

@ -25,7 +25,7 @@ public SeasonRepository(IDatabase database)
public IList<int> GetSeasonNumbers(int seriesId) public IList<int> GetSeasonNumbers(int seriesId)
{ {
return Query.Where(c => c.SeriesId == seriesId).Select(c => c.SeriesId).ToList(); return Query.Where(c => c.SeriesId == seriesId).Select(c => c.SeasonNumber).ToList();
} }
public Season Get(int seriesId, int seasonNumber) public Season Get(int seriesId, int seasonNumber)

View File

@ -34,14 +34,14 @@ public class SeriesService : ISeriesService
private readonly TvRageMappingProvider _tvRageMappingProvider; private readonly TvRageMappingProvider _tvRageMappingProvider;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly IQualityProfileService _qualityProfileService; private readonly IQualityProfileService _qualityProfileService;
private readonly Logger _logger;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly SceneMappingService _sceneNameMappingService; private readonly ISceneMappingService _sceneNameMappingService;
public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService,
TvDbProxy tvDbProxyProxy, SceneMappingService sceneNameMappingService, TvDbProxy tvDbProxyProxy, ISceneMappingService sceneNameMappingService,
TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator, IQualityProfileService qualityProfileService) TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator, IQualityProfileService qualityProfileService, Logger logger)
{ {
_seriesRepository = seriesRepository; _seriesRepository = seriesRepository;
_configService = configServiceService; _configService = configServiceService;
@ -50,6 +50,7 @@ public SeriesService(ISeriesRepository seriesRepository, IConfigService configSe
_tvRageMappingProvider = tvRageMappingProvider; _tvRageMappingProvider = tvRageMappingProvider;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_qualityProfileService = qualityProfileService; _qualityProfileService = qualityProfileService;
_logger = logger;
} }
@ -84,7 +85,7 @@ public Series UpdateSeriesInfo(int seriesId)
catch (Exception ex) catch (Exception ex)
{ {
logger.ErrorException("Error getting TvRage information for series: " + series.Title, ex); _logger.ErrorException("Error getting TvRage information for series: " + series.Title, ex);
} }
_seriesRepository.Update(series); _seriesRepository.Update(series);
@ -110,7 +111,7 @@ public Series FindSeries(string title)
public void AddSeries(string title, string path, int tvDbSeriesId, int qualityProfileId, DateTime? airedAfter) public void AddSeries(string title, string path, int tvDbSeriesId, int qualityProfileId, DateTime? airedAfter)
{ {
logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path); _logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path);
Ensure.That(() => tvDbSeriesId).IsGreaterThan(0); Ensure.That(() => tvDbSeriesId).IsGreaterThan(0);
Ensure.That(() => title).IsNotNullOrWhiteSpace(); Ensure.That(() => title).IsNotNullOrWhiteSpace();

View File

@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Test.Common
{
public static class NBuilderExtensions
{
public static T BuildNew<T>(this ISingleObjectBuilder<T> builder) where T : ModelBase, new()
{
return builder.With(c => c.Id = 0).Build();
}
public static List<T> BuildList<T>(this IOperable<T> builder) where T : ModelBase, new()
{
return builder.Build().ToList();
}
public static List<T> BuildListOfNew<T>(this IOperable<T> builder) where T : ModelBase, new()
{
return BuildList<T>(builder.All().With(c => c.Id = 0));
}
}
}

View File

@ -53,6 +53,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="FizzWare.NBuilder">
<HintPath>..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation"> <Reference Include="Microsoft.Practices.ServiceLocation">
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath> <HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference> </Reference>
@ -89,6 +92,7 @@
<Compile Include="ExceptionVerification.cs" /> <Compile Include="ExceptionVerification.cs" />
<Compile Include="LoggingTest.cs" /> <Compile Include="LoggingTest.cs" />
<Compile Include="MockerExtensions.cs" /> <Compile Include="MockerExtensions.cs" />
<Compile Include="NBuilderExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReflectionExtensions.cs" /> <Compile Include="ReflectionExtensions.cs" />
<Compile Include="TestBase.cs" /> <Compile Include="TestBase.cs" />
@ -104,6 +108,10 @@
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project> <Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name> <Name>NzbDrone.Common</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
<Name>NzbDrone.Core</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> <Import Project="$(SolutionDir)\.nuget\nuget.targets" />

View File

@ -2,6 +2,7 @@
<packages> <packages>
<package id="CommonServiceLocator" version="1.0" /> <package id="CommonServiceLocator" version="1.0" />
<package id="Moq" version="4.0.10827" /> <package id="Moq" version="4.0.10827" />
<package id="NBuilder" version="3.0.1.1" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" /> <package id="NLog" version="2.0.0.2000" />
<package id="NUnit" version="2.6.2" targetFramework="net40" /> <package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="Unity" version="2.1.505.2" targetFramework="net40" /> <package id="Unity" version="2.1.505.2" targetFramework="net40" />

View File

@ -2,6 +2,7 @@
<FileVersion>1</FileVersion> <FileVersion>1</FileVersion>
<AutoEnableOnStartup>True</AutoEnableOnStartup> <AutoEnableOnStartup>True</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution> <AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit> <FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio> <FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec> <FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>