mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
cleaned up some tests.
This commit is contained in:
parent
1ccbb3c9d8
commit
35cb7e55c7
@ -1,44 +0,0 @@
|
||||
using Autofac;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class CentralDispatchTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void Kernel_can_get_kernel()
|
||||
{
|
||||
NzbDroneBootstrapper.Container.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Kernel_should_return_same_kernel()
|
||||
{
|
||||
var firstKernel = NzbDroneBootstrapper.Container;
|
||||
var secondKernel = NzbDroneBootstrapper.Container;
|
||||
|
||||
firstKernel.Should().BeSameAs(secondKernel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Kernel_should_be_able_to_resolve_ApplicationServer()
|
||||
{
|
||||
var appServer = NzbDroneBootstrapper.Container.Resolve<ApplicationServer>();
|
||||
|
||||
appServer.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Kernel_should_resolve_same_ApplicationServer_instance()
|
||||
{
|
||||
var appServer1 = NzbDroneBootstrapper.Container.Resolve<ApplicationServer>();
|
||||
var appServer2 = NzbDroneBootstrapper.Container.Resolve<ApplicationServer>();
|
||||
|
||||
appServer1.Should().BeSameAs(appServer2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -81,7 +81,6 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CentralDispatchTests.cs" />
|
||||
<Compile Include="IISProviderFixture.cs" />
|
||||
<Compile Include="RouterTest.cs" />
|
||||
<Compile Include="MonitoringProviderTest.cs" />
|
||||
|
@ -147,7 +147,7 @@
|
||||
<Content Include="Shared\ModalRegion.js" />
|
||||
<Content Include="Shared\NotificationCollection.js" />
|
||||
<Content Include="Shared\NotificationModel.js" />
|
||||
<Content Include="Shared\NotificationsView.js" />
|
||||
<Content Include="Shared\NotificationView.js" />
|
||||
<Content Include="Shared\SpinnerTemplate.html" />
|
||||
<Content Include="Shared\SpinnerView.js" />
|
||||
<Content Include="Upcoming\UpcomingCollection.js" />
|
||||
|
@ -8,8 +8,7 @@
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore
|
||||
{
|
||||
|
||||
public class SampleType : ModelBase
|
||||
public class BaiscType : ModelBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Tilte { get; set; }
|
||||
@ -17,25 +16,25 @@ public class SampleType : ModelBase
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class SimpleRepositoryFixture : ObjectDbTest<BasicRepository<SampleType>,SampleType>
|
||||
public class BasicRepositoryFixture : ObjectDbTest<BasicRepository<BaiscType>,BaiscType>
|
||||
{
|
||||
private SampleType sampleType;
|
||||
private BaiscType _baiscType;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
sampleType = Builder<SampleType>
|
||||
.CreateNew()
|
||||
.With(c => c.Id = 0)
|
||||
.Build();
|
||||
_baiscType = Builder<BaiscType>
|
||||
.CreateNew()
|
||||
.With(c => c.Id = 0)
|
||||
.Build();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_add()
|
||||
{
|
||||
Subject.Insert(sampleType);
|
||||
Subject.Insert(_baiscType);
|
||||
Subject.All().Should().HaveCount(1);
|
||||
}
|
||||
|
||||
@ -44,21 +43,21 @@ public void should_be_able_to_add()
|
||||
[Test]
|
||||
public void should_be_able_to_delete_model()
|
||||
{
|
||||
Subject.Insert(sampleType);
|
||||
Subject.Insert(_baiscType);
|
||||
Subject.All().Should().HaveCount(1);
|
||||
|
||||
Subject.Delete(sampleType.Id);
|
||||
Subject.Delete(_baiscType.Id);
|
||||
Subject.All().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_find_by_id()
|
||||
{
|
||||
Subject.Insert(sampleType);
|
||||
Subject.Get(sampleType.Id)
|
||||
.ShouldHave()
|
||||
.AllProperties()
|
||||
.EqualTo(sampleType);
|
||||
Subject.Insert(_baiscType);
|
||||
Subject.Get(_baiscType.Id)
|
||||
.ShouldHave()
|
||||
.AllProperties()
|
||||
.EqualTo(_baiscType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -73,5 +72,13 @@ public void get_all_with_empty_db_should_return_empty_list()
|
||||
{
|
||||
Subject.All().Should().BeEmpty();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_call_ToList_on_empty_quariable()
|
||||
{
|
||||
Subject.All().ToList().Should().BeEmpty();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -205,9 +205,9 @@ public void update_field_should_only_update_that_filed()
|
||||
|
||||
Db.Insert(childModel);
|
||||
|
||||
_childModel.A = "A_New";
|
||||
_childModel.B = 2;
|
||||
_childModel.C = 2;
|
||||
childModel.A = "A_New";
|
||||
childModel.B = 2;
|
||||
childModel.C = 2;
|
||||
|
||||
Db.UpdateField(childModel, "B");
|
||||
|
||||
|
@ -0,0 +1,82 @@
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaFileRepositoryFixture : ObjectDbTest<MediaFileRepository, EpisodeFile>
|
||||
{
|
||||
[Test]
|
||||
public void get_files_by_series()
|
||||
{
|
||||
var files = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Id = 0)
|
||||
.Random(4)
|
||||
.With(s => s.SeriesId = 12)
|
||||
.Build();
|
||||
|
||||
|
||||
Db.InsertMany(files);
|
||||
|
||||
var seriesFiles = Subject.GetFilesBySeries(12);
|
||||
|
||||
seriesFiles.Should().HaveCount(4);
|
||||
seriesFiles.Should().OnlyContain(c => c.SeriesId == 12);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_files_by_season()
|
||||
{
|
||||
var files = Builder<EpisodeFile>.CreateListOfSize(20)
|
||||
.All()
|
||||
.With(c => c.Id = 0)
|
||||
.With(s => s.SeasonNumber = 10)
|
||||
.TheFirst(10)
|
||||
.With(c => c.SeriesId = 1)
|
||||
.TheNext(10)
|
||||
.With(c => c.SeriesId = 2)
|
||||
.Random(10)
|
||||
.With(s => s.SeasonNumber = 20)
|
||||
.Build();
|
||||
|
||||
|
||||
Db.InsertMany(files);
|
||||
|
||||
|
||||
Subject.GetFilesBySeason(1, 20).Should().OnlyContain(c => c.SeriesId == 1 && c.SeasonNumber == 20);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database()
|
||||
{
|
||||
Subject.GetFileByPath(@"C:\Test\EpisodeFile.avi").Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database()
|
||||
{
|
||||
var path = @"C:\Test\EpisodeFile.avi";
|
||||
|
||||
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(f => f.Id = 0)
|
||||
.With(f => f.Path = path.NormalizePath())
|
||||
.Build();
|
||||
|
||||
Subject.Insert(episodeFile);
|
||||
|
||||
var file = Subject.GetFileByPath(path);
|
||||
|
||||
//Resolve
|
||||
file.Should().NotBeNull();
|
||||
file.Path.Should().Be(path.NormalizePath());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,112 +1,23 @@
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class MediaFileServiceTest : ObjectDbTest
|
||||
public class MediaFileServiceTest : CoreTest<MediaFileService>
|
||||
{
|
||||
[Test]
|
||||
public void get_series_files()
|
||||
{
|
||||
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.With(s => s.SeriesId = 12).Build();
|
||||
|
||||
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.With(s => s.SeriesId = 20).Build();
|
||||
|
||||
|
||||
|
||||
|
||||
Db.InsertMany(firstSeriesFiles);
|
||||
Db.InsertMany(secondSeriesFiles);
|
||||
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFilesBySeries(12);
|
||||
|
||||
|
||||
result.Should().HaveSameCount(firstSeriesFiles);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_season_files()
|
||||
{
|
||||
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.With(s => s.SeriesId = 12)
|
||||
.With(s => s.SeasonNumber = 1)
|
||||
.Build();
|
||||
|
||||
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.With(s => s.SeriesId = 12)
|
||||
.With(s => s.SeasonNumber = 2)
|
||||
.Build();
|
||||
|
||||
|
||||
|
||||
Db.InsertMany(firstSeriesFiles);
|
||||
Db.InsertMany(secondSeriesFiles);
|
||||
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFilesBySeason(12, 1);
|
||||
|
||||
result.Should().HaveSameCount(firstSeriesFiles);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Scan_series_should_skip_series_with_no_episodes()
|
||||
{
|
||||
WithStrictMocker();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.GetEpisodeBySeries(12))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.Id = 12).Build();
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<DiskScanProvider>().Scan(series);
|
||||
|
||||
//Assert
|
||||
Mocker.VerifyAllMocks();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]", "Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")]
|
||||
public void CleanFileName(string name, string expectedName)
|
||||
{
|
||||
//Act
|
||||
var result = MediaFileService.CleanFilename(name);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(expectedName, result);
|
||||
MediaFileService.CleanFilename(name).Should().Be(expectedName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -117,74 +28,15 @@ public void CleanFileName(string name, string expectedName)
|
||||
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "ReallyUglySeasonFolder %s", @"C:\Test\30 Rock\ReallyUglySeasonFolder 1\30 Rock - S01E05 - Episode Title.mkv")]
|
||||
public void CalculateFilePath_SeasonFolder_SingleNumber(string filename, int seasonNumber, bool useSeasonFolder, string seasonFolderFormat, string expectedPath)
|
||||
{
|
||||
//Setup
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.Title = "30 Rock")
|
||||
.With(s => s.Path = @"C:\Test\30 Rock")
|
||||
.With(s => s.SeasonFolder = useSeasonFolder)
|
||||
.Build();
|
||||
|
||||
|
||||
Mocker.GetMock<IConfigService>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat);
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<IMediaFileService>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(expectedPath, result.FullName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteEpisodeFile()
|
||||
{
|
||||
//Setup
|
||||
var episodeFiles = Builder<EpisodeFile>
|
||||
.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.Build();
|
||||
|
||||
|
||||
Db.InsertMany(episodeFiles);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<IMediaFileService>().Delete(1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database()
|
||||
{
|
||||
//Setup
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFileByPath(@"C:\Test\EpisodeFile.avi");
|
||||
|
||||
//Resolve
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database()
|
||||
{
|
||||
var path = @"C:\Test\EpisodeFile.avi";
|
||||
|
||||
//Setup
|
||||
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(c => c.Quality = Quality.SDTV)
|
||||
.With(f => f.Path = path.NormalizePath())
|
||||
.Build();
|
||||
|
||||
var episodeFileId = Convert.ToInt32(Db.Insert(episodeFile));
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<IMediaFileService>().GetFileByPath(path);
|
||||
|
||||
//Resolve
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path.NormalizePath());
|
||||
result.Id.Should().Be(episodeFileId);
|
||||
Subject.CalculateFilePath(fakeSeries, 1, filename, ".mkv").FullName.Should().Be(expectedPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -131,7 +131,7 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Datastore\SimpleRepositoryFixture.cs" />
|
||||
<Compile Include="Datastore\BasicRepositoryFixture.cs" />
|
||||
<Compile Include="Datastore\ObjectDatabaseFixture.cs" />
|
||||
<Compile Include="Framework\CoreTest.cs" />
|
||||
<Compile Include="Framework\ObjectDbTest.cs" />
|
||||
@ -141,6 +141,7 @@
|
||||
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\LanguageSpecificationFixture.cs" />
|
||||
<Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" />
|
||||
<Compile Include="MediaFileTests\MediaFileRepositoryFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadProviderTests\ContainsRecentEpisode.cs" />
|
||||
|
@ -119,7 +119,8 @@ public void DeleteMany<T>(IEnumerable<T> objects) where T : ModelBase
|
||||
|
||||
public void UpdateField<T>(T model, string fieldName) where T : ModelBase
|
||||
{
|
||||
_db.UpdateObjectBy(model, fieldName);
|
||||
_db.StoreObjectPartially(model, fieldName);
|
||||
|
||||
}
|
||||
|
||||
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function) where T : ModelBase
|
||||
|
Loading…
Reference in New Issue
Block a user