public void MigrateXprojProjectFactory_MigrateOutput_LoggedCorrectly()
        {
            // Runner returns valid response, standard exit code
            var procRunner = ProcessRunnerFactory.ImplementRunner(ProcessVerifier, outputText: "Standard Output", errorText: "Standard Error");
            var migrator   = new MigrateXprojProjectFactory(procRunner, CreateFileSystem(false));

            var loggedMessages = new List <LogMessage>();
            var logger         = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages);

            Assert.True(migrator.MigrateProject(RootLocation, XprojLocation, "XprojMigrationTests", logger));
            Assert.Equal(2, loggedMessages.Count);
            Assert.Equal(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL,
                Message = "Standard Output",
                Project = "XprojMigrationTests"
            }, loggedMessages[0]);
            Assert.Equal(new LogMessage
            {
                File    = XprojLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_WARNING,
                Message = "Standard Error",
                Project = "XprojMigrationTests"
            }, loggedMessages[1]);
        }
예제 #2
0
        public static void SetServiceProvider(this MigrateXprojProjectFactory fact, ServiceProvider provider)
        {
            var t     = typeof(FlavoredProjectFactoryBase);
            var field = t.GetField("_serviceProvider", BindingFlags.NonPublic | BindingFlags.Instance);

            field.SetValue(fact, provider);
        }
예제 #3
0
        private MigrateXprojProjectFactory CreateInstance(ProcessRunner processRunner, IFileSystem fileSystem, IVsSolution solutionParam = null)
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var solution        = solutionParam ?? IVsSolutionFactory.CreateWithSolutionDirectory(CreateSolutionInfo());
            var serviceProvider = IServiceProviderFactory.Create(typeof(SVsSolution), solution);

            var migrator = new MigrateXprojProjectFactory(processRunner, fileSystem, serviceProvider);

            return(migrator);
        }
        public void MigrateXprojProjectFactory_ValidCsproj_FindsCsproj()
        {
            var csproj     = Path.Combine(RootLocation, "XprojMigrationTests.csproj");
            var fileSystem = CreateFileSystem();

            fileSystem.Create(csproj);

            var loggedMessages = new List <LogMessage>();
            var logger         = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages);
            var migrator       = new MigrateXprojProjectFactory(ProcessRunnerFactory.CreateRunner(), fileSystem);

            Assert.Equal(csproj, migrator.GetCsproj(RootLocation, "XprojMigrationTests", XprojLocation, logger));
            Assert.Equal(0, loggedMessages.Count);
        }
        public void MigrateXprojProjectFactory_ValidProject_IsUpgradable()
        {
            var fileSystem = CreateFileSystem();

            var  loggedMessages = new List <LogMessage>();
            var  logger         = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages);
            int  upgradeRequired;
            Guid newProjectFactory;
            uint capabilityFlags;

            var migrator = new MigrateXprojProjectFactory(ProcessRunnerFactory.CreateRunner(), fileSystem);

            Assert.Equal(VSConstants.S_OK,
                         migrator.UpgradeProject_CheckOnly(XprojLocation, logger, out upgradeRequired, out newProjectFactory, out capabilityFlags));
            Assert.Equal((int)__VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE, upgradeRequired);
            Assert.Equal(Guid.Parse(CSharpProjectSystemPackage.ProjectTypeGuid), newProjectFactory);
            Assert.Equal((uint)(__VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_BACKUPSUPPORTED | __VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_COPYBACKUP),
                         capabilityFlags);
        }
        public void MigrateXprojProjectFactory_NoCsproj_LogsError()
        {
            var csproj     = Path.Combine(RootLocation, "XprojMigrationTests.csproj");
            var fileSystem = CreateFileSystem();

            var loggedMessages = new List <LogMessage>();
            var logger         = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages);
            var migrator       = new MigrateXprojProjectFactory(ProcessRunnerFactory.CreateRunner(), fileSystem);

            Assert.Equal("", migrator.GetCsproj(RootLocation, "XprojMigrationTests", XprojLocation, logger));
            Assert.Equal(1, loggedMessages.Count);
            Assert.Equal(new LogMessage
            {
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_ERROR,
                Project = "XprojMigrationTests",
                File    = XprojLocation,
                Message = $"Expected to find migrated cpsroj in {RootLocation}, but did not find any."
            }, loggedMessages[0]);
        }
        public void MigrateXprojProjectFactory_MigrateError_ReturnsFalse()
        {
            // Runner returns valid response, standard exit code
            var procRunner = ProcessRunnerFactory.ImplementRunner(ProcessVerifier, exitCode: VSConstants.E_FAIL);
            var migrator   = new MigrateXprojProjectFactory(procRunner, CreateFileSystem(false));

            var loggedMessages = new List <LogMessage>();
            var logger         = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages);

            Assert.False(migrator.MigrateProject(RootLocation, XprojLocation, "XprojMigrationTests", logger));
            Assert.Equal(1, loggedMessages.Count);
            Assert.Equal(new LogMessage
            {
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_ERROR,
                Project = "XprojMigrationTests",
                File    = XprojLocation,
                Message = $"Failed to migrate XProj project XprojMigrationTests. 'dotnet migrate --skip-backup -s -p \"{RootLocation}\" -x \"{XprojLocation}\"' exited with error code {VSConstants.E_FAIL}."
            }, loggedMessages[0]);
        }