Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: pkg/shelf/test/stack_test.dart

Issue 219283008: pkg/shelf (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/test/shelf_io_test.dart ('k') | pkg/shelf/test/string_scanner_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library shelf.shelf_stack_test;
6
7 import 'package:shelf/shelf.dart';
8 import 'package:unittest/unittest.dart';
9
10 import 'test_util.dart';
11
12 void main() {
13 test('compose middleware with Stack', () {
14 int accessLocation = 0;
15
16 var middlewareA = createMiddleware(requestHandler: (request) {
17 expect(accessLocation, 0);
18 accessLocation = 1;
19 return null;
20 }, responseHandler: (response) {
21 expect(accessLocation, 4);
22 accessLocation = 5;
23 return response;
24 });
25
26 var middlewareB = createMiddleware(requestHandler: (request) {
27 expect(accessLocation, 1);
28 accessLocation = 2;
29 return null;
30 }, responseHandler: (response) {
31 expect(accessLocation, 3);
32 accessLocation = 4;
33 return response;
34 });
35
36 var handler = const Stack()
37 .addMiddleware(middlewareA)
38 .addMiddleware(middlewareB)
39 .addHandler((request) {
40 expect(accessLocation, 2);
41 accessLocation = 3;
42 return syncHandler(request);
43 });
44
45 return makeSimpleRequest(handler).then((response) {
46 expect(response, isNotNull);
47 expect(accessLocation, 5);
48 });
49 });
50
51 test('Stack can be used as middleware', () {
52 int accessLocation = 0;
53
54 var middlewareA = createMiddleware(requestHandler: (request) {
55 expect(accessLocation, 0);
56 accessLocation = 1;
57 return null;
58 }, responseHandler: (response) {
59 expect(accessLocation, 4);
60 accessLocation = 5;
61 return response;
62 });
63
64 var middlewareB = createMiddleware(requestHandler: (request) {
65 expect(accessLocation, 1);
66 accessLocation = 2;
67 return null;
68 }, responseHandler: (response) {
69 expect(accessLocation, 3);
70 accessLocation = 4;
71 return response;
72 });
73
74 var innerStack = const Stack()
75 .addMiddleware(middlewareA)
76 .addMiddleware(middlewareB);
77
78 var handler = const Stack()
79 .addMiddleware(innerStack.middleware)
80 .addHandler((request) {
81 expect(accessLocation, 2);
82 accessLocation = 3;
83 return syncHandler(request);
84 });
85
86 return makeSimpleRequest(handler).then((response) {
87 expect(response, isNotNull);
88 expect(accessLocation, 5);
89 });
90 });
91 }
OLDNEW
« no previous file with comments | « pkg/shelf/test/shelf_io_test.dart ('k') | pkg/shelf/test/string_scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698