File tree Expand file tree Collapse file tree 4 files changed +8
-20
lines changed Expand file tree Collapse file tree 4 files changed +8
-20
lines changed Original file line number Diff line number Diff line change 1
- import 'dart:developer' ;
2
-
3
1
import 'package:dart_frog/dart_frog.dart' ;
4
2
5
- final _counter = Counter ( 'counter' , 'a simple request counter' ) ;
3
+ int _count = 0 ;
6
4
7
5
Handler middleware (Handler handler) {
8
- return handler.use (provider <Counter >((_) => _counter ));
6
+ return handler.use (provider <int >((_) => ++ _count ));
9
7
}
Original file line number Diff line number Diff line change 1
- import 'dart:developer' ;
2
-
3
1
import 'package:dart_frog/dart_frog.dart' ;
4
2
5
3
Response onRequest (RequestContext context) {
6
- final counter = context.read <Counter >()..value += 1 ;
4
+ final count = context.read <int >();
7
5
return Response (
8
- body: 'You have requested this route ${ counter . value . toInt ()} time(s).' ,
6
+ body: 'You have requested this route $count time(s).' ,
9
7
);
10
8
}
Original file line number Diff line number Diff line change 1
- import 'dart:developer' ;
2
-
3
1
import 'package:dart_frog/dart_frog.dart' ;
4
2
import 'package:mocktail/mocktail.dart' ;
5
3
import 'package:test/test.dart' ;
@@ -10,12 +8,11 @@ class _MockRequestContext extends Mock implements RequestContext {}
10
8
11
9
void main () {
12
10
group ('middleware' , () {
13
- test ('provides count instance ' , () async {
14
- double ? count;
11
+ test ('provides incremented count ' , () async {
12
+ int ? count;
15
13
final handler = middleware (
16
14
(context) {
17
- final counter = context.read <Counter >();
18
- count = counter.value += 1 ;
15
+ count = context.read <int >();
19
16
return Response (body: '' );
20
17
},
21
18
);
Original file line number Diff line number Diff line change 1
- import 'dart:developer' ;
2
1
import 'dart:io' ;
3
2
4
3
import 'package:dart_frog/dart_frog.dart' ;
@@ -9,16 +8,12 @@ import '../../../routes/count/index.dart' as route;
9
8
10
9
class _MockRequestContext extends Mock implements RequestContext {}
11
10
12
- class _MockCounter extends Mock implements Counter {}
13
-
14
11
void main () {
15
12
group ('GET /' , () {
16
13
test ('responds with a 200 and count.' , () async {
17
14
const count = 42 ;
18
- final counter = _MockCounter ();
19
- when (() => counter.value).thenReturn (count.toDouble ());
20
15
final context = _MockRequestContext ();
21
- when (() => context.read <Counter >()).thenReturn (counter );
16
+ when (() => context.read <int >()).thenReturn (count );
22
17
final response = route.onRequest (context);
23
18
expect (response.statusCode, equals (HttpStatus .ok));
24
19
expect (
You can’t perform that action at this time.
0 commit comments