/
api_route_grouper.cs
69 lines (57 loc) · 2.35 KB
/
api_route_grouper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Linq;
using FubuMVC.Core.Registration;
using FubuMVC.Core.Registration.Nodes;
using NUnit.Framework;
namespace FubuMVC.Swagger.Tests
{
public class api_route_grouper : Context<APIRouteGrouper>
{
private IEnumerable<IGrouping<string, ActionCall>> _groupedActions;
public override void Given()
{
var actions = getAPIActions();
_groupedActions = _cut.Group(actions);
}
[Test]
public void should_find_three_groups()
{
_groupedActions.Count().ShouldEqual(3);
}
[Test]
public void should_have_group1_actions()
{
var group1Actions = _groupedActions.First(a => a.Key == "group1");
group1Actions.First().ParentChain().Route.Pattern.ShouldStartWith("api/group1");
}
[Test]
public void should_have_group2_actions()
{
var group1Actions = _groupedActions.First(a => a.Key == "group2");
group1Actions.Count().ShouldEqual(2);
group1Actions.First().ParentChain().Route.Pattern.ShouldStartWith("api/group2");
}
[Test]
public void should_have_group3_actions()
{
var group1Actions = _groupedActions.First(a => a.Key == "group3");
group1Actions.Count().ShouldEqual(3);
group1Actions.First().ParentChain().Route.Pattern.ShouldStartWith("api/group3");
}
private static IEnumerable<ActionCall> getAPIActions()
{
var graph = new BehaviorGraph();
graph.AddActionFor("api/group1/{input}", typeof (Action1));
graph.AddActionFor("api/group2/{input}", typeof(Action1));
graph.AddActionFor("api/group2/foo/", typeof(Action1));
graph.AddActionFor("api/group3", typeof(Action1));
graph.AddActionFor("api/group3/foobar", typeof(Action1));
graph.AddActionFor("api/group3/{input}", typeof(Action1));
graph.AddActionFor("home", typeof(Action1));
graph.AddActionFor("home/foo", typeof(Action1));
graph.AddActionFor("home/foo/baz", typeof(Action1));
graph.AddActionFor("bar", typeof(Action1));
return graph.Actions();
}
}
}