2013-08-11 22:55:26 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
2013-09-10 17:54:59 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
2013-08-11 22:55:26 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class NotInUseSpecificationFixture : CoreTest<NotInUseSpecification>
|
|
|
|
|
{
|
|
|
|
|
private LocalEpisode _localEpisode;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
_localEpisode = new LocalEpisode
|
|
|
|
|
{
|
|
|
|
|
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
|
|
|
|
|
Size = 100,
|
|
|
|
|
Series = Builder<Series>.CreateNew().Build()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenChildOfSeries()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenNewFile()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_true_if_file_is_under_series_folder()
|
|
|
|
|
{
|
|
|
|
|
GivenChildOfSeries();
|
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_check_for_file_in_use_if_child_of_series_folder()
|
|
|
|
|
{
|
|
|
|
|
GivenChildOfSeries();
|
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-09-12 06:52:37 +00:00
|
|
|
|
.Verify(v => v.IsFileLocked(It.IsAny<string>()), Times.Never());
|
2013-08-11 22:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_false_if_file_is_in_use()
|
|
|
|
|
{
|
|
|
|
|
GivenNewFile();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-09-12 06:52:37 +00:00
|
|
|
|
.Setup(s => s.IsFileLocked(It.IsAny<string>()))
|
2013-08-11 22:55:26 +00:00
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_true_if_file_is_not_in_use()
|
|
|
|
|
{
|
|
|
|
|
GivenNewFile();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-09-12 06:52:37 +00:00
|
|
|
|
.Setup(s => s.IsFileLocked(It.IsAny<string>()))
|
2013-08-11 22:55:26 +00:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|