2013-08-08 18:52:22 +03:00
|
|
|
using System;
|
2013-08-12 18:29:01 +03:00
|
|
|
using System.IO;
|
2013-08-08 18:52:22 +03:00
|
|
|
using System.Linq;
|
|
|
|
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 20:54:59 +03:00
|
|
|
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
2013-08-08 18:52:22 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification>
|
|
|
|
{
|
|
|
|
private Series _series;
|
|
|
|
private LocalEpisode _localEpisode;
|
2013-08-12 18:43:40 +03:00
|
|
|
private String _rootFolder;
|
2013-08-08 18:52:22 +03:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2013-08-12 18:43:40 +03:00
|
|
|
_rootFolder = @"C:\Test\TV".AsOsAgnostic();
|
|
|
|
|
2013-08-08 18:52:22 +03:00
|
|
|
_series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesType = SeriesTypes.Standard)
|
2013-08-12 18:43:40 +03:00
|
|
|
.With(s => s.Path = Path.Combine(_rootFolder, "30 Rock"))
|
2013-08-08 18:52:22 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
.All()
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.Build()
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
_localEpisode = new LocalEpisode
|
|
|
|
{
|
2013-09-13 21:41:21 +03:00
|
|
|
Path = @"C:\Test\Unsorted\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
|
2013-08-08 18:52:22 +03:00
|
|
|
Episodes = episodes,
|
|
|
|
Series = _series
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GivenFileSize(long size)
|
|
|
|
{
|
|
|
|
_localEpisode.Size = size;
|
|
|
|
}
|
|
|
|
|
2013-09-10 18:31:58 +03:00
|
|
|
private void GivenFreeSpace(long? size)
|
2013-08-08 18:52:22 +03:00
|
|
|
{
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-09-01 07:38:06 +03:00
|
|
|
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
|
2013-08-08 18:52:22 +03:00
|
|
|
.Returns(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_reject_when_there_isnt_enough_disk_space()
|
|
|
|
{
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
GivenFreeSpace(80.Megabytes());
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
|
|
|
|
2013-08-08 19:24:23 +03:00
|
|
|
[Test]
|
|
|
|
public void should_reject_when_there_isnt_enough_space_for_file_plus_100mb_padding()
|
|
|
|
{
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
GivenFreeSpace(150.Megabytes());
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:52:22 +03:00
|
|
|
[Test]
|
|
|
|
public void should_accept_when_there_is_enough_disk_space()
|
|
|
|
{
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
GivenFreeSpace(1.Gigabytes());
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
}
|
2013-08-12 18:29:01 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_use_series_paths_parent_for_free_space_check()
|
|
|
|
{
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
GivenFreeSpace(1.Gigabytes());
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-09-01 07:38:06 +03:00
|
|
|
.Verify(v => v.GetAvailableSpace(_rootFolder), Times.Once());
|
2013-08-12 18:29:01 +03:00
|
|
|
}
|
2013-09-10 18:31:58 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_pass_if_free_space_is_null()
|
|
|
|
{
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
GivenFreeSpace(null);
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_pass_if_exception_is_thrown()
|
|
|
|
{
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-09-13 21:41:21 +03:00
|
|
|
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
|
|
|
|
.Throws(new TestException());
|
2013-09-10 18:31:58 +03:00
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
2013-09-10 20:54:59 +03:00
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
2013-09-10 18:31:58 +03:00
|
|
|
}
|
2013-09-13 21:41:21 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_skip_check_for_files_under_series_folder()
|
|
|
|
{
|
2013-09-14 03:41:14 +03:00
|
|
|
_localEpisode.ExistingFile = true;
|
2013-09-13 21:41:21 +03:00
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Verify(s => s.GetAvailableSpace(It.IsAny<String>()), Times.Never());
|
|
|
|
}
|
2013-09-14 03:41:14 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_free_space_is_null()
|
|
|
|
{
|
|
|
|
long? freeSpace = null;
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
|
|
|
|
.Returns(freeSpace);
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
}
|
2013-08-08 18:52:22 +03:00
|
|
|
}
|
|
|
|
}
|