Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 388c2ad

Browse files
committed
Code cleanup
1 parent a86f724 commit 388c2ad

File tree

1 file changed

+46
-47
lines changed

1 file changed

+46
-47
lines changed

src/Nancy.Owin.Tests/NancyOwinHostFixture.cs

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,62 @@ namespace Nancy.Owin.Tests
1010
using FakeItEasy;
1111

1212
using Nancy.Bootstrapper;
13-
using Nancy.Owin;
1413
using Nancy.Tests;
1514

1615
using Xunit;
1716

1817
public class NancyOwinHostFixture
1918
{
20-
private readonly NancyOwinHost host;
2119
private readonly Dictionary<string, object> environment;
22-
private readonly INancyEngine fakeEngine;
2320
private readonly INancyBootstrapper fakeBootstrapper;
21+
private readonly INancyEngine fakeEngine;
22+
private readonly NancyOwinHost host;
2423

2524
public NancyOwinHostFixture()
2625
{
2726
this.fakeEngine = A.Fake<INancyEngine>();
2827
this.fakeBootstrapper = A.Fake<INancyBootstrapper>();
2928
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+
};
4645
}
4746

4847
[Fact]
4948
public void Should_immediately_invoke_nancy_if_no_request_body_delegate()
5049
{
5150
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);
5357
}
5458

5559
[Fact]
5660
public void Should_set_return_code_in_response_callback()
5761
{
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};
6464
this.SetupFakeNancyCompleteCallback(fakeContext);
6565
this.host.Invoke(this.environment);
6666

6767
((int)this.environment["owin.ResponseStatusCode"]).ShouldEqual(200);
68-
((string)this.environment["owin.ResponseReasonPhrase"]).ShouldEqual("OK");
68+
this.environment["owin.ResponseReasonPhrase"].ShouldEqual("OK");
6969
}
7070

7171
[Fact]
@@ -74,10 +74,10 @@ public void Should_set_headers_in_response_callback()
7474
var fakeResponse = new Response
7575
{
7676
StatusCode = HttpStatusCode.OK,
77-
Headers = new Dictionary<string, string> { { "TestHeader", "TestValue" } },
77+
Headers = new Dictionary<string, string> {{"TestHeader", "TestValue"}},
7878
Contents = s => { }
7979
};
80-
var fakeContext = new NancyContext() { Response = fakeResponse };
80+
var fakeContext = new NancyContext {Response = fakeResponse};
8181
this.SetupFakeNancyCompleteCallback(fakeContext);
8282

8383
this.host.Invoke(this.environment);
@@ -94,16 +94,16 @@ public void Should_send_entire_body()
9494
{
9595
var data1 = Encoding.ASCII.GetBytes("Some content");
9696
var data2 = Encoding.ASCII.GetBytes("Some more content");
97-
var fakeResponse = new Response()
97+
var fakeResponse = new Response
9898
{
9999
StatusCode = HttpStatusCode.OK,
100100
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+
}
105105
};
106-
var fakeContext = new NancyContext { Response = fakeResponse };
106+
var fakeContext = new NancyContext {Response = fakeResponse};
107107
this.SetupFakeNancyCompleteCallback(fakeContext);
108108

109109
this.host.Invoke(this.environment);
@@ -116,14 +116,10 @@ public void Should_send_entire_body()
116116
public void Should_dispose_context_on_completion_of_body_delegate()
117117
{
118118
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};
125121
var mockDisposable = A.Fake<IDisposable>();
126-
fakeContext.Items.Add("Test", mockDisposable);
122+
fakeContext.Items.Add("Test", mockDisposable);
127123
this.SetupFakeNancyCompleteCallback(fakeContext);
128124

129125
this.host.Invoke(environment);
@@ -134,10 +130,10 @@ public void Should_dispose_context_on_completion_of_body_delegate()
134130
[Fact]
135131
public void Should_set_cookie_with_valid_header()
136132
{
137-
var fakeResponse = new Response() { StatusCode = HttpStatusCode.OK };
133+
var fakeResponse = new Response {StatusCode = HttpStatusCode.OK};
138134
fakeResponse.AddCookie("test", "testvalue");
139135
fakeResponse.AddCookie("test1", "testvalue1");
140-
var fakeContext = new NancyContext() { Response = fakeResponse };
136+
var fakeContext = new NancyContext {Response = fakeResponse};
141137

142138
this.SetupFakeNancyCompleteCallback(fakeContext);
143139

@@ -156,15 +152,18 @@ public void Should_set_cookie_with_valid_header()
156152
/// <param name="context">Context to return</param>
157153
private void SetupFakeNancyCompleteCallback(NancyContext context)
158154
{
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)));
161161
}
162162

163163
private static T Get<T>(IDictionary<string, object> env, string key)
164164
{
165165
object value;
166166
return env.TryGetValue(key, out value) && value is T ? (T)value : default(T);
167167
}
168-
169168
}
170169
}

0 commit comments

Comments
 (0)