示例#1
0
        private async Task <IGitHubAppModelService> SubmitBuild(BuildDetails buildDetails, string owner,
                                                                string repository, string sha, LogAnalyzerConfiguration analyzerConfiguration = null)
        {
            var binaryLogProcessor = Substitute.For <IBinaryLogProcessor>();

            binaryLogProcessor.ProcessLog(null, null).ReturnsForAnyArgs(buildDetails);

            var id  = Faker.Random.Long();
            var url = Faker.Internet.Url();

            var gitHubAppModelService = Substitute.For <IGitHubAppModelService>();

            gitHubAppModelService.GetLogAnalyzerConfigurationAsync(null, null, null).ReturnsForAnyArgs(analyzerConfiguration);

            gitHubAppModelService.CreateCheckRunAsync(null, null, null, null, null, null, false, null, null, null)
            .ReturnsForAnyArgs(new CheckRun
            {
                Id  = id,
                Url = url
            });

            var msblocService = CreateTarget(binaryLogProcessor, gitHubAppModelService);

            var expectedCloneRoot  = Faker.System.DirectoryPath();
            var expectedBinLogPath = Faker.System.FilePath();

            var checkRun = await msblocService
                           .SubmitAsync(owner, repository, sha, expectedCloneRoot, expectedBinLogPath).ConfigureAwait(false);

            checkRun.Id.Should().Be(id);
            checkRun.Url.Should().Be(url);

            binaryLogProcessor.Received(1).ProcessLog(Arg.Is(expectedBinLogPath), Arg.Is(expectedCloneRoot));

            return(gitHubAppModelService);
        }
示例#2
0
        private Annotation[] CreateAnnotations(BuildDetails buildDetails, string repoOwner, string repoName, string sha, LogAnalyzerConfiguration logAnalyzerConfiguration)
        {
            var lookup = logAnalyzerConfiguration?.Rules?.ToLookup(rule => rule.Code);

            return(buildDetails.BuildMessages
                   .Select(buildMessage => CreateAnnotation(buildDetails, repoOwner, repoName, sha, buildMessage, lookup))
                   .Where(annotation => annotation != null)
                   .ToArray());
        }
示例#3
0
        public async Task SubmitBuildDetailsWithWarningIgnored()
        {
            var cloneRoot   = @"c:" + Faker.System.DirectoryPath().Replace("/", @"\");
            var projectPath = Path.Combine(cloneRoot, Faker.Lorem.Word());
            var projectFile = Path.Combine(projectPath, Faker.System.FileName("csproj"));

            var projectDetails  = new ProjectDetails(cloneRoot, projectFile);
            var projectCodeFile = Path.Combine(Faker.Lorem.Word(), Faker.System.FileName("cs"));

            projectDetails.AddItems(projectCodeFile);

            var solutionDetails = new SolutionDetails(cloneRoot)
            {
                projectDetails
            };

            var buildDetails  = new BuildDetails(solutionDetails);
            var lineNumber    = Faker.Random.Int(2);
            var endLineNumber = lineNumber + 1;
            var message       = Faker.Lorem.Sentence();
            var messageCode   = Faker.Lorem.Word();

            buildDetails.AddMessage(new BuildMessage(BuildMessageLevel.Warning, projectFile, projectCodeFile,
                                                     lineNumber, endLineNumber, message, messageCode));

            var filename   = Path.Combine(projectPath, projectCodeFile).Substring(cloneRoot.Length).Replace(@"\", "/").TrimStart('/');
            var owner      = Faker.Lorem.Word();
            var repository = Faker.Lorem.Word();
            var sha        = Faker.Random.String();

            var logAnalyzerConfiguration = new LogAnalyzerConfiguration
            {
                Rules = new List <LogAnalyzerRule>
                {
                    new LogAnalyzerRule
                    {
                        Code     = messageCode,
                        ReportAs = ReportAs.Ignore
                    }
                }
            };

            var gitHubAppModelService = await SubmitBuild(buildDetails, owner, repository, sha, logAnalyzerConfiguration);

            Received.InOrder(async() =>
            {
                await gitHubAppModelService.Received(1).GetLogAnalyzerConfigurationAsync(Arg.Is(owner),
                                                                                         Arg.Is(repository),
                                                                                         Arg.Is(sha));

                await gitHubAppModelService.Received(1).CreateCheckRunAsync(
                    Arg.Is(owner),
                    Arg.Is(repository),
                    Arg.Is(sha),
                    Arg.Is("MSBuildLog Analyzer"),
                    Arg.Is("MSBuildLog Analysis"),
                    Arg.Is(""),
                    Arg.Is(true),
                    Arg.Any <Annotation[]>(),
                    Arg.Any <DateTimeOffset>(),
                    Arg.Any <DateTimeOffset>());
            });

            var arguments   = gitHubAppModelService.ReceivedCalls().Skip(1).First().GetArguments().ToArray();
            var annotations = (Annotation[])arguments[7];

            annotations.Should().BeNull();
        }