Permalink
Browse files

Merge

  • Loading branch information...
2 parents 08cfb10 + c7248a2 commit 4ed078e9ceec3ccef0111eca5e0abe652464335a @mazur mazur committed Nov 28, 2010
Showing with 1,986 additions and 7 deletions.
  1. +2 −2 .gitignore
  2. BIN dependencies/mspec/Machine.Specifications.dll
  3. BIN dependencies/mspec/Machine.Specifications.pdb
  4. +30 −0 src/Nancy.Tests/Catch.cs
  5. +47 −0 src/Nancy.Tests/Fakes/FakeNancyModuleWithBasePath.cs
  6. +30 −0 src/Nancy.Tests/Fakes/FakeNancyModuleWithoutBasePath.cs
  7. +18 −0 src/Nancy.Tests/Fakes/FakeRoute.cs
  8. +27 −0 src/Nancy.Tests/Fakes/FakeRouteResolver.cs
  9. +27 −5 src/Nancy.Tests/Nancy.Tests.csproj
  10. +116 −0 src/Nancy.Tests/ShouldExtensions.cs
  11. +43 −0 src/Nancy.Tests/Specifications/Handling a DELETE request.cs
  12. +43 −0 src/Nancy.Tests/Specifications/Handling a GET request.cs
  13. +43 −0 src/Nancy.Tests/Specifications/Handling a POST request.cs
  14. +43 −0 src/Nancy.Tests/Specifications/Handling a PUT request.cs
  15. +40 −0 src/Nancy.Tests/Specifications/RequestSpec.cs
  16. +314 −0 src/Nancy.Tests/Unit/NancyEngineFixture.cs
  17. +34 −0 src/Nancy.Tests/Unit/NancyModuleLocatorFixture.cs
  18. +77 −0 src/Nancy.Tests/Unit/ResponseFixture.cs
  19. +32 −0 src/Nancy.Tests/Unit/Routing/NoMatchingRouteFixture.cs
  20. +109 −0 src/Nancy.Tests/Unit/Routing/RouteFixture.cs
  21. +22 −0 src/Nancy.Tests/Unit/Routing/RouteParametersFixture.cs
  22. +200 −0 src/Nancy.Tests/Unit/Routing/RouteResolverFixture.cs
  23. +32 −0 src/Nancy/Extensions/NancyExtensions.cs
  24. +12 −0 src/Nancy/Extensions/RouteDescriptionExtensions.cs
  25. +51 −0 src/Nancy/Extensions/StringExtensions.cs
  26. +53 −0 src/Nancy/Hosting/NancyHttpRequestHandler.cs
  27. +12 −0 src/Nancy/INancyEngine.cs
  28. +24 −0 src/Nancy/IRequest.cs
  29. +6 −0 src/Nancy/IResponseFormatter.cs
  30. +6 −0 src/Nancy/IViewEngine.cs
  31. +24 −0 src/Nancy/Nancy.csproj
  32. +79 −0 src/Nancy/NancyEngine.cs
  33. +39 −0 src/Nancy/NancyModule.cs
  34. +45 −0 src/Nancy/NancyModuleLocator.cs
  35. +14 −0 src/Nancy/NotFoundResponse.cs
  36. +33 −0 src/Nancy/Response.cs
  37. +15 −0 src/Nancy/Routing/IRoute.cs
  38. +9 −0 src/Nancy/Routing/IRouteResolver.cs
  39. +10 −0 src/Nancy/Routing/NoMatchingRouteFoundRoute.cs
  40. +35 −0 src/Nancy/Routing/Route.cs
  41. +39 −0 src/Nancy/Routing/RouteDescription.cs
  42. +48 −0 src/Nancy/Routing/RouteParameters.cs
  43. +103 −0 src/Nancy/Routing/RouteResolver.cs
