-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathDummyHTTPMessageHandler.ts
59 lines (53 loc) · 1.52 KB
/
DummyHTTPMessageHandler.ts
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
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module DummyHTTPMessageHandler
*/
import { Context } from "../src/IContext";
import { Middleware } from "../src/middleware/IMiddleware";
/**
* @class
* @implements Middleware
* Class representing DummyHTTPMessageHandler
*/
export class DummyHTTPMessageHandler implements Middleware {
/**
* @private
* A member holding the array of response objects
*/
private responses: Response[];
/**
* @public
* @constructor
* To create an instance of DummyHTTPMessageHandler
* @param {Response[]} [responses = []] - The array of response objects
* @returns An instance of DummyHTTPMessageHandler
*/
public constructor(responses: Response[] = []) {
this.responses = responses;
}
/**
* @public
* To set the array of responses
* @param {Response[]} response - The array of responses
* @returns Nothing
*/
public setResponses(responses: Response[]): void {
this.responses = responses;
}
/**
* @public
* @async
* To execute the current middleware
* @param {Context} context - The request context object
* @returns A promise that resolves to nothing
*/
public async execute(context: Context) {
context.response = this.responses.shift();
return;
}
}