1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 18:12:37 +01:00

Merge branch 'markus101'

This commit is contained in:
kay.one 2011-06-19 20:28:09 -07:00
commit 852b1e9bb5
7 changed files with 261 additions and 51 deletions

View File

@ -41,7 +41,7 @@ public void GetEpisodes_exists()
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1);
//Assert
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
}
@ -90,6 +90,35 @@ public void GetEpisodes_by_season_episode_doesnt_exists()
episode.Should().BeNull();
}
[Test]
public void GetEpisode_with_EpisodeFile()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 1).Have(e => e.EpisodeFile = fakeFile).Build();
db.InsertMany(fakeEpisodes);
db.Insert(fakeFile);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetSeries(1))
.Returns(fakeSeries);
//Act
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1);
//Assert
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
episode.EpisodeFile.Should().NotBeNull();
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")]
public void GetEpisodes_invalid_series()
@ -124,7 +153,6 @@ public void AttachSeries_empty_list()
result.Should().HaveCount(0);
}
[Test]
public void AttachSeries_list_success()
{
@ -195,7 +223,6 @@ public void AttachSeries_single_invalid_series()
var returnedEpisode = mocker.Resolve<EpisodeProvider>().AttachSeries(fakeEpisodes);
}
[Test]
public void GetEpisodesBySeason_success()
{
@ -255,7 +282,6 @@ public void RefreshEpisodeInfo_emptyRepo()
mocker.VerifyAllMocks();
}
[Test]
public void new_episodes_only_calls_Insert()
{
@ -276,7 +302,7 @@ public void new_episodes_only_calls_Insert()
.Returns(tvdbSeries);
mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(currentEpisodes);
@ -290,7 +316,6 @@ public void new_episodes_only_calls_Insert()
mocker.VerifyAllMocks();
}
[Test]
public void existing_episodes_only_calls_Update()
{
@ -314,7 +339,7 @@ public void existing_episodes_only_calls_Update()
.Returns(tvdbSeries);
mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(currentEpisodes);
//Act
@ -326,7 +351,6 @@ public void existing_episodes_only_calls_Update()
mocker.VerifyAllMocks();
}
[Test]
public void should_try_to_get_existing_episode_using_tvdbid_first()
{
@ -345,7 +369,7 @@ public void should_try_to_get_existing_episode_using_tvdbid_first()
var mocker = new AutoMoqer();
mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(fakeEpisodeList);
mocker.GetMock<TvDbProvider>()
@ -393,7 +417,7 @@ public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_ep
.Returns(tvdbSeries);
mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(new List<Episode> { localEpisode });
//Act
@ -404,7 +428,6 @@ public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_ep
mocker.GetMock<IDatabase>().Verify(c => c.Update(localEpisode), Times.Once());
}
[Test]
public void existing_episodes_keep_their_episodeId_file_id()
{
@ -430,7 +453,7 @@ public void existing_episodes_keep_their_episodeId_file_id()
var updatedEpisodes = new List<Episode>();
mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(currentEpisodes);
mocker.GetMock<IDatabase>()
@ -448,7 +471,6 @@ public void existing_episodes_keep_their_episodeId_file_id()
updatedEpisodes.Should().OnlyContain(c => c.Ignored == true);
}
[Test]
public void IsSeasonIgnored_should_return_true_if_all_episodes_ignored()
{
@ -556,6 +578,112 @@ public void Add_daily_show_episodes()
episodes.Should().NotBeEmpty();
}
[Test]
public void GetEpisode_by_Season_Episode_with_EpisodeFile()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 1).Have(e => e.EpisodeFile = fakeFile).Build();
db.InsertMany(fakeEpisodes);
db.Insert(fakeFile);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetSeries(1))
.Returns(fakeSeries);
//Act
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, 1, 1);
//Assert
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
episode.EpisodeFile.Should().NotBeNull();
}
[Test]
public void GetEpisode_by_Season_Episode_without_EpisodeFile()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 0).Build();
db.InsertMany(fakeEpisodes);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetSeries(1))
.Returns(fakeSeries);
//Act
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, 1, 1);
//Assert
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
episode.EpisodeFile.Should().BeNull();
}
[Test]
public void GetEpisode_by_AirDate_with_EpisodeFile()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 1).Have(e => e.EpisodeFile = fakeFile).Build();
db.InsertMany(fakeEpisodes);
db.Insert(fakeFile);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetSeries(1))
.Returns(fakeSeries);
//Act
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, fakeEpisodes[0].AirDate);
//Assert
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
episode.EpisodeFile.Should().NotBeNull();
}
[Test]
public void GetEpisode_by_AirDate_without_EpisodeFile()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 0).Build();
db.InsertMany(fakeEpisodes);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.GetSeries(1))
.Returns(fakeSeries);
//Act
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, fakeEpisodes[0].AirDate);
//Assert
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
episode.EpisodeFile.Should().BeNull();
}
}
}

