Skip to content

Commit

Permalink
Merged old code to new project
Browse files Browse the repository at this point in the history
  • Loading branch information
staticage committed Jun 14, 2013
1 parent 0cedab8 commit c723879
Show file tree
Hide file tree
Showing 56 changed files with 1,858 additions and 105 deletions.
10 changes: 10 additions & 0 deletions Radish.UnitTests/Extractors/UriRequestExtractorTests.cs
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(){}
}
}
19 changes: 19 additions & 0 deletions Radish.UnitTests/Helpers/ArrayHelperTest.cs
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);
// }
}
}
37 changes: 37 additions & 0 deletions Radish.UnitTests/HttpServerMappingTest.cs
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");
// }
}


}
37 changes: 37 additions & 0 deletions Radish.UnitTests/HttpServerTest.cs
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"));
}
}
}
15 changes: 0 additions & 15 deletions Radish.UnitTests/HttpServerTests.cs

This file was deleted.

47 changes: 47 additions & 0 deletions Radish.UnitTests/HttpTest.cs
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);
// }
}
}
47 changes: 47 additions & 0 deletions Radish.UnitTests/Matchers/AndRequestMatcherTests.cs
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);
}
}
}
21 changes: 21 additions & 0 deletions Radish.UnitTests/Matchers/AnyRequestMatcherTests.cs
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);
}
}
}
35 changes: 35 additions & 0 deletions Radish.UnitTests/Matchers/EqualRequestMatcherTests.cs
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 Radish.UnitTests/Matchers/ExpressionRequestMatcherTests.cs
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);
}
}
}
48 changes: 48 additions & 0 deletions Radish.UnitTests/Matchers/OrRequestMatcherTests.cs
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);
}
}
}
6 changes: 3 additions & 3 deletions Radish.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Radish.UnitTests")]
[assembly: AssemblyTitle("Radish.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Radish.UnitTests")]
[assembly: AssemblyProduct("Radish.Test")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand All @@ -20,7 +20,7 @@
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("372d007d-5ac9-4bbe-810d-21ad853ac763")]
[assembly: Guid("d29fd689-9b3f-4656-a9f6-32e6e5f6f5e0")]

// Version information for an assembly consists of the following four values:
//
Expand Down
Loading

0 comments on commit c723879

Please sign in to comment.