forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockRequestContext.cs
More file actions
72 lines (63 loc) · 2.29 KB
/
MockRequestContext.cs
File metadata and controls
72 lines (63 loc) · 2.29 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
using System;
using System.Collections.Generic;
using System.Net;
using Funq;
using ServiceStack.Server;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.Auth;
using ServiceStack.WebHost.Endpoints;
namespace ServiceStack.ServiceInterface.Testing
{
public class MockRequestContext : IRequestContext
{
public MockRequestContext()
{
this.Cookies = new Dictionary<string, Cookie>();
this.Files = new IFile[0];
this.Container = new Container();
var httpReq = new MockHttpRequest { Container = this.Container };
httpReq.AddSessionCookies();
this.Container.Register<IHttpRequest>(httpReq);
var httpRes = new MockHttpResponse();
this.Container.Register<IHttpResponse>(httpRes);
httpReq.Container = this.Container;
}
public T Get<T>() where T : class
{
return Container.TryResolve<T>();
}
public string IpAddress { get; private set; }
public string GetHeader(string headerName)
{
return Get<IHttpRequest>().Headers[headerName];
}
public Container Container { get; private set; }
public IDictionary<string, Cookie> Cookies { get; private set; }
public EndpointAttributes EndpointAttributes { get; private set; }
public IRequestAttributes RequestAttributes { get; private set; }
public string ContentType { get; private set; }
public string ResponseContentType { get; set; }
public string CompressionType { get; private set; }
public string AbsoluteUri { get; private set; }
public string PathInfo { get; private set; }
public IFile[] Files { get; private set; }
public AuthUserSession RemoveSession()
{
var httpReq = this.Get<IHttpRequest>();
httpReq.RemoveSession();
return httpReq.GetSession() as AuthUserSession;
}
public AuthUserSession ReloadSession()
{
var httpReq = this.Get<IHttpRequest>();
return httpReq.GetSession() as AuthUserSession;
}
public void Dispose()
{
}
public IAppHost CreateAppHost()
{
return new TestAppHost(this.Container);
}
}
}