コード例 #1
0
        public async Task ImportTestAsync()
        {
            var issue = await client.ImportIssueAsync(new ImportIssueParams(projectId, "ImportTest", issueTypes.First().Id, IssuePriorityType.High)
            {
                Description   = "Description",
                CreatedUserId = anotherUser.Id,
                Created       = new DateTime(2017, 8, 1, 10, 5, 10, DateTimeKind.Utc),
            });

            Assert.AreEqual(issue.Description, "Description");
            Assert.AreEqual(issue.CreatedUser.Id, anotherUser.Id);
            Assert.AreEqual(issue.Created, new DateTime(2017, 8, 1, 10, 5, 10, DateTimeKind.Utc));

            await client.DeleteIssueAsync(issue.Id);
        }
コード例 #2
0
        public async Task WatchingTestAsync()
        {
            var issueTypes = await client.GetIssueTypesAsync(projectId);

            var issue = await client.CreateIssueAsync(new CreateIssueParams(projectId, "WatchingTestIssue", issueTypes.First().Id, IssuePriorityType.High));

            var watch = await client.AddWatchToIssueAsync(issue.Id, "Note");

            Assert.AreNotEqual(watch.Id, 0);
            Assert.AreEqual(watch.Issue.Id, issue.Id);
            Assert.AreEqual(watch.Note, "Note");
            Assert.IsNotNull(watch.Created);
            Assert.IsNotNull(watch.Updated);

            await client.MarkAsCheckedUserWatchesAsync(ownUser.Id);

            var watchGet = await client.GetWatchAsync(watch.Id);

            Assert.AreEqual(watchGet.Id, watch.Id);
            Assert.AreEqual(watchGet.Note, watch.Note);
            Assert.AreEqual(watchGet.Issue.Id, watch.Issue.Id);

            var watchUpdated = await client.UpdateWatchAsync(new UpdateWatchParams(watch.Id) { Note = "NoteUpdated" });

            Assert.AreEqual(watchUpdated.Id, watch.Id);
            Assert.AreEqual(watchUpdated.Note, "NoteUpdated");

            var watchDeleted = await client.DeleteWatchAsync(watch.Id);

            Assert.AreEqual(watchDeleted.Id, watchUpdated.Id);
            Assert.AreEqual(watchDeleted.Note, watchUpdated.Note);

            await client.DeleteIssueAsync(issue.Id);
        }
コード例 #3
0
ファイル: UserMethodsTest.cs プロジェクト: ats124/backlog4net
        public async Task GetUserActivitiesTestAsync()
        {
            var issueTypes = await client.GetIssueTypesAsync(projectId);

            var issue = await client.CreateIssueAsync(new CreateIssueParams(projectId, "GetUserActivitiesTest", issueTypes.First().Id, IssuePriorityType.High));

            await client.DeleteIssueAsync(issue.Id);

            var ownuser = await client.GetMyselfAsync();

            var activities = await client.GetUserActivitiesAsync(ownuser.Id, new ActivityQueryParams()
            {
                ActivityType = new[] { ActivityType.IssueCreated }
            });

            Assert.IsTrue(activities.Any(x => x is IssueCreatedActivity issueCreated && issueCreated.Content.Id == issue.Id));
        }
コード例 #4
0
ファイル: StarMethodsTest.cs プロジェクト: ats124/backlog4net
        public async Task AddStarToIssueAndCommentAsync()
        {
            var issueTypes = await client.GetIssueTypesAsync(projectId);

            var issue = await client.CreateIssueAsync(new CreateIssueParams(projectId, "StarTestIssue", issueTypes.First().Id, IssuePriorityType.High));

            await client.AddStarToIssueAsync(issue.Id);

            var issueComment = await client.AddIssueCommentAsync(new AddIssueCommentParams(issue.Id, "Comment"));

            await client.AddStarToCommentAsync(issueComment.Id);

            await client.DeleteIssueAsync(issue.Id);
        }
