2013-04-15 01:41:39 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-05-19 22:57:01 +00:00
|
|
|
|
using System.Linq;
|
2011-09-14 04:37:22 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-03-07 00:19:49 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-02-27 03:19:22 +00:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2011-09-14 04:37:22 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2017-08-14 02:58:42 +00:00
|
|
|
|
using NzbDrone.Core.Music;
|
2011-09-14 04:37:22 +00:00
|
|
|
|
|
2013-02-19 02:19:38 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
|
|
|
|
public class AcceptableSizeSpecificationFixture : CoreTest<AcceptableSizeSpecification>
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
2017-12-28 02:41:11 +00:00
|
|
|
|
private const int HIGH_KBPS_BITRATE = 1600;
|
|
|
|
|
private const int TWENTY_MINUTE_EP_MILLIS = 20 * 60 * 1000;
|
|
|
|
|
private const int FORTY_FIVE_MINUTE_LP_MILLIS = 45 * 60 * 1000;
|
2017-08-14 02:58:42 +00:00
|
|
|
|
private RemoteAlbum parseResultMultiSet;
|
|
|
|
|
private RemoteAlbum parseResultMulti;
|
|
|
|
|
private RemoteAlbum parseResultSingle;
|
|
|
|
|
private Artist artist;
|
2014-01-18 11:44:36 +00:00
|
|
|
|
private QualityDefinition qualityType;
|
2011-09-14 04:37:22 +00:00
|
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
|
private Album AlbumBuilder(int id = 0)
|
|
|
|
|
{
|
|
|
|
|
return new Album
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
AlbumReleases = new List<AlbumRelease> { new AlbumRelease
|
|
|
|
|
{
|
|
|
|
|
Duration = 0,
|
|
|
|
|
Monitored = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 04:37:22 +00:00
|
|
|
|
[SetUp]
|
2011-10-24 05:54:09 +00:00
|
|
|
|
public void Setup()
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
|
artist = Builder<Artist>.CreateNew()
|
2014-02-15 10:51:52 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultMultiSet = new RemoteAlbum
|
|
|
|
|
{
|
|
|
|
|
Artist = artist,
|
2014-02-15 10:51:52 +00:00
|
|
|
|
Release = new ReleaseInfo(),
|
2017-08-14 02:58:42 +00:00
|
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
2018-12-15 00:02:43 +00:00
|
|
|
|
Albums = new List<Album> { AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder() }
|
2014-02-15 10:51:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultMulti = new RemoteAlbum
|
|
|
|
|
{
|
|
|
|
|
Artist = artist,
|
2014-02-15 10:51:52 +00:00
|
|
|
|
Release = new ReleaseInfo(),
|
2017-08-14 02:58:42 +00:00
|
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
2018-12-15 00:02:43 +00:00
|
|
|
|
Albums = new List<Album> { AlbumBuilder(), AlbumBuilder() }
|
2014-02-15 10:51:52 +00:00
|
|
|
|
};
|
2011-09-14 04:37:22 +00:00
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultSingle = new RemoteAlbum
|
|
|
|
|
{
|
|
|
|
|
Artist = artist,
|
2013-09-13 23:17:58 +00:00
|
|
|
|
Release = new ReleaseInfo(),
|
2017-08-14 02:58:42 +00:00
|
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
2018-12-15 00:02:43 +00:00
|
|
|
|
Albums = new List<Album> { AlbumBuilder(2) }
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
2011-09-14 04:37:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-05-19 22:57:01 +00:00
|
|
|
|
Mocker.GetMock<IQualityDefinitionService>()
|
|
|
|
|
.Setup(v => v.Get(It.IsAny<Quality>()))
|
|
|
|
|
.Returns<Quality>(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v));
|
|
|
|
|
|
2014-01-18 11:44:36 +00:00
|
|
|
|
qualityType = Builder<QualityDefinition>.CreateNew()
|
2017-12-28 02:41:11 +00:00
|
|
|
|
.With(q => q.MinSize = 150)
|
|
|
|
|
.With(q => q.MaxSize = 210)
|
2017-07-03 18:39:06 +00:00
|
|
|
|
.With(q => q.Quality = Quality.MP3_192)
|
2011-09-14 04:37:22 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2017-07-03 18:39:06 +00:00
|
|
|
|
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.MP3_192)).Returns(qualityType);
|
2014-05-02 22:04:58 +00:00
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
|
Mocker.GetMock<IAlbumService>().Setup(
|
|
|
|
|
s => s.GetAlbumsByArtist(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Album>() {
|
2018-12-15 00:02:43 +00:00
|
|
|
|
AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(),
|
|
|
|
|
AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(2), AlbumBuilder() });
|
2014-02-17 01:05:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
|
private void GivenLastAlbum()
|
2014-02-17 01:05:11 +00:00
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
|
Mocker.GetMock<IAlbumService>().Setup(
|
|
|
|
|
s => s.GetAlbumsByArtist(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Album> {
|
2018-12-15 00:02:43 +00:00
|
|
|
|
AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(),
|
|
|
|
|
AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(), AlbumBuilder(2) });
|
2011-09-14 04:37:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 02:41:11 +00:00
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 20, false)]
|
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 25, true)]
|
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 35, false)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 45, false)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 55, true)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 75, false)]
|
2017-08-14 02:58:42 +00:00
|
|
|
|
public void single_album(int runtime, int sizeInMegaBytes, bool expectedResult)
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
|
parseResultSingle.Albums.Select(c => { c.AlbumReleases.Value[0].Duration = runtime; return c; }).ToList();
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultSingle.Artist = artist;
|
2014-02-15 10:51:52 +00:00
|
|
|
|
parseResultSingle.Release.Size = sizeInMegaBytes.Megabytes();
|
2011-09-14 04:37:22 +00:00
|
|
|
|
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(parseResultSingle, null).Accepted.Should().Be(expectedResult);
|
2011-09-14 04:37:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 02:41:11 +00:00
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 20 * 2, false)]
|
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 25 * 2, true)]
|
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 35 * 2, false)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 45 * 2, false)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 55 * 2, true)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 75 * 2, false)]
|
2017-08-14 02:58:42 +00:00
|
|
|
|
public void multi_album(int runtime, int sizeInMegaBytes, bool expectedResult)
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
|
parseResultMulti.Albums.Select(c => { c.AlbumReleases.Value[0].Duration = runtime; return c; }).ToList();
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultMulti.Artist = artist;
|
2014-02-15 10:51:52 +00:00
|
|
|
|
parseResultMulti.Release.Size = sizeInMegaBytes.Megabytes();
|
2011-09-14 04:37:22 +00:00
|
|
|
|
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(parseResultMulti, null).Accepted.Should().Be(expectedResult);
|
2011-09-14 04:37:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 02:41:11 +00:00
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 20 * 6, false)]
|
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 25 * 6, true)]
|
|
|
|
|
[TestCase(TWENTY_MINUTE_EP_MILLIS, 35 * 6, false)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 45 * 6, false)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 55 * 6, true)]
|
|
|
|
|
[TestCase(FORTY_FIVE_MINUTE_LP_MILLIS, 75 * 6, false)]
|
2017-08-14 02:58:42 +00:00
|
|
|
|
public void multiset_album(int runtime, int sizeInMegaBytes, bool expectedResult)
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
|
parseResultMultiSet.Albums.Select(c => { c.AlbumReleases.Value[0].Duration = runtime; return c; }).ToList();
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultMultiSet.Artist = artist;
|
2014-02-15 10:51:52 +00:00
|
|
|
|
parseResultMultiSet.Release.Size = sizeInMegaBytes.Megabytes();
|
2011-09-14 04:37:22 +00:00
|
|
|
|
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(parseResultMultiSet, null).Accepted.Should().Be(expectedResult);
|
2011-09-14 04:37:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-14 20:57:45 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_true_if_size_is_zero()
|
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
|
GivenLastAlbum();
|
2018-12-15 00:02:43 +00:00
|
|
|
|
parseResultSingle.Albums.Select(c => { c.AlbumReleases.Value[0].Duration = TWENTY_MINUTE_EP_MILLIS; return c; }).ToList();
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultSingle.Artist = artist;
|
2015-05-14 20:57:45 +00:00
|
|
|
|
parseResultSingle.Release.Size = 0;
|
2017-12-28 02:41:11 +00:00
|
|
|
|
qualityType.MinSize = 150;
|
|
|
|
|
qualityType.MaxSize = 210;
|
2015-05-14 20:57:45 +00:00
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(parseResultSingle, null).Accepted.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 04:37:22 +00:00
|
|
|
|
[Test]
|
2017-12-28 02:41:11 +00:00
|
|
|
|
public void should_return_true_if_unlimited_20_minute()
|
2011-09-14 04:37:22 +00:00
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
|
GivenLastAlbum();
|
2018-12-15 00:02:43 +00:00
|
|
|
|
parseResultSingle.Albums.Select(c => { c.AlbumReleases.Value[0].Duration = TWENTY_MINUTE_EP_MILLIS; return c; }).ToList();
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultSingle.Artist = artist;
|
2017-12-28 02:41:11 +00:00
|
|
|
|
parseResultSingle.Release.Size = (HIGH_KBPS_BITRATE * 128) * (TWENTY_MINUTE_EP_MILLIS / 1000);
|
2015-05-19 22:57:01 +00:00
|
|
|
|
qualityType.MaxSize = null;
|
2011-09-16 04:42:30 +00:00
|
|
|
|
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(parseResultSingle, null).Accepted.Should().BeTrue();
|
2011-09-16 04:42:30 +00:00
|
|
|
|
}
|
2014-02-17 01:05:11 +00:00
|
|
|
|
|
2011-09-16 04:42:30 +00:00
|
|
|
|
[Test]
|
2017-12-28 02:41:11 +00:00
|
|
|
|
public void should_return_true_if_unlimited_45_minute()
|
2011-09-16 04:42:30 +00:00
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
|
GivenLastAlbum();
|
2018-12-15 00:02:43 +00:00
|
|
|
|
parseResultSingle.Albums.Select(c => { c.AlbumReleases.Value[0].Duration = FORTY_FIVE_MINUTE_LP_MILLIS; return c; }).ToList();
|
2017-08-14 02:58:42 +00:00
|
|
|
|
parseResultSingle.Artist = artist;
|
2017-12-28 02:41:11 +00:00
|
|
|
|
parseResultSingle.Release.Size = (HIGH_KBPS_BITRATE * 128) * (FORTY_FIVE_MINUTE_LP_MILLIS / 1000);
|
2015-05-19 22:57:01 +00:00
|
|
|
|
qualityType.MaxSize = null;
|
2011-09-16 04:42:30 +00:00
|
|
|
|
|
2015-05-19 22:57:01 +00:00
|
|
|
|
Subject.IsSatisfiedBy(parseResultSingle, null).Accepted.Should().BeTrue();
|
2011-09-16 04:42:30 +00:00
|
|
|
|
}
|
2011-12-01 05:08:36 +00:00
|
|
|
|
|
2011-09-14 04:37:22 +00:00
|
|
|
|
}
|
2014-12-09 03:27:33 +00:00
|
|
|
|
}
|