Skip to content

Commit 0229575

Browse files
author
yb-nuc
committed
routing complier bug fixed & add routing unit test
1 parent 222548e commit 0229575

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

CatLib.VS/CatLib.Tests/CatLib.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="Config\ConfigTests.cs" />
7878
<Compile Include="Config\ConfigProviderTests.cs" />
7979
<Compile Include="Core\EnvTests.cs" />
80+
<Compile Include="Routing\AttrCompilerRouting.cs" />
8081
<Compile Include="Routing\RouterExceptionTests.cs" />
8182
<Compile Include="Stl\Container\BindDataTests.cs" />
8283
<Compile Include="Stl\Container\ContainerTests.cs" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the CatLib package.
3+
*
4+
* (c) Yu Bin <support@catlib.io>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Document: http://catlib.io/
10+
*/
11+
12+
using CatLib.API.Routing;
13+
14+
namespace CatLib.Tests.Routing
15+
{
16+
[Routed]
17+
public class AttrCompilerRouting
18+
{
19+
[Routed("routed://first-compiler-then-group/{str?}",Group = "DefaultGroup")]
20+
public void FirstCompilerThenAddGroup(IRequest request,IResponse response)
21+
{
22+
response.SetContext(request["str"]);
23+
}
24+
25+
[Routed("routed://use-group-and-local-defaults/{str?}",Group = "DefaultGroup2" , Defaults = "str=>hello world")]
26+
public void UseGroupAndLocalDefaults(IRequest request, IResponse response)
27+
{
28+
response.SetContext(request["str"]);
29+
}
30+
}
31+
}

CatLib.VS/CatLib.Tests/Routing/RouterTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void TestInitialize()
5959
next(req, res);
6060
res.SetContext(res.GetContext() + "[with throw error group middleware]");
6161
});
62+
router.Group("DefaultGroup2").Defaults("str", "TestUseGroupAndLocalDefaults");
6263
});
6364

6465
app.On(RouterEvents.OnDispatcher, (sender, args) =>
@@ -529,5 +530,22 @@ public void TestUndefindScheme()
529530

530531
router.SetDefaultScheme("catlib");
531532
}
533+
534+
[TestMethod]
535+
public void TestFirstCompilerThenAddGroup()
536+
{
537+
var router = App.Instance.Make<IRouter>();
538+
router.Group("DefaultGroup").Defaults("str", "TestFirstCompilerThenAddGroup");
539+
var response = router.Dispatch("routed://first-compiler-then-group");
540+
Assert.AreEqual("TestFirstCompilerThenAddGroup[global middleware]", response.GetContext());
541+
}
542+
543+
[TestMethod]
544+
public void TestUseGroupAndLocalDefaults()
545+
{
546+
var router = App.Instance.Make<IRouter>();
547+
var response = router.Dispatch("routed://use-group-and-local-defaults");
548+
Assert.AreEqual("hello world[global middleware]", response.GetContext());
549+
}
532550
}
533551
}

CatLib.VS/CatLib/Routing/AttrRouteCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ private void ComplieController(Type type, RoutedAttribute baseRouted)
152152

153153
foreach (var route in routeList)
154154
{
155-
ComplieOptionsGroup(route, baseRouted);
156155
ComplieOptionsWhere(route, controllerWhere);
157156
ComplieOptionsDefaults(route, controllerDefaults);
157+
ComplieOptionsGroup(route, baseRouted);
158158
}
159159
}
160160

@@ -245,9 +245,9 @@ private void CheckRepeat(string path, Type controllerType, MethodInfo method)
245245
/// <param name="routed">路由特性</param>
246246
private void ComplieOptions(IRoute route, RoutedAttribute routed)
247247
{
248-
ComplieOptionsGroup(route, routed);
249248
ComplieOptionsWhere(route, ComplieDirection(routed.Where));
250249
ComplieOptionsDefaults(route, ComplieDirection(routed.Defaults));
250+
ComplieOptionsGroup(route, routed);
251251
}
252252

253253
/// <summary>

0 commit comments

Comments
 (0)