Пример #1
0
        public async Task UpdateTestsUser(int userId, int testId, bool isAssignee, SystemUser who)
        {
            var testToUpdate = await GetTest(testId);

            var user = await _dbContext.SystemUsers.FirstOrDefaultAsync(p => p.Id == userId);

            if (isAssignee)
            {
                testToUpdate.Assignee = user;
                testToUpdate.HistoryItems.Add(new TestCaseHistory
                {
                    Author  = who,
                    Message = $@"changed assignee to <strong>{user.Name}</strong>"
                });
                if (!string.IsNullOrEmpty(user.GitHubToken))
                {
                    var client = new GithubApiClient(user.GitHubAccount, user.GitHubToken);
                    client.AddAssignees(testToUpdate.GitHubId, new [] { user.GitHubAccount });
                }
            }
            else
            {
                testToUpdate.Reviewer = user;
                testToUpdate.HistoryItems.Add(new TestCaseHistory
                {
                    Author  = who,
                    Message = $@"changed reviewer to <strong>{user.Name}</strong>"
                });
                if (!string.IsNullOrEmpty(user.GitHubToken) && testToUpdate.PullRequestId != 0)
                {
                    var client = new GithubApiClient(user.GitHubAccount, user.GitHubToken);
                    client.AddReviewer(testToUpdate.PullRequestId, new [] { user.GitHubAccount });
                }
            }

            await UpdateTest(testToUpdate);
        }
Пример #2
0
        public async Task <IActionResult> SwitchState(int id, int statusId, string returnurl)
        {
            var test = await _testLabProvider.GetTest(id);

            var who = await _usersProvider.GetUser(User.GetUserId());

            var statusType  = (Status)statusId;
            var historyItem = new TestCaseHistory
            {
                Author  = who,
                Message = $@"changed status from <strong>{test.Status.GetDescription()}</strong> to <strong>{statusType.GetDescription()}</strong>"
            };

            switch (statusType)
            {
            case Status.New:
                break;

            case Status.ReadyForAutomation:
                break;

            case Status.InProgress:
                test.Assignee  = who;
                test.StartedOn = DateTime.Now;
                if (!string.IsNullOrEmpty(who.GitHubToken))
                {
                    var gitClient = new GithubApiClient(who.GitHubAccount, who.GitHubToken);
                    gitClient.AddAssignees(test.GitHubId, new [] { who.GitHubAccount });
                }
                break;

            case Status.ToCrossPlatform:
                break;

            case Status.ReadyForReview:
                return(RedirectToAction("SubmitForReview", "TestLab", new { @id = id }));

            case Status.ReviewStarted:
                test.Reviewer = who;
                if (!string.IsNullOrEmpty(who.GitHubToken))
                {
                    var gitClient = new GithubApiClient(who.GitHubAccount, who.GitHubToken);
                    gitClient.AddReviewer(test.PullRequestId, new [] { who.GitHubAccount });
                }
                break;

            case Status.CannotAutomate:
                break;

            case Status.Finished:
                test.FinishedOn = DateTime.Now;
                break;

            case Status.ChangesRequested:
                return(RedirectToAction("RequestChange", "TestLab", new { @id = id }));

            case Status.Fixed:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            test.Status = statusType;
            test.HistoryItems.Add(historyItem);
            await _testLabProvider.UpdateTest(test);

            if (string.IsNullOrEmpty(returnurl))
            {
                return(Redirect(Url.RouteUrl(new { controller = "TestLab", action = "TestSuite" }) + "/" +
                                test.TestSuite.Id + "#test-" + test.Id));
            }
            else
            {
                return(LocalRedirect(returnurl));
            }
        }