mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-31 03:11:07 +02:00
Cleaned and fixed broken tests
This commit is contained in:
parent
db585b3bd7
commit
f9370a8aec
@ -77,9 +77,11 @@ public virtual long GetDirectorySize(string path)
|
||||
|
||||
public virtual long GetSize(string path)
|
||||
{
|
||||
if (!FileExists(path))
|
||||
throw new FileNotFoundException("File doesn't exist: " + path);
|
||||
|
||||
var fi = new FileInfo(path);
|
||||
return fi.Length;
|
||||
//return new FileInfo(path).Length;
|
||||
}
|
||||
|
||||
public virtual String CreateDirectory(string path)
|
||||
@ -218,14 +220,6 @@ public static bool PathEquals(string firstPath, string secondPath)
|
||||
return String.Equals(firstPath.NormalizePath(), secondPath.NormalizePath(), StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public virtual long GetFileSize(string path)
|
||||
{
|
||||
if (!FileExists(path))
|
||||
throw new FileNotFoundException("File doesn't exist: " + path);
|
||||
|
||||
return new FileInfo(path).Length;
|
||||
}
|
||||
|
||||
public virtual void FileSetLastWriteTimeUtc(string path, DateTime dateTime)
|
||||
{
|
||||
File.SetLastWriteTimeUtc(path, dateTime);
|
||||
|
@ -22,11 +22,20 @@ public class ImportFileFixture : CoreTest
|
||||
{
|
||||
public static object[] ImportTestCases =
|
||||
{
|
||||
new object[] { QualityTypes.SDTV },
|
||||
new object[] { QualityTypes.DVD },
|
||||
new object[] { QualityTypes.HDTV }
|
||||
new object[] { QualityTypes.SDTV, false },
|
||||
new object[] { QualityTypes.DVD, true },
|
||||
new object[] { QualityTypes.HDTV, false }
|
||||
};
|
||||
|
||||
private readonly long SIZE = 50.Megabytes();
|
||||
|
||||
public void With50MBFile()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(d => d.GetSize(It.IsAny<String>()))
|
||||
.Returns(50.Megabytes());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_new_file_should_succeed()
|
||||
{
|
||||
@ -36,10 +45,7 @@ public void import_new_file_should_succeed()
|
||||
var fakeEpisode = Builder<Episode>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -52,7 +58,7 @@ public void import_new_file_should_succeed()
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
|
||||
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
||||
|
||||
}
|
||||
|
||||
@ -60,7 +66,6 @@ public void import_new_file_should_succeed()
|
||||
public void import_new_file_with_better_same_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper)
|
||||
{
|
||||
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
|
||||
const int size = 12345;
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
@ -69,13 +74,9 @@ public void import_new_file_with_better_same_quality_should_succeed(QualityTypes
|
||||
.With(g => g.Quality = (QualityTypes)currentFileQuality)
|
||||
.And(g => g.Proper = currentFileProper).Build()
|
||||
).Build();
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
||||
|
||||
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
||||
@ -84,7 +85,7 @@ public void import_new_file_with_better_same_quality_should_succeed(QualityTypes
|
||||
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")]
|
||||
@ -101,10 +102,7 @@ public void import_new_file_episode_has_same_or_better_quality_should_skip(strin
|
||||
.Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -123,19 +121,14 @@ public void import_new_file_episode_has_same_or_better_quality_should_skip(strin
|
||||
[Test]
|
||||
public void import_unparsable_file_should_skip()
|
||||
{
|
||||
const string fileName = @"WEEDS.avi";
|
||||
const int size = 12345;
|
||||
const string fileName = @"C:\Test\WEEDS.avi";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
@ -145,30 +138,6 @@ public void import_unparsable_file_should_skip()
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_sample_file_should_skip()
|
||||
{
|
||||
const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv";
|
||||
const int size = 12345;
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, Mocker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_existing_file_should_skip()
|
||||
{
|
||||
@ -181,6 +150,8 @@ public void import_existing_file_should_skip()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
With50MBFile();
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
@ -198,14 +169,12 @@ public void import_file_with_no_episode_in_db_should_skip()
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
||||
.Setup(e => e.GetSize(fileName)).Returns(90000000000);
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(new List<Episode>());
|
||||
@ -222,7 +191,6 @@ public void import_file_with_no_episode_in_db_should_skip()
|
||||
[TestCase("WEEDS.S03E01.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv")]
|
||||
public void import_new_file_episode_has_better_quality_than_existing(string fileName)
|
||||
{
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
@ -232,10 +200,7 @@ public void import_new_file_episode_has_better_quality_than_existing(string file
|
||||
.Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -248,7 +213,7 @@ public void import_new_file_episode_has_better_quality_than_existing(string file
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
|
||||
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
||||
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
@ -267,8 +232,7 @@ public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_
|
||||
.Build())
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -281,7 +245,7 @@ public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, Mocker, fakeEpisodes[0], 12345);
|
||||
VerifyFileImport(result, Mocker, fakeEpisodes[0], SIZE);
|
||||
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
@ -301,9 +265,7 @@ public void skip_import_new_multi_part_file_episode_existing_has_better_quality(
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -341,10 +303,7 @@ public void import_new_multi_part_file_episode_replace_two_files()
|
||||
.Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -357,7 +316,7 @@ public void import_new_multi_part_file_episode_replace_two_files()
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, Mocker, fakeEpisode1, 12345);
|
||||
VerifyFileImport(result, Mocker, fakeEpisode1, SIZE);
|
||||
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
@ -375,10 +334,7 @@ public void import_new_episode_no_existing_episode_file()
|
||||
.Build();
|
||||
|
||||
//Mocks
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
With50MBFile();
|
||||
|
||||
Mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
@ -391,7 +347,7 @@ public void import_new_episode_no_existing_episode_file()
|
||||
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
|
||||
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
||||
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
@ -409,15 +365,14 @@ public void should_return_null_if_file_size_is_under_40MB()
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(d => d.GetFileSize(path))
|
||||
.Setup(d => d.GetSize(path))
|
||||
.Returns(20.Megabytes());
|
||||
|
||||
Mocker.Resolve<DiskScanProvider>().ImportFile(series, path).Should().BeNull();
|
||||
}
|
||||
|
||||
private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episode fakeEpisode, int size)
|
||||
private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episode fakeEpisode, long size)
|
||||
{
|
||||
Mocker.VerifyAllMocks();
|
||||
result.Should().NotBeNull();
|
||||
result.SeriesId.Should().Be(fakeEpisode.SeriesId);
|
||||
result.Size.Should().Be(size);
|
||||
@ -432,7 +387,6 @@ private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episo
|
||||
|
||||
private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker)
|
||||
{
|
||||
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());
|
||||
|
@ -111,7 +111,7 @@ public void should_return_if_series_is_not_found()
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(file);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFileSize(It.IsAny<String>()), Times.Never());
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetSize(It.IsAny<String>()), Times.Never());
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ public void should_logError_and_return_if_size_exceeds_free_space()
|
||||
.Returns(series);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetFileSize(downloadName))
|
||||
.Setup(s => s.GetSize(downloadName))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
@ -178,7 +178,7 @@ public void should_process_if_free_disk_space_exceeds_size()
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetFileSize(downloadName))
|
||||
.Setup(s => s.GetSize(downloadName))
|
||||
.Returns(8);
|
||||
|
||||
//Act
|
||||
|
@ -138,7 +138,7 @@ public virtual void ProcessVideoFile(string videoFile)
|
||||
return;
|
||||
}
|
||||
|
||||
var size = _diskProvider.GetFileSize(videoFile);
|
||||
var size = _diskProvider.GetSize(videoFile);
|
||||
var freeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(series.Path));
|
||||
|
||||
if (Convert.ToUInt64(size) > freeSpace)
|
||||
|
Loading…
Reference in New Issue
Block a user