コード例 #5
0
        public async Task NotificationTestAsync()
        {
            var conf = new BacklogJpConfigure(generalConfig.SpaceKey);

            conf.ApiKey = generalConfig.ApiKey2;
            var client2 = new BacklogClientFactory(conf).NewClient();

            var issueTypes = await client.GetIssueTypesAsync(projectId);

            var issue = await client2.CreateIssueAsync(new CreateIssueParams(projectId, "NotificationTestIssue", issueTypes.First().Id, IssuePriorityType.High)
            {
                NotifiedUserIds = new[] { ownUser.Id }
            });

            var count = await client.GetNotificationCountAsync(new GetNotificationCountParams());

            Assert.IsTrue(count > 0);
            await client.GetNotificationCountAsync(new GetNotificationCountParams()
            {
                AlreadyRead = true
            });

            await client.GetNotificationCountAsync(new GetNotificationCountParams()
            {
                ResourceAlreadyRead = true
            });

            await client.GetNotificationsAsync(new QueryParams()
            {
                Count = 100, MinId = 1, MaxId = int.MaxValue, Order = Order.Desc
            });

            var notifications = await client.GetNotificationsAsync();

            Assert.IsTrue(notifications.Any(x => x?.Issue.Id == issue.Id));

            var notification = notifications.First(x => x?.Issue.Id == issue.Id);
            await client.MarkAsReadNotificationAsync(notification.Id);

            await client.ResetNotificationCountAsync();

            await client.DeleteIssueAsync(issue.Id);
        }
