1
1
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
2
2
3
3
using System ;
4
+ using System . Collections . Generic ;
4
5
using System . IO ;
5
6
using System . Xml ;
6
7
using NSubstitute ;
@@ -14,25 +15,43 @@ namespace NUnit.ConsoleRunner.Tests
14
15
{
15
16
class ConsoleRunnerTests
16
17
{
18
+ private ITestEngine _testEngine ;
19
+ private IResultService _resultService ;
20
+
21
+ [ SetUp ]
22
+ public void Setup ( )
23
+ {
24
+ _testEngine = Substitute . For < ITestEngine > ( ) ;
25
+ _resultService = new FakeResultService ( ) ;
26
+
27
+ _testEngine . Services . GetService < IResultService > ( ) . Returns ( _resultService ) ;
28
+ }
29
+
17
30
[ Test ]
18
31
public void ThrowsNUnitEngineExceptionWhenTestResultsAreNotWriteable ( )
19
32
{
20
- using ( var testEngine = new TestEngine ( ) )
21
- {
22
- testEngine . Services . Add ( new FakeResultService ( ) ) ;
23
- testEngine . Services . Add ( new TestFilterService ( ) ) ;
24
- testEngine . Services . Add ( Substitute . For < IService , IExtensionService > ( ) ) ;
33
+ ( ( FakeResultService ) _resultService ) . ThrowsUnauthorizedAccessException = true ;
25
34
26
- var consoleRunner = new ConsoleRunner ( testEngine , ConsoleMocks . Options ( "mock-assembly.dll" ) , new ColorConsoleWriter ( ) ) ;
35
+ var consoleRunner = new ConsoleRunner ( _testEngine , ConsoleMocks . Options ( "mock-assembly.dll" ) , new ColorConsoleWriter ( ) ) ;
27
36
28
- var ex = Assert . Throws < NUnitEngineException > ( ( ) => { consoleRunner . Execute ( ) ; } ) ;
29
- Assert . That ( ex , Has . Message . EqualTo ( "The path specified in --result TestResult.xml could not be written to" ) ) ;
30
- }
37
+ var ex = Assert . Throws < NUnitEngineException > ( ( ) => { consoleRunner . Execute ( ) ; } ) ;
38
+ Assert . That ( ex , Has . Message . EqualTo ( "The path specified in --result TestResult.xml could not be written to" ) ) ;
39
+ }
40
+
41
+ [ Test ]
42
+ public void ThrowsNUnitExceptionWhenTeamcityOptionIsSpecifiedButNotAvailable ( )
43
+ {
44
+ var ex = Assert . Throws < NUnitEngineException > (
45
+ ( ) => new ConsoleRunner ( _testEngine , ConsoleMocks . Options ( "mock-assembly.dll" , "--teamcity" ) , new ColorConsoleWriter ( ) ) ) ;
46
+
47
+ Assert . That ( ex , Has . Message . Contains ( "teamcity" ) ) ;
31
48
}
32
49
}
33
50
34
51
internal class FakeResultService : Service , IResultService
35
52
{
53
+ public bool ThrowsUnauthorizedAccessException ;
54
+
36
55
public string [ ] Formats
37
56
{
38
57
get
@@ -43,25 +62,33 @@ public string[] Formats
43
62
44
63
public IResultWriter GetResultWriter ( string format , object [ ] args )
45
64
{
46
- return new FakeResultWriter ( ) ;
65
+ return new FakeResultWriter ( this ) ;
47
66
}
48
- }
49
67
50
- internal class FakeResultWriter : IResultWriter
51
- {
52
- public void CheckWritability ( string outputPath )
68
+ class FakeResultWriter : IResultWriter
53
69
{
54
- throw new UnauthorizedAccessException ( ) ;
55
- }
70
+ private FakeResultService _service ;
56
71
57
- public void WriteResultFile ( XmlNode resultNode , string outputPath )
58
- {
59
- throw new System . NotImplementedException ( ) ;
60
- }
72
+ public FakeResultWriter ( FakeResultService service )
73
+ {
74
+ _service = service ;
75
+ }
61
76
62
- public void WriteResultFile ( XmlNode resultNode , TextWriter writer )
63
- {
64
- throw new System . NotImplementedException ( ) ;
77
+ public void CheckWritability ( string outputPath )
78
+ {
79
+ if ( _service . ThrowsUnauthorizedAccessException )
80
+ throw new UnauthorizedAccessException ( ) ;
81
+ }
82
+
83
+ public void WriteResultFile ( XmlNode resultNode , string outputPath )
84
+ {
85
+ throw new System . NotImplementedException ( ) ;
86
+ }
87
+
88
+ public void WriteResultFile ( XmlNode resultNode , TextWriter writer )
89
+ {
90
+ throw new System . NotImplementedException ( ) ;
91
+ }
65
92
}
66
93
}
67
94
}
0 commit comments