Skip to content

Commit c58c702

Browse files
shmuelgutmancleemullinsStevenic
authored
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 <cleemullins@users.noreply.github.com> Co-authored-by: Steven Ickman <stevenic@microsoft.com>
1 parent 335357f commit c58c702

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libraries/botbuilder-core/src/testAdapter.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,22 @@ export class TestAdapter extends BotAdapter implements IUserTokenProvider {
185185
if (!request.id) { request.id = (this.nextId++).toString(); }
186186

187187
// Create context object and run middleware
188-
const context: TurnContext = new TurnContext(this, request);
188+
const context: TurnContext = this.createContext(request);
189189

190190
return this.runMiddleware(context, this.logic);
191191
}
192192

193+
/**
194+
* Creates a turn context.
195+
*
196+
* @param request An incoming request body.
197+
*
198+
* @remarks
199+
* Override this in a derived class to modify how the adapter creates a turn context.
200+
*/
201+
protected createContext(request: Partial<Activity>): TurnContext {
202+
return new TurnContext(this, request);
203+
}
193204
/**
194205
* Sends something to the bot. This returns a new `TestFlow` instance which can be used to add
195206
* additional steps for inspecting the bots reply and then sending additional activities.

0 commit comments

Comments
 (0)