forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockHttpResponse.cs
More file actions
99 lines (78 loc) · 2.56 KB
/
Copy pathMockHttpResponse.cs
File metadata and controls
99 lines (78 loc) · 2.56 KB
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
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using ServiceStack.Host;
using ServiceStack.Text;
using ServiceStack.Web;
namespace ServiceStack.Testing
{
public class MockHttpResponse : IHttpResponse
{
public MockHttpResponse()
{
this.Headers = PclExportClient.Instance.NewNameValueCollection();
this.OutputStream = new MemoryStream();
this.TextWritten = new StringBuilder();
this.Cookies = new Cookies(this);
this.Items = new Dictionary<string, object>();
}
public object OriginalResponse { get; private set; }
public int StatusCode { set; get; }
public string StatusDescription { set; get; }
public string ContentType { get; set; }
public StringBuilder TextWritten { get; set; }
public INameValueCollection Headers { get; set; }
public ICookies Cookies { get; set; }
public void AddHeader(string name, string value)
{
this.Headers.Add(name, value);
}
public void Redirect(string url)
{
this.Headers.Add(HttpHeaders.Location, url.MapServerPath());
}
public Stream OutputStream { get; private set; }
public object Dto { get; set; }
public void Write(string text)
{
this.TextWritten.Append(text);
}
public bool UseBufferedStream { get; set; }
public void Close()
{
this.IsClosed = true;
}
public void End()
{
Close();
}
public void Flush()
{
OutputStream.Flush();
}
public string ReadAsString()
{
if (!IsClosed) this.OutputStream.Seek(0, SeekOrigin.Begin);
var bytes = ((MemoryStream)OutputStream).ToArray();
return bytes.FromUtf8Bytes();
}
public byte[] ReadAsBytes()
{
if (!IsClosed) this.OutputStream.Seek(0, SeekOrigin.Begin);
var ms = (MemoryStream)this.OutputStream;
return ms.ToArray();
}
public bool IsClosed { get; private set; }
public void SetContentLength(long contentLength)
{
Headers[HttpHeaders.ContentLength] = contentLength.ToString(CultureInfo.InvariantCulture);
}
public bool KeepAlive { get; set; }
public Dictionary<string, object> Items { get; private set; }
public void SetCookie(Cookie cookie)
{
}
}
}