View
@@ -1,6 +1,6 @@
*.[Cc]ache
*.csproj.user
-*.resharper.user
+*.[Rr]e[Ss]harper*
*.sln.cache
*.suo
*.user
@@ -15,4 +15,4 @@ build/
[Dd]ebug/
[Oo]bj/
[Rr]elease/
-_ReSharper.*/
+_[Rr]e[Ss]harper.*/
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,30 @@
+namespace Nancy.Tests
+{
+ using System;
+
+ /// <summary>
+ /// Test helper class that traps any exception that is thrown while executing the specified code expression.
+ /// </summary>
+ public class Catch
+ {
+ /// <summary>
+ /// Executes the expression specified by the <paramref name="context"/> paramater
+ /// and traps any <see cref="Exception"/> that is thrown and returns it.
+ /// </summary>
+ /// <param name="context">The expression to execute.</param>
+ /// <returns>If an exception was trapped then an <see cref="Exception"/> instance is returned; otherwise <see langword="null" />.</returns>
+ public static Exception Exception(Action context)
+ {
+ try
+ {
+ context();
+ }
+ catch (Exception thrownException)
+ {
+ return thrownException;
+ }
+
+ return null;
+ }
+ }
+}
@@ -0,0 +1,47 @@
+namespace Nancy.Tests.Fakes
+{
+ using System;
+ using Nancy;
+
+ public class FakeNancyModuleWithBasePath : NancyModule
+ {
+ public FakeNancyModuleWithBasePath() : base("/fake")
+ {
+ Delete["/"] = x => {
+ throw new NotImplementedException();
+ };
+
+ Get["/route/with/some/parts"] = x => {
+ return new Response { Contents = "FakeNancyModuleWithBasePath" };
+ };
+
+ Get["/should/have/conflicting/route/defined"] = x => {
+ return new Response { Contents = "FakeNancyModuleWithBasePath" };
+ };
+
+ Get["/child/{value}"] = x => {
+ throw new NotImplementedException();
+ };
+
+ Get["/child/route/{value}"] = x => {
+ return new Response { Contents = "test" };
+ };
+
+ Get["/"] = x => {
+ throw new NotImplementedException();
+ };
+
+ Get["/foo/{value}/bar/{capture}"] = x => {
+ throw new NotImplementedException();
+ };
+
+ Post["/"] = x => {
+ return new Response { Contents = "Action result" };
+ };
+
+ Put["/"] = x => {
+ throw new NotImplementedException();
+ };
+ }
+ }
+}
@@ -0,0 +1,30 @@
+namespace Nancy.Tests.Fakes
+{
+ using System;
+
+ public class FakeNancyModuleWithoutBasePath : NancyModule
+ {
+ public FakeNancyModuleWithoutBasePath()
+ {
+ Delete["/"] = x => {
+ return "Default delete root";
+ };
+
+ Get["/"] = x => {
+ return "Default get root";
+ };
+
+ Get["/fake/should/have/conflicting/route/defined"] = x => {
+ return new Response { Contents = "FakeNancyModuleWithoutBasePath" };
+ };
+
+ Post["/"] = x => {
+ return "Default post root";
+ };
+
+ Put["/"] = x => {
+ return "Default put root";
+ };
+ }
+ }
+}
@@ -0,0 +1,18 @@
+namespace Nancy.Tests.Fakes
+{
+ using Nancy.Routing;
+
+ public class FakeRoute : Route
+ {
+ public bool ActionWasInvoked;
+
+ public FakeRoute()
+ : base(string.Empty, null, x => new Response())
+ {
+ this.Action = x => {
+ this.ActionWasInvoked = true;
+ return new Response();
+ };
+ }
+ }
+}
@@ -0,0 +1,27 @@
+namespace Nancy.Tests.Fakes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Nancy.Routing;
+
+ public class FakeRouteResolver : IRouteResolver
+ {
+ public IRoute GetRoute(IRequest request, IEnumerable<RouteDescription> descriptions)
+ {
+ var description = descriptions.First();
+
+ this.Action = description.Action;
+ this.ModulePath = description.ModulePath;
+ this.Path = description.Path;
+
+ return new FakeRoute();
+ }
+
+ public Func<object, Response> Action { get; private set; }
+
+ public string Path { get; private set; }
+
+ public string ModulePath { get; private set; }
+ }
+}
@@ -34,6 +34,10 @@
<Reference Include="FakeItEasy">
<HintPath>..\..\dependencies\fakeiteasy\FakeItEasy.dll</HintPath>
</Reference>
+ <Reference Include="Machine.Specifications">
+ <HintPath>..\..\dependencies\mspec\Machine.Specifications.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="xunit">
@@ -44,16 +48,34 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\SharedAssemblyInfo.cs">
+ <Link>Properties\SharedAssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="Catch.cs" />
+ <Compile Include="Fakes\FakeNancyModuleWithBasePath.cs" />
+ <Compile Include="Fakes\FakeNancyModuleWithoutBasePath.cs" />
+ <Compile Include="Fakes\FakeRoute.cs" />
+ <Compile Include="Fakes\FakeRouteResolver.cs" />
+ <Compile Include="Specifications\Handling a DELETE request.cs" />
+ <Compile Include="Specifications\Handling a GET request.cs" />
+ <Compile Include="ShouldExtensions.cs" />
+ <Compile Include="Specifications\Handling a POST request.cs" />
+ <Compile Include="Specifications\Handling a PUT request.cs" />
+ <Compile Include="Specifications\RequestSpec.cs" />
+ <Compile Include="Unit\NancyEngineFixture.cs" />
+ <Compile Include="Unit\NancyModuleLocatorFixture.cs" />
+ <Compile Include="Unit\Routing\NoMatchingRouteFixture.cs" />
+ <Compile Include="Unit\ResponseFixture.cs" />
+ <Compile Include="Unit\Routing\RouteFixture.cs" />
+ <Compile Include="Unit\Routing\RouteParametersFixture.cs" />
+ <Compile Include="Unit\Routing\RouteResolverFixture.cs" />
+ </ItemGroup>
+ <ItemGroup>
<ProjectReference Include="..\Nancy\Nancy.csproj">
<Project>{34576216-0DCA-4B0F-A0DC-9075E75A676F}</Project>
<Name>Nancy</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <Compile Include="..\SharedAssemblyInfo.cs">
- <Link>Properties\SharedAssemblyInfo.cs</Link>
- </Compile>
- </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -0,0 +1,116 @@
+namespace Nancy.Tests
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Xunit;
+
+ public static class ShouldAssertExtensions
+ {
+ public static void ShouldMatch<T>(this T actual, Func<T, bool> condition)
+ {
+ Assert.True(condition.Invoke(actual));
+ }
+
+ public static void ShouldImplementInterface<T>(this Type actual)
+ {
+ var found =
+ actual.GetInterfaces().Contains(typeof(T));
+
+ Assert.True(found);
+ }
+
+ public static void ShouldContainType<T>(this IEnumerable collection)
+ {
+ var selection =
+ from c in collection.Cast<object>()
+ where c.GetType().IsAssignableFrom(typeof(T))
+ select c;
+
+ Assert.True(selection.Count() > 0);
+ }
+
+ public static void ShouldHaveCount<T>(this IList<T> list, int expected)
+ {
+ list.Count.ShouldEqual(expected);
+ }
+
+ public static void ShouldBeTrue(this bool actual)
+ {
+ Assert.True(actual);
+ }
+
+ public static void ShouldBeFalse(this bool actual)
+ {
+ Assert.False(actual);
+ }
+
+ public static void ShouldEqual(this object actual, object expected)
+ {
+ Assert.Equal(expected, actual);
+ }
+
+ public static void ShouldBeGreaterThan(this int actual, int smallestValueNotAccepted)
+ {
+ Assert.True(actual > smallestValueNotAccepted);
+ }
+
+ public static void ShouldNotEqual(this object actual, object expected)
+ {
+ Assert.NotEqual(expected, actual);
+ }
+
+ public static void ShouldNotBeSameAs(this object actual, object expected)
+ {
+ Assert.NotSame(expected, actual);
+ }
+
+ public static void ShouldBeSameAs(this object actual, object expected)
+ {
+ Assert.Same(expected, actual);
+ }
+
+ public static void ShouldBeNull(this object actual)
+ {
+ Assert.Null(actual);
+ }
+
+ public static void ShouldNotBeNull(this object actual)
+ {
+ Assert.NotNull(actual);
+ }
+
+ public static void ShouldBeOfType<T>(this Type asserted)
+ {
+ Assert.True(asserted == typeof(T));
+ }
+
+ public static void ShouldBeOfType<T>(this object asserted)
+ {
+ asserted.ShouldBeOfType(typeof(T));
+ }
+
+ public static void ShouldBeOfType(this object asserted, Type expected)
+ {
+ Assert.IsAssignableFrom(expected, asserted);
+ }
+
+ public static void ShouldNotBeOfType<T>(this object asserted)
+ {
+ Assert.True(!asserted.GetType().Equals(typeof(T)));
+ }
+
+ public static void ShouldBeThrownBy(this Type expectedType, Action context)
+ {
+ try
+ {
+ context();
+ }
+ catch (Exception thrownException)
+ {
+ Assert.Equal(expectedType, thrownException.GetType());
+ }
+ }
+ }
+}
@@ -0,0 +1,43 @@
+namespace Nancy.Tests.Specifications
+{
+ using System.Net;
+ using Machine.Specifications;
+
+ [Subject("Handling a DELETE request")]
+ public class when_delete_request_matched_existing_route : RequestSpec
+ {
+ Establish context = () =>
+ request = ManufactureDELETERequestForRoute("/");
+
+ Because of = () =>
+ response = engine.HandleRequest(request);
+
+ It should_set_status_code_to_ok = () =>
+ response.StatusCode.ShouldEqual(HttpStatusCode.OK);
+
+ It should_set_content_type_to_text_html = () =>
+ response.ContentType.ShouldEqual("text/html");
+
+ It should_set_content = () =>
+ response.Contents.ShouldEqual("Default delete root");
+ }
+
+ [Subject("Handling a DELETE request")]
+ public class when_delete_request_does_not_matched_existing_route : RequestSpec
+ {
+ Establish context = () =>
+ request = ManufactureDELETERequestForRoute("/invalid");
+
+ Because of = () =>
+ response = engine.HandleRequest(request);
+
+ It should_set_status_code_to_not_found = () =>
+ response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
+
+ It should_set_content_type_to_text_html = () =>
+ response.ContentType.ShouldEqual("text/html");
+
+ It should_set_blank_content = () =>
+ response.Contents.ShouldEqual(string.Empty);
+ }
+}
Oops, something went wrong.

0 comments on commit 4ed078e

Please sign in to comment.