public async Task HandlesBotAndSkillsTestCases(FlowTestCase testCase, bool shouldSendEoc) { var dialog = new SimpleComponentDialog(); var testFlow = CreateTestFlow(dialog, testCase, locale: "en-GB"); await testFlow.Send("Hi") .AssertReply("Hello, what is your name?") .Send("SomeName") .AssertReply("Hello SomeName, nice to meet you!") .StartTestAsync(); Assert.AreEqual(DialogReason.EndCalled, dialog.EndReason); if (shouldSendEoc) { Assert.IsNotNull(_eocSent, "Skills should send EndConversation to channel"); Assert.AreEqual(ActivityTypes.EndOfConversation, _eocSent.Type); Assert.AreEqual(EndOfConversationCodes.CompletedSuccessfully, _eocSent.Code); Assert.AreEqual("SomeName", _eocSent.Value); Assert.AreEqual("en-GB", _eocSent.Locale); } else { Assert.IsNull(_eocSent, "Root bot should not send EndConversation to channel"); } }
/// <summary> /// Creates a TestFlow instance with state data to recreate and assert the different test case. /// </summary> private TestFlow CreateTestFlow(Dialog dialog, FlowTestCase testCase) { var conversationId = Guid.NewGuid().ToString(); var storage = new MemoryStorage(); 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 AutoSaveStateMiddleware(userState, convoState)) .Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false))); return(new TestFlow(adapter, async(turnContext, cancellationToken) => { if (testCase != FlowTestCase.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 == FlowTestCase.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 == FlowTestCase.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); }); // Invoke RunAsync on the dialog. await dialog.RunAsync(turnContext, convoState.CreateProperty <DialogState>("DialogState"), cancellationToken); })); }
private void changeTest(FlowTestCase testCase) { var method = GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).SingleOrDefault(m => m.GetCustomAttribute <FlowTestCaseAttribute>()?.TestCase == testCase); if (method != null) { method.Invoke(this, new object[0]); } }
public async Task <FlowTestCase> ExtractFlowTestAsync(string fullFileName, CancellationToken cancellationToken) { var flowTest = new FlowTestCase(); var lines = new Queue <string>(); using (var fileStream = File.OpenRead(fullFileName)) using (var streamReader = new StreamReader(fileStream, Encoding.UTF8)) { string line; while ((line = await streamReader.ReadLineAsync()) != null && !cancellationToken.IsCancellationRequested) { lines.Enqueue(line.Replace("\\n", "\n")); } } //var user = lines.Dequeue(); //user = user.Replace("User:"******"Channel:", string.Empty).Trim(); //flowTest.Channel = channel; //var identifier = lines.Dequeue(); //identifier = identifier.Replace("Identifier:", string.Empty).Trim(); //flowTest.Identifier = identifier; //var accessKey = lines.Dequeue(); //accessKey = accessKey.Replace("AccessKey:", string.Empty).Trim(); //flowTest.AccessKey = accessKey; while (lines.Count > 0) { var item = lines.Dequeue(); item = item.TrimStart(); TestMessage message = _messageProvider.BuildMessage(item); flowTest.AddTestMessage(message); } return(flowTest); }
public async Task <FlowTestResult> ExecuteTestCaseAsync(FlowTestCase testCase, CancellationToken cancellationToken) { var result = new FlowTestResult { IsSuccessfully = true }; var messages = testCase.TestMessagesQueue; while (messages.Any()) { var message = messages.Dequeue(); if (message is ToBotMessage) { await _channel.SendTextAsync(message.RawTextContent, cancellationToken); continue; } if (message is FromBotMessage) { var document = await _channel.ReceiveAsync(cancellationToken); var localTestResult = CheckDocument(document, message as FromBotMessage); if (!localTestResult.Works) { result.IsSuccessfully = false; } continue; } //Ignore the rest } return(result); }
public FlowTestCaseAttribute(FlowTestCase testCase) { TestCase = testCase; }
public override void Reset() { base.Reset(); scheduledAdder?.Cancel(); Add(new Container { RelativeSizeAxes = Axes.Both, Width = 0.2f, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, Depth = float.MinValue, Children = new[] { new FillFlowContainer { Direction = FillDirection.Vertical, RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Children = new Drawable[] { new SpriteText { Text = @"Fill mode" }, selectionDropdown = new FillDirectionDropdown { RelativeSizeAxes = Axes.X, Items = Enum.GetValues(typeof(FlowTestCase)).Cast <FlowTestCase>() .Select(value => new KeyValuePair <string, FlowTestCase>(value.ToString(), value)), }, new SpriteText { Text = @"Child anchor" }, anchorDropdown = new AnchorDropdown { RelativeSizeAxes = Axes.X, Items = new[] { Anchor.TopLeft, Anchor.TopCentre, Anchor.TopRight, Anchor.CentreLeft, Anchor.Centre, Anchor.CentreRight, Anchor.BottomLeft, Anchor.BottomCentre, Anchor.BottomRight, }.Select(anchor => new KeyValuePair <string, Anchor>(anchor.ToString(), anchor)), }, new SpriteText { Text = @"Child origin" }, originDropdown = new AnchorDropdown { RelativeSizeAxes = Axes.X, Items = new[] { Anchor.TopLeft, Anchor.TopCentre, Anchor.TopRight, Anchor.CentreLeft, Anchor.Centre, Anchor.CentreRight, Anchor.BottomLeft, Anchor.BottomCentre, Anchor.BottomRight, }.Select(anchor => new KeyValuePair <string, Anchor>(anchor.ToString(), anchor)), }, } } } }); selectionDropdown.Current.ValueChanged += newValue => { if (current == newValue) { return; } current = newValue; Reset(); }; selectionDropdown.Current.Value = current; changeTest(current); }
public MockBotIdentityMiddleware(FlowTestCase flowTestCase) { _flowTestCase = flowTestCase; }