blob: 705f8196e4250ed386f62443a32d4894d5f7cdd2 (
plain)
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
|
// ****************************************************************
// Copyright 2008, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
// ****************************************************************
using System.IO;
namespace NUnit.Core
{
/// <summary>
/// Abstract base for classes that capture text output
/// and redirect it to a TextWriter.
/// </summary>
public abstract class TextCapture
{
#region Private Fields
/// <summary>
/// True if capture is enabled
/// </summary>
private bool enabled;
/// <summary>
/// The TextWriter to which text is redirected
/// </summary>
private TextWriter writer;
#endregion
#region Properties
/// <summary>
/// The TextWriter to which text is redirected
/// </summary>
public TextWriter Writer
{
get { return writer; }
set
{
writer = value;
if (writer != null && enabled)
StartCapture();
}
}
/// <summary>
/// Controls whether text is captured or not
/// </summary>
public bool Enabled
{
get { return enabled; }
set
{
if (enabled != value)
{
if (writer != null && enabled)
StopCapture();
enabled = value;
if (writer != null && enabled && DefaultThreshold != "Off")
StartCapture();
}
}
}
/// <summary>
/// Returns the default threshold value, which represents
/// the degree of verbosity of the output text stream.
/// Returns "None" in the base class. Derived classes that
/// support verbosity levels should override it.
/// </summary>
public virtual string DefaultThreshold
{
get { return "None"; }
}
#endregion
#region Abstract Members
/// <summary>
/// Override this to perform whatever actions are needed
/// to start capturing text and sending it to the Writer.
/// </summary>
protected abstract void StartCapture();
/// <summary>
/// Override this to perform whatever actions are needed
/// to flush remaining output and stop capturing text.
/// The Writer should not be changed, allowing capture
/// to be restarted at a future point.
/// </summary>
protected abstract void StopCapture();
#endregion
}
}
|