View File

@ -29,7 +29,6 @@ public void AllItems()
db.InsertMany(historyItem);
//Act
var result = mocker.Resolve<HistoryProvider>().AllItems();
@ -37,6 +36,39 @@ public void AllItems()
result.Should().HaveSameCount(historyItem);
}
[Test]
public void AllItemsWithRelationships()
{
//Setup
var seriesOne = Builder<Series>.CreateNew().With(s => s.SeriesId = 12345).Build();
var seriesTwo = Builder<Series>.CreateNew().With(s => s.SeriesId = 54321).Build();
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
var historyItems = Builder<History>.CreateListOfSize(10).WhereTheFirst(5).Have(h => h.SeriesId = seriesOne.SeriesId).WhereTheLast(5).Have(h => h.SeriesId = seriesTwo.SeriesId).Build();
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
db.InsertMany(historyItems);
db.InsertMany(episodes);
db.Insert(seriesOne);
db.Insert(seriesTwo);
//Act
var result = mocker.Resolve<HistoryProvider>().AllItemsWithRelationships();
//Assert
result.Should().HaveSameCount(historyItems);
foreach (var history in result)
{
Assert.NotNull(history.Episode);
Assert.That(!String.IsNullOrEmpty(history.SeriesTitle));
}
}
[Test]
public void PurgeItem()
{
@ -157,7 +189,5 @@ public void add_item()
Assert.AreEqual(history.Quality, storedHistory.First().Quality);
Assert.AreEqual(history.IsProper, storedHistory.First().IsProper);
}
}
}

View File

@ -35,27 +35,73 @@ public virtual void AddEpisode(Episode episode)
public virtual Episode GetEpisode(long id)
{
return AttachSeries(_database.Single<Episode>(id));
var episode = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
WHERE EpisodeId = @0", id).Single());
if (episode.EpisodeFileId == 0)
episode.EpisodeFile = null;
return episode;
}
public virtual Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber)
{
return AttachSeries(_database.SingleOrDefault<Episode>("WHERE SeriesId = @0 AND SeasonNumber = @1 AND EpisodeNumber = @2", seriesId, seasonNumber, episodeNumber));
var episode = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
WHERE Episodes.SeriesId = @0 AND Episodes.SeasonNumber = @1 AND Episodes.EpisodeNumber = @2", seriesId, seasonNumber, episodeNumber).SingleOrDefault());
if (episode == null)
return null;
if (episode.EpisodeFileId == 0)
episode.EpisodeFile = null;
return episode;
}
public virtual Episode GetEpisode(int seriesId, DateTime date)
{
return AttachSeries(_database.SingleOrDefault<Episode>("WHERE SeriesId = @0 AND AirDate = @1", seriesId, date.Date));
var episode = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
WHERE Episodes.SeriesId = @0 AND AirDate = @1", seriesId, date.Date)).SingleOrDefault();
if (episode == null)
return null;
if (episode.EpisodeFileId == 0)
episode.EpisodeFile = null;
return episode;
}
public virtual IList<Episode> GetEpisodeBySeries(long seriesId)
{
return AttachSeries(_database.Fetch<Episode>("WHERE SeriesId = @0", seriesId));
var episodes = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
WHERE Episodes.SeriesId = @0", seriesId));
foreach (var episode in episodes)
{
if (episode.EpisodeFileId == 0)
episode.EpisodeFile = null;
}
return episodes;
}
public virtual IList<Episode> GetEpisodesBySeason(long seriesId, int seasonNumber)
{
return AttachSeries(_database.Fetch<Episode>("WHERE SeriesId = @0 AND SeasonNumber = @1", seriesId, seasonNumber));
var episodes = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
WHERE Episodes.SeriesId = @0 AND Episodes.SeasonNumber = @1", seriesId, seasonNumber));
foreach (var episode in episodes)
{
if (episode.EpisodeFileId == 0)
episode.EpisodeFile = null;
}
return episodes;
}
public virtual List<Episode> GetEpisodes(EpisodeParseResult parseResult)
@ -78,6 +124,12 @@ public virtual List<Episode> GetEpisodes(EpisodeParseResult parseResult)
episodes.Add(episode);
}
foreach (var episode in episodes)
{
if (episode.EpisodeFileId == 0)
episode.EpisodeFile = null;
}
return episodes;
}

