2013-07-19 05:05:07 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2011-06-02 21:06:46 +00:00
|
|
|
using FluentAssertions;
|
2013-07-19 05:05:07 +00:00
|
|
|
using Moq;
|
2011-06-02 21:06:46 +00:00
|
|
|
using NUnit.Framework;
|
2013-03-01 07:03:41 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-03-06 21:20:33 +00:00
|
|
|
using NzbDrone.Core.Organizer;
|
2011-05-19 03:55:35 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-07-26 06:32:41 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
2013-09-10 17:54:59 +00:00
|
|
|
namespace NzbDrone.Core.Test.MediaFiles
|
2010-10-21 01:49:23 +00:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-03-05 01:47:51 +00:00
|
|
|
public class MediaFileServiceTest : CoreTest<MediaFileService>
|
2010-10-21 01:49:23 +00:00
|
|
|
{
|
2011-06-18 04:08:17 +00:00
|
|
|
|
2011-06-20 23:46:54 +00:00
|
|
|
[Test]
|
2013-07-19 05:05:07 +00:00
|
|
|
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]",
|
|
|
|
"Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")]
|
2011-06-20 23:46:54 +00:00
|
|
|
public void CleanFileName(string name, string expectedName)
|
|
|
|
{
|
2013-03-06 21:20:33 +00:00
|
|
|
FileNameBuilder.CleanFilename(name).Should().Be(expectedName);
|
2011-06-20 23:46:54 +00:00
|
|
|
}
|
2013-07-19 05:05:07 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void filter_should_return_all_files_if_no_existing_files()
|
|
|
|
{
|
|
|
|
var files = new List<string>()
|
|
|
|
{
|
2013-07-26 06:32:41 +00:00
|
|
|
"c:\\file1.avi".AsOsAgnostic(),
|
|
|
|
"c:\\file2.avi".AsOsAgnostic(),
|
|
|
|
"c:\\file3.avi".AsOsAgnostic()
|
2013-07-19 05:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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>()
|
|
|
|
{
|
2013-07-26 06:32:41 +00:00
|
|
|
"c:\\file1.avi".AsOsAgnostic(),
|
|
|
|
"c:\\file2.avi".AsOsAgnostic(),
|
|
|
|
"c:\\file3.avi".AsOsAgnostic()
|
2013-07-19 05:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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>()
|
|
|
|
{
|
2013-07-26 06:32:41 +00:00
|
|
|
"c:\\file1.avi".AsOsAgnostic(),
|
|
|
|
"c:\\file2.avi".AsOsAgnostic(),
|
|
|
|
"c:\\file3.avi".AsOsAgnostic()
|
2013-07-19 05:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileRepository>()
|
|
|
|
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
|
|
|
.Returns(new List<EpisodeFile>
|
|
|
|
{
|
2013-07-26 06:32:41 +00:00
|
|
|
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
2013-07-19 05:05:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Subject.FilterExistingFiles(files, 10).Should().HaveCount(2);
|
2013-07-26 06:32:41 +00:00
|
|
|
Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic());
|
2013-07-19 05:05:07 +00:00
|
|
|
}
|
2013-08-20 21:29:10 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void filter_should_return_none_existing_files_ignoring_case()
|
|
|
|
{
|
2013-08-27 19:13:11 +00:00
|
|
|
WindowsOnly();
|
|
|
|
|
2013-08-20 21:29:10 +00:00
|
|
|
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());
|
|
|
|
}
|
2013-08-27 19:13:11 +00:00
|
|
|
|
|
|
|
[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());
|
|
|
|
}
|
2010-10-21 01:49:23 +00:00
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
}
|