-
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.
- Loading branch information
Alex Liu
committed
Jun 15, 2013
1 parent
42b5814
commit bf23845
Showing
18 changed files
with
217 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Radish.IntegrationTests | ||
{ | ||
public class HttpServerTests | ||
{ | ||
[Test] | ||
public void Handle_when_matched_request_should_reponse_setting_content() | ||
{ | ||
// Assert | ||
var httpServer = new HttpServer(); | ||
httpServer.When(request => request.Uri.Is("/home/index")) | ||
.Then(response => response.Text("hello")); | ||
|
||
var httpEngine = new HttpServerEngine(httpServer, 9000); | ||
httpEngine.Start(); | ||
|
||
// Act | ||
var result = Http.Get("http://localhost:9000/home/index").GetContent(); | ||
httpEngine.Stop(); | ||
|
||
// Assert | ||
result.Should().Be("hello"); | ||
} | ||
|
||
[Test] | ||
public void Handle_when_request_not_matched_should_return_404() | ||
{ | ||
// Assert | ||
var httpServer = new HttpServer(); | ||
|
||
var httpEngine = new HttpServerEngine(httpServer, 9000); | ||
httpEngine.Start(); | ||
|
||
// Act | ||
var result = Http.Get("http://localhost:9000/home/index").GetContent(); | ||
httpEngine.Stop(); | ||
|
||
// Assert | ||
result.Should().Be(string.Empty); | ||
} | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="FluentAssertions" version="2.0.1" targetFramework="net45" /> | ||
<package id="NUnit" version="2.6.2" targetFramework="net45" /> | ||
</packages> |
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 |
---|---|---|
@@ -1,35 +1,41 @@ | ||
namespace Radish.UnitTests.Matchers | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Radish.UnitTests.Matchers | ||
{ | ||
public class EqualRequestMatcherTests | ||
{ | ||
// [Test] | ||
// public void Match_for_are_equal() | ||
// { | ||
// // Arrange | ||
// var extractor = Substitute.For<IRequestExtractor>(); | ||
// var matcher = new EqualRequestMatcher(extractor, "/home/index"); | ||
// extractor.Extract(null).ReturnsForAnyArgs("/home/index"); | ||
// | ||
// // Act | ||
// var result = matcher.Match(null); | ||
// | ||
// // Assert | ||
// Assert.True(result); | ||
// } | ||
// | ||
// [Test] | ||
// public void IsMatch_for_uri() | ||
// { | ||
// // Arrange | ||
// var extractor = Substitute.For<IRequestExtractor>(); | ||
// var matcher = new EqualRequestMatcher(extractor, "/home/index"); | ||
// extractor.Extract(null).ReturnsForAnyArgs("invalid"); | ||
// | ||
// // Act | ||
// var result = matcher.Match(null); | ||
// | ||
// // Assert | ||
// Assert.False(result); | ||
// } | ||
[Test] | ||
public void Match_for_are_equal() | ||
{ | ||
// Arrange | ||
var extractor = Substitute.For<IRequestExtractor>(); | ||
var request = Substitute.For<IHttpRequest>(); | ||
extractor.Extract(request).ReturnsForAnyArgs("/home/index"); | ||
var matcher = new EqualRequestMatcher(extractor, "/home/index"); | ||
|
||
// Act | ||
var result = matcher.Match(request); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Test] | ||
public void IsMatch_for_uri() | ||
{ | ||
// Arrange | ||
var extractor = Substitute.For<IRequestExtractor>(); | ||
var matcher = new EqualRequestMatcher(extractor, "/home/index"); | ||
var request = Substitute.For<IHttpRequest>(); | ||
|
||
extractor.Extract(request).ReturnsForAnyArgs("invalid"); | ||
|
||
// Act | ||
var result = matcher.Match(request); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
} | ||
} |
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
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 FileResponseWriterTests | ||
{ | ||
[Test] | ||
public void Write() | ||
{ | ||
// Arrange | ||
var responseStream = new MemoryStream(); | ||
var response = Substitute.For<IHttpResponse>(); | ||
response.OutputStream.Returns(responseStream); | ||
var fileWriter = new FileResponseWriter("test.txt"); | ||
|
||
// Act | ||
fileWriter.Write(response); | ||
|
||
// Assert | ||
Encoding.UTF8.GetString(responseStream.ToArray()).Should().Be("hello"); | ||
} | ||
} | ||
} |
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 @@ | ||
hello |
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
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,28 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Radish.Writers | ||
{ | ||
public class FileResponseWriter : IResponseWriter | ||
{ | ||
private readonly string _file; | ||
|
||
public FileResponseWriter(string file) | ||
{ | ||
_file = file; | ||
} | ||
|
||
public void Write(IHttpResponse response) | ||
{ | ||
using (var stream = File.Open(_file, FileMode.Open)) | ||
{ | ||
var data = (byte)stream.ReadByte(); | ||
while (data != -1) | ||
{ | ||
response.OutputStream.WriteByte(data); | ||
data = (byte)stream.ReadByte(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,19 @@ | ||
using System; | ||
|
||
namespace Radish.Writers | ||
{ | ||
public class ResponseStatusCodeWriter : IResponseWriter | ||
{ | ||
private readonly int _statusCode; | ||
|
||
public ResponseStatusCodeWriter(int statusCode) | ||
{ | ||
_statusCode = statusCode; | ||
} | ||
|
||
public void Write(IHttpResponse response) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.