Added episode status to back end, getting ready for backlog

pull/3113/head
kay.one 14 years ago
parent 3bfa1c52b7
commit f33c2c4939

@ -0,0 +1,119 @@
// ReSharper disable RedundantUsingDirective
// ReSharper disable RedundantUsingDirective
using System;
using FizzWare.NBuilder;
using MbUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class EpisodeStatusTest : TestBase
{
[Test]
[Row(1, false, false, EpisodeStatusType.NotAired)]
[Row(-2, false, false, EpisodeStatusType.Missing)]
[Row(1, true, false, EpisodeStatusType.Ready)]
[Row(1, true, true, EpisodeStatusType.Ignored)]
[Row(1, false, true, EpisodeStatusType.Ignored)]
public void no_grab_date(int offsetDays, bool hasEpisodes, bool ignored, EpisodeStatusType status)
{
Episode episode = Builder<Episode>.CreateNew()
.With(e => e.Season = Builder<Season>.CreateNew()
.With(s => s.Monitored = true).Build())
.With(e => e.AirDate = DateTime.Now.AddDays(offsetDays))
.With(e => e.Ignored = ignored)
.With(e => e.EpisodeFileId = 0)
.With(e => e.GrabDate = null)
.Build();
if (hasEpisodes)
{
episode.EpisodeFileId = 12;
}
Assert.AreEqual(status, episode.Status);
}
[Test]
[Row(1, false, false, EpisodeStatusType.NotAired)]
[Row(-2, false, false, EpisodeStatusType.Missing)]
[Row(1, true, false, EpisodeStatusType.Ready)]
[Row(1, true, true, EpisodeStatusType.Ignored)]
[Row(1, false, true, EpisodeStatusType.Ignored)]
public void old_grab_date(int offsetDays, bool hasEpisodes, bool ignored,
EpisodeStatusType status)
{
Episode episode = Builder<Episode>.CreateNew()
.With(e => e.Season = Builder<Season>.CreateNew()
.With(s => s.Monitored = true).Build()).With(
e => e.AirDate = DateTime.Now.AddDays(offsetDays))
.With(e => e.Ignored = ignored)
.With(e => e.EpisodeFileId = 0)
.With(e => e.GrabDate = DateTime.Now.AddDays(-1).AddHours(-1))
.Build();
if (hasEpisodes)
{
episode.EpisodeFileId = 12;
}
Assert.AreEqual(status, episode.Status);
}
[Test]
[Row(1, false, false, EpisodeStatusType.Downloading)]
[Row(-2, false, false, EpisodeStatusType.Downloading)]
[Row(1, true, false, EpisodeStatusType.Downloading)]
[Row(1, true, true, EpisodeStatusType.Ignored)]
[Row(1, false, true, EpisodeStatusType.Ignored)]
public void recent_grab_date(int offsetDays, bool hasEpisodes, bool ignored,
EpisodeStatusType status)
{
Episode episode = Builder<Episode>.CreateNew()
.With(e => e.Season = Builder<Season>.CreateNew()
.With(s => s.Monitored = true).Build())
.With(e => e.AirDate = DateTime.Now.AddDays(offsetDays))
.With(e => e.Ignored = ignored)
.With(e => e.EpisodeFileId = 0)
.With(e => e.GrabDate = DateTime.Now.AddDays(-1))
.Build();
if (hasEpisodes)
{
episode.EpisodeFileId = 12;
}
Assert.AreEqual(status, episode.Status);
}
[Test]
[Row(1, false, false, EpisodeStatusType.Ignored)]
[Row(-2, false, false, EpisodeStatusType.Ignored)]
[Row(1, true, false, EpisodeStatusType.Ignored)]
[Row(1, true, true, EpisodeStatusType.Ignored)]
[Row(1, false, true, EpisodeStatusType.Ignored)]
public void skipped_season(int offsetDays, bool hasEpisodes, bool ignored, EpisodeStatusType status)
{
Episode episode = Builder<Episode>.CreateNew()
.With(e => e.AirDate = DateTime.Now.AddDays(offsetDays))
.With(e => e.Ignored = ignored)
.With(e => e.EpisodeFileId = 0)
.With(e => e.Season = Builder<Season>.CreateNew()
.With(s => s.Monitored == false).Build())
.Build();
if (hasEpisodes)
{
episode.EpisodeFileId = 12;
}
Assert.AreEqual(status, episode.Status);
}
}
}

