예제 #1
0
        public async Task GetAccountsTest()
        {
            var service = new VstsService();

            Guid memberId = Guid.NewGuid();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => service.GetAccounts(null, memberId));

            using (ShimsContext.Create())
            {
                var expected = new List <Account>();

                InitializeConnectionShim(GetAccountHttpClient(expected));

                IList <Account> actual = await service.GetAccounts(this.token, memberId);

                Assert.AreEqual(expected, actual);
            }
        }
예제 #2
0
        public void GivenIsAuthorized()
        {
            var authService = new AuthenticationService();
            var vstsService = new VstsService();

            var botData = Config.GetBotData();

            botData.LoadAsync(CancellationToken.None).Wait();

            if (!botData.UserData.TryGetValue("userData", out UserData data))
            {
                data = new UserData();
            }

            var refreshToken = Config.RefreshToken;

            if (data.Profile != null && !Config.RefreshTokenReinitialize)
            {
                refreshToken = data.Profile.Token.RefreshToken;
            }

            Config.RefreshTokenReinitialize = false;

            var oldToken = new OAuthToken
            {
                AppSecret    = Config.AppSecret,
                AuthorizeUrl = Config.AuthorizeUrl,
                RefreshToken = refreshToken
            };
            var token    = authService.GetToken(oldToken).Result;
            var p        = vstsService.GetProfile(token).Result;
            var accounts = vstsService.GetAccounts(token, p.Id).Result;
            var profile  = new Profile
            {
                Accounts = accounts.Select(a => a.AccountName).ToList(),
                Id       = p.Id,
                Token    = token
            };

            data.Profiles.Clear();
            data.SelectProfile(profile);

            botData.UserData.SetValue("userData", data);

            botData.FlushAsync(CancellationToken.None).Wait();

            Config.Profile = profile;
            Config.Token   = token;
        }
예제 #3
0
        public void GivenIsAuthorized()
        {
            var authService = new AuthenticationService(Config.AppSecret, Config.AuthorizeUrl);
            var vstsService = new VstsService();

            var data         = Config.BotState.GetUserData(ChannelIds.Directline, Config.UserName);
            var profile      = data.GetProperty <VstsProfile>("Profile");
            var refreshToken = Config.RefreshToken;

            if (profile != null && !Config.RefreshTokenReinitialize)
            {
                refreshToken = profile.Token.RefreshToken;
            }

            Config.RefreshTokenReinitialize = false;

            var token = authService.GetToken(new OAuthToken {
                RefreshToken = refreshToken
            }).Result;
            var p        = vstsService.GetProfile(token).Result;
            var accounts = vstsService.GetAccounts(token, p.Id).Result;

            profile = new VstsProfile
            {
                Accounts     = accounts.Select(a => a.AccountName).ToList(),
                Id           = p.Id,
                DisplayName  = p.DisplayName,
                EmailAddress = p.EmailAddress,
                Token        = token
            };

            data.SetProfile(profile);
            data.SetProfiles(new List <VstsProfile> {
                profile
            });

            Config.BotState.SetUserDataAsync(ChannelIds.Directline, Config.UserName, data).Wait();

            Config.Profile = profile;
            Config.Token   = token;
        }