-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMockWebResponse.cs
106 lines (90 loc) · 2.8 KB
/
MockWebResponse.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
103
104
105
106
using System;
using System.IO;
using System.Text;
namespace Inversion.Web {
/// <summary>
/// Implements a mock MockWebResponse for use with MockWebContext
/// to facilitate testing.
/// </summary>
public class MockWebResponse: IWebResponse {
private readonly StringBuilder _output = new StringBuilder();
/// <summary>
/// The end result of anything that's been written to the mock response.
/// </summary>
public string Result {
get { return _output.ToString(); }
}
/// <summary>
/// The text writer used for writing to the response stream.
/// </summary>
public TextWriter Output {
get { throw new NotImplementedException("The output stream has not been mocked."); }
}
/// <summary>
/// The response stream.
/// </summary>
public Stream OutputStream {
get { throw new NotImplementedException("The output stream has not been mocked."); }
}
/// <summary>
/// The status code of the response.
/// </summary>
public int StatusCode { get; set; }
/// <summary>
/// The status description of the response stream.
/// </summary>
public string StatusDescription { get; set; }
/// <summary>
/// The content type of the response stream.
/// </summary>
public string ContentType { get; set; }
/// <summary>
/// Access to the response cookies.
/// </summary>
public IResponseCookieCollection Cookies {
get { throw new NotImplementedException("The IResponseCookieCollection has not been mocked."); }
}
/// <summary>
/// Access to the response headers.
/// </summary>
public IResponseHeaderCollection Headers {
get { throw new NotImplementedException("The IResponseHeaderCollection has not been mocked."); }
}
/// <summary>
/// Flushes the response steam and ends the response.
/// </summary>
public void End() {
// no side-effect
}
/// <summary>
/// Writes the provided text to the response stream.
/// </summary>
/// <param name="text">The text to write to the response stream.</param>
public void Write(string text) {
_output.Append(text);
}
/// <summary>
/// Writes the provided formatted text to the response stream.
/// </summary>
/// <param name="text">The text to write to the response stream.</param>
/// <param name="args">The arguments to interpolate into the text.</param>
public void WriteFormat(string text, params object[] args) {
_output.AppendFormat(text, args);
}
/// <summary>
/// Redirects the request to the provided url.
/// </summary>
/// <param name="url">The url to redirect to.</param>
public void Redirect(string url) {
// no side-effect
}
/// <summary>
/// Redirects the request permanently to the provided url
/// issuing a `301` in the response.
/// </summary>
/// <param name="url"></param>
public void PermanentRedirect(string url) {
// no side-effect
}
}
}