You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.7 KiB
147 lines
4.7 KiB
12 years ago
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
14 years ago
|
using FluentAssertions;
|
||
12 years ago
|
using Moq;
|
||
14 years ago
|
using NUnit.Framework;
|
||
12 years ago
|
using NzbDrone.Core.MediaFiles;
|
||
12 years ago
|
using NzbDrone.Core.Organizer;
|
||
14 years ago
|
using NzbDrone.Core.Test.Framework;
|
||
12 years ago
|
using NzbDrone.Test.Common;
|
||
14 years ago
|
|
||
11 years ago
|
namespace NzbDrone.Core.Test.MediaFiles
|
||
14 years ago
|
{
|
||
|
[TestFixture]
|
||
12 years ago
|
public class MediaFileServiceTest : CoreTest<MediaFileService>
|
||
14 years ago
|
{
|
||
14 years ago
|
|
||
14 years ago
|
[Test]
|
||
12 years ago
|
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]",
|
||
|
"Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")]
|
||
14 years ago
|
public void CleanFileName(string name, string expectedName)
|
||
|
{
|
||
12 years ago
|
FileNameBuilder.CleanFilename(name).Should().Be(expectedName);
|
||
14 years ago
|
}
|
||
12 years ago
|
|
||
|
[Test]
|
||
|
public void filter_should_return_all_files_if_no_existing_files()
|
||
|
{
|
||
|
var files = new List<string>()
|
||
|
{
|
||
12 years ago
|
"c:\\file1.avi".AsOsAgnostic(),
|
||
|
"c:\\file2.avi".AsOsAgnostic(),
|
||
|
"c:\\file3.avi".AsOsAgnostic()
|
||
12 years ago
|
};
|
||
|
|
||
|
Mocker.GetMock<IMediaFileRepository>()
|
||
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||
|
.Returns(new List<EpisodeFile>());
|
||
|
|
||
|
|
||
|
Subject.FilterExistingFiles(files, 10).Should().BeEquivalentTo(files);
|
||
|
}
|
||
|
|
||
|
|
||
|
[Test]
|
||
|
public void filter_should_return_none_if_all_files_exist()
|
||
|
{
|
||
|
var files = new List<string>()
|
||
|
{
|
||
12 years ago
|
"c:\\file1.avi".AsOsAgnostic(),
|
||
|
"c:\\file2.avi".AsOsAgnostic(),
|
||
|
"c:\\file3.avi".AsOsAgnostic()
|
||
12 years ago
|
};
|
||
|
|
||
|
Mocker.GetMock<IMediaFileRepository>()
|
||
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||
|
.Returns(files.Select(f => new EpisodeFile { Path = f }).ToList());
|
||
|
|
||
|
|
||
|
Subject.FilterExistingFiles(files, 10).Should().BeEmpty();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void filter_should_return_none_existing_files()
|
||
|
{
|
||
|
var files = new List<string>()
|
||
|
{
|
||
12 years ago
|
"c:\\file1.avi".AsOsAgnostic(),
|
||
|
"c:\\file2.avi".AsOsAgnostic(),
|
||
|
"c:\\file3.avi".AsOsAgnostic()
|
||
12 years ago
|
};
|
||
|
|
||
|
Mocker.GetMock<IMediaFileRepository>()
|
||
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||
|
.Returns(new List<EpisodeFile>
|
||
|
{
|
||
12 years ago
|
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
||
12 years ago
|
});
|
||
|
|
||
|
|
||
|
Subject.FilterExistingFiles(files, 10).Should().HaveCount(2);
|
||
12 years ago
|
Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic());
|
||
12 years ago
|
}
|
||
11 years ago
|
|
||
|
[Test]
|
||
|
public void filter_should_return_none_existing_files_ignoring_case()
|
||
|
{
|
||
11 years ago
|
WindowsOnly();
|
||
|
|
||
11 years ago
|
var files = new List<string>()
|
||
|
{
|
||
|
"c:\\file1.avi".AsOsAgnostic(),
|
||
|
"c:\\FILE2.avi".AsOsAgnostic(),
|
||
|
"c:\\file3.avi".AsOsAgnostic()
|
||
|
};
|
||
|
|
||
|
Mocker.GetMock<IMediaFileRepository>()
|
||
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||
|
.Returns(new List<EpisodeFile>
|
||
|
{
|
||
|
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
||
|
});
|
||
|
|
||
|
|
||
|
Subject.FilterExistingFiles(files, 10).Should().HaveCount(2);
|
||
|
Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic());
|
||
|
}
|
||
11 years ago
|
|
||
|
[Test]
|
||
|
public void filter_should_return_none_existing_files_not_ignoring_case()
|
||
|
{
|
||
|
LinuxOnly();
|
||
|
|
||
|
var files = new List<string>()
|
||
|
{
|
||
|
"c:\\file1.avi".AsOsAgnostic(),
|
||
|
"c:\\FILE2.avi".AsOsAgnostic(),
|
||
|
"c:\\file3.avi".AsOsAgnostic()
|
||
|
};
|
||
|
|
||
|
Mocker.GetMock<IMediaFileRepository>()
|
||
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||
|
.Returns(new List<EpisodeFile>
|
||
|
{
|
||
|
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
||
|
});
|
||
|
|
||
|
Subject.FilterExistingFiles(files, 10).Should().HaveCount(3);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void filter_should_not_change_casing()
|
||
|
{
|
||
|
var files = new List<string>()
|
||
|
{
|
||
|
"c:\\FILE1.avi".AsOsAgnostic()
|
||
|
};
|
||
|
|
||
|
Mocker.GetMock<IMediaFileRepository>()
|
||
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||
|
.Returns(new List<EpisodeFile>());
|
||
|
|
||
|
Subject.FilterExistingFiles(files, 10).Should().HaveCount(1);
|
||
|
Subject.FilterExistingFiles(files, 10).Should().NotContain(files.First().ToLower());
|
||
|
Subject.FilterExistingFiles(files, 10).Should().Contain(files.First());
|
||
|
}
|
||
14 years ago
|
}
|
||
14 years ago
|
}
|