Exemplo n.º 1
0
        public async Task WhenICreatedAServiceHook(KeyValuePair <string, string> teamProject)
        {
            var service = new VstsService();

            var teamProjects = await service.GetProjects(Config.Account, Config.Token);

            var tp = teamProjects.FirstOrDefault(p => p.Name.Equals(teamProject.Value, StringComparison.OrdinalIgnoreCase));

            var subscription = new Subscription
            {
                ConsumerActionId = "httpRequest",
                ConsumerId       = "webHooks",
                ConsumerInputs   = new Dictionary <string, string> {
                    { "url", "https://myservice/myhookeventreceiver" }
                },
                EventType       = "build.complete",
                PublisherId     = "tfs",
                PublisherInputs = new Dictionary <string, string> {
                    { "buildStatus", "Failed" }, { "definitionName", "Build 1" }, { "projectId", tp.Id.ToString() }
                },
                ResourceVersion = "1.0-preview.1"
            };

            subscription = await service.CreateSubscription(Config.Account, subscription, Config.Token);

            ScenarioContext.Current["SubscriptionId"] = subscription.Id;
        }
Exemplo n.º 2
0
        public async Task GetBuildTest()
        {
            var accountName     = "myaccount";
            var teamProjectName = "myproject";
            var service         = new VstsService();
            var id = 1;

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildAsync(null, teamProjectName, id, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildAsync(accountName, null, id, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await service.GetBuildAsync(accountName, teamProjectName, 0, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildAsync(accountName, teamProjectName, 1, null));

            using (ShimsContext.Create())
            {
                var client = new ShimBuildHttpClientBase(new ShimBuildHttpClient());

                InitializeConnectionShim(client.Instance);

                client.GetBuildAsyncStringInt32StringObjectCancellationToken = (teamProject, buildId, arg3, arg4, cancellationToken) =>
                                                                               Task.Run(
                    () =>
                {
                    teamProject.Should().Be(teamProjectName);
                    buildId.Should().Be(id);

                    return(new Build());
                },
                    cancellationToken);

                await service.GetBuildAsync(accountName, teamProjectName, id, this.token);
            }
        }
        public async void VstsService_GetWorkItemById_ReturnsWorkItem(long id)
        {
            var sut    = new VstsService();
            var result = sut.GetIssueAsync(id);

            Assert.IsType <Issue>(result);
        }
Exemplo n.º 4
0
        public async Task ThenIDeleteTheServiceHook()
        {
            var subscriptionId = (Guid)ScenarioContext.Current["SubscriptionId"];
            var service        = new VstsService();

            await service.DeleteSubscription(Config.Account, subscriptionId, Config.Token);
        }
Exemplo n.º 5
0
        public void GivenIHaveAnApprovalForRelease(KeyValuePair <string, string> teamProject, int releaseDefinitionId)
        {
            var service   = new VstsService();
            var approvals = service.GetApprovals(Config.Account, teamProject.Value, Config.Profile).Result;

            Config.Approval = approvals.FirstOrDefault(a => a.ReleaseDefinitionReference.Id.Equals(releaseDefinitionId));
        }
Exemplo n.º 6
0
        public async Task GetReleaseAsyncTest()
        {
            var accountName = "myaccount";
            var projectName = "myproject";
            var release     = new Release();
            var releaseId   = 99;
            var service     = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetReleaseAsync(null, projectName, releaseId, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetReleaseAsync(accountName, null, releaseId, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await service.GetReleaseAsync(accountName, projectName, -10, this.token));

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

            using (ShimsContext.Create())
            {
                var client = new ShimReleaseHttpClientBase(new ShimReleaseHttpClient2())
                {
                    GetReleaseAsyncStringInt32NullableOfBooleanIEnumerableOfStringObjectCancellationToken =
                        (teamProject, id, arg3, arg4, arg5, cancellationToken) =>
                        Task.Run(
                            () =>
                    {
                        teamProject.Should().Be(projectName);
                        id.Should().Be(releaseId);

                        return(release);
                    },
                            cancellationToken)
                };
            }
        }
Exemplo n.º 7
0
        public async Task GetBuildDefinitionsTest()
        {
            var service = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync(null, "myproject", this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync("myaccount", null, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync("myaccount", "myproject", null));

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

                var clients = new VssHttpClientBase[]
                {
                    new ShimBuildHttpClient
                    {
                        GetDefinitionsAsyncStringStringStringStringNullableOfDefinitionQueryOrderNullableOfInt32StringNullableOfDateTimeIEnumerableOfInt32StringNullableOfDateTimeNullableOfDateTimeObjectCancellationToken =
                            (s, s1, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, cancellationToken) => Task.Run(() => expected, cancellationToken)
                    }.Instance
                };

                InitializeConnectionShim(clients);

                IEnumerable <BuildDefinitionReference> actual = await service.GetBuildDefinitionsAsync("myaccount", "myproject", this.token);

                expected.ShouldAllBeEquivalentTo(actual);
            }
        }
Exemplo n.º 8
0
        public void ThenIsRejectedWithComment(KeyValuePair <string, string> teamProject)
        {
            var service  = new VstsService();
            var approval = service.GetApproval(Config.Account, teamProject.Value, Config.Approval.Id, Config.Profile.Token).Result;

            approval.Status.Should().Be(ApprovalStatus.Rejected);
        }
Exemplo n.º 9
0
        public void ThenACreatedReleaseShouldExistOn(KeyValuePair <string, string> teamProject)
        {
            var service = new VstsService();

            var build = service.GetReleaseAsync(Config.Account, teamProject.Value, Config.ReleaseId, Config.Token).Result;

            build.Should().NotBeNull();
        }
Exemplo n.º 10
0
        public void GivenIStartedOn(int definitionId, KeyValuePair <string, string> teamProject)
        {
            var service = new VstsService();

            service.CreateReleaseAsync(Config.Account, teamProject.Value, definitionId, Config.Token).Wait();

            Thread.Sleep(TimeSpan.FromSeconds(2));
        }
Exemplo n.º 11
0
        public void ThenABuildWithIdShouldExist(KeyValuePair <string, string> teamProject)
        {
            var service = new VstsService();

            var build = service.GetBuildAsync(Config.Account, teamProject.Value, Config.BuildId, Config.Token).Result;

            build.Should().NotBeNull();
        }
Exemplo n.º 12
0
        public async Task ThenIListTheServiceHook()
        {
            var service = new VstsService();

            var subscriptions = await service.GetSubscriptions(Config.Account, Config.Token);

            subscriptions.Should().HaveCount(1);
        }
Exemplo n.º 13
0
        public async Task ThenIGetTheServiceHook()
        {
            var subscriptionId = (Guid)ScenarioContext.Current["SubscriptionId"];
            var service        = new VstsService();

            var subscription = await service.GetSubscription(Config.Account, subscriptionId, Config.Token);

            subscription.Should().NotBeNull();
        }
Exemplo n.º 14
0
        public void GivenNoApprovalsAreWaitingIn(KeyValuePair <string, string> teamProject)
        {
            var service   = new VstsService();
            var approvals = service.GetApprovals(Config.Account, teamProject.Value, Config.Profile).Result;

            foreach (var approval in approvals)
            {
                service.ChangeApprovalStatus(Config.Account, teamProject.Value, Config.Profile, approval.Id, ApprovalStatus.Rejected, string.Empty).Wait();
            }
        }
Exemplo n.º 15
0
        public async Task GetApprovalTest()
        {
            var accountName = "myaccount";
            var projectName = "myproject";
            var service     = new VstsService();
            int id          = 1;

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetApproval(null, projectName, id, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetApproval(accountName, null, id, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await service.GetApproval(accountName, projectName, 0, this.token));

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

            using (ShimsContext.Create())
            {
                var expected = 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(new Profile()),
                    new ShimReleaseHttpClientBase(new ShimReleaseHttpClient2())
                    {
                        GetApprovalAsyncStringInt32NullableOfBooleanObjectCancellationToken
                            = (project, approvalId, includeHistory, objectState, cancellationToken) => Task.Run(
                                  () =>
                        {
                            expected.Id = approvalId;
                            return(expected);
                        },
                                  cancellationToken)
                    }.Instance
                });

                ReleaseApproval actual = await service.GetApproval(accountName, projectName, id, this.token);

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected, actual);
                Assert.AreEqual(id, actual.Id);
            }
        }
        public void GeStandards()
        {
            var httpHelperMock = new Mock <IVstsClient>();
            var mockLogger     = new Mock <ILog>(MockBehavior.Loose);

            httpHelperMock.Setup(m => m.Get(It.IsAny <string>())).Returns(AllIdsResponse);

            var vsts      = new VstsService(_appServiceSettings, new GitDynamicModelGenerator(), new JsonMetaDataConvert(null), httpHelperMock.Object, mockLogger.Object);
            var standards = vsts.GetStandards();

            Assert.AreEqual(5, standards.Count());
        }
        public void ShouldReturnNewDictionaryIfBlobsAreNull()
        {
            var httpHelperMock = new Mock <IVstsClient>();
            var mockLogger     = new Mock <ILog>(MockBehavior.Loose);

            httpHelperMock.Setup(m => m.Get(It.IsAny <string>())).Returns(AllIdsResponse);
            var vsts = new VstsService(_appServiceSettings, new GitDynamicModelGenerator(), null, httpHelperMock.Object, mockLogger.Object);

            httpHelperMock.Setup(m => m.Get(It.IsAny <string>())).Returns(string.Empty);
            var ids = vsts.GetAllFileContents(_appServiceSettings.VstsGitGetFilesUrl);

            Assert.AreEqual(ids, new Dictionary <string, string>());
        }
Exemplo n.º 18
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;
        }
        public void GetIds()
        {
            var httpHelperMock = new Mock <IVstsClient>();
            var mockLogger     = new Mock <ILog>(MockBehavior.Loose);

            httpHelperMock.Setup(m => m.Get(It.IsAny <string>())).Returns(AllIdsResponse);
            var vsts = new VstsService(_appServiceSettings, new GitDynamicModelGenerator(), null, httpHelperMock.Object, mockLogger.Object);
            var ids  = vsts.GetExistingStandardIds();

            Debug.Assert(ids != null, "ids != null");

            Assert.AreEqual(5, ids.Count());
            Assert.IsTrue(ids.Contains("13"));
            Assert.IsFalse(ids.Contains("14"));
        }
