Skip to content

Commit d35709d

Browse files
authored
Merge pull request #895 from drewnoakes/throwing-trace-listener
Make System.Diagnostics.Debug failures throw in unit tests
2 parents 68b4598 + e527e17 commit d35709d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/NetMQ.Tests/App.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.diagnostics>
4+
<trace>
5+
<listeners>
6+
<remove name="Default" />
7+
<add name="ThrowingTraceListener" type="NetMQ.Tests.ThrowingTraceListener, NetMQ.Tests" />
8+
</listeners>
9+
</trace>
10+
</system.diagnostics>
11+
</configuration>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.Serialization;
4+
5+
namespace NetMQ.Tests
6+
{
7+
public sealed class ThrowingTraceListener : TraceListener
8+
{
9+
public override void Fail(string message, string detailMessage)
10+
{
11+
throw new DebugAssertFailureException((message + Environment.NewLine + detailMessage).Trim());
12+
}
13+
14+
public override void Write(string message)
15+
{
16+
}
17+
18+
public override void WriteLine(string message)
19+
{
20+
}
21+
22+
[Serializable]
23+
public class DebugAssertFailureException : Exception
24+
{
25+
public DebugAssertFailureException()
26+
{
27+
}
28+
29+
public DebugAssertFailureException(string message) : base(message)
30+
{
31+
}
32+
33+
public DebugAssertFailureException(string message, Exception inner) : base(message, inner)
34+
{
35+
}
36+
37+
protected DebugAssertFailureException(SerializationInfo info, StreamingContext context) : base(info, context)
38+
{
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)