Exemple #1
0
        public async Task TestAdapter_GetUserTokenAsyncReturnsToken()
        {
            TestAdapter adapter        = new TestAdapter();
            string      connectionName = "myConnection";
            string      channelId      = "directline";
            string      userId         = "testUser";
            string      token          = "abc123";
            Activity    activity       = new Activity()
            {
                ChannelId = channelId,
                From      = new ChannelAccount()
                {
                    Id = userId,
                },
            };
            TurnContext turnContext = new TurnContext(adapter, activity);

            adapter.AddUserToken(connectionName, channelId, userId, token);

            var tokenResponse = await adapter.GetUserTokenAsync(turnContext, connectionName, null, CancellationToken.None);

            Assert.NotNull(tokenResponse);
            Assert.Equal(token, tokenResponse.Token);
            Assert.Equal(connectionName, tokenResponse.ConnectionName);

            var oAuthAppCredentials = MicrosoftAppCredentials.Empty;

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, connectionName, null, CancellationToken.None);

            Assert.NotNull(tokenResponse);
            Assert.Equal(token, tokenResponse.Token);
            Assert.Equal(connectionName, tokenResponse.ConnectionName);
        }
Exemple #2
0
        public async Task TestAdapter_SignOut()
        {
            TestAdapter adapter        = new TestAdapter();
            string      connectionName = "myConnection";
            string      channelId      = "directline";
            string      userId         = "testUser";
            string      token          = "abc123";
            Activity    activity       = new Activity()
            {
                ChannelId = channelId,
                From      = new ChannelAccount()
                {
                    Id = userId,
                },
            };
            TurnContext turnContext = new TurnContext(adapter, activity);

            adapter.AddUserToken(connectionName, channelId, userId, token);

            var tokenResponse = await adapter.GetUserTokenAsync(turnContext, connectionName, null, CancellationToken.None);

            Assert.IsNotNull(tokenResponse);
            Assert.AreEqual(token, tokenResponse.Token);
            Assert.AreEqual(connectionName, tokenResponse.ConnectionName);

            await adapter.SignOutUserAsync(turnContext, connectionName, userId);

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, connectionName, null, CancellationToken.None);

            Assert.IsNull(tokenResponse);
        }
Exemple #3
0
        public async Task TestAdapter_GetUserTokenAsyncReturnsTokenWithMagicCode()
        {
            TestAdapter adapter        = new TestAdapter();
            string      connectionName = "myConnection";
            string      channelId      = "directline";
            string      userId         = "testUser";
            string      token          = "abc123";
            string      magicCode      = "888999";
            Activity    activity       = new Activity()
            {
                ChannelId = channelId,
                From      = new ChannelAccount()
                {
                    Id = userId,
                },
            };
            TurnContext turnContext = new TurnContext(adapter, activity);

            adapter.AddUserToken(connectionName, channelId, userId, token, magicCode);

            // First it's null
            var tokenResponse = await adapter.GetUserTokenAsync(turnContext, connectionName, null, CancellationToken.None);

            Assert.Null(tokenResponse);

            // Can be retrieved with magic code
            tokenResponse = await adapter.GetUserTokenAsync(turnContext, connectionName, magicCode, CancellationToken.None);

            Assert.NotNull(tokenResponse);
            Assert.Equal(token, tokenResponse.Token);
            Assert.Equal(connectionName, tokenResponse.ConnectionName);

            // Then can be retrieved without magic code
            tokenResponse = await adapter.GetUserTokenAsync(turnContext, connectionName, null, CancellationToken.None);

            Assert.NotNull(tokenResponse);
            Assert.Equal(token, tokenResponse.Token);
            Assert.Equal(connectionName, tokenResponse.ConnectionName);

            // Then can be retrieved using customized AppCredentials
            var oAuthAppCredentials = MicrosoftAppCredentials.Empty;

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, connectionName, null, CancellationToken.None);

            Assert.NotNull(tokenResponse);
            Assert.Equal(token, tokenResponse.Token);
            Assert.Equal(connectionName, tokenResponse.ConnectionName);
        }
