5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . IO ;
8
+ using System . Linq ;
8
9
using System . Text ;
9
10
10
11
namespace NUnit . Engine . Internal . Tests
11
12
{
12
13
/// <summary>
13
- /// Tests the implementation of <see cref="AddinsFileReader "/>.
14
+ /// Tests the implementation of <see cref="AddinsFile "/>.
14
15
/// </summary>
15
16
[ TestFixture ]
16
- public class AddinsFileReaderTests
17
+ public class AddinsFileTests
17
18
{
18
19
[ Test ]
19
20
public void Read_IFile_Null ( )
20
21
{
21
- var reader = new AddinsFileReader ( ) ;
22
-
23
- Assert . That ( ( ) => reader . Read ( ( IFile ) null ) , Throws . ArgumentNullException ) ;
22
+ Assert . That ( ( ) => AddinsFile . Read ( ( IFile ) null ) , Throws . ArgumentNullException ) ;
24
23
}
25
24
26
25
[ Test ]
27
26
public void Read_Stream ( )
28
27
{
29
- var input = string . Join ( Environment . NewLine , new string [ ]
28
+ var content = new [ ]
30
29
{
31
30
"# This line is a comment and is ignored. The next (blank) line is ignored as well." ,
32
31
"" ,
@@ -36,59 +35,59 @@ public void Read_Stream()
36
35
"some/other/directory/ # process another directory, which may contain its own addins file" ,
37
36
"# note that an absolute path is allowed, but is probably not a good idea in most cases" ,
38
37
"/unix/absolute/directory"
39
- } ) ;
40
-
41
- IEnumerable < string > result ;
38
+ } ;
42
39
43
- using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( input ) ) )
40
+ using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( string . Join ( Environment . NewLine , content ) ) ) )
44
41
{
45
- // Act
46
- result = AddinsFileReader . Read ( stream ) ;
42
+ var result = AddinsFile . Read ( stream ) ;
43
+
44
+ Assert . That ( result , Has . Count . EqualTo ( 8 ) ) ;
45
+ for ( int i = 0 ; i < 8 ; i ++ )
46
+ Assert . That ( result [ i ] , Is . EqualTo (
47
+ new AddinsFileEntry ( i + 1 , content [ i ] ) ) ) ;
47
48
}
49
+ }
48
50
49
- Assert . That ( result , Has . Count . EqualTo ( 5 ) ) ;
50
- Assert . That ( result , Contains . Item ( "*.dll" ) ) ;
51
- Assert . That ( result , Contains . Item ( "addins/*.dll" ) ) ;
52
- Assert . That ( result , Contains . Item ( "special/myassembly.dll" ) ) ;
53
- Assert . That ( result , Contains . Item ( "some/other/directory/" ) ) ;
54
- Assert . That ( result , Contains . Item ( "/unix/absolute/directory" ) ) ;
51
+ [ Test ]
52
+ public void Read_InvalidEntry ( )
53
+ {
54
+ var content = "// This is not valid" ;
55
+ using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( content ) ) )
56
+ {
57
+ Assert . That ( ( ) => AddinsFile . Read ( stream ) , Throws . Exception ) ;
58
+ }
55
59
}
56
60
57
61
[ Test ]
58
62
[ Platform ( "win" ) ]
59
63
public void Read_Stream_TransformBackslash_Windows ( )
60
64
{
61
- var input = string . Join ( Environment . NewLine , new string [ ]
62
- {
63
- "c:\\ windows\\ absolute\\ directory"
64
- } ) ;
65
+ var content = "c:\\ windows\\ absolute\\ directory" ;
65
66
66
- IEnumerable < string > result ;
67
-
68
- using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( input ) ) )
67
+ using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( content ) ) )
69
68
{
70
- // Act
71
- result = AddinsFileReader . Read ( stream ) ;
72
- }
69
+ var result = AddinsFile . Read ( stream ) ;
73
70
74
- Assert . That ( result , Has . Count . EqualTo ( 1 ) ) ;
75
- Assert . That ( result , Contains . Item ( "c:/windows/absolute/directory" ) ) ;
71
+ Assert . That ( result , Has . Count . EqualTo ( 1 ) ) ;
72
+ Assert . That ( result [ 0 ] , Is . EqualTo ( new AddinsFileEntry ( 1 , content ) ) ) ;
73
+ Assert . That ( result [ 0 ] . Text , Is . EqualTo ( "c:/windows/absolute/directory" ) ) ;
74
+ }
76
75
}
77
76
78
77
[ Test ]
79
78
[ Platform ( "linux,macosx,unix" ) ]
80
79
public void Read_Stream_TransformBackslash_NonWindows ( )
81
80
{
82
- IEnumerable < string > result ;
81
+ var content = "this/is/a \\ path \\ with \\ spaces/" ;
83
82
84
- using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( "this/is/a \\ path \\ with \\ spaces/" ) ) )
83
+ using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( content ) ) )
85
84
{
86
- // Act
87
- result = AddinsFileReader . Read ( stream ) ;
88
- }
85
+ var result = AddinsFile . Read ( stream ) ;
89
86
90
- Assert . That ( result , Has . Count . EqualTo ( 1 ) ) ;
91
- Assert . That ( result , Contains . Item ( "this/is/a\\ path\\ with\\ spaces/" ) ) ;
87
+ Assert . That ( result , Has . Count . EqualTo ( 1 ) ) ;
88
+ Assert . That ( result [ 0 ] , Is . EqualTo ( new AddinsFileEntry ( 1 , content ) ) ) ;
89
+ Assert . That ( result [ 0 ] . Text , Is . EqualTo ( content ) ) ;
90
+ }
92
91
}
93
92
}
94
93
}
0 commit comments