@@ -19,7 +19,7 @@ import XCTest
19
19
20
20
final class RouteControllerTests : XCTestCase {
21
21
/// Test using a controller inside a router builder.
22
- func testRouteControllerBody ( ) async throws {
22
+ func testRouteController ( ) async throws {
23
23
struct TestController : RouteController {
24
24
typealias Context = BasicRouterRequestContext
25
25
var body : some RouterMiddleware < Context > {
@@ -41,7 +41,7 @@ final class RouteControllerTests: XCTestCase {
41
41
}
42
42
43
43
/// Test nesting controllers inside a router builder.
44
- func testRouteControllerBodyWithNestedControllers ( ) async throws {
44
+ func testRouteControllerWithNestedControllers ( ) async throws {
45
45
struct ChildAController : RouteController {
46
46
typealias Context = BasicRouterRequestContext
47
47
var body : some RouterMiddleware < Context > {
@@ -102,4 +102,68 @@ final class RouteControllerTests: XCTestCase {
102
102
}
103
103
}
104
104
}
105
+
106
+ func testRouteControllerWithGenericRouteControllerContent( ) async throws {
107
+ struct ChildController : RouteController {
108
+ typealias Context = BasicRouterRequestContext
109
+ var body : some RouterMiddleware < Context > {
110
+ Get { _, _ in " child " }
111
+ }
112
+ }
113
+
114
+ struct ParentController < Content: RouteController > : RouteController {
115
+
116
+ @RouteBuilder < Context > var content : ( ) -> Content
117
+
118
+ typealias Context = BasicRouterRequestContext
119
+ var body : some RouterMiddleware < Context > {
120
+ RouteGroup ( " /parent " ) {
121
+ content ( )
122
+ }
123
+ }
124
+ }
125
+
126
+ let router = RouterBuilder ( context: BasicRouterRequestContext . self) {
127
+ ParentController {
128
+ ChildController ( )
129
+ }
130
+ }
131
+
132
+ let app = Application ( responder: router)
133
+
134
+ try await app. test ( . router) { client in
135
+ try await client. execute ( uri: " /parent/child " , method: . get) { response in
136
+ XCTAssertEqual ( String ( buffer: response. body) , " child " )
137
+ }
138
+ }
139
+ }
140
+
141
+
142
+ func testRouteControllerWithGenericMiddlewareContent( ) async throws {
143
+ struct ParentController < Content: RouterMiddleware > : RouteController {
144
+
145
+ @RouteBuilder < Context > var content : ( ) -> Content
146
+
147
+ typealias Context = BasicRouterRequestContext
148
+ var body : some RouterMiddleware < Context > {
149
+ RouteGroup ( " /parent " ) {
150
+ content ( )
151
+ }
152
+ }
153
+ }
154
+
155
+ let router = RouterBuilder ( context: BasicRouterRequestContext . self) {
156
+ ParentController {
157
+ Get ( " foo " ) { _, _ in " foo " }
158
+ }
159
+ }
160
+
161
+ let app = Application ( responder: router)
162
+
163
+ try await app. test ( . router) { client in
164
+ try await client. execute ( uri: " /parent/foo " , method: . get) { response in
165
+ XCTAssertEqual ( String ( buffer: response. body) , " foo " )
166
+ }
167
+ }
168
+ }
105
169
}
0 commit comments