public async Task TokenExchanged_OnTurnFires() { // Arrange bool wasCalled = false; var adapter = new TeamsSSOAdapter(CreateConversationReference()) .Use(new TeamsSSOTokenExchangeMiddleware(new MemoryStorage(), ConnectionName)); adapter.AddExchangeableToken(ConnectionName, Channels.Msteams, TeamsUserId, FakeExchangeableItem, Token); // Act await new TestFlow(adapter, async(context, cancellationToken) => { // note the Middleware should not cause the Responded flag to be set Assert.False(context.Responded); wasCalled = true; await context.SendActivityAsync("processed", cancellationToken: cancellationToken); await Task.CompletedTask; }) .Send("test") .AssertReply("processed") .StartTestAsync(); // Assert Assert.True(wasCalled, "Delegate was not called"); }
public async Task TokenExchanged_SecondSendsInvokeResponse() { // Arrange int calledCount = 0; var adapter = new TeamsSSOAdapter(CreateConversationReference()) .Use(new TeamsSSOTokenExchangeMiddleware(new MemoryStorage(), ConnectionName)); adapter.AddExchangeableToken(ConnectionName, Channels.Msteams, TeamsUserId, FakeExchangeableItem, Token); // Act await new TestFlow(adapter, async(context, cancellationToken) => { // note the Middleware should not cause the Responded flag to be set Assert.False(context.Responded); calledCount++; await context.SendActivityAsync("processed", cancellationToken: cancellationToken); await Task.CompletedTask; }) .Send("test") .AssertReply("processed") .Send("test") .AssertReply((activity) => { // When the 2nd message goes through, it is not processed due to deduplication // but an invokeResponse of 200 status with empty body is sent back Assert.Equal(ActivityTypesEx.InvokeResponse, activity.Type); var invokeResponse = (activity as Activity).Value as InvokeResponse; Assert.Null(invokeResponse.Body); Assert.Equal(200, invokeResponse.Status); }) .StartTestAsync(); // Assert Assert.False(calledCount == 0, "Delegate was not called"); Assert.True(calledCount == 1, "OnTurn delegate called more than once"); }