2013-08-08 15:52:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
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.Providers;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification>
|
|
|
|
|
{
|
|
|
|
|
private Series _series;
|
|
|
|
|
private LocalEpisode _localEpisode;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
_series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesType = SeriesTypes.Standard)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.Build()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
_localEpisode = new LocalEpisode
|
|
|
|
|
{
|
|
|
|
|
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
|
|
|
|
Episodes = episodes,
|
|
|
|
|
Series = _series
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenFileSize(long size)
|
|
|
|
|
{
|
|
|
|
|
_localEpisode.Size = size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenFreeSpace(long size)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.GetAvilableSpace(It.IsAny<String>()))
|
|
|
|
|
.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 16:24:23 +00: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 15:52:22 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_accept_when_there_is_enough_disk_space()
|
|
|
|
|
{
|
|
|
|
|
GivenFileSize(100.Megabytes());
|
|
|
|
|
GivenFreeSpace(1.Gigabytes());
|
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|