public void ShouldTestConsoleApp1Error()
        {
            var cloneRoot = @"C:\projects\testconsoleapp1\";

            var solutionDetails = new SolutionDetails(cloneRoot);

            var projectFile = @"C:\projects\testconsoleapp1\TestConsoleApp1\TestConsoleApp1.csproj";
            var project     = new ProjectDetails(cloneRoot, projectFile);

            project.AddItems("Program.cs", @"Properties\AssemblyInfo.cs");
            solutionDetails.Add(project);

            var parsedBinaryLog = ParseLogs("testconsoleapp1-1error.binlog", cloneRoot);

            parsedBinaryLog.BuildMessages.ToArray().Should().BeEquivalentTo(new[]
            {
                new BuildMessage(BuildMessageLevel.Error, projectFile, "Program.cs", 13, 13, "; expected", "CS1002"),
            });

            parsedBinaryLog.SolutionDetails.Should().BeEquivalentTo(solutionDetails,
                                                                    options => options.IncludingNestedObjects().IncludingProperties());

            parsedBinaryLog.SolutionDetails.Keys.ToArray().Should().BeEquivalentTo(
                cloneRoot + @"TestConsoleApp1\TestConsoleApp1.csproj");

            parsedBinaryLog.BuildMessages.Any(message => Path.IsPathRooted(message.File)).Should().BeFalse();
        }
        public void CreateSolutionMetric_Returns_Expected_Metric()
        {
            var    solutionPath          = "C:/Users/CustomerName/nopCommerce/src/NopCommerce.sln";
            var    encryptedSolutionPath = "462eb7f46af82bd5155ef9f28ca3f5f638f702a7423b105478fa3d9267a344da";
            var    solutionName          = "testSolution";
            var    encryptedSolutionName = "204ca3d6a6e14bf11f8e0992afc0276d262585065fe37ab595a5cba5bbbcb766";
            var    targetFramework       = "netcoreapp3.1";
            string version        = "testVersion";
            string source         = "test_cli";
            string tag            = "test";
            double analysisTime   = 0;
            var    date           = DateTime.Now;
            var    sha256hash     = SHA256.Create();
            var    solutionDetail = new SolutionDetails
            {
                SolutionName     = solutionName,
                SolutionFilePath = solutionPath,
                ApplicationGuid  = "test-application-guid",
                SolutionGuid     = "test-solution-guid",
                RepositoryUrl    = "https://github.com/test-project",
            };
            var actualSolutionMetric = TelemetryCollector.createSolutionMetric(solutionDetail, targetFramework, version, source, analysisTime, tag, sha256hash, date);

            Assert.AreEqual(actualSolutionMetric.solutionPath, encryptedSolutionPath);
            Assert.AreEqual(actualSolutionMetric.solutionName, encryptedSolutionName);
            Assert.AreEqual(actualSolutionMetric.ApplicationGuid, "test-application-guid");
            Assert.AreEqual(actualSolutionMetric.SolutionGuid, "test-solution-guid");
            Assert.AreEqual(actualSolutionMetric.RepositoryUrl, "https://github.com/test-project");
        }
        public void ShouldThrowWhenBuildPathOutisdeCloneRoot()
        {
            var solutionDetails = new SolutionDetails(@"C:\projects\testconsoleapp1\");

            var project = new ProjectDetails(@"C:\projects\testconsoleapp1\", @"C:\projects\testconsoleapp1\TestConsoleApp1.sln");

            solutionDetails.Add(project);

            var projectFile = @"C:\projects\testconsoleapp1\TestConsoleApp1\TestConsoleApp1.csproj";

            project = new ProjectDetails(@"C:\projects\testconsoleapp1\", projectFile);
            project.AddItems("Program.cs", @"Properties\AssemblyInfo.cs");
            solutionDetails.Add(project);

            var incorrectConsoleRoot = @"C:\projects\testconsoleapp2\";

            var binaryLogProcessingException = Assert.Throws <BinaryLogProcessingException>(() =>
            {
                var parsedBinaryLog = ParseLogs("testconsoleapp1-1warning.binlog", incorrectConsoleRoot);

                parsedBinaryLog.BuildMessages.ToArray().Should().BeEquivalentTo(new BuildMessage[0]);

                parsedBinaryLog.SolutionDetails.Should().BeEquivalentTo(solutionDetails, options => options.IncludingNestedObjects().IncludingProperties());
            });

            binaryLogProcessingException.Message.Should().MatchRegex($"^Error processing log. binLogPath:\'.*?testconsoleapp1-1warning.binlog\' cloneRoot:\'{incorrectConsoleRoot.Replace("\\", "\\\\")}\'$");
            binaryLogProcessingException.InnerException.Message.Should().Be($@"Project file path ""C:\projects\testconsoleapp1\TestConsoleApp1\TestConsoleApp1.csproj"" is not a subpath of ""{incorrectConsoleRoot}""");
        }
Ejemplo n.º 4
0
        public SolutionDetails <Direction> SolveMaze(string name, int algo)
        {
            SolutionDetails <Direction>    sol_det;
            Searcher <Position, Direction> s;

            if (Sol.TryGetValue(name, out sol_det))
            {
                return(sol_det);
            }
            Maze maze;

            Mazes.TryGetValue(name, out maze);
            if (maze == null)
            {
                return(null);
            }
            if (algo == BFS)
            {
                s = new BestFS();
            }
            else
            {
                s = new DFS();
            }

            sol_det = new SolutionDetails <Direction>(s.search(new SearchableMaze(maze)), s.getNumberOfNodesEvaluated());

            Sol.Add(name, sol_det);
            return(sol_det);
        }
        public void ShouldThrowWhenBuildPathOutisdeCloneRoot()
        {
            var solutionDetails = new SolutionDetails(@"C:\projects\testconsoleapp1\");

            var project = new ProjectDetails(@"C:\projects\testconsoleapp1\", @"C:\projects\testconsoleapp1\TestConsoleApp1.sln");

            solutionDetails.Add(project);

            var projectFile = @"C:\projects\testconsoleapp1\TestConsoleApp1\TestConsoleApp1.csproj";

            project = new ProjectDetails(@"C:\projects\testconsoleapp1\", projectFile);
            project.AddItems("Program.cs", @"Properties\AssemblyInfo.cs");
            solutionDetails.Add(project);

            var projectDetailsException = Assert.Throws <ProjectDetailsException>(() =>
            {
                var parsedBinaryLog = ParseLogs("testconsoleapp1-1warning.binlog", @"C:\projects\testconsoleapp2\");

                parsedBinaryLog.BuildMessages.ToArray().Should().BeEquivalentTo(new BuildMessage[0]);

                parsedBinaryLog.SolutionDetails.Should().BeEquivalentTo(solutionDetails, options => options.IncludingNestedObjects().IncludingProperties());
            });

            projectDetailsException.Message.Should().Be(@"Project file path ""C:\projects\testconsoleapp1\TestConsoleApp1\TestConsoleApp1.csproj"" is not a subpath of ""C:\projects\testconsoleapp2\""");
        }
        protected override void Execute(CodeActivityContext context)
        {
            SolutionDetails details = SolutionDetails.Create(SolutionFile.Get(context));

            details.SolutionVersion = SolutionVersion.Get(context);

            details.Save();
        }
Ejemplo n.º 7
0
        public string Execute(string[] args, TcpClient client)
        {
            string name = args[0];
            int    algo = int.Parse(args[1]);

            SolutionDetails sol = model.SolveMaze(name, algo);

            return(Sol.ToJSON());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// reads parameters for the solve command from user input
        /// </summary>
        /// <returns>solve maze parameters</returns>
        public string GetParamsForSolveMaze()
        {
            SolutionDetails sd = new SolutionDetails();

            sd.ShowDialog();
            string mazeName = sd.MazeName;
            string algo     = sd.Algorithm;

            return(mazeName + " " + algo);
        }
Ejemplo n.º 9
0
        //public string Execute(string[] args, TcpClient client)
        public string Execute(string[] args, ICClientHandler client)
        {
            string name = args[0];
            int    algo = int.Parse(args[1]);
            SolutionDetails <Direction> sol = model.SolveMaze(name, algo);
            PasrseSolve p = new PasrseSolve(name, sol.solv.getSolve(), sol.NodesEvaluated);

            Console.WriteLine(JsonConvert.SerializeObject(p));
            return(JsonConvert.SerializeObject(p));
        }
        public void UpdateSolutionPackageType_Managed_Test()
        {
            SolutionDetails solutionDetails = new SolutionDetails();

            solutionDetails.FoundSolutionDetails = true;
            solutionDetails.PackageType          = SolutionPackageType.Managed;
            solutionDetails.ProjectFilePath      = @"C:\PowerMeUpExamples\TestNewDesign\Solution\TestingSolution\TestingSolution.cdsproj";
#if DEBUG
            SolutionDetailsHelper helper = new SolutionDetailsHelper();
            helper.UpdateSolutionPackageType(solutionDetails);
#endif
        }
        public void ShouldTestConsoleApp1CodeAnalysis()
        {
            var cloneRoot = @"C:\projects\testconsoleapp1\";

            var solutionDetails = new SolutionDetails(cloneRoot);

            var projectFile = @"C:\projects\testconsoleapp1\TestConsoleApp1\TestConsoleApp1.csproj";
            var project     = new ProjectDetails(cloneRoot, projectFile);

            project.AddItems("Program.cs", @"Properties\AssemblyInfo.cs");
            solutionDetails.Add(project);

            var parsedBinaryLog = ParseLogs("testconsoleapp1-codeanalysis.binlog", cloneRoot);

            parsedBinaryLog.BuildMessages.Any(message => Path.IsPathRooted(message.File)).Should().BeFalse();
        }
Ejemplo n.º 12
0
 public AddSolution(int stageId, int decisionId
                    , int institutionId, DateTime decisionDate, string decisionNumber,
                    ConfiscationDetails confiscationDetails,
                    RecoveryDetails recoveryDetails,
                    SolutionDetails solutionDetails,
                    SequesterDetails sequesterDetails) : base(stageId,
                                                              decisionId,
                                                              institutionId,
                                                              decisionDate,
                                                              decisionNumber,
                                                              confiscationDetails,
                                                              recoveryDetails,
                                                              solutionDetails,
                                                              sequesterDetails)
 {
 }
Ejemplo n.º 13
0
 public AddSolutionRequest(int stageId, int decisionId
                           , int institutionId, DateTime decisionDate, string decisionNumber,
                           ConfiscationDetails confiscationDetails,
                           RecoveryDetails recoveryDetails,
                           SolutionDetails solutionDetails,
                           SequesterDetails sequesterDetails)
 {
     StageId             = stageId;
     DecisionId          = decisionId;
     InstitutionId       = institutionId;
     DecisionDate        = decisionDate;
     DecisionNumber      = decisionNumber;
     ConfiscationDetails = confiscationDetails;
     RecoveryDetails     = recoveryDetails;
     SolutionDetails     = solutionDetails;
     SequesterDetails    = sequesterDetails;
 }
Ejemplo n.º 14
0
 public static SolutionMetrics createSolutionMetric(SolutionDetails solutionDetail, string targetFramework, string version, string source, double analysisTime, string tag, SHA256 sha256hash, DateTime date)
 {
     return(new SolutionMetrics
     {
         metricsType = MetricsType.solution,
         version = version,
         portingAssistantSource = source,
         tag = tag,
         targetFramework = targetFramework,
         timeStamp = date.ToString("MM/dd/yyyy HH:mm"),
         solutionName = GetHash(sha256hash, solutionDetail.SolutionName),
         solutionPath = GetHash(sha256hash, solutionDetail.SolutionFilePath),
         ApplicationGuid = solutionDetail.ApplicationGuid,
         SolutionGuid = solutionDetail.SolutionGuid,
         RepositoryUrl = solutionDetail.RepositoryUrl,
         analysisTime = analysisTime,
     });
 }
Ejemplo n.º 15
0
        private static async Task <SolutionAnalysisResult> AnalyzeSolutionGenerator(IPortingAssistantClient portingAssistantClient, string solutionPath, AnalyzerSettings solutionSettings)
        {
            List <ProjectAnalysisResult> projectAnalysisResults = new List <ProjectAnalysisResult>();
            var failedProjects = new List <string>();
            var projectAnalysisResultEnumerator = portingAssistantClient.AnalyzeSolutionGeneratorAsync(solutionPath, solutionSettings).GetAsyncEnumerator();

            while (await projectAnalysisResultEnumerator.MoveNextAsync().ConfigureAwait(false))
            {
                var result = projectAnalysisResultEnumerator.Current;
                projectAnalysisResults.Add(result);

                if (result.IsBuildFailed)
                {
                    failedProjects.Add(result.ProjectFilePath);
                }
            }


            var solutionDetails = new SolutionDetails
            {
                SolutionName     = Path.GetFileNameWithoutExtension(solutionPath),
                SolutionFilePath = solutionPath,
                Projects         = projectAnalysisResults.ConvertAll(p => new ProjectDetails
                {
                    PackageReferences = p.PackageReferences,
                    ProjectFilePath   = p.ProjectFilePath,
                    ProjectGuid       = p.ProjectGuid,
                    ProjectName       = p.ProjectName,
                    ProjectReferences = p.ProjectReferences,
                    ProjectType       = p.ProjectType,
                    TargetFrameworks  = p.TargetFrameworks,
                    IsBuildFailed     = p.IsBuildFailed
                }),

                FailedProjects = failedProjects
            };

            return(new SolutionAnalysisResult
            {
                FailedProjects = failedProjects,
                SolutionDetails = solutionDetails,
                ProjectAnalysisResults = projectAnalysisResults
            });
        }
Ejemplo n.º 16
0
        public static void GenerateLicenseDependencies(SolutionDetails solutionDetails, string filePath)
        {
            using (var writer = new StreamWriter(filePath, false, Encoding.UTF8))
            {
                if (!solutionDetails.Projects.Any(q => q.Packages.Any()))
                {
                    writer.WriteLine("No packages found");
                    return;
                }

                writer.WriteLine("# LICENSE DEPENDENCIES");
                writer.WriteLine();

                foreach (var project in solutionDetails.Projects)
                {
                    writer.WriteLine($"## Project {project.Config.ProjectName}");
                    writer.WriteLine();
                    writer.WriteLine("|Package Name|Type|Version|License url|");
                    writer.WriteLine("|---|---|---|---|");

                    foreach (var package in project.Packages.OrderBy(q => q.Name).ThenBy(q => q.PackageType))
                    {
                        var license        = package.Metadata?.LicenseUrl?.ToString();
                        var licenseUrlData = "n/a";

                        if (!string.IsNullOrEmpty(license))
                        {
                            licenseUrlData = $"[{license}]({license})";
                        }


                        writer.WriteLine($"|{package.Name}|{package.PackageType}|{package.Version}|{licenseUrlData}|");
                    }

                    writer.WriteLine();
                }

                writer.WriteLine("---");
                writer.WriteLine("Made with ❤️ by [NuGet Helper](https://github.com/RustamIrzaev/NuGetHelper)");
            }
        }
        public void ShouldMSBLOC()
        {
            var cloneRoot = @"C:\projects\msbuildlogoctokitchecker\";

            var solutionDetails = new SolutionDetails(cloneRoot);

            var project = new ProjectDetails(cloneRoot, @"C:\projects\msbuildlogoctokitchecker\MSBLOC.Core\MSBLOC.Core.csproj");

            solutionDetails.Add(project);

            project = new ProjectDetails(cloneRoot, @"C:\projects\msbuildlogoctokitchecker\MSBLOC.Web\MSBLOC.Web.csproj");
            solutionDetails.Add(project);

            project = new ProjectDetails(cloneRoot, @"C:\projects\msbuildlogoctokitchecker\MSBLOC.Web.Tests\MSBLOC.Web.Tests.csproj");
            solutionDetails.Add(project);

            project = new ProjectDetails(cloneRoot, @"C:\projects\msbuildlogoctokitchecker\MSBLOC.Core.Tests\MSBLOC.Core.Tests.csproj");
            solutionDetails.Add(project);

            project = new ProjectDetails(cloneRoot, @"C:\projects\msbuildlogoctokitchecker\MSBLOC.Infrastructure\MSBLOC.Infrastructure.csproj");
            solutionDetails.Add(project);

            project = new ProjectDetails(cloneRoot, @"C:\projects\msbuildlogoctokitchecker\MSBLOC.Core.IntegrationTests\MSBLOC.Core.IntegrationTests.csproj");
            solutionDetails.Add(project);

            var parsedBinaryLog = ParseLogs("msbloc.binlog", cloneRoot);

            parsedBinaryLog.SolutionDetails.Should().BeEquivalentTo(solutionDetails,
                                                                    options => options.IncludingNestedObjects().IncludingProperties()
                                                                    .Excluding(info => info.SelectedMemberInfo.Name == "Paths"));

            parsedBinaryLog.SolutionDetails.GetProjectItemPath(cloneRoot + @"MSBLOC.Core.Tests\MSBLOC.Core.Tests.csproj", @"Services\GitHubAppModelServiceTests.cs")
            .Should().NotBeNull();

            var list = parsedBinaryLog.BuildMessages
                       .GroupBy(message => (message.ProjectFile, message.Code, message.File, message.LineNumber))
                       .ToList();

            parsedBinaryLog.BuildMessages.Count.Should().Be(list.Count);
        }
        public void UpdateSolutionPackageType(SolutionDetails solutionDetails)
        {
            XmlDocument solutionXMLFile = new XmlDocument();

            solutionXMLFile.Load(solutionDetails.ProjectFilePath);

            var  childNodes = solutionXMLFile["Project"].ChildNodes;
            bool nodeFound  = false;

            foreach (XmlNode node in childNodes)
            {
                if (node.Name == "PropertyGroup")
                {
                    var pgChildnodes = node.ChildNodes;
                    foreach (XmlNode pgChild in pgChildnodes)
                    {
                        if (pgChild.Name == "SolutionPackageType")
                        {
                            pgChild.InnerText = solutionDetails.PackageType.ToString();
                            nodeFound         = true;
                        }
                    }
                }
            }

            if (!nodeFound)
            {
                XmlNode parentNode = solutionXMLFile["Project"];

                XmlNode newPGNode = parentNode.AppendChild(solutionXMLFile.CreateNode(XmlNodeType.Element, "PropertyGroup", parentNode.NamespaceURI));

                XmlNode newSPTNode = solutionXMLFile.CreateNode(XmlNodeType.Element, "SolutionPackageType", parentNode.NamespaceURI);
                newSPTNode.InnerText = solutionDetails.PackageType.ToString();
                newPGNode.AppendChild(newSPTNode);
            }

            solutionXMLFile.Save(solutionDetails.ProjectFilePath);
        }
        public async Task <SolutionAnalysisResult> AnalyzeSolutionAsync(string solutionFilePath, AnalyzerSettings settings)
        {
            try
            {
                var solution       = SolutionFile.Parse(solutionFilePath);
                var failedProjects = new List <string>();

                var projects = solution.ProjectsInOrder.Where(p =>
                                                              (p.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat ||
                                                               p.ProjectType == SolutionProjectType.WebProject) &&
                                                              (settings.IgnoreProjects?.Contains(p.AbsolutePath) != true))
                               .Select(p => p.AbsolutePath)
                               .ToList();

                var targetFramework = settings.TargetFramework ?? "netcoreapp3.1";

                var projectAnalysisResultsDict = await _analysisHandler.AnalyzeSolution(solutionFilePath, projects, targetFramework);

                var projectAnalysisResults = projects.Select(p =>
                {
                    var projectAnalysisResult = projectAnalysisResultsDict.GetValueOrDefault(p, null);
                    if (projectAnalysisResult != null)
                    {
                        if (projectAnalysisResult.IsBuildFailed)
                        {
                            failedProjects.Add(p);
                        }
                        return(projectAnalysisResult);
                    }
                    return(null);
                }).Where(p => p != null).ToList();

                var solutionDetails = new SolutionDetails
                {
                    SolutionName     = Path.GetFileNameWithoutExtension(solutionFilePath),
                    SolutionFilePath = solutionFilePath,
                    Projects         = projectAnalysisResults.ConvertAll(p => new ProjectDetails
                    {
                        PackageReferences = p.PackageReferences,
                        ProjectFilePath   = p.ProjectFilePath,
                        ProjectGuid       = p.ProjectGuid,
                        ProjectName       = p.ProjectName,
                        ProjectReferences = p.ProjectReferences,
                        ProjectType       = p.ProjectType,
                        TargetFrameworks  = p.TargetFrameworks,
                        IsBuildFailed     = p.IsBuildFailed
                    }),

                    FailedProjects = failedProjects
                };


                return(new SolutionAnalysisResult
                {
                    FailedProjects = failedProjects,
                    SolutionDetails = solutionDetails,
                    ProjectAnalysisResults = projectAnalysisResults
                });
            }
            catch (Exception ex)
            {
                throw new PortingAssistantException($"Cannot Analyze solution {solutionFilePath}", ex);
            }
        }
        /// <inheritdoc />
        public BuildDetails ProcessLog(string binLogPath, string cloneRoot)
        {
            try
            {
                var binLogReader = new StructuredLogger::Microsoft.Build.Logging.BinaryLogReplayEventSource();

                var solutionDetails = new SolutionDetails(cloneRoot);
                var buildDetails    = new BuildDetails(solutionDetails);
                var buildMessages   = new List <BuildMessage>();

                foreach (var record in binLogReader.ReadRecords(binLogPath))
                {
                    var buildEventArgs = record.Args;
                    if (buildEventArgs is ProjectStartedEventArgs startedEventArgs)
                    {
                        var notPresent = !solutionDetails.ContainsKey(startedEventArgs.ProjectFile);

                        var items = startedEventArgs.Items?.Cast <DictionaryEntry>()
                                    .Where(entry => (string)entry.Key == "Compile")
                                    .Select(entry => entry.Value)
                                    .Cast <ITaskItem>()
                                    .Select(item => item.ItemSpec)
                                    .ToArray();

                        if (notPresent && (items?.Any() ?? false))
                        {
                            var projectDetails = new ProjectDetails(cloneRoot, startedEventArgs.ProjectFile);
                            solutionDetails.Add(projectDetails);

                            if (items != null)
                            {
                                projectDetails.AddItems(items);
                            }
                        }
                    }

                    BuildMessage buildMessage = null;
                    if (buildEventArgs is BuildWarningEventArgs buildWarning)
                    {
                        buildMessage = CreateBuildMessage(
                            BuildMessageLevel.Warning,
                            buildWarning.ProjectFile,
                            buildWarning.File,
                            buildWarning.LineNumber,
                            buildWarning.EndLineNumber == 0 ? buildWarning.LineNumber : buildWarning.EndLineNumber,
                            buildWarning.Message,
                            buildWarning.Code,
                            buildDetails);
                    }

                    if (buildEventArgs is BuildErrorEventArgs buildError)
                    {
                        buildMessage = CreateBuildMessage(
                            BuildMessageLevel.Error,
                            buildError.ProjectFile,
                            buildError.File,
                            buildError.LineNumber,
                            buildError.EndLineNumber == 0 ? buildError.LineNumber : buildError.EndLineNumber,
                            buildError.Message,
                            buildError.Code,
                            buildDetails);
                    }

                    if (buildMessage != null)
                    {
                        buildMessages.Add(buildMessage);
                    }
                }

                var distinctBy = buildMessages
                                 .DistinctBy(message => (message.ProjectFile, message.MessageLevel, message.File, message.Code, message.Message, message.LineNumber, message.EndLineNumber))
                                 .ToArray();

                buildDetails.AddMessages(distinctBy);

                return(buildDetails);
            }
            catch (Exception ex)
            {
                throw new BinaryLogProcessingException($"Error processing log. binLogPath:'{binLogPath}' cloneRoot:'{cloneRoot}'", ex);
            }
        }
Ejemplo n.º 21
0
        public async Task <SolutionAnalysisResult> AnalyzeSolutionAsync(string solutionFilePath, AnalyzerSettings settings)
        {
            try
            {
                var solution       = SolutionFile.Parse(solutionFilePath);
                var failedProjects = new List <string>();

                var projects = ProjectsToAnalyze(solutionFilePath, settings);

                var targetFramework = settings.TargetFramework ?? DEFAULT_TARGET;

                Dictionary <string, ProjectAnalysisResult> projectAnalysisResultsDict;

                if (settings.ContiniousEnabled)
                {
                    projectAnalysisResultsDict = await _analysisHandler.AnalyzeSolutionIncremental(solutionFilePath, projects, targetFramework);
                }
                else
                {
                    projectAnalysisResultsDict = await _analysisHandler.AnalyzeSolution(solutionFilePath, projects, targetFramework);
                }

                var projectAnalysisResults = projects.Select(p =>
                {
                    var projectAnalysisResult = projectAnalysisResultsDict.GetValueOrDefault(p, null);
                    if (projectAnalysisResult != null)
                    {
                        if (projectAnalysisResult.IsBuildFailed)
                        {
                            failedProjects.Add(p);
                        }
                        return(projectAnalysisResult);
                    }
                    return(null);
                }).Where(p => p != null).ToList();

                string solutionGuid    = FileParser.SolutionFileParser.getSolutionGuid(solutionFilePath);
                var    solutionDetails = new SolutionDetails
                {
                    SolutionName     = Path.GetFileNameWithoutExtension(solutionFilePath),
                    SolutionFilePath = solutionFilePath,
                    SolutionGuid     = solutionGuid,
                    RepositoryUrl    = FileParser.GitConfigFileParser.getGitRepositoryUrl(
                        FileParser.GitConfigFileParser.getGitRepositoryRootPath(solutionFilePath)),
                    ApplicationGuid = solutionGuid ?? Utils.HashUtils.GenerateGuid(
                        projectAnalysisResults.Select(p => p.ProjectGuid).ToList()),
                    Projects = projectAnalysisResults.ConvertAll(p => new ProjectDetails
                    {
                        PackageReferences = p.PackageReferences,
                        ProjectFilePath   = p.ProjectFilePath,
                        ProjectGuid       = p.ProjectGuid,
                        FeatureType       = p.FeatureType,
                        ProjectName       = p.ProjectName,
                        ProjectReferences = p.ProjectReferences,
                        ProjectType       = p.ProjectType,
                        TargetFrameworks  = p.TargetFrameworks,
                        IsBuildFailed     = p.IsBuildFailed
                    }),

                    FailedProjects = failedProjects
                };


                return(new SolutionAnalysisResult
                {
                    FailedProjects = failedProjects,
                    SolutionDetails = solutionDetails,
                    ProjectAnalysisResults = projectAnalysisResults
                });
            }
            catch (Exception ex)
            {
                throw new PortingAssistantException($"Cannot Analyze solution {solutionFilePath}", ex);
            }
        }
Ejemplo n.º 22
0
        public async Task Submit100To150BuildDetails()
        {
            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 solutionDetails = new SolutionDetails(cloneRoot)
            {
                projectDetails
            };
            var buildDetails = new BuildDetails(solutionDetails);

            var projectCodeFiles = GenerateFileNames().Distinct().Take(Faker.Random.Int(200, 300)).ToArray();

            projectDetails.AddItems(projectCodeFiles);

            foreach (var projectCodeFile in Faker.PickRandom(projectCodeFiles, Faker.Random.Int(101, 150)))
            {
                buildDetails.AddMessage(new BuildMessage(BuildMessageLevel.Warning, projectFile, projectCodeFile,
                                                         Faker.Random.Int(2), Faker.Random.Int(2), Faker.Lorem.Sentence(), Faker.Lorem.Word()));
            }

            buildDetails.BuildMessages.Count.Should().BeGreaterThan(100);
            buildDetails.BuildMessages.Count.Should().BeLessOrEqualTo(150);

            _logger.LogInformation("Build Message Count: {0}", buildDetails.BuildMessages.Count);

            var owner      = Faker.Lorem.Word();
            var repository = Faker.Lorem.Word();
            var sha        = Faker.Random.String();

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

            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.Is <Annotation[]>(annotations => annotations.Length == 50),
                    Arg.Any <DateTimeOffset>(),
                    Arg.Any <DateTimeOffset>());

                await gitHubAppModelService.Received(1)
                .UpdateCheckRunAsync(
                    Arg.Any <long>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Is <Annotation[]>(annotations => annotations.Length == 50),
                    Arg.Any <DateTimeOffset?>(),
                    Arg.Any <DateTimeOffset?>());

                await gitHubAppModelService.Received(1)
                .UpdateCheckRunAsync(
                    Arg.Any <long>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Is <Annotation[]>(annotations => annotations.Length == buildDetails.BuildMessages.Count - 100),
                    Arg.Any <DateTimeOffset?>(),
                    Arg.Any <DateTimeOffset?>());
            });
        }
Ejemplo n.º 23
0
        public async Task SubmitBuildDetailsWithError()
        {
            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.Error, 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 gitHubAppModelService = await SubmitBuild(buildDetails, owner, repository, sha);

            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(false),
                    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().BeEquivalentTo(new Annotation(
                                                    filename,
                                                    CheckWarningLevel.Failure,
                                                    messageCode,
                                                    messageCode + ": " + message,
                                                    lineNumber,
                                                    endLineNumber));
        }