-
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
Showing
56 changed files
with
1,858 additions
and
105 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,10 @@ | ||
using NUnit.Framework; | ||
|
||
namespace Radish.UnitTests.Extractors | ||
{ | ||
public class UriRequestExtractorTests | ||
{ | ||
[Test] | ||
public void Extract(){} | ||
} | ||
} |
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 @@ | ||
namespace Radish.UnitTests.Helpers | ||
{ | ||
public class ArrayHelperTest | ||
{ | ||
// [Test] | ||
// public bool Equals_when_array_length_not_equal_should_return_false() | ||
// { | ||
// // Arrange | ||
// var array1 = new byte[2]; | ||
// var array2 = new byte[3]; | ||
// | ||
// // Act | ||
// var result = ArrayHelper.Equals(array1, array2); | ||
// | ||
// // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Radish.UnitTests | ||
{ | ||
public class HttpServerMappingTest | ||
{ | ||
// [Test] | ||
// public void Mapping_url_to_content() | ||
// { | ||
// // Arrange | ||
// var server = Server.Create(9009); | ||
// | ||
// // Act | ||
// server.Mapping(Matcher.By("test"), Response.Content("foo")) | ||
// .Run(); | ||
// var result = Http.Get("http://localhost:9009/test"); | ||
// | ||
// // Assert | ||
// Assert.Equal(result.Text, "foo"); | ||
// } | ||
// | ||
// [Test] | ||
// public void Mapping() | ||
// { | ||
// // Arrange | ||
// var server = Server.Create(9009); | ||
// | ||
// // Act | ||
// server.Mapping(Matcher.By("/api/getusers"), Response.Content("[{name:'aaa',pwd:'bbb'}]")) | ||
// .Run(); | ||
// var result = Http.Get("http://localhost:9009/test"); | ||
// | ||
// // Assert | ||
// Assert.Equal(result.Text, "foo"); | ||
// } | ||
} | ||
|
||
|
||
} |
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,37 @@ | ||
using NUnit.Framework; | ||
|
||
namespace Radish.UnitTests | ||
{ | ||
public class HttpServerTest | ||
{ | ||
[Test] | ||
public void Create() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
HttpServer server = new HttpServer(); | ||
|
||
// Assert | ||
Assert.NotNull(server); | ||
} | ||
|
||
[Test] | ||
public void Run() | ||
{ | ||
// Arrange | ||
HttpServer server = new HttpServer(); | ||
server.When(request => request.Uri.Is("/home/index")) | ||
.Then(response => response.Text("foo")); | ||
|
||
var engine = new HttpServerEngine(server,9000).Start(); | ||
|
||
// Act | ||
var result = Http.Get("http://localhost:9000/home/index").GetContent(); | ||
engine.Stop(); | ||
|
||
// Assert | ||
Assert.That(result, Is.EqualTo("foo")); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Radish.UnitTests | ||
{ | ||
public class HttpTest | ||
{ | ||
[Test] | ||
public void Get() | ||
{ | ||
// Arrange | ||
var url = "http://www.baidu.com"; | ||
|
||
// Act | ||
ResponseResult result = Http.Get(url); | ||
|
||
// Assert | ||
result.GetContent().Should().NotBeNull(); | ||
} | ||
|
||
|
||
// [Test] | ||
// public void Put() | ||
// { | ||
// // dev.onlineacademy.se/api | ||
// // Arrange | ||
// var url = "http://dev.onlineacademy.se/api/user/addorupdate/"; | ||
// // var url = "http://dev.onlineacademy.se/api/user/view"; | ||
// | ||
// var data = "email=xusl@shinetechchina.com&password=123&firstname=xu&lastname=shilin&company=shinetechchina&city=xian&phone=18723232323"; | ||
// // var data = "username=previa@onlineacademy.se"; | ||
// // Act | ||
// var result = Http.Put(url, data); | ||
// } | ||
// | ||
// [Test] | ||
// public void Post() | ||
// { | ||
// // Arrange | ||
// var url = "http://dev.onlineacademy.se/api/user/view"; | ||
// // var data = "username=previa@onlineacademy.se"; | ||
// var data = "userid=835"; | ||
// // Act | ||
// var result = Http.Post(url, data); | ||
// } | ||
} | ||
} |
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,47 @@ | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Radish.UnitTests.Matchers | ||
{ | ||
public class AndRequestMatcherTests | ||
{ | ||
[Test] | ||
public void Match_when_all_matchers_are_matched_should_return_true() | ||
{ | ||
// Arrange | ||
var matcher1 = Substitute.For<IRequestMatcher>(); | ||
matcher1.Match(null).ReturnsForAnyArgs(true); | ||
|
||
var matcher2 = Substitute.For<IRequestMatcher>(); | ||
matcher2.Match(null).ReturnsForAnyArgs(true); | ||
|
||
var andRequestMatcher = new AndRequestMatcher(new[] { matcher1, matcher2 }); | ||
|
||
// Act | ||
var result = andRequestMatcher.Match(null); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
|
||
[Test] | ||
public void Match_when_matchers_has_any_unmatched_should_return_false() | ||
{ | ||
// Arrange | ||
var matcher1 = Substitute.For<IRequestMatcher>(); | ||
matcher1.Match(null).ReturnsForAnyArgs(true); | ||
|
||
var matcher2 = Substitute.For<IRequestMatcher>(); | ||
matcher2.Match(null).ReturnsForAnyArgs(false); | ||
|
||
var andRequestMatcher = new AndRequestMatcher(new[] { matcher1, matcher2 }); | ||
|
||
// Act | ||
var result = andRequestMatcher.Match(null); | ||
|
||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using NUnit.Framework; | ||
using Radish.Matchers; | ||
|
||
namespace Radish.UnitTests.Matchers | ||
{ | ||
public class AnyRequestMatcherTests | ||
{ | ||
[Test] | ||
public void Match_should_always_return_true() | ||
{ | ||
// Arrange | ||
var matcher = new AnyRequestMatcher(); | ||
|
||
// Act | ||
var result = matcher.Match(null); | ||
|
||
// Assert | ||
Assert.True(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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); | ||
// } | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Radish.UnitTests/Matchers/ExpressionRequestMatcherTests.cs
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,47 @@ | ||
using System.Collections.Specialized; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using Radish.Matchers; | ||
|
||
namespace Radish.UnitTests.Matchers | ||
{ | ||
public class ExpressionRequestMatcherTests | ||
{ | ||
[Test] | ||
public void Match_when_matched_expression_should_return_true() | ||
{ | ||
// Arrange | ||
var request = Substitute.For<IHttpRequest>(); | ||
request.Headers.Returns(new NameValueCollection() | ||
{ | ||
{"head","test"} | ||
}); | ||
var matcher = new ExpressionRequestMatcher(x => x.Headers["head"] == "test"); | ||
|
||
// Act | ||
var result = matcher.Match(request); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
|
||
[Test] | ||
public void Match_when_unmatched_expression_should_return_false() | ||
{ | ||
// Arrange | ||
var request = Substitute.For<IHttpRequest>(); | ||
request.Headers.Returns(new NameValueCollection() | ||
{ | ||
{"head","invalid"} | ||
}); | ||
var matcher = new ExpressionRequestMatcher(x => x.Headers["head"] == "test"); | ||
|
||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using Radish.Matchers; | ||
|
||
namespace Radish.UnitTests.Matchers | ||
{ | ||
public class OrRequestMatcherTests | ||
{ | ||
[Test] | ||
public void Match_when_all_matchers_are_unmatched_should_return_false() | ||
{ | ||
// Arrange | ||
var matcher1 = Substitute.For<IRequestMatcher>(); | ||
matcher1.Match(null).ReturnsForAnyArgs(false); | ||
|
||
var matcher2 = Substitute.For<IRequestMatcher>(); | ||
matcher2.Match(null).ReturnsForAnyArgs(false); | ||
|
||
var andRequestMatcher = new OrRequestMatcher(new[] { matcher1, matcher2 }); | ||
|
||
// Act | ||
var result = andRequestMatcher.Match(null); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
|
||
[Test] | ||
public void Match_when_matchers_has_any_matched_should_return_true() | ||
{ | ||
// Arrange | ||
var matcher1 = Substitute.For<IRequestMatcher>(); | ||
matcher1.Match(null).ReturnsForAnyArgs(true); | ||
|
||
var matcher2 = Substitute.For<IRequestMatcher>(); | ||
matcher2.Match(null).ReturnsForAnyArgs(false); | ||
|
||
var andRequestMatcher = new OrRequestMatcher(new[] { matcher1, matcher2 }); | ||
|
||
// Act | ||
var result = andRequestMatcher.Match(null); | ||
|
||
// Assert | ||
Assert.True(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
Oops, something went wrong.