Exemple #4
0
        public async Task TestAdapter_GetUserTokenAsyncReturnsNullWithCode()
        {
            TestAdapter adapter  = new TestAdapter();
            Activity    activity = new Activity()
            {
                ChannelId = "directline",
                From      = new ChannelAccount()
                {
                    Id = "testUser",
                },
            };
            TurnContext turnContext = new TurnContext(adapter, activity);

            var token = await adapter.GetUserTokenAsync(turnContext, "myConnection", "abc123", CancellationToken.None);

            Assert.Null(token);

            var oAuthAppCredentials = MicrosoftAppCredentials.Empty;

            token = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, "myConnection", "abc123", CancellationToken.None);

            Assert.Null(token);
        }
Exemple #5
0
        public async Task TestAdapter_GetUserTokenAsyncReturnsNull()
        {
            TestAdapter adapter  = new TestAdapter();
            Activity    activity = new Activity()
            {
                ChannelId = "directline",
                From      = new ChannelAccount()
                {
                    Id = "testUser",
                },
            };
            TurnContext turnContext = new TurnContext(adapter, activity);

            var token = await adapter.GetUserTokenAsync(turnContext, "myConnection", null, CancellationToken.None);

            Assert.IsNull(token);
        }
        public async Task TestAdapter_SignOutAll()
        {
            TestAdapter adapter   = new TestAdapter();
            string      channelId = "directline";
            string      userId    = "testUser";
            string      token     = "abc123";
            Activity    activity  = new Activity()
            {
                ChannelId = channelId,
                From      = new ChannelAccount()
                {
                    Id = userId,
                },
            };
            TurnContext turnContext = new TurnContext(adapter, activity);

            adapter.AddUserToken("ABC", channelId, userId, token);
            adapter.AddUserToken("DEF", channelId, userId, token);

            var tokenResponse = await adapter.GetUserTokenAsync(turnContext, "ABC", null, CancellationToken.None);

            Assert.IsNotNull(tokenResponse);
            Assert.AreEqual(token, tokenResponse.Token);
            Assert.AreEqual("ABC", tokenResponse.ConnectionName);

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, "DEF", null, CancellationToken.None);

            Assert.IsNotNull(tokenResponse);
            Assert.AreEqual(token, tokenResponse.Token);
            Assert.AreEqual("DEF", tokenResponse.ConnectionName);

            await adapter.SignOutUserAsync(turnContext, connectionName : null, userId);

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, "ABC", null, CancellationToken.None);

            Assert.IsNull(tokenResponse);
            tokenResponse = await adapter.GetUserTokenAsync(turnContext, "DEF", null, CancellationToken.None);

            Assert.IsNull(tokenResponse);

            adapter.AddUserToken("ABC", channelId, userId, token);
            adapter.AddUserToken("DEF", channelId, userId, token);

            var oAuthAppCredentials = MicrosoftAppCredentials.Empty;

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, "ABC", null, CancellationToken.None);

            Assert.IsNotNull(tokenResponse);
            Assert.AreEqual(token, tokenResponse.Token);
            Assert.AreEqual("ABC", tokenResponse.ConnectionName);

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, "DEF", null, CancellationToken.None);

            Assert.IsNotNull(tokenResponse);
            Assert.AreEqual(token, tokenResponse.Token);
            Assert.AreEqual("DEF", tokenResponse.ConnectionName);

            await adapter.SignOutUserAsync(turnContext, connectionName : null, userId);

            tokenResponse = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, "ABC", null, CancellationToken.None);

            Assert.IsNull(tokenResponse);
            tokenResponse = await adapter.GetUserTokenAsync(turnContext, oAuthAppCredentials, "DEF", null, CancellationToken.None);

            Assert.IsNull(tokenResponse);
        }