Skip to content

Commit

Permalink
added mroe jasmine-based integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalltd committed Mar 10, 2013
1 parent 7ee7956 commit 67463c6
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 97 deletions.
19 changes: 12 additions & 7 deletions src/AttributeRouting.Tests/AttributeRouting.Tests.csproj
Expand Up @@ -113,22 +113,27 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Integration\SpecRunnerController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Subjects\Mvc\BasicUsageController.cs" />
<Compile Include="Subjects\Http\HttpBasicUsageController.cs" />
<Compile Include="Subjects\Http\HttpRouteDefaultsController.cs" />
<Compile Include="Subjects\Mvc\RouteDefaultsController.cs" />
<Compile Include="Subjects\Color.cs" />
<Compile Include="Subjects\Mvc\BasicsController.cs" />
<Compile Include="Subjects\Http\HttpBasicsController.cs" />
<Compile Include="Subjects\Http\HttpDefaultsController.cs" />
<Compile Include="Subjects\Mvc\ConstraintsControllers.cs" />
<Compile Include="Subjects\Mvc\DefaultsController.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Integration\css\jasmine.css" />
<Content Include="Global.asax" />
<Content Include="Integration\css\runner.css" />
<Content Include="Integration\js\lib\jasmine-html.js" />
<Content Include="Integration\js\lib\jasmine.js" />
<Content Include="Integration\js\specs\basic-usage.js" />
<Content Include="Integration\js\specs\route-defaults.js" />
<Content Include="Integration\js\specs\basics.js" />
<Content Include="Integration\js\specs\constraints.js" />
<Content Include="Integration\js\specs\defaults.js" />
<Content Include="Integration\js\specs\matchers.js" />
<Content Include="Integration\js\specs\specs.js" />
<Content Include="Integration\runner.html" />
<None Include="Integration\SpecRunner.cshtml" />
<Content Include="Integration\js\lib\jquery-1.9.1.min.js" />
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
Expand Down
17 changes: 15 additions & 2 deletions src/AttributeRouting.Tests/Global.asax.cs
@@ -1,7 +1,10 @@
using System.Web.Http;
using System.Web.Routing;
using AttributeRouting.Tests.Subjects;
using AttributeRouting.Web.Http.WebHost;
using AttributeRouting.Web.Mvc;
using WebConstraints = AttributeRouting.Web.Constraints;
using HttpConstraints = AttributeRouting.Web.Http.Constraints;

namespace AttributeRouting.Tests
{
Expand All @@ -11,8 +14,18 @@ public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
RouteTable.Routes.MapAttributeRoutes();
GlobalConfiguration.Configuration.Routes.MapHttpAttributeRoutes();
RouteTable.Routes.MapAttributeRoutes(cfg =>
{
cfg.AddRoutesFromAssemblyOf<MvcApplication>();
cfg.InlineRouteConstraints.Add("color", typeof(WebConstraints.EnumRouteConstraint<Color>));
cfg.InlineRouteConstraints.Add("colorValue", typeof(WebConstraints.EnumValueRouteConstraint<Color>));
});
GlobalConfiguration.Configuration.Routes.MapHttpAttributeRoutes(cfg =>
{
cfg.AddRoutesFromAssemblyOf<MvcApplication>();
cfg.InlineRouteConstraints.Add("color", typeof(HttpConstraints.EnumRouteConstraint<Color>));
cfg.InlineRouteConstraints.Add("colorValue", typeof(HttpConstraints.EnumValueRouteConstraint<Color>));
});
}
}
}
@@ -1,20 +1,23 @@
<!DOCTYPE html>
@inherits System.Web.Mvc.WebViewPage
<!DOCTYPE html>
<html>
<head>
<title>AttributeRouting Integration Tests</title>
<link rel="stylesheet" type="text/css" href="css/jasmine.css">
<link rel="stylesheet" type="text/css" href="css/runner.css">
<link rel="stylesheet" type="text/css" href="~/Integration/css/jasmine.css">
<link rel="stylesheet" type="text/css" href="~/Integration/css/runner.css">
</head>

<body>
<a href="/routes.axd" class="view-all-routes">Wanna see all the registered routes?</a>

<script src="js/lib/jasmine.js"></script>
<script src="js/lib/jasmine-html.js"></script>
<script src="js/lib/jquery-1.9.1.min.js"></script>
<script src="js/specs/specs.js"></script>
<script src="js/specs/basic-usage.js"></script>
<script src="js/specs/route-defaults.js"></script>
<script src="~/Integration/js/lib/jasmine.js"></script>
<script src="~/Integration/js/lib/jasmine-html.js"></script>
<script src="~/Integration/js/lib/jquery-1.9.1.min.js"></script>
<script src="~/Integration/js/specs/matchers.js"></script>
<script src="~/Integration/js/specs/specs.js"></script>
<script src="~/Integration/js/specs/basics.js"></script>
<script src="~/Integration/js/specs/defaults.js"></script>
<script src="~/Integration/js/specs/constraints.js"></script>

