From c58c702ba1fb80da9b24c4524b1d895d090a88c0 Mon Sep 17 00:00:00 2001 From: shmuelgutman Date: Wed, 19 Feb 2020 03:55:52 +0200 Subject: [PATCH] Create new TurnContext using function so that derived classes can override the default TurnContext (#1513) Like happens in the regular adapter, use helper function to create new instance of the TurnContext so so that derived classes can override the default TurnContext Co-authored-by: Chris Mullins Co-authored-by: Steven Ickman --- libraries/botbuilder-core/src/testAdapter.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder-core/src/testAdapter.ts b/libraries/botbuilder-core/src/testAdapter.ts index b16754220e..010144b36e 100644 --- a/libraries/botbuilder-core/src/testAdapter.ts +++ b/libraries/botbuilder-core/src/testAdapter.ts @@ -185,11 +185,22 @@ export class TestAdapter extends BotAdapter implements IUserTokenProvider { if (!request.id) { request.id = (this.nextId++).toString(); } // Create context object and run middleware - const context: TurnContext = new TurnContext(this, request); + const context: TurnContext = this.createContext(request); return this.runMiddleware(context, this.logic); } + /** + * Creates a turn context. + * + * @param request An incoming request body. + * + * @remarks + * Override this in a derived class to modify how the adapter creates a turn context. + */ + protected createContext(request: Partial): TurnContext { + return new TurnContext(this, request); + } /** * Sends something to the bot. This returns a new `TestFlow` instance which can be used to add * additional steps for inspecting the bots reply and then sending additional activities.