Exemplo n.º 20
0
        public async Task GetReleaseAsyncTest()
        {
            var accountName = "myaccount";
            var projectName = "myproject";
            var releaseId   = 99;
            var service     = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetReleaseAsync(null, projectName, releaseId, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetReleaseAsync(accountName, null, releaseId, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await service.GetReleaseAsync(accountName, projectName, -10, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetReleaseAsync(accountName, projectName, releaseId, null));
        }
Exemplo n.º 21
0
        public async Task GetProfileTest()
        {
            var service = new VstsService();

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

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

                InitializeConnectionShim(GetProfileHttpClient(expected));

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

                Assert.AreEqual(expected, actual);
            }
        }
Exemplo n.º 22
0
        public async Task GetProjectsTest()
        {
            var account = "anaccount";
            var service = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProjects(null, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProjects(account, null));

            using (ShimsContext.Create())
            {
                var accounts = new List <Account>
                {
                    new Account(Guid.Empty)
                    {
                        AccountName = "myaccount",
                        AccountUri  = new Uri("https://myaccount.visualstudio.com")
                    }
                };

                var expected = new List <TeamProjectReference>
                {
                    new TeamProjectReference
                    {
                        Id   = Guid.NewGuid(),
                        Name = "My Project",
                        Url  = "https://myaccount.visualstudio.com/my%20project"
                    }
                };

                var clients = new VssHttpClientBase[]
                {
                    GetAccountHttpClient(accounts), GetProjectHttpClient(expected), GetProfileHttpClient(new Profile())
                };

                InitializeConnectionShim(clients);

                // await Assert.ThrowsExceptionAsync<ArgumentOutOfRangeException>(async () => await service.GetProjects("someaccount", this.token));
                IEnumerable <TeamProjectReference> actual = await service.GetProjects(accounts[0].AccountName, this.token);

                expected.ShouldAllBeEquivalentTo(actual);
            }
        }
Exemplo n.º 23
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);
            }
        }
