GetEpisodesByParseResult will properly handle Daily episodes.

pull/2/head
Mark McDowall 13 years ago
parent 1317b8fbef
commit 38790e9f9c

@ -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 @@ namespace NzbDrone.Core.Test.ProviderTests
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());
}
}
}

@ -25,6 +25,7 @@ namespace NzbDrone.Core.Test.ProviderTests
private Episode episode;
private Episode episode2;
private EpisodeParseResult parseResultSingle;
private EpisodeParseResult parseResultDaily;
[SetUp]
public void Setup()
@ -49,6 +50,14 @@ namespace NzbDrone.Core.Test.ProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests
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();
}
}
}

@ -125,6 +125,30 @@ namespace NzbDrone.Core.Providers
{
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;

Loading…
Cancel
Save