Ejemplo n.º 1
0
        public void OneTimeSetup()
        {
            var workingDirectory = Environment.CurrentDirectory;

            _testProjectPath = Directory.GetParent(workingDirectory).Parent.Parent.FullName;

            var codeAnalyzer = CreateDefaultCodeAnalyzer();
            // Get analyzer results from codelyzer (syntax trees, semantic models, package references, project references, etc)
            var analyzerResult = codeAnalyzer.AnalyzeProject(DownloadTestProjectsFixture.EShopLegacyWebFormsProjectPath).Result;

            var ctaArgs = new[]
            {
                "-p", DownloadTestProjectsFixture.EShopLegacyWebFormsProjectPath, // can hardcode for local use
                "-v", "net5.0",                                                   // set the Target Framework version
                "-d", "true",                                                     // use the default rules files (these will get downloaded from S3 and will tell CTA which packages to add to the new .csproj file)
                "-m", "false",                                                    // this is the "mock run" flag. Setting it to false means rules will be applied if we do a full port.
            };

            // Handle argument assignment
            PortCoreRulesCli cli = new PortCoreRulesCli();

            cli.HandleCommand(ctaArgs);
            if (cli.DefaultRules)
            {
                // Since we're using default rules, we want to specify where to find those rules (once they are downloaded)
                cli.RulesDir = Constants.RulesDefaultPath;
            }

            var packageReferences = new Dictionary <string, Tuple <string, string> >
            {
                { "Autofac", new Tuple <string, string>("4.9.1.0", "4.9.3") },
                { "EntityFramework", new Tuple <string, string>("6.0.0.0", "6.4.4") },
                { "log4net", new Tuple <string, string>("2.0.8.0", "2.0.12") },
                { "Microsoft.Extensions.Logging.Log4Net.AspNetCore", new Tuple <string, string>("1.0.0", "2.2.12") }
            };

            // Create a configuration object using the CLI and other arbitrary values
            PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
            {
                ProjectPath       = cli.FilePath,
                RulesDir          = cli.RulesDir,
                IsMockRun         = cli.IsMockRun,
                UseDefaultRules   = cli.DefaultRules,
                PackageReferences = packageReferences,
                PortCode          = false,
                PortProject       = true,
                TargetVersions    = new List <string> {
                    cli.Version
                }
            };

            var           projectRewriter = new ProjectRewriter(analyzerResult, projectConfiguration);
            ProjectResult projectResult   = projectRewriter.Initialize();

            _webFormsProjectAnalyzer = new ProjectAnalyzer(_testProjectPath, analyzerResult, projectConfiguration, projectResult);
            _blazorWorkspaceManager  = new WorkspaceManagerService();
        }
Ejemplo n.º 2
0
        public void TestCli()
        {
            string mvcMusicStorePath        = Directory.EnumerateFiles(tempDir, "MvcMusicStore.sln", SearchOption.AllDirectories).FirstOrDefault();
            string mvcMusicStoreProjectPath = Directory.EnumerateFiles(tempDir, "MvcMusicStore.csproj", SearchOption.AllDirectories).FirstOrDefault();

            string[] args = { "-p", mvcMusicStoreProjectPath, "-s", mvcMusicStorePath, "-r", Path.Combine(tempDir, "Input"), "-d", "true", "-a", "", "-v", "net5.0", "-m", "false" };
            var      cli  = new PortCoreRulesCli();

            cli.HandleCommand(args);
            Assert.NotNull(cli);
            Assert.NotNull(cli.FilePath);
            Assert.NotNull(cli.AssembliesDir);
            Assert.NotNull(cli.DefaultRules);
            Assert.NotNull(cli.IsMockRun);
            Assert.NotNull(cli.Version);


            string[] args2 = { "-s", mvcMusicStorePath, "-r", Path.Combine(tempDir, "Input"), "-d", "true", "-a", "", "-m", "true" };
            var      cli2  = new PortCoreRulesCli();

            cli2.HandleCommand(args2);
        }