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

EpisodesWithFiles now returns the full series object, instead of just the SeriesTitle (So we don't need to add junk to the Episode class)

This commit is contained in:
Mark McDowall 2011-09-04 00:45:58 -07:00
parent 421ba466a8
commit 0a65e85e21
6 changed files with 46 additions and 30 deletions

View File

@ -1272,7 +1272,7 @@ public void EpisodesWithFiles_success()
foreach (var withFile in withFiles)
{
withFile.EpisodeFile.Should().NotBeNull();
withFile.SeriesTitle.Should().NotBeNullOrEmpty();
withFile.Series.Title.Should().NotBeNullOrEmpty();
}
mocker.VerifyAllMocks();

View File

@ -22,6 +22,10 @@ public class MisnamedProviderTest
public void no_misnamed_files()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.WhereTheFirst(1)
.Has(f => f.EpisodeFileId = 1)
@ -32,14 +36,14 @@ public void no_misnamed_files()
.Build();
var episodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll()
.Have(e => e.Series = series)
.WhereTheFirst(1)
.Has(e => e.EpisodeFileId = 1)
.Has(e => e.EpisodeFile = episodeFiles[0])
.Has(e => e.SeriesTitle = "SeriesTitle1")
.AndTheNext(1)
.Has(e => e.EpisodeFileId = 2)
.Has(e => e.EpisodeFile = episodeFiles[1])
.Has(e => e.SeriesTitle = "SeriesTitle2")
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -48,11 +52,11 @@ public void no_misnamed_files()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> {episodes[0]}, "SeriesTitle1", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> {episodes[0]}, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title1");
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> {episodes[1]}, "SeriesTitle2", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> {episodes[1]}, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2");
//Act
@ -67,6 +71,10 @@ public void no_misnamed_files()
public void all_misnamed_files()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.WhereTheFirst(1)
.Has(f => f.EpisodeFileId = 1)
@ -77,14 +85,14 @@ public void all_misnamed_files()
.Build();
var episodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll()
.Have(e => e.Series = series)
.WhereTheFirst(1)
.Has(e => e.EpisodeFileId = 1)
.Has(e => e.EpisodeFile = episodeFiles[0])
.Has(e => e.SeriesTitle = "SeriesTitle1")
.AndTheNext(1)
.Has(e => e.EpisodeFileId = 2)
.Has(e => e.EpisodeFile = episodeFiles[1])
.Has(e => e.SeriesTitle = "SeriesTitle2")
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -93,11 +101,11 @@ public void all_misnamed_files()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle1", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 1");
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle2", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 2");
//Act
@ -112,6 +120,10 @@ public void all_misnamed_files()
public void one_misnamed_file()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.WhereTheFirst(1)
.Has(f => f.EpisodeFileId = 1)
@ -122,14 +134,14 @@ public void one_misnamed_file()
.Build();
var episodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll()
.Have(e => e.Series = series)
.WhereTheFirst(1)
.Has(e => e.EpisodeFileId = 1)
.Has(e => e.EpisodeFile = episodeFiles[0])
.Has(e => e.SeriesTitle = "SeriesTitle1")
.AndTheNext(1)
.Has(e => e.EpisodeFileId = 2)
.Has(e => e.EpisodeFile = episodeFiles[1])
.Has(e => e.SeriesTitle = "SeriesTitle2")
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -138,11 +150,11 @@ public void one_misnamed_file()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle1", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 1");
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle2", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2");
//Act
@ -159,6 +171,10 @@ public void one_misnamed_file()
public void misnamed_multi_episode_file()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.WhereTheFirst(1)
.Has(f => f.EpisodeFileId = 1)
@ -169,14 +185,14 @@ public void misnamed_multi_episode_file()
.Build();
var episodes = Builder<Episode>.CreateListOfSize(3)
.WhereAll()
.Have(e => e.Series = series)
.WhereTheFirst(2)
.Has(e => e.EpisodeFileId = 1)
.Has(e => e.EpisodeFile = episodeFiles[0])
.Has(e => e.SeriesTitle = "SeriesTitle1")
.AndTheNext(1)
.Has(e => e.EpisodeFileId = 2)
.Has(e => e.EpisodeFile = episodeFiles[1])
.Has(e => e.SeriesTitle = "SeriesTitle2")
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -185,11 +201,11 @@ public void misnamed_multi_episode_file()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle1", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("New Title 1");
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle2", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2");
//Act
@ -206,6 +222,10 @@ public void misnamed_multi_episode_file()
public void no_misnamed_multi_episode_file()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.WhereTheFirst(1)
.Has(f => f.EpisodeFileId = 1)
@ -216,14 +236,14 @@ public void no_misnamed_multi_episode_file()
.Build();
var episodes = Builder<Episode>.CreateListOfSize(3)
.WhereAll()
.Have(e => e.Series = series)
.WhereTheFirst(2)
.Has(e => e.EpisodeFileId = 1)
.Has(e => e.EpisodeFile = episodeFiles[0])
.Has(e => e.SeriesTitle = "SeriesTitle1")
.AndTheNext(1)
.Has(e => e.EpisodeFileId = 2)
.Has(e => e.EpisodeFile = episodeFiles[1])
.Has(e => e.SeriesTitle = "SeriesTitle2")
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -232,11 +252,11 @@ public void no_misnamed_multi_episode_file()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle1", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title1");
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle2", It.IsAny<QualityTypes>()))
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>()))
.Returns("Title2");
//Act

