@ -1,4 +1,5 @@
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using FluentAssertions ;
using Moq ;
@ -6,20 +7,24 @@ using NUnit.Framework;
using NzbDrone.Core.MediaFiles ;
using NzbDrone.Core.Organizer ;
using NzbDrone.Core.Test.Framework ;
using NzbDrone.Core.Tv ;
using NzbDrone.Test.Common ;
namespace NzbDrone.Core.Test.MediaFiles
namespace NzbDrone.Core.Test.MediaFiles .MediaFileServiceTests
{
[TestFixture]
public class MediaFileServiceTest : CoreTest < MediaFileService >
public class FilterFixture : CoreTest < MediaFileService >
{
private Series _series ;
[Test]
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p] ",
"Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]" ) ]
public void CleanFileName ( string name , string expectedName )
[SetUp]
public void Setup ( )
{
FileNameBuilder . CleanFileName ( name ) . Should ( ) . Be ( expectedName ) ;
_series = new Series
{
Id = 10 ,
Path = @"C:\" . AsOsAgnostic ( )
} ;
}
[Test]
@ -27,9 +32,9 @@ namespace NzbDrone.Core.Test.MediaFiles
{
var files = new List < string > ( )
{
" c :\\file1.avi". AsOsAgnostic ( ) ,
" c :\\file2.avi". AsOsAgnostic ( ) ,
" c :\\file3.avi". AsOsAgnostic ( )
" C :\\file1.avi". AsOsAgnostic ( ) ,
" C :\\file2.avi". AsOsAgnostic ( ) ,
" C :\\file3.avi". AsOsAgnostic ( )
} ;
Mocker . GetMock < IMediaFileRepository > ( )
@ -37,26 +42,25 @@ namespace NzbDrone.Core.Test.MediaFiles
. Returns ( new List < EpisodeFile > ( ) ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . BeEquivalentTo ( files ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . BeEquivalentTo ( files ) ;
}
[Test]
public void filter_should_return_none_if_all_files_exist ( )
{
var files = new List < string > ( )
{
" c :\\file1.avi". AsOsAgnostic ( ) ,
" c :\\file2.avi". AsOsAgnostic ( ) ,
" c :\\file3.avi". AsOsAgnostic ( )
" C :\\file1.avi". AsOsAgnostic ( ) ,
" C :\\file2.avi". AsOsAgnostic ( ) ,
" C :\\file3.avi". AsOsAgnostic ( )
} ;
Mocker . GetMock < IMediaFileRepository > ( )
. Setup ( c = > c . GetFilesBySeries ( It . IsAny < int > ( ) ) )
. Returns ( files . Select ( f = > new EpisodeFile { Path = f } ) . ToList ( ) ) ;
. Returns ( files . Select ( f = > new EpisodeFile { Relative Path = Path. GetFileName ( f) } ) . ToList ( ) ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . BeEmpty ( ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . BeEmpty ( ) ;
}
[Test]
@ -64,21 +68,21 @@ namespace NzbDrone.Core.Test.MediaFiles
{
var files = new List < string > ( )
{
" c :\\file1.avi". AsOsAgnostic ( ) ,
" c :\\file2.avi". AsOsAgnostic ( ) ,
" c :\\file3.avi". AsOsAgnostic ( )
" C :\\file1.avi". AsOsAgnostic ( ) ,
" C :\\file2.avi". AsOsAgnostic ( ) ,
" C :\\file3.avi". AsOsAgnostic ( )
} ;
Mocker . GetMock < IMediaFileRepository > ( )
. Setup ( c = > c . GetFilesBySeries ( It . IsAny < int > ( ) ) )
. Returns ( new List < EpisodeFile >
{
new EpisodeFile { Path = " c:\\ file2.avi". AsOsAgnostic ( ) }
new EpisodeFile { Relative Path = " file2.avi". AsOsAgnostic ( ) }
} ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . HaveCount ( 2 ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . NotContain ( "c :\\file2.avi". AsOsAgnostic ( ) ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . HaveCount ( 2 ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . NotContain ( "C :\\file2.avi". AsOsAgnostic ( ) ) ;
}
[Test]
@ -88,21 +92,21 @@ namespace NzbDrone.Core.Test.MediaFiles
var files = new List < string > ( )
{
" c :\\file1.avi". AsOsAgnostic ( ) ,
" c :\\FILE2.avi". AsOsAgnostic ( ) ,
" c :\\file3.avi". AsOsAgnostic ( )
" C :\\file1.avi". AsOsAgnostic ( ) ,
" C :\\FILE2.avi". AsOsAgnostic ( ) ,
" C :\\file3.avi". AsOsAgnostic ( )
} ;
Mocker . GetMock < IMediaFileRepository > ( )
. Setup ( c = > c . GetFilesBySeries ( It . IsAny < int > ( ) ) )
. Returns ( new List < EpisodeFile >
{
new EpisodeFile { Path = " c:\\ file2.avi". AsOsAgnostic ( ) }
new EpisodeFile { Relative Path = " file2.avi". AsOsAgnostic ( ) }
} ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . HaveCount ( 2 ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . NotContain ( "c :\\file2.avi". AsOsAgnostic ( ) ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . HaveCount ( 2 ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . NotContain ( "C :\\file2.avi". AsOsAgnostic ( ) ) ;
}
[Test]
@ -112,19 +116,19 @@ namespace NzbDrone.Core.Test.MediaFiles
var files = new List < string > ( )
{
" c :\\file1.avi". AsOsAgnostic ( ) ,
" c :\\FILE2.avi". AsOsAgnostic ( ) ,
" c :\\file3.avi". AsOsAgnostic ( )
" C :\\file1.avi". AsOsAgnostic ( ) ,
" C :\\FILE2.avi". AsOsAgnostic ( ) ,
" C :\\file3.avi". AsOsAgnostic ( )
} ;
Mocker . GetMock < IMediaFileRepository > ( )
. Setup ( c = > c . GetFilesBySeries ( It . IsAny < int > ( ) ) )
. Returns ( new List < EpisodeFile >
{
new EpisodeFile { Path = " c:\\ file2.avi". AsOsAgnostic ( ) }
new EpisodeFile { Relative Path = " file2.avi". AsOsAgnostic ( ) }
} ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . HaveCount ( 3 ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . HaveCount ( 3 ) ;
}
[Test]
@ -132,16 +136,16 @@ namespace NzbDrone.Core.Test.MediaFiles
{
var files = new List < string > ( )
{
" c :\\FILE1.avi". AsOsAgnostic ( )
" C :\\FILE1.avi". AsOsAgnostic ( )
} ;
Mocker . GetMock < IMediaFileRepository > ( )
. Setup ( c = > c . GetFilesBySeries ( It . IsAny < int > ( ) ) )
. Returns ( new List < EpisodeFile > ( ) ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . HaveCount ( 1 ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . NotContain ( files . First ( ) . ToLower ( ) ) ;
Subject . FilterExistingFiles ( files , 10 ) . Should ( ) . Contain ( files . First ( ) ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . HaveCount ( 1 ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . NotContain ( files . First ( ) . ToLower ( ) ) ;
Subject . FilterExistingFiles ( files , _series ) . Should ( ) . Contain ( files . First ( ) ) ;
}
}
}