1- using System . Linq ;
2- using NUnit . Framework ;
3- using ServiceStack . ServiceClient . Web ;
4- using ServiceStack . ServiceInterface ;
5-
6- namespace ServiceStack . ServiceHost . Tests . Routes
7- {
8- [ TestFixture ]
9- public class ServiceRoutesTests
10- {
11- [ Test ]
12- public void Can_Register_Routes_From_Assembly ( )
13- {
14- var routes = new ServiceRoutes ( ) ;
15- routes . AddFromAssembly ( typeof ( RestServiceWithAllVerbsImplemented ) . Assembly ) ;
16-
17- RestPath restWithAllMethodsRoute = ( from r in routes . RestPaths
18- where r . Path == "RestServiceWithAllVerbsImplemented"
19- select r ) . FirstOrDefault ( ) ;
20-
21- Assert . That ( restWithAllMethodsRoute , Is . Not . Null ) ;
22-
23- Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "GET" ) ) ;
24- Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "POST" ) ) ;
25- Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "PUT" ) ) ;
26- Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "DELETE" ) ) ;
27- Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "PATCH" ) ) ;
28- }
29-
30- [ Test ]
31- public void Can_Register_Routes_With_Partially_Implemented_REST_Verbs ( )
32- {
33- var routes = new ServiceRoutes ( ) ;
34- routes . AddFromAssembly ( typeof ( RestServiceWithSomeVerbsImplemented ) . Assembly ) ;
35-
36- RestPath restWithAFewMethodsRoute = ( from r in routes . RestPaths
37- where r . Path == "RestServiceWithSomeVerbsImplemented"
38- select r ) . FirstOrDefault ( ) ;
39-
40- Assert . That ( restWithAFewMethodsRoute , Is . Not . Null ) ;
41-
42- Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "GET" ) , Is . True ) ;
43- Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "POST" ) , Is . False ) ;
44- Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "PUT" ) , Is . True ) ;
45- Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "DELETE" ) , Is . False ) ;
46- Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "PATCH" ) , Is . False ) ;
47- }
48-
49- [ Test ]
50- public void Can_Register_Routes_Using_Add_Extension ( )
51- {
52- var routes = new ServiceRoutes ( ) ;
53- routes . Add < Customer > ( HttpMethod . Get , "/Users/{0}/Orders/{1}" , x => x . Name , x => x . OrderId ) ;
54- var route = routes . RestPaths [ 0 ] ;
55- Assert . That ( route . Path == "/Users/{Name}/Orders/{OrderId}" ) ;
56- }
57- }
58-
59- public class Customer
60- {
61- public string Name { get ; set ; }
62- public int OrderId { get ; set ; }
63- }
1+ using System . Linq ;
2+ using NUnit . Framework ;
3+ using ServiceStack . ServiceClient . Web ;
4+ using ServiceStack . ServiceInterface ;
5+
6+ namespace ServiceStack . ServiceHost . Tests . Routes
7+ {
8+ [ TestFixture ]
9+ public class ServiceRoutesTests
10+ {
11+ [ Test ]
12+ public void Can_Register_Routes_From_Assembly ( )
13+ {
14+ var routes = new ServiceRoutes ( ) ;
15+ routes . AddFromAssembly ( typeof ( RestServiceWithAllVerbsImplemented ) . Assembly ) ;
16+
17+ RestPath restWithAllMethodsRoute =
18+ ( from r in routes . RestPaths
19+ where r . Path == "RequestDto2"
20+ select r ) . FirstOrDefault ( ) ;
21+
22+ Assert . That ( restWithAllMethodsRoute , Is . Not . Null ) ;
23+
24+ Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "GET" ) ) ;
25+ Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "POST" ) ) ;
26+ Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "PUT" ) ) ;
27+ Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "DELETE" ) ) ;
28+ Assert . That ( restWithAllMethodsRoute . AllowedVerbs . Contains ( "PATCH" ) ) ;
29+ }
30+
31+ [ Test ]
32+ public void Can_Register_Routes_With_Partially_Implemented_REST_Verbs ( )
33+ {
34+ var routes = new ServiceRoutes ( ) ;
35+ routes . AddFromAssembly ( typeof ( RestServiceWithSomeVerbsImplemented ) . Assembly ) ;
36+
37+ RestPath restWithAFewMethodsRoute =
38+ ( from r in routes . RestPaths
39+ where r . Path == "RequestDto"
40+ select r ) . FirstOrDefault ( ) ;
41+
42+ Assert . That ( restWithAFewMethodsRoute , Is . Not . Null ) ;
43+
44+ Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "GET" ) , Is . True ) ;
45+ Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "POST" ) , Is . False ) ;
46+ Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "PUT" ) , Is . True ) ;
47+ Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "DELETE" ) , Is . False ) ;
48+ Assert . That ( restWithAFewMethodsRoute . AllowedVerbs . Contains ( "PATCH" ) , Is . False ) ;
49+ }
50+
51+ [ Test ]
52+ public void Can_Register_Routes_Using_Add_Extension ( )
53+ {
54+ var routes = new ServiceRoutes ( ) ;
55+ routes . Add < Customer > ( HttpMethod . Get , "/Users/{0}/Orders/{1}" , x => x . Name , x => x . OrderId ) ;
56+ var route = routes . RestPaths [ 0 ] ;
57+ Assert . That ( route . Path == "/Users/{Name}/Orders/{OrderId}" ) ;
58+ }
59+ }
60+
61+ public class Customer
62+ {
63+ public string Name { get ; set ; }
64+ public int OrderId { get ; set ; }
65+ }
6466}
0 commit comments