1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core.Test/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs

106 lines
3.8 KiB
C#
Raw Normal View History

2013-04-07 10:30:37 +03:00
using System.Collections.Generic;
using System.Linq;
2013-03-07 06:45:36 +03:00
using FluentAssertions;
using Moq;
using NUnit.Framework;
2013-02-19 05:19:38 +03:00
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
2013-02-19 05:19:38 +03:00
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
2013-04-07 10:30:37 +03:00
public class AllowedDownloadSpecificationFixture : CoreTest<DownloadDecisionMaker>
{
private List<ReportInfo> _reports;
private RemoteEpisode _remoteEpisode;
2013-04-07 10:30:37 +03:00
private Mock<IDecisionEngineSpecification> _pass1;
private Mock<IDecisionEngineSpecification> _pass2;
private Mock<IDecisionEngineSpecification> _pass3;
2013-04-07 10:30:37 +03:00
private Mock<IDecisionEngineSpecification> _fail1;
private Mock<IDecisionEngineSpecification> _fail2;
private Mock<IDecisionEngineSpecification> _fail3;
2013-03-07 04:51:47 +03:00
[SetUp]
public void Setup()
{
2013-04-07 10:30:37 +03:00
_pass1 = new Mock<IDecisionEngineSpecification>();
_pass2 = new Mock<IDecisionEngineSpecification>();
_pass3 = new Mock<IDecisionEngineSpecification>();
2013-04-07 10:30:37 +03:00
_fail1 = new Mock<IDecisionEngineSpecification>();
_fail2 = new Mock<IDecisionEngineSpecification>();
_fail3 = new Mock<IDecisionEngineSpecification>();
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>())).Returns(true);
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>())).Returns(true);
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>())).Returns(true);
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>())).Returns(false);
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>())).Returns(false);
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>())).Returns(false);
2013-04-15 06:33:03 +03:00
_reports = new List<ReportInfo> {new ReportInfo()};
_remoteEpisode = new RemoteEpisode();
Mocker.GetMock<IParsingService>().Setup(c => c.Map(It.IsAny<ReportInfo>()))
.Returns(_remoteEpisode);
2012-02-17 12:52:29 +03:00
2012-09-19 18:13:26 +03:00
}
2013-04-07 10:30:37 +03:00
private void GivenSpecifications(params Mock<IDecisionEngineSpecification>[] mocks)
2013-03-07 06:45:36 +03:00
{
2013-04-07 20:53:04 +03:00
Mocker.SetConstant<IEnumerable<IRejectWithReason>>(mocks.Select(c => c.Object));
2013-03-07 06:45:36 +03:00
}
[Test]
2013-03-07 04:51:47 +03:00
public void should_call_all_specifications()
{
2013-03-07 06:45:36 +03:00
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
Subject.GetRssDecision(_reports).ToList();
2013-03-07 06:45:36 +03:00
_fail1.Verify(c => c.IsSatisfiedBy(_remoteEpisode), Times.Once());
_fail2.Verify(c => c.IsSatisfiedBy(_remoteEpisode), Times.Once());
_fail3.Verify(c => c.IsSatisfiedBy(_remoteEpisode), Times.Once());
_pass1.Verify(c => c.IsSatisfiedBy(_remoteEpisode), Times.Once());
_pass2.Verify(c => c.IsSatisfiedBy(_remoteEpisode), Times.Once());
_pass3.Verify(c => c.IsSatisfiedBy(_remoteEpisode), Times.Once());
2013-03-07 06:45:36 +03:00
}
[Test]
public void should_return_rejected_if_one_of_specs_fail()
{
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
var result = Subject.GetRssDecision(_reports);
2013-03-07 06:45:36 +03:00
2013-04-07 10:30:37 +03:00
result.Single().Approved.Should().BeFalse();
2013-03-07 06:45:36 +03:00
}
[Test]
public void should_return_pass_if_all_specs_pass()
{
GivenSpecifications(_pass1, _pass2, _pass3);
var result = Subject.GetRssDecision(_reports);
2013-03-07 06:45:36 +03:00
2013-04-07 10:30:37 +03:00
result.Single().Approved.Should().BeTrue();
2013-03-07 06:45:36 +03:00
}
[Test]
public void should_have_same_number_of_rejections_as_specs_that_failed()
{
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
var result = Subject.GetRssDecision(_reports);
2013-04-07 10:30:37 +03:00
result.Single().Rejections.Should().HaveCount(3);
}
}
}