Exemplo n.º 24
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;
        }
Exemplo n.º 25
0
        public async Task GetReleaseDefinitionsAsyncTest()
        {
            var accountName = "myaccount";
            var projectName = "myproject";
            var service     = new VstsService();

            var expected = new List <ReleaseDefinition>();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync(null, projectName, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync(accountName, null, this.token));

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

            using (ShimsContext.Create())
            {
                var client = new ShimReleaseHttpClientBase(new ShimReleaseHttpClient2())
                {
                    GetReleaseDefinitionsAsyncStringStringNullableOfReleaseDefinitionExpandsStringStringNullableOfInt32StringNullableOfReleaseDefinitionQueryOrderStringNullableOfBooleanIEnumerableOfStringIEnumerableOfStringIEnumerableOfStringObjectCancellationToken
                        = (teamProject, s1, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, cancellationToken) =>
                          Task.Run(
                              () =>
                    {
                        teamProject.Should().Be(projectName);

                        return(expected);
                    },
                              cancellationToken)
                };

                InitializeConnectionShim(client);

                var actual = await service.GetReleaseDefinitionsAsync(accountName, projectName, this.token);

                actual.ShouldBeEquivalentTo(expected);
            }
        }
Exemplo n.º 26
0
        public async Task ChangeApprovalStatusTest()
        {
            var       account = "MyAccount";
            var       project = "MyProject";
            const int id      = 1234;
            var       comment = "My comment";
            var       status  = ApprovalStatus.Undefined;

            var profile = new VstsProfile
            {
                Id           = Guid.NewGuid(),
                Token        = this.token,
                EmailAddress = "*****@*****.**"
            };

            var service = new VstsService();

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.ChangeApprovalStatus(null, project, profile, id, status, comment));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.ChangeApprovalStatus(account, null, profile, id, status, comment));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.ChangeApprovalStatus(account, project, null, id, status, comment));

            using (ShimsContext.Create())
            {
                ReleaseApproval updatedApproval = null;

                InitializeConnectionShim(new VssHttpClientBase[]
                {
                    GetAccountHttpClient(new List <Account>
                    {
                        new Account(Guid.Empty)
                        {
                            AccountName = "myaccount",
                            AccountUri  = new Uri("https://myaccount.visualstudio.com")
                        }
                    }),
                    GetProfileHttpClient(new Profile()),
                    new ShimReleaseHttpClientBase(new ShimReleaseHttpClient2())
                    {
                        GetApprovalAsyncStringInt32NullableOfBooleanObjectCancellationToken = (p, i, includeHistory, userState, cancellationToken) => Task.Run(
                            () => new ReleaseApproval {
                            Id = i
                        },
                            cancellationToken),
                        UpdateReleaseApprovalAsyncReleaseApprovalStringInt32ObjectCancellationToken = (releaseApproval, p, i, userState, cancellationToken) => Task.Run(
                            delegate
                        {
                            Assert.AreEqual(project, p);
                            updatedApproval = releaseApproval;
                            return(updatedApproval);
                        },
                            cancellationToken)
                    }.Instance
                });

                await service.ChangeApprovalStatus(account, project, profile, 4, ApprovalStatus.Canceled, comment);

                Assert.IsNotNull(updatedApproval);
                Assert.AreEqual(4, updatedApproval.Id);
                Assert.AreEqual(ApprovalStatus.Canceled, updatedApproval.Status);
                Assert.AreEqual(comment, updatedApproval.Comments);
            }
        }
