Permalink
Browse files

Updating Response and CascadeTests

  • Loading branch information...
1 parent fec8375 commit 32cde6ca6cbb2862f0214be8fafe914a8ab2eccb @loudej loudej committed Sep 7, 2012
Showing with 15 additions and 9 deletions.
  1. +0 −1 Gate.sln
  2. +3 −5 src/Main/Gate/Response.cs
  3. +12 −3 src/Tests/Gate.Middleware.Tests/CascadeTests.cs
View
@@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{4E00A931
ProjectSection(SolutionItems) = preProject
build = build
build.cmd = build.cmd
- src\CommonAssemblyInfo.cs = src\CommonAssemblyInfo.cs
Sakefile.shade = Sakefile.shade
EndProjectSection
EndProject
@@ -219,7 +219,7 @@ public Stream OutputStream
public void Write(string text)
{
- var data = (Encoding ?? Encoding.UTF8).GetBytes(text);
+ var data = Encoding.GetBytes(text);
Write(data);
}
@@ -245,19 +245,17 @@ public void Write(ArraySegment<byte> data)
public Task WriteAsync(string text, CancellationToken cancellationToken = default(CancellationToken))
{
- var data = (Encoding ?? Encoding.UTF8).GetBytes(text);
- return WriteAsync(data,cancellationToken);
+ var data = Encoding.GetBytes(text);
+ return WriteAsync(data, cancellationToken);
}
public Task WriteAsync(byte[] buffer, CancellationToken cancellationToken = default(CancellationToken))
{
- TaskHelpers.Canceled();
return OutputStream.WriteAsync(buffer, 0, buffer.Length, cancellationToken);
}
public Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default(CancellationToken))
{
- TaskHelpers.Canceled();
return OutputStream.WriteAsync(buffer, offset, count, cancellationToken);
}
@@ -35,10 +35,19 @@ public void Cascade_with_no_apps_should_return_404()
Assert.That(response.StatusCode, Is.EqualTo(404));
}
+ AppFunc SetStatusApp(int statusCode)
+ {
+ return env =>
+ {
+ var resp = new Response(env) {StatusCode = statusCode};
+ return TaskHelpers.Completed();
+ };
+ }
+
[Test]
public void Cascade_with_app_calls_through()
{
- var cascade = Build(b => b.UseCascade((AppFunc)(env => new Response(env) { StatusCode = 200 }.EndAsync())));
+ var cascade = Build(b => b.UseCascade(SetStatusApp(200)));
Request request = new Request();
Response response = new Response(request.Environment);
@@ -50,8 +59,8 @@ public void Cascade_with_app_calls_through()
[Test]
public void Cascade_will_pass_along_to_first_non_404_app()
{
- AppFunc app1 = env => new Response(env) { StatusCode = 404 }.EndAsync();
- AppFunc app2 = env => new Response(env) { StatusCode = 200 }.EndAsync();
+ AppFunc app1 = SetStatusApp(404);
+ AppFunc app2 = SetStatusApp(200);
AppFunc app3 = env => TaskHelpers.FromError<object>(
new ApplicationException("This should not have been invoked"));

0 comments on commit 32cde6c

Please sign in to comment.