1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

Added episode status to back end, getting ready for backlog

This commit is contained in:
kay.one 2011-05-22 09:53:06 -07:00
parent 3bfa1c52b7
commit f33c2c4939
7 changed files with 177 additions and 31 deletions

View File

@ -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);
}
}
}

View File

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

View File

@ -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
{
}
}

View File

@ -2,8 +2,30 @@
{
public enum EpisodeStatusType
{
Missing = 0,
Grabbed = 1,
Downloaded = 2
/// <summary>
/// Episode has not aired yet
/// </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
}
}

View File

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

View File

@ -79,7 +79,6 @@ internal bool IsNeeded(EpisodeParseResult parseResult)
SeasonNumber = parseResult.SeasonNumber,
Title = parseResult.EpisodeTitle,
Overview = String.Empty,
Language = "en"
};
_episodeProvider.AddEpisode(episodeInfo);

View File

@ -23,12 +23,40 @@ public class Episode
[SubSonicLongString]
public string Overview { get; set; }
public string Language { get; set; }
public EpisodeStatusType Status { get; set; }
public Boolean Ignored { 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)]
public virtual Season Season { get; set; }