View File

@ -182,7 +182,6 @@
<Compile Include="Fluent.cs" />
<Compile Include="Helpers\EpisodeSortingHelper.cs" />
<Compile Include="Helpers\FileSizeFormatHelpercs.cs" />
<Compile Include="Helpers\LinqPageExtension.cs" />
<Compile Include="Instrumentation\LogProvider.cs" />
<Compile Include="Instrumentation\DatabaseTarget.cs" />
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />

View File

@ -177,7 +177,7 @@ public virtual IList<Episode> GetEpisodesByFileId(int episodeFileId)
public virtual IList<Episode> EpisodesWithFiles()
{
var episodes = _database.Fetch<Episode, EpisodeFile>(@"SELECT Episodes.*, Series.Title as SeriesTitle, EpisodeFiles.* FROM Episodes
var episodes = _database.Fetch<Episode, Series, EpisodeFile>(@"SELECT Episodes.*, Series.*, EpisodeFiles.* FROM Episodes
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
INNER JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId");

View File

@ -36,7 +36,7 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
var misnamedFilesSelect = episodesWithFiles.AsParallel().Where(
w =>
w.First().EpisodeFile.Path !=
_mediaFileProvider.GetNewFilename(w.Select(e => e).ToList(), w.First().SeriesTitle,
_mediaFileProvider.GetNewFilename(w.Select(e => e).ToList(), w.First().Series.Title,
w.First().EpisodeFile.Quality)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize);
//Process the episodes
@ -45,7 +45,7 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
var episodes = f.Select(e => e).ToList();
var firstEpisode = episodes[0];
var properName = _mediaFileProvider.GetNewFilename(episodes,
firstEpisode.SeriesTitle,
firstEpisode.Series.Title,
firstEpisode.EpisodeFile.Quality);
var currentName = Path.GetFileNameWithoutExtension(firstEpisode.EpisodeFile.Path);
@ -58,7 +58,7 @@ public virtual List<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int page
EpisodeFileId = firstEpisode.EpisodeFileId,
ProperName = properName,
SeriesId = firstEpisode.SeriesId,
SeriesTitle = firstEpisode.SeriesTitle
SeriesTitle = firstEpisode.Series.Title
});
}
});

View File

@ -53,15 +53,12 @@ public EpisodeStatusType Status
}
}
[Ignore]
[ResultColumn]
public Series Series { get; set; }
[ResultColumn]
public EpisodeFile EpisodeFile { get; set; }
[ResultColumn]
public string SeriesTitle { get; set; }
public override string ToString()
{
string seriesTitle = Series == null ? "[NULL]" : Series.Title;