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]); }
public void MigrateXprojProjectFactory_E2E_Works() { var fileSystem = CreateFileSystem(); var csproj = Path.Combine(BackupLocation, $"{ProjectName}.csproj"); var processRunner = ProcessRunnerFactory.ImplementRunner(pInfo => { ProcessVerifier(pInfo); fileSystem.Create(csproj); }); string outCsproj; int upgradeRequired; Guid newProjectFactory; var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); var migrator = new MigrateXprojProjectFactory(processRunner, fileSystem); Assert.Equal(VSConstants.S_OK, migrator.UpgradeProject(XprojLocation, 0, BackupLocation, out outCsproj, logger, out upgradeRequired, out newProjectFactory)); Assert.True(fileSystem.FileExists(csproj)); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, $"{ProjectName}.csproj"))); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, "project.json"))); Assert.Equal(csproj, outCsproj); Assert.Equal((int)__VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE, upgradeRequired); Assert.Equal(Guid.Parse(CSharpProjectSystemPackage.ProjectTypeGuid), newProjectFactory); }
public void E2E_Works() { var fileSystem = CreateFileSystem(withEntries: true, withXprojUser: true, withProjectLock: true, withGlobalJson: true); var processRunner = ProcessRunnerFactory.ImplementRunner(pInfo => { ProcessVerifier(pInfo); fileSystem.Create(CsprojLocation); }); var solution = IVsSolutionFactory.CreateWithSolutionDirectory(CreateSolutionInfo()); var setup = GlobalJsonSetupFactory.Create(true); var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); var migrator = CreateInstance(processRunner, fileSystem, solution, setup); Assert.Equal(VSConstants.S_OK, migrator.UpgradeProject(XprojLocation, 0, BackupLocation, out string outCsproj, logger, out int upgradeRequired, out Guid newProjectFactory)); Assert.True(fileSystem.FileExists(CsprojLocation)); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, $"{ProjectName}.xproj"))); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, "project.json"))); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, $"{ProjectName}.xproj.user"))); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, $"global.json"))); Assert.False(fileSystem.FileExists(XprojLocation)); Assert.False(fileSystem.FileExists(ProjectJsonLocation)); Assert.False(fileSystem.FileExists(XprojUserLocation)); Assert.False(fileSystem.FileExists(ProjectLockJsonLocation)); Assert.Equal(CsprojLocation, outCsproj); Assert.Equal((int)__VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE, upgradeRequired); Assert.Equal(Guid.Parse(CSharpProjectSystemPackage.ProjectTypeGuid), newProjectFactory); Mock.Get(setup).Verify(g => g.SetupRemoval(solution, It.IsAny <IServiceProvider>(), fileSystem)); }
public void MigrateXprojProjectFactory_ValidPaths_CallMigrateCorrectly() { // Runner returns valid response, standard exit code var procRunner = ProcessRunnerFactory.ImplementRunner(ProcessVerifier); 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(0, loggedMessages.Count); }
public void MigrateError_ReturnsErrorCode() { // Runner returns valid response, standard exit code var procRunner = ProcessRunnerFactory.ImplementRunner(ProcessVerifier, exitCode: VSConstants.E_FAIL); var migrator = CreateInstance(procRunner, CreateFileSystem(false)); var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); (string logFile, int exitCode) = migrator.MigrateProject(SlnLocation, RootLocation, XprojLocation, "XprojMigrationTests", logger); Assert.Equal(VSConstants.E_FAIL, exitCode); Assert.Equal(LogFileLocation, logFile); }
public void ValidPaths_CallMigrateCorrectly() { // Runner returns valid response, standard exit code var procRunner = ProcessRunnerFactory.ImplementRunner(ProcessVerifier); var migrator = CreateInstance(procRunner, CreateFileSystem(false)); var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); (string logFile, int exitCode) = migrator.MigrateProject(SlnLocation, RootLocation, XprojLocation, "XprojMigrationTests", logger); Assert.Equal(0, exitCode); Assert.Empty(loggedMessages); }
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]); }
public void MigrateXprojProjectFactory_E2E_Works() { var fileSystem = CreateFileSystem(withEntries: true, withXprojUser: true, withProjectLock: true, withGlobalJson: true); var processRunner = ProcessRunnerFactory.ImplementRunner(pInfo => { ProcessVerifier(pInfo); fileSystem.Create(CsprojLocation); }); GlobalJsonRemover remover = null; var solution = IVsSolutionFactory.Implement((IVsSolutionEvents events, out uint cookie) => { remover = (GlobalJsonRemover)events; cookie = 1234; return(VSConstants.S_OK); }, IVsSolutionFactory.DefaultUnadviseCallback, CreateSolutionInfo()); var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); var migrator = CreateInstance(processRunner, fileSystem, solution); Assert.Equal(VSConstants.S_OK, migrator.UpgradeProject(XprojLocation, 0, BackupLocation, out string outCsproj, logger, out int upgradeRequired, out Guid newProjectFactory)); Assert.True(fileSystem.FileExists(CsprojLocation)); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, $"{ProjectName}.xproj"))); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, "project.json"))); Assert.True(fileSystem.FileExists(Path.Combine(BackupLocation, $"{ProjectName}.xproj.user"))); Assert.False(fileSystem.FileExists(XprojLocation)); Assert.False(fileSystem.FileExists(ProjectJsonLocation)); Assert.False(fileSystem.FileExists(XprojUserLocation)); Assert.False(fileSystem.FileExists(ProjectLockJsonLocation)); Assert.False(fileSystem.FileExists(GlobalJsonLocation)); Assert.Equal(CsprojLocation, outCsproj); Assert.Equal((int)__VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE, upgradeRequired); Assert.Equal(Guid.Parse(CSharpProjectSystemPackage.ProjectTypeGuid), newProjectFactory); Assert.NotNull(remover); Assert.Equal(1234u, remover.SolutionCookie); }