@ -85,6 +85,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="EpisodeStatusTest.cs" />
<Compile Include="ImportNewSeriesJobTest.cs" /> <Compile Include="ImportNewSeriesJobTest.cs" />
<Compile Include="DiskScanJobTest.cs" /> <Compile Include="DiskScanJobTest.cs" />
<Compile Include="InventoryProviderTest.cs" /> <Compile Include="InventoryProviderTest.cs" />
@ -99,7 +100,6 @@
<Compile Include="Framework\ExceptionVerification.cs" /> <Compile Include="Framework\ExceptionVerification.cs" />
<Compile Include="Framework\TestBase.cs" /> <Compile Include="Framework\TestBase.cs" />
<Compile Include="JobProviderTest.cs" /> <Compile Include="JobProviderTest.cs" />
<Compile Include="SyncProviderTest.cs" />
<Compile Include="RootDirProviderTest.cs" /> <Compile Include="RootDirProviderTest.cs" />
<Compile Include="IndexerProviderTest.cs" /> <Compile Include="IndexerProviderTest.cs" />
<Compile Include="HistoryProviderTest.cs" /> <Compile Include="HistoryProviderTest.cs" />

@ -1,17 +0,0 @@
using System;
using AutoMoq;
using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SyncProviderTest : TestBase
{
}
}

@ -2,8 +2,30 @@
{ {
public enum EpisodeStatusType public enum EpisodeStatusType
{ {
Missing = 0, /// <summary>
Grabbed = 1, /// Episode has not aired yet
Downloaded = 2 /// </summary>
NotAired ,
/// <summary>
/// Episode is ignored
/// </summary>
Ignored,
/// <summary>
/// Episode has aired but no episode
/// files have avilable
/// </summary>
Missing ,
/// <summary>
/// Episode is being downloaded
/// </summary>
Downloading ,
/// <summary>
/// Episode is present in disk
/// </summary>
Ready
} }
} }

@ -144,14 +144,11 @@ namespace NzbDrone.Core.Providers
AirDate = episode.FirstAired.Date, AirDate = episode.FirstAired.Date,
TvDbEpisodeId = episode.Id, TvDbEpisodeId = episode.Id,
EpisodeNumber = episode.EpisodeNumber, EpisodeNumber = episode.EpisodeNumber,
Language = episode.Language.Abbriviation,
Overview = episode.Overview, Overview = episode.Overview,
SeasonId = episode.SeasonId, SeasonId = episode.SeasonId,
SeasonNumber = episode.SeasonNumber, SeasonNumber = episode.SeasonNumber,
SeriesId = seriesId, SeriesId = seriesId,
Title = episode.EpisodeName, Title = episode.EpisodeName,
LastInfoSync = DateTime.Now
}; };
var existingEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber); var existingEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
@ -161,8 +158,6 @@ namespace NzbDrone.Core.Providers
//TODO: Write test for this, possibly make it future proof, we should only copy fields that come from tvdb //TODO: Write test for this, possibly make it future proof, we should only copy fields that come from tvdb
newEpisode.EpisodeId = existingEpisode.EpisodeId; newEpisode.EpisodeId = existingEpisode.EpisodeId;
newEpisode.EpisodeFileId = existingEpisode.EpisodeFileId; newEpisode.EpisodeFileId = existingEpisode.EpisodeFileId;
newEpisode.LastDiskSync = existingEpisode.LastDiskSync;
newEpisode.Status = existingEpisode.Status;
updateList.Add(newEpisode); updateList.Add(newEpisode);
} }
else else

@ -79,7 +79,6 @@ namespace NzbDrone.Core.Providers.Indexer
SeasonNumber = parseResult.SeasonNumber, SeasonNumber = parseResult.SeasonNumber,
Title = parseResult.EpisodeTitle, Title = parseResult.EpisodeTitle,
Overview = String.Empty, Overview = String.Empty,
Language = "en"
}; };
_episodeProvider.AddEpisode(episodeInfo); _episodeProvider.AddEpisode(episodeInfo);

@ -23,12 +23,40 @@ namespace NzbDrone.Core.Repository
[SubSonicLongString] [SubSonicLongString]
public string Overview { get; set; } public string Overview { get; set; }
public string Language { get; set; } public Boolean Ignored { get; set; }
public EpisodeStatusType Status { get; set; }
public DateTime? LastInfoSync { get; set; }
public DateTime? LastDiskSync { get; set; } /// <summary>
/// Gets or sets the grab date.
/// </summary>
/// <remarks>
/// Used to specify when the episode was grapped.
/// this filed is used by status as an expirable "Grabbed" status.
/// </remarks>
public DateTime? GrabDate { get; set; }
[SubSonicIgnore]
public EpisodeStatusType Status
{
get
{
if (Ignored || (Season != null && !Season.Monitored)) return EpisodeStatusType.Ignored;
if (GrabDate != null && GrabDate.Value.AddDays(1) >= DateTime.Now)
{
return EpisodeStatusType.Downloading;
}
if (EpisodeFileId != 0) return EpisodeStatusType.Ready;
if (DateTime.Now.Date >= AirDate.Date)
{
return EpisodeStatusType.Missing;
}
return EpisodeStatusType.NotAired;
}
}
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)] [SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual Season Season { get; set; } public virtual Season Season { get; set; }

Loading…
Cancel
Save