You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/NzbDrone.Core.Test/TvTests/SeriesServiceTests/UpdateSeriesFixture.cs

75 lines
3.3 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv.Events;
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
{
[TestFixture]
public class UpdateSeriesFixture : CoreTest<SeriesService>
{
private Series _fakeSeries;
private Series _existingSeries;
[SetUp]
public void Setup()
{
_fakeSeries = Builder<Series>.CreateNew().Build();
_existingSeries = Builder<Series>.CreateNew().Build();
_fakeSeries.Seasons = new List<Season>
{
new Season{ SeasonNumber = 1, Monitored = true },
new Season{ SeasonNumber = 2, Monitored = true }
};
_existingSeries.Seasons = new List<Season>
{
new Season{ SeasonNumber = 1, Monitored = true },
new Season{ SeasonNumber = 2, Monitored = true }
};
}
private void GivenExistingSeries()
{
Mocker.GetMock<ISeriesRepository>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(_existingSeries);
}
[Test]
public void should_not_update_episodes_if_season_hasnt_changed()
{
GivenExistingSeries();
Subject.UpdateSeries(_fakeSeries);
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Never());
}
[Test]
public void should_update_series_when_it_changes()
{
GivenExistingSeries();
var seasonNumber = 1;
var monitored = false;
_fakeSeries.Seasons.Single(s => s.SeasonNumber == seasonNumber).Monitored = monitored;
Subject.UpdateSeries(_fakeSeries);
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, seasonNumber, monitored), Times.Once());
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Once());
}
}
}