Пример #1
0
        public TestSolutionAnalysis AnalyzeSolution(string solutionName, string tempDir, string downloadLocation, string version, bool skipCopy = false)
        {
            TestSolutionAnalysis result = new TestSolutionAnalysis();

            var sourceDir   = Directory.GetParent(Directory.EnumerateFiles(downloadLocation, solutionName, SearchOption.AllDirectories).FirstOrDefault());
            var solutionDir = Path.Combine(tempDir, version);

            if (!skipCopy)
            {
                CopyDirectory(sourceDir, new DirectoryInfo(solutionDir));
            }
            else
            {
                solutionDir = tempDir;
            }
            string solutionPath = Directory.EnumerateFiles(solutionDir, solutionName, SearchOption.AllDirectories).FirstOrDefault();

            if (solutionPath != null && solutionPath.Length > 0)
            {
                List <PortCoreConfiguration> solutionPortConfiguration = new List <PortCoreConfiguration>();
                IEnumerable <string>         projectFiles = Directory.EnumerateFiles(solutionDir, "*.csproj", SearchOption.AllDirectories);

                if (projectFiles != null && projectFiles.Count() > 0)
                {
                    foreach (string projectFile in projectFiles)
                    {
                        ProjectResult project = new ProjectResult();

                        Dictionary <string, string> packages = new Dictionary <string, string>();
                        packages.Add("Newtonsoft.Json", "*");
                        PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
                        {
                            ProjectPath     = projectFile,
                            UseDefaultRules = true,
                            TargetVersions  = new List <string> {
                                version
                            },
                            PackageReferences = packages
                        };

                        //project.CsProjectContent = File.ReadAllText(projectFile);
                        project.ProjectDirectory = Directory.GetParent(projectFile).FullName;
                        project.CsProjectPath    = projectFile;

                        result.ProjectResults.Add(project);

                        solutionPortConfiguration.Add(projectConfiguration);
                    }

                    SolutionPort solutionPort      = new SolutionPort(solutionPath, solutionPortConfiguration);
                    var          analysisRunResult = solutionPort.AnalysisRun();

                    foreach (var projectAction in analysisRunResult.Values)
                    {
                        Assert.IsTrue(projectAction.ToSummaryString()?.Length > 0);
                    }

                    StringBuilder str = new StringBuilder();
                    foreach (var k in analysisRunResult.Keys)
                    {
                        StringBuilder projectResults = new StringBuilder();
                        projectResults.AppendLine(k);
                        projectResults.AppendLine(analysisRunResult[k].ToString());
                        result.ProjectResults.Where(p => p.CsProjectPath == k).FirstOrDefault().ProjectAnalysisResult = projectResults.ToString();

                        str.Append(projectResults);
                    }

                    result.SolutionAnalysisResult = str.ToString();

                    var runResult = solutionPort.Run();
                    result.SolutionRunResult = runResult;

                    foreach (var project in result.ProjectResults)
                    {
                        project.CsProjectContent = File.ReadAllText(project.CsProjectPath);
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public void VerifyWebForms(string targetFramework, ProjectResult webFormsProjectResult)
        {
            var csProjContent = webFormsProjectResult.CsProjectContent;
            var projectDir    = Path.GetDirectoryName(webFormsProjectResult.CsProjectPath);

            // Validate csproj file contents
            StringAssert.Contains($"<TargetFramework>{targetFramework}</TargetFramework>", csProjContent);
            StringAssert.Contains(@"<PackageReference Include=""Microsoft.EntityFrameworkCore"" Version=""5.0.12"" />", csProjContent);
            StringAssert.Contains(@"<PackageReference Include=""Newtonsoft.Json"" Version=""*"" />", csProjContent);

            // Validate code changes
            // Verify host file
            var hostFile = File.ReadAllText(Path.Combine(projectDir, "Pages", "_Host.cshtml"));

            StringAssert.Contains(@"<app>@(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))</app>", hostFile);

            // Verify view files
            var aboutRazor   = File.ReadAllText(Path.Combine(projectDir, "Pages", "About.razor"));
            var contactRazor = File.ReadAllText(Path.Combine(projectDir, "Pages", "Contact.razor"));
            var defaultRazor = File.ReadAllText(Path.Combine(projectDir, "Pages", "Default.razor"));
            var detailsRazor = File.ReadAllText(Path.Combine(projectDir, "Pages", "Catalog", "Details.razor"));

            StringAssert.DoesNotContain("asp:Content", aboutRazor);
            StringAssert.Contains("@inherits eShopLegacyWebForms.About", aboutRazor);
            StringAssert.Contains(@"@page ""/About""", aboutRazor);
            StringAssert.DoesNotContain("<%#", aboutRazor);
            StringAssert.DoesNotContain("%>", aboutRazor);

            StringAssert.DoesNotContain("asp:Content", contactRazor);
            StringAssert.Contains(@"@page ""/Contact""", contactRazor);
            StringAssert.Contains("@inherits eShopLegacyWebForms.Contact", contactRazor);
            StringAssert.DoesNotContain("<%#", contactRazor);
            StringAssert.DoesNotContain("%>", contactRazor);

            StringAssert.DoesNotContain("asp:Content", defaultRazor);
            StringAssert.Contains(@"@page ""/""", defaultRazor);
            StringAssert.Contains("@inherits eShopLegacyWebForms._Default", defaultRazor);
            StringAssert.Contains("GridView", defaultRazor);
            StringAssert.Contains("Columns", defaultRazor);
            StringAssert.Contains("BoundField", defaultRazor);
            StringAssert.Contains("ListView", defaultRazor);
            StringAssert.Contains("EmptyDataTemplate", defaultRazor);
            StringAssert.Contains("LayoutTemplate", defaultRazor);
            StringAssert.Contains("ItemTemplate", defaultRazor);
            StringAssert.DoesNotContain("<%#", defaultRazor);
            StringAssert.DoesNotContain("%>", defaultRazor);

            StringAssert.DoesNotContain("asp:Content", detailsRazor);
            StringAssert.Contains("@inherits eShopLegacyWebForms.Catalog.Details", detailsRazor);
            StringAssert.Contains(@"@page ""/Catalog/Details""", detailsRazor);
            StringAssert.DoesNotContain("<%#", detailsRazor);
            StringAssert.DoesNotContain("%>", detailsRazor);

            // Verify code-behind files
            var aboutRazorCs   = File.ReadAllText(Path.Combine(projectDir, "Pages", "About.razor.cs"));
            var contactRazorCs = File.ReadAllText(Path.Combine(projectDir, "Pages", "Contact.razor.cs"));
            var defaultRazorCs = File.ReadAllText(Path.Combine(projectDir, "Pages", "Default.razor.cs"));
            var detailsRazorCs = File.ReadAllText(Path.Combine(projectDir, "Pages", "Catalog", "Details.razor.cs"));

            StringAssert.Contains("protected override void OnInitialized()", aboutRazorCs);
            StringAssert.Contains("protected override void OnInitialized()", contactRazorCs);
            StringAssert.Contains("protected override void OnInitialized()", defaultRazorCs);
            StringAssert.Contains("protected override void OnInitialized()", detailsRazorCs);

            // Verify application files
            var startupText        = File.ReadAllText(Path.Combine(projectDir, "Startup.cs"));
            var programText        = File.ReadAllText(Path.Combine(projectDir, "Program.cs"));
            var webRequestInfoText = File.ReadAllText(Path.Combine(projectDir, "WebRequestInfo.cs"));

            StringAssert.DoesNotContain("public class WebRequestInfo", startupText);
            StringAssert.Contains(ExpectedOutputConstants.BlazorConfigureFunctionText, startupText);
            StringAssert.Contains(ExpectedOutputConstants.BlazorProgramText, programText);
            StringAssert.Contains(ExpectedOutputConstants.BlazorWebRequestInfoText, webRequestInfoText);
        }