View File

@ -25,9 +25,18 @@ public HistoryProvider()
{
}
public virtual IEnumerable<History> AllItems()
public virtual List<History> AllItems()
{
return _database.Query<History>("");
return _database.Fetch<History>("");
}
public virtual List<History> AllItemsWithRelationships()
{
return _database.Fetch<History, Episode>(@"
SELECT History.*, Series.Title as SeriesTitle, Episodes.* FROM History
INNER JOIN Series ON History.SeriesId = Series.SeriesId
INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId
");
}
public virtual void Purge()

View File

@ -19,7 +19,6 @@ public class Episode
public string Title { get; set; }
public DateTime AirDate { get; set; }
public string Overview { get; set; }
public Boolean Ignored { get; set; }
@ -33,7 +32,6 @@ public class Episode
/// </remarks>
public DateTime? GrabDate { get; set; }
[Ignore]
public EpisodeStatusType Status
{
@ -58,15 +56,12 @@ public EpisodeStatusType Status
}
}
[Ignore]
public Series Series { get; set; }
[Ignore]
[ResultColumn]
public EpisodeFile EpisodeFile { get; set; }
public override string ToString()
{
string seriesTitle = Series == null ? "[NULL]" : Series.Title;

View File

@ -16,5 +16,11 @@ public class History
public DateTime Date { get; set; }
public bool IsProper { get; set; }
public string Indexer { get; set; }
[ResultColumn]
public Episode Episode { get; set; }
[ResultColumn]
public string SeriesTitle { get; set; }
}
}

View File

@ -46,30 +46,20 @@ public ActionResult Purge()
[GridAction]
public ActionResult _AjaxBinding()
{
var historyDb = _historyProvider.AllItems();
var history = new List<HistoryModel>();
foreach (var item in historyDb)
{
var episode = _episodeProvider.GetEpisode(item.EpisodeId);
var series = _seriesProvider.GetSeries(item.SeriesId);
history.Add(new HistoryModel
var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
{
HistoryId = item.HistoryId,
SeasonNumber = episode.SeasonNumber,
EpisodeNumber = episode.EpisodeNumber,
EpisodeTitle = episode.Title,
EpisodeOverview = episode.Overview,
SeriesTitle = series.Title,
NzbTitle = item.NzbTitle,
Quality = item.Quality.ToString(),
IsProper = item.IsProper,
Date = item.Date,
Indexer = item.Indexer
HistoryId = h.HistoryId,
SeasonNumber = h.Episode.SeasonNumber,
EpisodeNumber = h.Episode.EpisodeNumber,
EpisodeTitle = h.Episode.Title,
EpisodeOverview = h.Episode.Overview,
SeriesTitle = h.SeriesTitle,
NzbTitle = h.NzbTitle,
Quality = h.Quality.ToString(),
IsProper = h.IsProper,
Date = h.Date,
Indexer = h.Indexer
});
}
return View(new GridModel(history));
}