Added GetSeasonFiles to MediaFileProvider

pull/4/head
kay.one 14 years ago
parent 4ac4ba5067
commit 6c4f19b365

@ -300,12 +300,38 @@ namespace NzbDrone.Core.Test
.Setup(c => c.GetAllSeries())
.Returns(Builder<Series>.CreateListOfSize(2)
.WhereTheFirst(1).Has(c => c.LastInfoSync = DateTime.Now).Build().AsQueryable());
mocker.GetMock<MediaFileProvider>( MockBehavior.Strict)
.Setup(c=>c.Scan(It.Is<Series>(s=>s.LastInfoSync != null))).Returns(new List<EpisodeFile>()).Verifiable();
mocker.GetMock<MediaFileProvider>(MockBehavior.Strict)
.Setup(c => c.Scan(It.Is<Series>(s => s.LastInfoSync != null))).Returns(new List<EpisodeFile>()).Verifiable();
mocker.Resolve<MediaFileScanJob>().Start(new ProgressNotification("test"), 0);
mocker.VerifyAllMocks();
}
[Test]
public void get_season_files()
{
var episodes = Builder<Episode>.CreateListOfSize(20)
.WhereTheFirst(8)
.Has(c => c.EpisodeFile = new EpisodeFile())
.AndTheRemaining()
.Has(c => c.EpisodeFile = null)
.Build().ToList();
var mocker = new AutoMoqer();
mocker.GetMock<SeasonProvider>()
.Setup(c => c.GetSeason(12))
.Returns(Builder<Season>.CreateNew().With(c => c.Episodes = episodes).Build())
.Verifiable();
var result = mocker.Resolve<MediaFileProvider>().GetSeasonFiles(12);
Assert.Count(8, result);
Assert.DoesNotContain(result, null);
mocker.VerifyAllMocks();
}
}
}

@ -11,14 +11,16 @@ namespace NzbDrone.Core.Providers.Jobs
private readonly SeriesProvider _seriesProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly MediaFileProvider _mediaFileProvider;
private readonly SeasonProvider _seasonProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public NewSeriesUpdate(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider)
public NewSeriesUpdate(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider, SeasonProvider seasonProvider)
{
_seriesProvider = seriesProvider;
_episodeProvider = episodeProvider;
_mediaFileProvider = mediaFileProvider;
_seasonProvider = seasonProvider;
}
public string Name
@ -48,11 +50,12 @@ namespace NzbDrone.Core.Providers.Jobs
{
try
{
notification.CurrentMessage = String.Format("Searching for '{0}'", new DirectoryInfo(currentSeries.Path).Name);
notification.CurrentMessage = String.Format("Searching for '{0}'",
new DirectoryInfo(currentSeries.Path).Name);
var updatedSeries = _seriesProvider.UpdateSeriesInfo(currentSeries.SeriesId);
notification.CurrentMessage = String.Format("Downloading episode info for '{0}'",
updatedSeries.Title);
updatedSeries.Title);
_episodeProvider.RefreshEpisodeInfo(updatedSeries.SeriesId);
notification.CurrentMessage = String.Format("Scanning disk for '{0}' files", updatedSeries.Title);

@ -16,15 +16,17 @@ namespace NzbDrone.Core.Providers
private readonly DiskProvider _diskProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly SeriesProvider _seriesProvider;
private readonly SeasonProvider _seasonProvider;
private readonly IRepository _repository;
public MediaFileProvider(IRepository repository, DiskProvider diskProvider,
EpisodeProvider episodeProvider, SeriesProvider seriesProvider)
EpisodeProvider episodeProvider, SeriesProvider seriesProvider, SeasonProvider seasonProvider)
{
_repository = repository;
_diskProvider = diskProvider;
_episodeProvider = episodeProvider;
_seriesProvider = seriesProvider;
_seasonProvider = seasonProvider;
}
public MediaFileProvider() { }
@ -180,6 +182,13 @@ namespace NzbDrone.Core.Providers
return _repository.All<EpisodeFile>().ToList();
}
public virtual List<EpisodeFile> GetSeasonFiles(int seasonId)
{
var res = _seasonProvider.GetSeason(seasonId).Episodes.Where(c => c.EpisodeFile != null).Select(c => c.EpisodeFile);
return res.ToList();
}
private List<string> GetMediaFileList(string path)
{
Logger.Debug("Scanning '{0}' for episodes", path);

@ -18,9 +18,9 @@ namespace NzbDrone.Core.Repository
public DayOfWeek? LastDiskSync { get; set; }
[SubSonicToManyRelation]
public virtual List<Episode> Episodes { get; protected set; }
public virtual List<Episode> Episodes { get; set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual Series Series { get; protected set; }
public virtual Series Series { get; set; }
}
}
Loading…
Cancel
Save