1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 01:38:24 +00:00

GetEpisodesByParseResult will properly handle Daily episodes.

This commit is contained in:
Mark McDowall 2011-11-24 00:28:20 -08:00
parent 1317b8fbef
commit 38790e9f9c
3 changed files with 106 additions and 0 deletions

View file

@ -1,16 +1,19 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
using PetaPoco;
namespace NzbDrone.Core.Test.ProviderTests
{
@ -255,6 +258,57 @@ public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_em
episodes.Should().BeEmpty();
}
[Test]
public void GetEpisodeParseResult_should_return_single_episode_when_air_date_is_provided()
{
//Setup
var fakeEpisode = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.AirDate = DateTime.Today)
.Build()
.ToList();
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.Build();
Mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(fakeEpisode);
//Act
var episodes = Mocker.Resolve<EpisodeProvider>()
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, true);
//Assert
episodes.Should().HaveCount(1);
episodes.First().AirDate.Should().Be(DateTime.Today);
Mocker.GetMock<IDatabase>().Verify(v=> v.Insert(It.IsAny<Episode>()), Times.Never());
}
[Test]
public void GetEpisodeParseResult_get_daily_should_add_new_episode()
{
//Setup
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.Build();
Mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(new List<Episode>());
Mocker.GetMock<IDatabase>().Setup(s => s.Insert(It.IsAny<Episode>()))
.Returns(1);
//Act
var episodes = Mocker.Resolve<EpisodeProvider>()
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, true);
//Assert
episodes.Should().HaveCount(1);
episodes.First().AirDate.Should().Be(DateTime.Today);
Mocker.GetMock<IDatabase>().Verify(v => v.Insert(It.IsAny<Episode>()), Times.Once());
}
}
}

View file

@ -25,6 +25,7 @@ public class InventoryProvider_IsMonitoredTest : CoreTest
private Episode episode;
private Episode episode2;
private EpisodeParseResult parseResultSingle;
private EpisodeParseResult parseResultDaily;
[SetUp]
public void Setup()
@ -49,6 +50,14 @@ public void Setup()
AirDate = DateTime.Now.AddDays(-12).Date,
};
parseResultDaily = new EpisodeParseResult()
{
CleanTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.Bluray720p, true),
AirDate = DateTime.Now.AddDays(-12).Date,
};
episode = Builder<Episode>.CreateNew()
.With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[0])
@ -239,6 +248,25 @@ public void IsMonitored_multi_no_episodes_ignored_should_return_true()
mocker.VerifyAllMocks();
}
[Test]
public void IsMonitored_daily_not_ignored_should_return_true()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), true))
.Returns(new List<Episode> { episode });
episode.Ignored = false;
var result = mocker.Resolve<InventoryProvider>().IsMonitored(parseResultDaily);
//Assert
result.Should().BeTrue();
}
}
}

View file

@ -125,6 +125,30 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
{
var result = new List<Episode>();
if (parseResult.AirDate.HasValue)
{
var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value);
//if still null we should add the temp episode
if (episodeInfo == null && autoAddNew)
{
Logger.Debug("Episode {0} doesn't exist in db. adding it now.", parseResult);
episodeInfo = new Episode
{
SeriesId = parseResult.Series.SeriesId,
AirDate = parseResult.AirDate.Value,
Title = "TBD",
Overview = String.Empty,
};
AddEpisode(episodeInfo);
}
//Add to Result and Return (There will only be one episode to return)
result.Add(episodeInfo);
return result;
}
if (parseResult.EpisodeNumbers == null)
return result;