@@ -10,62 +10,62 @@ namespace Nancy.Owin.Tests
10
10
using FakeItEasy ;
11
11
12
12
using Nancy . Bootstrapper ;
13
- using Nancy . Owin ;
14
13
using Nancy . Tests ;
15
14
16
15
using Xunit ;
17
16
18
17
public class NancyOwinHostFixture
19
18
{
20
- private readonly NancyOwinHost host ;
21
19
private readonly Dictionary < string , object > environment ;
22
- private readonly INancyEngine fakeEngine ;
23
20
private readonly INancyBootstrapper fakeBootstrapper ;
21
+ private readonly INancyEngine fakeEngine ;
22
+ private readonly NancyOwinHost host ;
24
23
25
24
public NancyOwinHostFixture ( )
26
25
{
27
26
this . fakeEngine = A . Fake < INancyEngine > ( ) ;
28
27
this . fakeBootstrapper = A . Fake < INancyBootstrapper > ( ) ;
29
28
A . CallTo ( ( ) => this . fakeBootstrapper . GetEngine ( ) ) . Returns ( this . fakeEngine ) ;
30
- this . host = new NancyOwinHost ( null , new NancyOptions { Bootstrapper = this . fakeBootstrapper } ) ;
31
- this . environment = new Dictionary < string , object > ( )
32
- {
33
- { "owin.RequestMethod" , "GET" } ,
34
- { "owin.RequestPath" , "/test" } ,
35
- { "owin.RequestPathBase" , "/root" } ,
36
- { "owin.RequestQueryString" , "var=value" } ,
37
- { "owin.RequestBody" , Stream . Null } ,
38
- { "owin.RequestHeaders" , new Dictionary < string , string [ ] > ( StringComparer . OrdinalIgnoreCase ) } ,
39
- { "owin.RequestScheme" , "http" } ,
40
- { "owin.ResponseHeaders" , new Dictionary < string , string [ ] > ( StringComparer . OrdinalIgnoreCase ) } ,
41
- { "owin.ResponseBody" , new MemoryStream ( ) } ,
42
- { "owin.ResponseReasonPhrase" , string . Empty } ,
43
- { "owin.Version" , "1.0" } ,
44
- { "owin.CallCancelled" , CancellationToken . None }
45
- } ;
29
+ this . host = new NancyOwinHost ( null , new NancyOptions { Bootstrapper = this . fakeBootstrapper } ) ;
30
+ this . environment = new Dictionary < string , object >
31
+ {
32
+ { "owin.RequestMethod" , "GET" } ,
33
+ { "owin.RequestPath" , "/test" } ,
34
+ { "owin.RequestPathBase" , "/root" } ,
35
+ { "owin.RequestQueryString" , "var=value" } ,
36
+ { "owin.RequestBody" , Stream . Null } ,
37
+ { "owin.RequestHeaders" , new Dictionary < string , string [ ] > ( StringComparer . OrdinalIgnoreCase ) } ,
38
+ { "owin.RequestScheme" , "http" } ,
39
+ { "owin.ResponseHeaders" , new Dictionary < string , string [ ] > ( StringComparer . OrdinalIgnoreCase ) } ,
40
+ { "owin.ResponseBody" , new MemoryStream ( ) } ,
41
+ { "owin.ResponseReasonPhrase" , string . Empty } ,
42
+ { "owin.Version" , "1.0" } ,
43
+ { "owin.CallCancelled" , CancellationToken . None }
44
+ } ;
46
45
}
47
46
48
47
[ Fact ]
49
48
public void Should_immediately_invoke_nancy_if_no_request_body_delegate ( )
50
49
{
51
50
this . host . Invoke ( this . environment ) ;
52
- A . CallTo ( ( ) => this . fakeEngine . HandleRequest ( A < Request > . Ignored , A < Func < NancyContext , NancyContext > > . Ignored , A < Action < NancyContext > > . Ignored , A < Action < Exception > > . Ignored ) ) . MustHaveHappened ( Repeated . Exactly . Once ) ;
51
+ A . CallTo (
52
+ ( ) =>
53
+ this . fakeEngine . HandleRequest ( A < Request > . Ignored ,
54
+ A < Func < NancyContext , NancyContext > > . Ignored ,
55
+ A < Action < NancyContext > > . Ignored ,
56
+ A < Action < Exception > > . Ignored ) ) . MustHaveHappened ( Repeated . Exactly . Once ) ;
53
57
}
54
58
55
59
[ Fact ]
56
60
public void Should_set_return_code_in_response_callback ( )
57
61
{
58
- var fakeResponse = new Response
59
- {
60
- StatusCode = HttpStatusCode . OK ,
61
- Contents = s => { }
62
- } ;
63
- var fakeContext = new NancyContext ( ) { Response = fakeResponse } ;
62
+ var fakeResponse = new Response { StatusCode = HttpStatusCode . OK , Contents = s => { } } ;
63
+ var fakeContext = new NancyContext { Response = fakeResponse } ;
64
64
this . SetupFakeNancyCompleteCallback ( fakeContext ) ;
65
65
this . host . Invoke ( this . environment ) ;
66
66
67
67
( ( int ) this . environment [ "owin.ResponseStatusCode" ] ) . ShouldEqual ( 200 ) ;
68
- ( ( string ) this . environment [ "owin.ResponseReasonPhrase" ] ) . ShouldEqual ( "OK" ) ;
68
+ this . environment [ "owin.ResponseReasonPhrase" ] . ShouldEqual ( "OK" ) ;
69
69
}
70
70
71
71
[ Fact ]
@@ -74,10 +74,10 @@ public void Should_set_headers_in_response_callback()
74
74
var fakeResponse = new Response
75
75
{
76
76
StatusCode = HttpStatusCode . OK ,
77
- Headers = new Dictionary < string , string > { { "TestHeader" , "TestValue" } } ,
77
+ Headers = new Dictionary < string , string > { { "TestHeader" , "TestValue" } } ,
78
78
Contents = s => { }
79
79
} ;
80
- var fakeContext = new NancyContext ( ) { Response = fakeResponse } ;
80
+ var fakeContext = new NancyContext { Response = fakeResponse } ;
81
81
this . SetupFakeNancyCompleteCallback ( fakeContext ) ;
82
82
83
83
this . host . Invoke ( this . environment ) ;
@@ -94,16 +94,16 @@ public void Should_send_entire_body()
94
94
{
95
95
var data1 = Encoding . ASCII . GetBytes ( "Some content" ) ;
96
96
var data2 = Encoding . ASCII . GetBytes ( "Some more content" ) ;
97
- var fakeResponse = new Response ( )
97
+ var fakeResponse = new Response
98
98
{
99
99
StatusCode = HttpStatusCode . OK ,
100
100
Contents = s =>
101
- {
102
- s . Write ( data1 , 0 , data1 . Length ) ;
103
- s . Write ( data2 , 0 , data2 . Length ) ;
104
- }
101
+ {
102
+ s . Write ( data1 , 0 , data1 . Length ) ;
103
+ s . Write ( data2 , 0 , data2 . Length ) ;
104
+ }
105
105
} ;
106
- var fakeContext = new NancyContext { Response = fakeResponse } ;
106
+ var fakeContext = new NancyContext { Response = fakeResponse } ;
107
107
this . SetupFakeNancyCompleteCallback ( fakeContext ) ;
108
108
109
109
this . host . Invoke ( this . environment ) ;
@@ -116,14 +116,10 @@ public void Should_send_entire_body()
116
116
public void Should_dispose_context_on_completion_of_body_delegate ( )
117
117
{
118
118
var data1 = Encoding . ASCII . GetBytes ( "Some content" ) ;
119
- var fakeResponse = new Response ( )
120
- {
121
- StatusCode = HttpStatusCode . OK ,
122
- Contents = s => s . Write ( data1 , 0 , data1 . Length )
123
- } ;
124
- var fakeContext = new NancyContext ( ) { Response = fakeResponse } ;
119
+ var fakeResponse = new Response { StatusCode = HttpStatusCode . OK , Contents = s => s . Write ( data1 , 0 , data1 . Length ) } ;
120
+ var fakeContext = new NancyContext { Response = fakeResponse } ;
125
121
var mockDisposable = A . Fake < IDisposable > ( ) ;
126
- fakeContext . Items . Add ( "Test" , mockDisposable ) ;
122
+ fakeContext . Items . Add ( "Test" , mockDisposable ) ;
127
123
this . SetupFakeNancyCompleteCallback ( fakeContext ) ;
128
124
129
125
this . host . Invoke ( environment ) ;
@@ -134,10 +130,10 @@ public void Should_dispose_context_on_completion_of_body_delegate()
134
130
[ Fact ]
135
131
public void Should_set_cookie_with_valid_header ( )
136
132
{
137
- var fakeResponse = new Response ( ) { StatusCode = HttpStatusCode . OK } ;
133
+ var fakeResponse = new Response { StatusCode = HttpStatusCode . OK } ;
138
134
fakeResponse . AddCookie ( "test" , "testvalue" ) ;
139
135
fakeResponse . AddCookie ( "test1" , "testvalue1" ) ;
140
- var fakeContext = new NancyContext ( ) { Response = fakeResponse } ;
136
+ var fakeContext = new NancyContext { Response = fakeResponse } ;
141
137
142
138
this . SetupFakeNancyCompleteCallback ( fakeContext ) ;
143
139
@@ -156,15 +152,18 @@ public void Should_set_cookie_with_valid_header()
156
152
/// <param name="context">Context to return</param>
157
153
private void SetupFakeNancyCompleteCallback ( NancyContext context )
158
154
{
159
- A . CallTo ( ( ) => this . fakeEngine . HandleRequest ( A < Request > . Ignored , A < Func < NancyContext , NancyContext > > . Ignored , A < Action < NancyContext > > . Ignored , A < Action < Exception > > . Ignored ) )
160
- . Invokes ( ( i => ( ( Action < NancyContext > ) i . Arguments [ 2 ] ) . Invoke ( context ) ) ) ;
155
+ A . CallTo (
156
+ ( ) =>
157
+ this . fakeEngine . HandleRequest ( A < Request > . Ignored ,
158
+ A < Func < NancyContext , NancyContext > > . Ignored ,
159
+ A < Action < NancyContext > > . Ignored ,
160
+ A < Action < Exception > > . Ignored ) ) . Invokes ( ( i => ( ( Action < NancyContext > ) i . Arguments [ 2 ] ) . Invoke ( context ) ) ) ;
161
161
}
162
162
163
163
private static T Get < T > ( IDictionary < string , object > env , string key )
164
164
{
165
165
object value ;
166
166
return env . TryGetValue ( key , out value ) && value is T ? ( T ) value : default ( T ) ;
167
167
}
168
-
169
168
}
170
169
}
0 commit comments