-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HeaderResponseWriter,FileResponseWriter,StatusCodeResponseWriter
- Loading branch information
Alex Liu
committed
Jun 15, 2013
1 parent
7d10cd1
commit d28e434
Showing
11 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Net; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using Radish.Writers; | ||
|
||
namespace Radish.UnitTests.Writers | ||
{ | ||
public class HeaderResponseWriterTests | ||
{ | ||
[Test] | ||
public void Write() | ||
{ | ||
// Arrange | ||
var headers = new WebHeaderCollection(); | ||
var writer = new HeaderResponseWriter("Content-Type", "text/xml"); | ||
var response = Substitute.For<IHttpResponse>(); | ||
response.Headers.Returns(headers); | ||
|
||
// Act | ||
writer.Write(response); | ||
|
||
// Assert | ||
response.Received(1).AppendHeader("Content-Type","text/xml"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using Radish.Writers; | ||
|
||
namespace Radish.UnitTests.Writers | ||
{ | ||
public class StatusCodeResponseWriterTests | ||
{ | ||
[Test] | ||
public void Write() | ||
{ | ||
// Arrange | ||
var writer = new StatusCodeResponseWriter(404); | ||
var response = Substitute.For<IHttpResponse>(); | ||
|
||
// Act | ||
writer.Write(response); | ||
|
||
// Assert | ||
response.StatusCode.Should().Be(404); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.IO; | ||
using System.Text; | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using Radish.Writers; | ||
|
||
namespace Radish.UnitTests.Writers | ||
{ | ||
public class TextResponseWriterTests | ||
{ | ||
[Test] | ||
public void Write() | ||
{ | ||
// Arrange | ||
var responseStream = new MemoryStream(); | ||
var response = Substitute.For<IHttpResponse>(); | ||
response.OutputStream.Returns(responseStream); | ||
var fileWriter = new TextResponseWriter("test", Encoding.UTF8); | ||
|
||
// Act | ||
fileWriter.Write(response); | ||
|
||
// Assert | ||
responseStream.ToArray().Should().Equal(Encoding.UTF8.GetBytes("test")); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace Radish.Writers | ||
{ | ||
public class HeaderResponseWriter : IResponseWriter | ||
{ | ||
private readonly string _name; | ||
private readonly string _value; | ||
|
||
public HeaderResponseWriter(string name, string value) | ||
{ | ||
_name = name; | ||
_value = value; | ||
} | ||
|
||
public void Write(IHttpResponse response) | ||
{ | ||
response.AppendHeader(_name, _value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters