예제 #1
0
        public async Task List_Approvals()
        {
            var toBot = this.Fixture.CreateMessage();

            toBot.Text = "approvals";

            var profile = this.Fixture.CreateProfile();

            profile.Token.ExpiresIn = 0;
            var data = new UserData {
                Account = "anaccount", TeamProject = "anteamproject"
            };

            data.Profiles.Add(profile);

            var approval = new ReleaseApproval
            {
                Id = 1,
                ReleaseReference = new ReleaseShallowReference {
                    Name = "Release 1", Url = "urlToRelease"
                },
                ReleaseDefinitionReference = new ReleaseDefinitionShallowReference {
                    Name = "Release Definition 1"
                },
                ReleaseEnvironmentReference = new ReleaseEnvironmentShallowReference {
                    Name = "Development"
                }
            };
            var approvals = new List <ReleaseApproval> {
                approval
            };

            this.Fixture.UserData
            .Setup(ud => ud.TryGetValue("userData", out data))
            .Returns(true);
            this.Fixture.VstsService
            .Setup(s => s.GetApprovals(data.Account, data.TeamProject, profile))
            .ReturnsAsync(approvals);
            this.Fixture.AuthenticationService
            .Setup(a => a.GetToken(profile.Token))
            .ReturnsAsync(new OAuthToken());

            var target = new ApprovalsDialog(this.Fixture.AuthenticationService.Object, this.Fixture.VstsService.Object);

            await target.ApprovalsAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot));

            this.Fixture.DialogContext
            .Verify(c => c.PostAsync(It.IsAny <IMessageActivity>(), CancellationToken.None));

            this.Fixture.DialogContext
            .Verify(
                c => c.Wait(
                    It.Is <ResumeAfter <IMessageActivity> >(a => a.Method == target.GetType().GetMethod("ApproveOrRejectAsync"))));
        }
예제 #2
0
        public void Constructor()
        {
            var approval = new ReleaseApproval
            {
                ReleaseDefinitionReference = new ReleaseDefinitionShallowReference {
                    Id = 3, Name = "Release Def 3"
                },
                ReleaseEnvironmentReference = new ReleaseEnvironmentShallowReference {
                    Id = 2, Name = "DEV"
                },
                ReleaseReference = new ReleaseShallowReference {
                    Id = 1, Name = "release-1"
                }
            };

            var target = new ApprovalCard("account1", approval, "teamproject1");

            target.Subtitle.Should().Be("release-1");
            target.Text.Should().Be("DEV");
            target.Title.Should().Be("Release Def 3");
            target.Tap.Type.Should().Be(ActionTypes.OpenUrl);
            target.Tap.Value.Should().Be("https://account1.visualstudio.com/teamproject1/_release?definitionId=3&_a=release-summary&releaseId=1");
        }
예제 #3
0
        public void UpdateApproval_Succeeds()
        {
            VstsConfig vstsConfig = GetVstsConfig();

            IHttpClient      httpClient    = new HttpClient();
            ITokenRepository repository    = new JsonFileTokenRepository(new FileSystem());
            IAuthenticator   authenticator = new VstsOAuthAuthenticator(httpClient, repository, vstsConfig);

            File.Copy($"..//..//..//testdata//{TokenFilename}", fullTokenFilename, true);

            AuthenticationResult authResult = authenticator.Authenticate();

            File.Copy(fullTokenFilename, $"..//..//..//testdata//{TokenFilename}", true);

            this.sut = new VstsSyncReleaseClient(vstsConfig);

            ReleaseApproval result = this.sut.UpdateApproval(123, authResult.AccessToken);

            Assert.NotNull(result);
            Assert.Equal(ApprovalStatus.Approved, result.Status);

            SaveResultData(result, "../../../testdata/UpdateApproval.json");
        }
예제 #4
0
        public async Task List_Approvals()
        {
            var toBot = this.Fixture.CreateMessage();

            toBot.Text = "approvals";

            var account  = "anaccount";
            var approval = new ReleaseApproval
            {
                Id = 1,
                ReleaseReference = new ReleaseShallowReference {
                    Name = "Release 1", Url = "urlToRelease"
                },
                ReleaseDefinitionReference = new ReleaseDefinitionShallowReference {
                    Name = "Release Definition 1"
                },
                ReleaseEnvironmentReference = new ReleaseEnvironmentShallowReference {
                    Name = "Development"
                }
            };
            var approvals = new List <ReleaseApproval> {
                approval
            };
            var profile     = this.Fixture.CreateProfile();
            var teamProject = "anteamproject";

            var service = new Mock <IVstsService>();

            this.Fixture.UserData
            .Setup(ud => ud.TryGetValue("Account", out account))
            .Returns(true);
            this.Fixture.UserData
            .Setup(ud => ud.TryGetValue("Profile", out profile))
            .Returns(true);
            this.Fixture.UserData
            .Setup(ud => ud.TryGetValue("TeamProject", out teamProject))
            .Returns(true);
            service
            .Setup(s => s.GetApprovals(account, teamProject, profile))
            .ReturnsAsync(approvals);

            var applicationMock = new Mock <IVstsApplication>();

            applicationMock
            .Setup(application => application.AuthenticationService)
            .Returns(new Mock <IAuthenticationService>().Object);

            this.Fixture.VstsApplicationRegistry
            .Setup(registry => registry.GetVstsApplicationRegistration(It.IsAny <string>()))
            .Returns(applicationMock.Object);

            var target = new ApprovalsDialog(service.Object, this.Fixture.VstsApplicationRegistry.Object);

            await target.ApprovalsAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot));

            this.Fixture.DialogContext
            .Verify(c => c.PostAsync(It.IsAny <IMessageActivity>(), CancellationToken.None));

            this.Fixture.DialogContext
            .Verify(
                c => c.Wait(
                    It.Is <ResumeAfter <IMessageActivity> >(a => a.Method == target.GetType().GetMethod("ApproveOrRejectAsync"))));
        }