コード例 #6
0
        public async Task PullRequestTestAsync()
        {
            var issueTypes = await client.GetIssueTypesAsync(projectId);

            var issue1 = await client.CreateIssueAsync(new CreateIssueParams(projectId, "GetPullRequestTest1", issueTypes.First().Id, IssuePriorityType.High));

            var issue2 = await client.CreateIssueAsync(new CreateIssueParams(projectId, "GetPullRequestTest2", issueTypes.First().Id, IssuePriorityType.High));

            Attachment attachment1;

            using (var @params = new PostAttachmentParams("Test.txt",
                                                          new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes("TEST"))))
            {
                attachment1 = await client.PostAttachmentAsync(@params);
            }
            Attachment attachment2;

            using (var @params = new PostAttachmentParams("Test2.txt",
                                                          new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes("TEST2"))))
            {
                attachment2 = await client.PostAttachmentAsync(@params);
            }

            var pullRequest = await client.AddPullRequestAsync(new AddPullRequestParams(projectId, gitConfig.RepoName, "PRSummary", "PRDescription", gitConfig.Base, gitConfig.Branch)
            {
                AssigneeId      = assigneeUserIds[0],
                NotifiedUserIds = new[] { notifiedNumericUserIds[0], notifiedNumericUserIds[1] },
                IssueId         = issue1.Id,
                AttachmentIds   = new[] { attachment1.Id }
            });

            Assert.AreNotEqual(pullRequest.Id, 0L);
            Assert.AreEqual(pullRequest.Summary, "PRSummary");
            Assert.AreEqual(pullRequest.Description, "PRDescription");
            Assert.AreEqual(pullRequest.Base, gitConfig.Base);
            Assert.AreEqual(pullRequest.Branch, gitConfig.Branch);
            Assert.AreEqual(pullRequest.Assignee.Id, assigneeUserIds[0]);
            Assert.AreEqual(pullRequest.Issue.Id, issue1.Id);
            Assert.IsTrue(pullRequest.Attachments.Any(x => x.Name == attachment1.Name));

            var attachments = await client.GetPullRequestAttachmentsAsync(pullRequest.ProjectId, pullRequest.RepositoryId, pullRequest.Number);

            Assert.AreEqual(attachments[0].Id, pullRequest.Attachments[0].Id);

            using (var attachmentData = await client.DownloadPullRequestAttachmentAsync(pullRequest.ProjectId, pullRequest.RepositoryId, pullRequest.Number, attachments[0].Id))
                using (var memStream = new System.IO.MemoryStream())
                {
                    await attachmentData.Content.CopyToAsync(memStream);

                    var text = System.Text.Encoding.UTF8.GetString(memStream.ToArray());
                    Assert.AreEqual(text, "TEST");
                }

            var count = await client.GetPullRequestCountAsync(projectId, gitConfig.RepoName);

            Assert.IsTrue(count > 0);

            count = await client.GetPullRequestCountAsync(projectId, gitConfig.RepoName, new PullRequestQueryParams()
            {
                Count          = 10,
                Offset         = 1,
                AssigneeIds    = new[] { ownUser.Id },
                IssueIds       = new[] { ownUser.Id },
                CreatedUserIds = new[] { ownUser.Id },
                StatusType     = new[] { PullRequestStatusType.Open }
            });

            var pullRequests = await client.GetPullRequestsAsync(projectId, gitConfig.RepoName);

            Assert.IsTrue(pullRequests.Any(x => x.Id == pullRequest.Id));

            pullRequests = await client.GetPullRequestsAsync(projectId, gitConfig.RepoName, new PullRequestQueryParams()
            {
                Count          = 10,
                Offset         = 1,
                AssigneeIds    = new[] { ownUser.Id },
                IssueIds       = new[] { ownUser.Id },
                CreatedUserIds = new[] { ownUser.Id },
                StatusType     = new[] { PullRequestStatusType.Open }
            });

            var pullRequestUpdated = await client.UpdatePullRequestAsync(new UpdatePullRequestParams(projectId, gitConfig.RepoName, pullRequest.Number)
            {
                Summary         = "PRSummaryUpdated",
                Description     = "PRDescription",
                AssigneeId      = assigneeUserIds[1],
                NotifiedUserIds = new[] { notifiedNumericUserIds[1], notifiedNumericUserIds[2] },
                //IssueId = issue2.Id, デッドロックを引き起こしてしまう
            });

            Assert.AreNotEqual(pullRequestUpdated.Id, 0L);
            Assert.AreEqual(pullRequestUpdated.Summary, "PRSummaryUpdated");
            Assert.AreEqual(pullRequestUpdated.Description, "PRDescription");
            Assert.AreEqual(pullRequestUpdated.Assignee.Id, assigneeUserIds[1]);
            //Assert.AreEqual(pullRequestUpdated.Issue.Id, issue2.Id);

            var prComment = await client.AddPullRequestCommentAsync(new AddPullRequestCommentParams(pullRequest.ProjectId, pullRequest.RepositoryId, pullRequest.Number, "Test") { NotifiedUserIds = new[] { notifiedNumericUserIds[0] } });

            Assert.AreNotEqual(prComment.Id, 0L);
            Assert.AreEqual(prComment.Content, "Test");
            Assert.IsTrue(prComment.Notifications.Any(x => x.User.Id == notifiedNumericUserIds[0]));
            Assert.AreEqual(prComment.CreatedUser.Id, ownUser.Id);
            Assert.IsNotNull(prComment.Created);
            Assert.IsNotNull(prComment.Updated);

            count = await client.GetPullRequestCommentCountAsync(pullRequest.ProjectId, pullRequest.RepositoryId, pullRequest.Number);

            Assert.IsTrue(count > 0);

            var prComments = await client.GetPullRequestCommentsAsync(pullRequest.ProjectId, pullRequest.RepositoryId, pullRequest.Number, new QueryParams()
            {
                MinId = 0,
                MaxId = int.MaxValue,
                Count = 100,
                Order = Order.Asc,
            });

            Assert.IsTrue(prComments.Any(x => x.Id == prComment.Id));

            var prCommentUpdated = await client.UpdatePullRequestCommentAsync(new UpdatePullRequestCommentParams(pullRequest.ProjectId, pullRequest.RepositoryId, pullRequest.Number, prComment.Id, "TestUpdated"));

            Assert.AreEqual(prCommentUpdated.Id, prComment.Id);
            Assert.AreEqual(prCommentUpdated.Content, "TestUpdated");

            await client.DeleteIssueAsync(issue1.Id);

            await client.DeleteIssueAsync(issue2.Id);
        }