2013-03-05 02:47:51 +01:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-04-01 08:22:16 +02:00
|
|
|
using NzbDrone.Core.Qualities;
|
2013-03-05 02:47:51 +01:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-04-01 08:22:16 +02:00
|
|
|
using NzbDrone.Core.Tv;
|
2013-07-27 06:34:11 +02:00
|
|
|
using NzbDrone.Test.Common;
|
2013-03-05 02:47:51 +01:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.MediaFileTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-03-24 05:16:00 +01:00
|
|
|
public class MediaFileRepositoryFixture : DbTest<MediaFileRepository, EpisodeFile>
|
2013-03-05 02:47:51 +01:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void get_files_by_series()
|
|
|
|
{
|
|
|
|
var files = Builder<EpisodeFile>.CreateListOfSize(10)
|
|
|
|
.All()
|
|
|
|
.With(c => c.Id = 0)
|
2013-04-01 08:22:16 +02:00
|
|
|
.With(c => c.Quality =new QualityModel(Quality.Bluray720p))
|
2013-03-05 02:47:51 +01:00
|
|
|
.Random(4)
|
|
|
|
.With(s => s.SeriesId = 12)
|
2013-04-01 08:22:16 +02:00
|
|
|
.BuildListOfNew();
|
2013-03-05 02:47:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(files);
|
|
|
|
|
|
|
|
var seriesFiles = Subject.GetFilesBySeries(12);
|
|
|
|
|
|
|
|
seriesFiles.Should().HaveCount(4);
|
|
|
|
seriesFiles.Should().OnlyContain(c => c.SeriesId == 12);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database()
|
|
|
|
{
|
|
|
|
Subject.GetFileByPath(@"C:\Test\EpisodeFile.avi").Should().BeNull();
|
|
|
|
}
|
|
|
|
|
2013-06-03 05:44:31 +02:00
|
|
|
[Test]
|
|
|
|
public void exists_should_return_false_if_file_doesnt_exist()
|
|
|
|
{
|
|
|
|
Subject.Exists(@"C:\Test\EpisodeFile.avi").Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
2013-03-05 02:47:51 +01:00
|
|
|
[Test]
|
|
|
|
public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database()
|
|
|
|
{
|
2013-07-27 06:34:11 +02:00
|
|
|
var path = @"C:\Test\EpisodeFile.avi".AsOsAgnostic();
|
2013-03-05 02:47:51 +01:00
|
|
|
|
|
|
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
.With(f => f.Id = 0)
|
2013-07-26 07:22:22 +02:00
|
|
|
.With(f => f.Path = path.CleanFilePath())
|
2013-03-05 02:47:51 +01:00
|
|
|
.Build();
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
Subject.Insert(episodeFile);
|
2013-03-05 02:47:51 +01:00
|
|
|
|
|
|
|
var file = Subject.GetFileByPath(path);
|
|
|
|
|
|
|
|
//Resolve
|
|
|
|
file.Should().NotBeNull();
|
2013-07-26 07:22:22 +02:00
|
|
|
file.Path.Should().Be(path.CleanFilePath());
|
2013-03-05 02:47:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|