private TestFlow CreateFlow(Dialog dialog, IStorage storage, string conversationId, string dialogStateProperty = null, bool isSkillFlow = false) { var convoState = new ConversationState(storage); var userState = new UserState(storage); var adapter = new TestAdapter(TestAdapter.CreateConversation(conversationId)); adapter .UseStorage(storage) .UseState(userState, convoState) .Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false))); var dm = new DialogManager(dialog, dialogStateProperty: dialogStateProperty); return(new TestFlow(adapter, async(turnContext, cancellationToken) => { if (isSkillFlow) { // Create a skill ClaimsIdentity and put it in TurnState so SkillValidation.IsSkillClaim() returns true. var claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.VersionClaim, "2.0")); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AudienceClaim, _skillBotId)); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AuthorizedParty, _parentBotId)); turnContext.TurnState.Add(BotAdapter.BotIdentityKey, claimsIdentity); } // Capture the last DialogManager turn result for assertions. _dmTurnResult = await dm.OnTurnAsync(turnContext, cancellationToken: cancellationToken).ConfigureAwait(false); })); }
private TestFlow CreateFlow(Dialog dialog, IStorage storage, string conversationId, string dialogStateProperty = null, SkillFlowTestCase testCase = SkillFlowTestCase.RootBotOnly, string locale = null) { var convoState = new ConversationState(storage); var userState = new UserState(storage); var adapter = new TestAdapter(TestAdapter.CreateConversation(conversationId)); adapter .UseStorage(storage) .UseBotState(userState, convoState) .Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false))); if (!string.IsNullOrEmpty(locale)) { adapter.Locale = locale; } var dm = new DialogManager(dialog, dialogStateProperty: dialogStateProperty); return(new TestFlow(adapter, async(turnContext, cancellationToken) => { if (testCase != SkillFlowTestCase.RootBotOnly) { // Create a skill ClaimsIdentity and put it in TurnState so SkillValidation.IsSkillClaim() returns true. var claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.VersionClaim, "2.0")); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AudienceClaim, _skillBotId)); claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AuthorizedParty, _parentBotId)); turnContext.TurnState.Add(BotAdapter.BotIdentityKey, claimsIdentity); if (testCase == SkillFlowTestCase.RootBotConsumingSkill) { // Simulate the SkillConversationReference with a channel OAuthScope stored in TurnState. // This emulates a response coming to a root bot through SkillHandler. turnContext.TurnState.Add(SkillHandler.SkillConversationReferenceKey, new SkillConversationReference { OAuthScope = AuthenticationConstants.ToChannelFromBotOAuthScope }); } if (testCase == SkillFlowTestCase.MiddleSkill) { // Simulate the SkillConversationReference with a parent Bot ID stored in TurnState. // This emulates a response coming to a skill from another skill through SkillHandler. turnContext.TurnState.Add(SkillHandler.SkillConversationReferenceKey, new SkillConversationReference { OAuthScope = _parentBotId }); } } // Interceptor to capture the EoC activity if it was sent so we can assert it in the tests. turnContext.OnSendActivities(async(tc, activities, next) => { _eocSent = activities.FirstOrDefault(activity => activity.Type == ActivityTypes.EndOfConversation); return await next().ConfigureAwait(false); }); // Capture the last DialogManager turn result for assertions. _dmTurnResult = await dm.OnTurnAsync(turnContext, cancellationToken: cancellationToken).ConfigureAwait(false); })); }