Пример #1
0
        public async Task SetAnalysisState(long stepId, AnalysisResolution resolution, bool isAlreadyExists, int issueId, string title, string message, long suiteId, SystemUser user)
        {
            var suite = await _dbContext.TestSuites.FirstOrDefaultAsync(p => p.Id == suiteId);

            var gitClient = new GithubApiClient(user.GitHubAccount, user.GitHubToken);
            var step      = await GetStep(stepId);

            if (step == null)
            {
                throw new Exception("Can't find requested step!");
            }
            var newAnalysis = new StepAnalysisItem
            {
                AddedBy            = user,
                AnalysisResolution = resolution,
                Message            = message
            };

            switch (resolution)
            {
            case AnalysisResolution.CannotReproduce:
                if (isAlreadyExists)
                {
                    var existingIssue = gitClient.GetIssue(issueId);
                    if (existingIssue == null)
                    {
                        throw new Exception("Can't find requested issue id");
                    }
                    //gitClient.AddComment(issueId, message);
                    newAnalysis.GitHubId = issueId;
                }
                else
                {
                    var issue = gitClient.CreateNewIssue(title, message, suite.GitHubProjectId);
                    newAnalysis.GitHubId = issue.number;
                    await _testLabProvider.AddNewIssue(issue.number, suiteId, user);
                }
                break;

            case AnalysisResolution.KnownIssue:
                //gitClient.AddComment(issueId, message);
                newAnalysis.GitHubId = issueId;
                break;

            case AnalysisResolution.NewIssue:
                var newIssue = gitClient.CreateNewIssue(title, message, suite.GitHubProjectId);
                newAnalysis.GitHubId = newIssue.number;
                await _testLabProvider.AddNewIssue(newIssue.number, suiteId, user);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null);
            }
            step.StepAnalysisItem.Add(newAnalysis);
            await _dbContext.SaveChangesAsync();
        }
Пример #2
0
        public async Task <AnalysisResult> SetTestAnalysisState(
            SystemUser user,
            int testSuiteId,
            int status,
            long analysisId,
            int issueId,
            string title,
            string message,
            bool isAlreadyExists)
        {
            var analysis = await _dbContext.AnalysisResults
                           .Include(p => p.IdentifiedAt)
                           .ThenInclude(p => p.Test)
                           .FirstOrDefaultAsync(p => p.Id == analysisId);

            var analysisState = (AnalysisStatus)status;
            var gitClient     = new GithubApiClient(user.GitHubAccount, user.GitHubToken);
            var testSuite     = await _dbContext.TestSuites.FirstOrDefaultAsync(p => p.Id == testSuiteId);

            switch (analysisState)
            {
            case AnalysisStatus.NewIssue:
                var newIssue = gitClient.CreateNewIssue(title, message, testSuite.GitHubProjectId);
                analysis.GitHubId = newIssue.number;
                await _testLabProvider.AddNewIssue(newIssue.number, testSuite.Id, user);

                break;

            case AnalysisStatus.KnownIssue:
                var existingKnownIssue = gitClient.GetIssue(issueId);
                if (existingKnownIssue == null)
                {
                    throw new Exception("Can't find requested issue id");
                }
                analysis.GitHubId = issueId;
                break;

            case AnalysisStatus.CantReproduce:
                if (isAlreadyExists)
                {
                    var existingIssue = gitClient.GetIssue(issueId);
                    if (existingIssue == null)
                    {
                        throw new Exception("Can't find requested issue id");
                    }
                    analysis.GitHubId = issueId;
                }
                else
                {
                    var issue = gitClient.CreateNewIssue(title, message, testSuite.GitHubProjectId);
                    analysis.GitHubId = issue.number;
                    await _testLabProvider.AddNewIssue(issue.number, testSuite.Id, user);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            analysis.FinishedOn     = DateTime.Now;
            analysis.Message        = message;
            analysis.AnalysisStatus = analysisState;
            _dbContext.AnalysisResults.Update(analysis);

            //find the same steps within tests and apply the same analysis result
            if (analysisState == AnalysisStatus.NewIssue || analysisState == AnalysisStatus.KnownIssue)
            {
                var testName     = analysis.IdentifiedAt.Test.Name;
                var stepMessage  = analysis.IdentifiedAt.Message;
                var similarTests = await _dbContext.Tests
                                   .Include(p => p.Steps)
                                   .Where(p => p.Name == testName &&
                                          p.AnalysisResult == null &&
                                          p.Steps.Any(step => !step.IsPassed) &&
                                          p.Steps.Any(z => z.Message == stepMessage))
                                   .ToListAsync();

                foreach (var similarTest in similarTests)
                {
                    var newAnalysis = new AnalysisResult
                    {
                        AnalysisStatus = AnalysisStatus.KnownIssue,
                        By             = analysis.By,
                        FinishedOn     = DateTime.Now,
                        GitHubId       = analysis.GitHubId,
                        Message        = analysis.Message,
                        IdentifiedAt   = similarTest.Steps.FirstOrDefault(p => !p.IsPassed)
                    };
                    similarTest.AnalysisResult = newAnalysis;
                    _dbContext.Tests.Update(similarTest);
                }
            }

            await _dbContext.SaveChangesAsync();

            return(analysis);
        }