public async Task Reject_Approval() { var toBot = this.Fixture.CreateMessage(); toBot.Text = "reject 1 a comment"; var account = "anaccount"; var profile = this.Fixture.CreateProfile(); var teamProject = "anteamproject"; 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); var target = new ApprovalsDialog(this.Fixture.VstsService.Object) { Account = account, Profile = profile, TeamProject = teamProject }; await target.ApproveOrRejectAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot)); this.Fixture.VstsService .Verify(s => s.ChangeApprovalStatus(account, teamProject, profile, 1, ApprovalStatus.Rejected, "a comment")); this.Fixture.DialogContext .Verify(c => c.PostAsync(It.IsAny <IMessageActivity>(), CancellationToken.None)); }
public async Task List_Approvals_Empty_List() { var toBot = this.Fixture.CreateMessage(); toBot.Text = "approvals"; var approvals = new List <ReleaseApproval>(); var profile = this.Fixture.CreateProfile(); var data = new UserData { Account = "anaccount", TeamProject = "anteamproject" }; data.Profiles.Add(profile); 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); 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.Done(It.IsAny <IMessageActivity>())); }
public async Task Reject_Approval_Without_Comment() { var toBot = this.Fixture.CreateMessage(); toBot.Text = "reject 1"; var account = "anaccount"; 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); var target = new ApprovalsDialog(service.Object) { Account = account, Profile = profile, TeamProject = teamProject }; await target.ApproveOrRejectAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot)); this.Fixture.DialogContext .Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text.Equals("Please provide a comment.", StringComparison.OrdinalIgnoreCase)), CancellationToken.None)); this.Fixture.DialogContext.Verify(c => c.Wait <IMessageActivity>(target.ChangeStatusAsync)); }
public async Task Constructor() { var target = new ApprovalsDialog(this.Fixture.VstsService.Object, this.Fixture.VstsApplicationRegistry.Object); Assert.IsNotNull(target); await Task.CompletedTask; }
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")))); }
public async Task Approval_Invalid_Message() { var toBot = this.Fixture.CreateMessage(); toBot.Text = "invalid"; var target = new ApprovalsDialog(this.Fixture.VstsService.Object); await target.ApproveOrRejectAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot)); this.Fixture.DialogContext.Verify(c => c.Fail(It.IsAny <UnknownCommandException>())); }
public async Task List_Approvals_Empty_List() { var toBot = this.Fixture.CreateMessage(); toBot.Text = "approvals"; var account = "anaccount"; var approvals = new List <ReleaseApproval>(); 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.Done(It.IsAny <IMessageActivity>())); }
public async Task List_Approvals_Null_Message() { var toBot = this.Fixture.CreateMessage(); toBot.Text = null; var profile = this.Fixture.CreateProfile(); var data = new UserData { Account = "anaccount", TeamProject = "anteamproject" }; data.Profiles.Add(profile); this.Fixture.UserData .Setup(ud => ud.TryGetValue("userData", out data)) .Returns(true); 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.Fail(It.IsAny <UnknownCommandException>())); }
public async Task Constructor() { var target = new ApprovalsDialog(this.Fixture.VstsService.Object); await Task.CompletedTask; }
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")))); }