Exemplo n.º 27
0
        public async Task CreateReleaseAsyncTest()
        {
            var accountName = "myaccount";
            var projectName = "myproject";
            var service     = new VstsService();
            int id          = 1;

            var builds = new List <Build> {
                new Build {
                    Id = 12345, LastChangedDate = DateTime.Now
                }
            };

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.CreateReleaseAsync(null, projectName, id, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.CreateReleaseAsync(accountName, null, id, this.token));

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await service.CreateReleaseAsync(accountName, projectName, 0, this.token));

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

            using (ShimsContext.Create())
            {
                var shimBuildHttpClient = new ShimBuildHttpClient();

                shimBuildHttpClient.SendAsyncOf1HttpMethodGuidObjectApiResourceVersionHttpContentIEnumerableOfKeyValuePairOfStringStringObjectCancellationTokenFuncOfHttpResponseMessageCancellationTokenTaskOfM0 <IPagedList <Build> >((method, guid, arg3, apiResourceVersion, content, queryParams, arg7, cancellationToken, arg9) =>
                                                                                                                                                                                                                                        Task.Run(
                                                                                                                                                                                                                                            () => new PagedList <Build>(builds, string.Empty) as IPagedList <Build>,
                                                                                                                                                                                                                                            cancellationToken));

                InitializeConnectionShim(new VssHttpClientBase[]
                {
                    GetAccountHttpClient(new List <Account>
                    {
                        new Account(Guid.Empty)
                        {
                            AccountName = "myaccount",
                            AccountUri  = new Uri("https://myaccount.visualstudio.com")
                        }
                    }),
                    GetProfileHttpClient(new Profile()),
                    new ShimReleaseHttpClientBase(new ShimReleaseHttpClient2())
                    {
                        GetReleaseDefinitionAsyncStringInt32IEnumerableOfStringObjectCancellationToken = (project, definitionId, filters, userState, cancellationToken) => Task.Run(
                            () =>
                        {
                            return(new ReleaseDefinition()
                            {
                                Artifacts = new List <Artifact>
                                {
                                    new Artifact
                                    {
                                        IsPrimary = true,
                                        Alias = "mybuildartifcat",
                                        DefinitionReference = new Dictionary <string, ArtifactSourceReference>
                                        {
                                            { "definition", new ArtifactSourceReference {
                                                  Id = "1234"
                                              } }
                                        },
                                        Type = ArtifactTypes.BuildArtifactType
                                    }
                                }
                            });
                        }),
                        CreateReleaseAsyncReleaseStartMetadataStringObjectCancellationToken = (startMetadata, project, userState, cancellationToken) => Task.Run(
                            () =>
                        {
                            Assert.AreEqual(projectName, project);
                            return(new Release());
                        },
                            cancellationToken)
                    },
                    shimBuildHttpClient.Instance
                });

                await service.CreateReleaseAsync(accountName, projectName, id, this.token);
            }
        }
Exemplo n.º 28
0
        public async Task GetApprovalsTest()
        {
            var accountName = "MyAccount";
            var projectName = "MyProject";
            var profile     = new VstsProfile
            {
                Id           = Guid.NewGuid(),
                Token        = this.token,
                EmailAddress = "*****@*****.**"
            };
            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(new Profile()),
                    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
                });

                IList <ReleaseApproval> 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]);
                }
            }
        }