-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathConsoleRunnerTests.cs
102 lines (83 loc) · 2.93 KB
/
ConsoleRunnerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
using System;
using System.IO;
using System.Xml;
using NSubstitute;
using NUnit.ConsoleRunner.Options;
using NUnit.Engine;
using NUnit.Engine.Extensibility;
using NUnit.Engine.Services;
using NUnit.Framework;
using NUnit.TextDisplay;
namespace NUnit.ConsoleRunner
{
class ConsoleRunnerTests
{
private ITestEngine _testEngine;
private IResultService _resultService;
[SetUp]
public void SetUp()
{
_testEngine = Substitute.For<ITestEngine>();
_resultService = new FakeResultService();
_testEngine.Services.GetService<IResultService>().Returns(_resultService);
}
[TearDown]
public void TearDown()
{
(_resultService as IDisposable)?.Dispose();
_testEngine.Dispose();
}
[Test]
public void ThrowsNUnitEngineExceptionWhenTestResultsAreNotWriteable()
{
((FakeResultService)_resultService).ThrowsUnauthorizedAccessException = true;
var consoleRunner = new ConsoleRunner(_testEngine, ConsoleMocks.Options("mock-assembly.dll"), new ColorConsoleWriter());
var ex = Assert.Throws<NUnitEngineException>(() => { consoleRunner.Execute(); });
Assert.That(ex, Has.Message.EqualTo("The path specified in --result TestResult.xml could not be written to"));
}
[Test]
public void ThrowsNUnitExceptionWhenTeamcityOptionIsSpecifiedButNotAvailable()
{
var ex = Assert.Throws<NUnitEngineException>(
() => new ConsoleRunner(_testEngine, ConsoleMocks.Options("mock-assembly.dll", "--teamcity"), new ColorConsoleWriter()));
Assert.That(ex, Has.Message.Contains("teamcity"));
}
}
internal class FakeResultService : Service, IResultService
{
public bool ThrowsUnauthorizedAccessException;
public string[] Formats
{
get
{
return new[] { "nunit3" };
}
}
public IResultWriter GetResultWriter(string format, params object?[]? args)
{
return new FakeResultWriter(this);
}
}
internal class FakeResultWriter : IResultWriter
{
private FakeResultService _service;
public FakeResultWriter(FakeResultService service)
{
_service = service;
}
public void CheckWritability(string outputPath)
{
if (_service.ThrowsUnauthorizedAccessException)
throw new UnauthorizedAccessException();
}
public void WriteResultFile(XmlNode resultNode, string outputPath)
{
throw new System.NotImplementedException();
}
public void WriteResultFile(XmlNode resultNode, TextWriter writer)
{
throw new System.NotImplementedException();
}
}
}