<script>
(function () {
Expand Down
14 changes: 14 additions & 0 deletions src/AttributeRouting.Tests/Integration/SpecRunnerController.cs
@@ -0,0 +1,14 @@
using System.Web.Mvc;
using AttributeRouting.Web.Mvc;

namespace AttributeRouting.Tests.Integration
{
public class SpecRunnerController : Controller
{
[GET("", SitePrecedence = 1)]
public ActionResult Index()
{
return View("~/Integration/SpecRunner.cshtml");
}
}
}
17 changes: 0 additions & 17 deletions src/AttributeRouting.Tests/Integration/js/specs/basic-usage.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/AttributeRouting.Tests/Integration/js/specs/basics.js
@@ -0,0 +1,17 @@
/// <reference path="../lib/jasmine.js" />
/// <reference path="specs.js" />

describe('Basic Usage', function() {
describe('BasicsController', function () {
it('should respond to GET "/Basics" with "Basics.Index"', specs.respondsWith);
it('should respond to POST "/Basics" with "Basics.Create"', specs.respondsWith);
it('should respond to PUT "/Basics/1" with "Basics.Update(1)"', specs.respondsWith);
it('should respond to DELETE "/Basics/1" with "Basics.Delete(1)"', specs.respondsWith);
});
describe('HttpBasicsController', function () {
it('should respond to GET "/HttpBasics" with "HttpBasics.Index"', specs.respondsWith);
it('should respond to POST "/HttpBasics" with "HttpBasics.Create"', specs.respondsWith);
it('should respond to PUT "/HttpBasics/1" with "HttpBasics.Update(1)"', specs.respondsWith);
it('should respond to DELETE "/HttpBasics/1" with "HttpBasics.Delete(1)"', specs.respondsWith);
});
});
76 changes: 76 additions & 0 deletions src/AttributeRouting.Tests/Integration/js/specs/constraints.js
@@ -0,0 +1,76 @@
/// <reference path="../lib/jasmine.js" />
/// <reference path="specs.js" />

describe('Route Constraints', function() {
describe('ConstraintsController', function () {
it('should respond to GET "/Constraints/Alpha/abc" with "Constraints.Alpha(abc)"', specs.respondsWith);
it('should respond to GET "/Constraints/Alpha/123" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Int/123" with "Constraints.Int(123)"', specs.respondsWith);
it('should respond to GET "/Constraints/Int/abc" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Long/123" with "Constraints.Long(123)"', specs.respondsWith);
it('should respond to GET "/Constraints/Long/abc" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Float/256" with "Constraints.Float(256)"', specs.respondsWith);
it('should respond to GET "/Constraints/Float/abc" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Double/256" with "Constraints.Double(256)"', specs.respondsWith);
it('should respond to GET "/Constraints/Double/abc" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Decimal/256" with "Constraints.Decimal(256)"', specs.respondsWith);
it('should respond to GET "/Constraints/Decimal/abc" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Bool/true" with "Constraints.Bool(True)"', specs.respondsWith);
it('should respond to GET "/Constraints/Bool/false" with "Constraints.Bool(False)"', specs.respondsWith);
it('should respond to GET "/Constraints/Bool/0" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Guid/C568BCD6-7D2B-4241-9191-F4B1ED4E1632" with "Constraints.Guid(C568BCD6-7D2B-4241-9191-F4B1ED4E1632)"', specs.respondsWith);
it('should respond to GET "/Constraints/Guid/0" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/DateTime/2013-01-01" with "Constraints.DateTime(1/1/2013 12:00:00 am)"', specs.respondsWith);
it('should respond to GET "/Constraints/DateTime/2013-9" with "Constraints.DateTime(9/1/2013 12:00:00 am)"', specs.respondsWith);
it('should respond to GET "/Constraints/DateTime/January" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Length/a" with "Constraints.Length(a)"', specs.respondsWith);
it('should respond to GET "/Constraints/Length/ab" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/MinLength/abcde" with "Constraints.MinLength(abcde)"', specs.respondsWith);
it('should respond to GET "/Constraints/MinLength/abcd" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/MaxLength/abcde" with "Constraints.MaxLength(abcde)"', specs.respondsWith);
it('should respond to GET "/Constraints/MaxLength/abcdef" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/LengthRange/ab" with "Constraints.LengthRange(ab)"', specs.respondsWith);
it('should respond to GET "/Constraints/LengthRange/abc" with "Constraints.LengthRange(abc)"', specs.respondsWith);
it('should respond to GET "/Constraints/LengthRange/a" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/LengthRange/abcd" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Min/1" with "Constraints.Min(1)"', specs.respondsWith);
it('should respond to GET "/Constraints/Min/0" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Max/10" with "Constraints.Max(10)"', specs.respondsWith);
it('should respond to GET "/Constraints/Max/11" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Range/1" with "Constraints.Range(1)"', specs.respondsWith);
it('should respond to GET "/Constraints/Range/10" with "Constraints.Range(10)"', specs.respondsWith);
it('should respond to GET "/Constraints/Range/0" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Range/11" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Regex/howdy" with Constraints.Regex(howdy)', specs.respondsWith);
it('should respond to GET "/Constraints/Regex/doody" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/RegexRange/abcd" with Constraints.RegexRange(abcd)', specs.respondsWith);
it('should respond to GET "/Constraints/RegexRange/a" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/EnumValue/0" with Constraints.EnumValue(Red)', specs.respondsWith);
it('should respond to GET "/Constraints/EnumValue/Red" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Enum/Red" with Constraints.Enum(Red)', specs.respondsWith);
it('should respond to GET "/Constraints/Enum/0" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Compound/5" with Constraints.Compound(5)', specs.respondsWith);
it('should respond to GET "/Constraints/Compound/15" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Compound/abc" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/WithOptional/red" with Constraints.WithOptional(Red)', specs.respondsWith);
it('should respond to GET "/Constraints/WithOptional" with Constraints.WithOptional()', specs.respondsWith);
it('should respond to GET "/Constraints/WithDefault" with Constraints.WithDefault(Red)', specs.respondsWith);
it('should respond to GET "/Constraints/WithDefault/green" with Constraints.WithDefault(Green)', specs.respondsWith);
it('should respond to GET "/Constraints/MultipleInSegment/2x4" with Constraints.MultipleInSegment(2, 4)', specs.respondsWith);
it('should respond to GET "/Constraints/MultipleInSegment/2x" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/MultipleInSegment/x4" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/MultipleInSegment/axb" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Query/?x=10&y=present" with Constraints.Query(10, present)', specs.respondsWith);
it('should respond to GET "/Constraints/Query/?x=abc&y=present" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Query/?x=&y=present" with 404', specs.respondsWith);
it('should respond to GET "/Constraints/Query/?x=10&y=" with 404', specs.respondsWith);
});
describe('ConstraintsInAreaPrefixController', function() {
it('should respond to GET "/Constraints/InAreaPrefix/123" with ConstraintsInAreaPrefix.Index(123)', specs.respondsWith);
it('should respond to GET "/Constraints/InAReaPrefix/abc" with 404', specs.respondsWith);
});
describe('ConstraintsInRoutePrefixController', function() {
it('should respond to GET "/Constraints/InRoutePrefix/123" with ConstraintsInRoutePrefix.Index(123)', specs.respondsWith);
it('should respond to GET "/Constraints/InRoutePrefix/abc" with 404', specs.respondsWith);
});
});
21 changes: 21 additions & 0 deletions src/AttributeRouting.Tests/Integration/js/specs/defaults.js
@@ -0,0 +1,21 @@
/// <reference path="../lib/jasmine.js" />
/// <reference path="specs.js" />

describe('Route Defaults', function() {
describe('DefaultsController', function () {
it('should respond to GET "/Defaults/Inline" with "Defaults.Inline(param, query)"', specs.respondsWith);
it('should respond to GET "/Defaults/Optional" with "Defaults.Optional(, )"', specs.respondsWith);
it('should respond to GET "/Defaults/Optional/param" with "Defaults.Optional(param, )"', specs.respondsWith);
it('should respond to GET "/Defaults/Optional/?q=bleary" with "Defaults.Optional(, bleary)"', specs.respondsWith);
it('should respond to GET "/Defaults/ControllerName" with "Defaults.ControllerName"', specs.respondsWith);
it('should respond to GET "/Defaults/ActionName" with "Defaults.ActionName"', specs.respondsWith);
});
describe('HttpDefaultsController', function () {
it('should respond to GET "/HttpDefaults/Inline" with "HttpDefaults.Inline(param, query)"', specs.respondsWith);
it('should respond to GET "/HttpDefaults/Optional" with "HttpDefaults.Optional(, )"', specs.respondsWith);
it('should respond to GET "/HttpDefaults/Optional/param" with "HttpDefaults.Optional(param, )"', specs.respondsWith);
it('should respond to GET "/HttpDefaults/Optional/?q=weary" with "HttpDefaults.Optional(, weary)"', specs.respondsWith);
it('should respond to GET "/HttpDefaults/ControllerName" with "HttpDefaults.ControllerName"', specs.respondsWith);
it('should respond to GET "/HttpDefaults/ActionName" with "HttpDefaults.ActionName"', specs.respondsWith);
});
});
11 changes: 11 additions & 0 deletions src/AttributeRouting.Tests/Integration/js/specs/matchers.js
@@ -0,0 +1,11 @@
beforeEach(function() {
this.addMatchers({
toEqualValue: function (expected) {
var actual = this.actual;
this.message = function() {
return "Expected " + actual + " to equal " + expected;
};
return actual.toLowerCase() === expected.toLowerCase();
}
});
});
21 changes: 0 additions & 21 deletions src/AttributeRouting.Tests/Integration/js/specs/route-defaults.js

This file was deleted.

0 comments on commit 67463c6

Please sign in to comment.