Пример #1
0
 private static Profile CreateProfile(IEnumerable <Account> accounts, Microsoft.VisualStudio.Services.Profile.Profile profile, OAuthToken token)
 {
     return(new Profile
     {
         Id = profile.Id, // First do the id, for the encryption / decryption.
         Accounts = accounts.Select(a => a.AccountName).ToList(),
         Token = token
     });
 }
Пример #2
0
 private static VstsProfile CreateVstsProfile(IEnumerable <Account> accounts, Microsoft.VisualStudio.Services.Profile.Profile profile, OAuthToken token)
 {
     return(new VstsProfile
     {
         Accounts = accounts.Select(a => a.AccountName).ToList(),
         EmailAddress = profile.EmailAddress,
         Id = profile.Id,
         Token = token
     });
 }
Пример #3
0
        private static ProfileHttpClient GetProfileHttpClient(Microsoft.VisualStudio.Services.Profile.Profile profile)
        {
            var shimProfileClient = new ShimProfileHttpClient
            {
                GetProfileAsyncProfileQueryContextObjectCancellationToken =
                    (context, objectState, cancelationToken) => Task.Run(() => profile, cancelationToken)
            };

            return(shimProfileClient.Instance);
        }
Пример #4
0
        public async Task GetProfileTest()
        {
            var service = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProfile(null));

            using (ShimsContext.Create())
            {
                var expected = new Microsoft.VisualStudio.Services.Profile.Profile();

                InitializeConnectionShim(GetProfileHttpClient(expected));

                Microsoft.VisualStudio.Services.Profile.Profile actual = await service.GetProfile(this.token);

                Assert.AreEqual(expected, actual);
            }
        }
Пример #5
0
        public async Task Authorize_A_Valid_LogOn()
        {
            var authenticationServiceMock = new Mock <IAuthenticationService>();
            var botDataFactoryMock        = new Mock <IBotDataFactory>();
            var botData         = new Mock <IBotData>();
            var botDataBag      = new Mock <IBotDataBag>();
            var vstsServiceMock = new Mock <IVstsService>();

            var token   = new OAuthToken();
            var profile = new Microsoft.VisualStudio.Services.Profile.Profile {
                DisplayName = "UniqueName"
            };
            var accounts = new List <Account> {
                new Account(Guid.NewGuid())
                {
                    AccountName = "Account1"
                }
            };

            var target = new AuthorizeController("appId", new Uri("http://authorize.url"), authenticationServiceMock.Object, botDataFactoryMock.Object, vstsServiceMock.Object);

            const string code  = "1234567890";
            const string state = "channel1;user1";
            var          data  = new UserData {
                Pin = "12345"
            };

            authenticationServiceMock
            .Setup(a => a.GetToken("appId", new Uri("http://authorize.url"), code))
            .ReturnsAsync(() => token);

            vstsServiceMock
            .Setup(p => p.GetProfile(token))
            .ReturnsAsync(profile);

            vstsServiceMock
            .Setup(p => p.GetAccounts(token, It.IsAny <Guid>()))
            .ReturnsAsync(accounts);

            botDataFactoryMock
            .Setup(b => b.Create(It.Is <Address>(a =>
                                                 a.ChannelId.Equals("channel1", StringComparison.Ordinal) &&
                                                 a.UserId.Equals("user1", StringComparison.Ordinal))))
            .Returns(botData.Object);

            botData
            .Setup(bd => bd.UserData)
            .Returns(botDataBag.Object);

            botDataBag
            .Setup(bd => bd.TryGetValue("userData", out data))
            .Returns(true);

            var result = await target.Index(code, string.Empty, state) as ViewResult;

            botDataBag
            .Verify(bd => bd.SetValue("userData", data));

            result.Should().NotBeNull();
            ((Authorize)result.Model).Pin.Should().Be(data.Pin);
            data.Profiles.Should().Contain(p => p.Id.Equals(profile.Id));
        }
Пример #6
0
        public async Task GetApprovalsTest()
        {
            var accountName = "MyAccount";
            var projectName = "MyProject";
            var profile     = new Profile
            {
                Id    = Guid.NewGuid(),
                Token = this.token
            };
            var pr = new Microsoft.VisualStudio.Services.Profile.Profile {
                DisplayName = "me"
            };

            var service = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetApprovals(null, projectName, profile));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetApprovals(accountName, null, profile));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetApprovals(accountName, projectName, null));

            using (ShimsContext.Create())
            {
                var expected = new List <ReleaseApproval>
                {
                    new ReleaseApproval
                    {
                        Id           = 1234,
                        ApprovalType = ApprovalType.Undefined
                    }
                };

                InitializeConnectionShim(new VssHttpClientBase[]
                {
                    GetAccountHttpClient(new List <Account>
                    {
                        new Account(Guid.Empty)
                        {
                            AccountName = "myaccount",
                            AccountUri  = new Uri("https://myaccount.visualstudio.com")
                        }
                    }),
                    GetProfileHttpClient(pr),
                    new ShimReleaseHttpClient2
                    {
                        GetApprovalsAsync2StringStringNullableOfApprovalStatusIEnumerableOfInt32NullableOfApprovalTypeNullableOfInt32NullableOfInt32NullableOfReleaseQueryOrderNullableOfBooleanObjectCancellationToken
                            = (project, assignedToFilter, statusFilter, releaseIdsFilter, typeFilter, top, continuationToken, queryOrder, includeMyGroupApprovals, userState, cancellationToken) =>
                              Task.Run(
                                  () => (IPagedCollection <ReleaseApproval>) new StubIPagedCollection <ReleaseApproval>
                        {
                            CountGet     = () => expected.Count,
                            ItemGetInt32 = i => expected[i]
                        },
                                  cancellationToken)
                    }.Instance
                });

                var actual = await service.GetApprovals(accountName, projectName, profile);

                Assert.AreEqual(expected.Count, actual.Count);

                for (var i = 0; i < actual.Count; i++)
                {
                    Assert.AreEqual(expected[i], actual[i]);
                }
            }
        }