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 GlobalJsonRemover_NoJson_DoesntCrash() { UnitTestHelper.IsRunningUnitTests = true; var solution = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback); var dteSolution = SolutionFactory.ImplementFindProjectItem(path => { Assert.Equal(Path.Combine(Directory, "global.json"), path); return(null); }); var dte = DteFactory.ImplementSolution(() => dteSolution); var serviceProvider = IServiceProviderFactory.ImplementGetService(t => { if (typeof(SVsSolution) == t) { return(solution); } if (typeof(DTE) == t) { return(dte); } Assert.False(true); throw new InvalidOperationException(); }); var remover = new GlobalJsonRemover(serviceProvider, IFileSystemFactory.Create()); GlobalJsonRemover.Remover = remover; Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0)); }
public void GlobalJsonHasSdkElement_ElementIsRemoved() { var fileSystem = CreateFileSystem(withEntries: true, withGlobalJson: true); var solution = IVsSolutionFactory.CreateWithSolutionDirectory(CreateSolutionInfo()); var setup = GlobalJsonSetupFactory.Create(true); var migrator = CreateInstance(ProcessRunnerFactory.CreateRunner(), fileSystem, globalJsonSetup: setup); var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); var globalJsonBackedUp = Path.Combine(BackupLocation, "global.json"); fileSystem.WriteAllText(GlobalJsonLocation, @" { ""sdk"": { ""version"": ""1.0.0-preview2-003121"" } }"); migrator.BackupAndDeleteGlobalJson(SlnLocation, solution, BackupLocation, XprojLocation, ProjectName, logger); Assert.True(fileSystem.FileExists(globalJsonBackedUp)); Assert.Single(loggedMessages); Assert.Equal(new LogMessage { File = GlobalJsonLocation, Level = (uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, Message = string.Format(VSResources.MigrationBackupFile, GlobalJsonLocation, globalJsonBackedUp), Project = ProjectName }, loggedMessages[0]); Mock.Get(setup).Verify(g => g.SetupRemoval(solution, It.IsAny <IServiceProvider>(), fileSystem)); Assert.True(JToken.DeepEquals(new JObject(), JsonConvert.DeserializeObject <JObject>(fileSystem.ReadAllText(GlobalJsonLocation)))); }
public void GlobalJsonRemover_RemovesJson_WhenExists() { UnitTestHelper.IsRunningUnitTests = true; var solution = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback); var projectItem = ProjectItemFactory.Create(); var dteSolution = SolutionFactory.ImplementFindProjectItem(path => { Assert.Equal(Path.Combine(Directory, "global.json"), path); return(projectItem); }); var dte = DteFactory.ImplementSolution(() => dteSolution); var serviceProvider = IServiceProviderFactory.ImplementGetService(t => { if (typeof(SVsSolution) == t) { return(solution); } if (typeof(DTE) == t) { return(dte); } Assert.False(true); throw new InvalidOperationException(); }); var remover = new GlobalJsonRemover(serviceProvider); Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0)); Mock.Get(projectItem).Verify(p => p.Remove(), Times.Once); }
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 GlobalJsonRemover_AfterRemoval_UnadvisesEvents() { UnitTestHelper.IsRunningUnitTests = true; var globalJsonPath = Path.Combine(Directory, "global.json"); var solution = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback); var projectItem = ProjectItemFactory.Create(); var dteSolution = SolutionFactory.ImplementFindProjectItem(path => { Assert.Equal(globalJsonPath, path); return(projectItem); }); var dte = DteFactory.ImplementSolution(() => dteSolution); var serviceProvider = IServiceProviderFactory.ImplementGetService(t => { if (typeof(SVsSolution) == t) { return(solution); } if (typeof(DTE) == t) { return(dte); } Assert.False(true); throw new InvalidOperationException(); }); var fileSystem = IFileSystemFactory.Create(); fileSystem.Create(globalJsonPath); var remover = new GlobalJsonRemover(serviceProvider, fileSystem) { SolutionCookie = 1234 }; GlobalJsonRemover.Remover = remover; Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0)); Mock.Get(solution).Verify(s => s.UnadviseSolutionEvents(1234), Times.Once); }
public void GlobalJsonExists_BacksUpAndRemovesGlobalJson() { var fileSystem = CreateFileSystem(withEntries: true, withGlobalJson: true); var solution = IVsSolutionFactory.CreateWithSolutionDirectory(CreateSolutionInfo()); var setup = GlobalJsonSetupFactory.Create(true); var migrator = CreateInstance(ProcessRunnerFactory.CreateRunner(), fileSystem, globalJsonSetup: setup); var loggedMessages = new List <LogMessage>(); var logger = IVsUpgradeLoggerFactory.CreateLogger(loggedMessages); var globalJsonBackedUp = Path.Combine(BackupLocation, "global.json"); migrator.BackupAndDeleteGlobalJson(SlnLocation, solution, BackupLocation, XprojLocation, ProjectName, logger); Assert.True(fileSystem.FileExists(globalJsonBackedUp)); Assert.Single(loggedMessages); Assert.Equal(new LogMessage { File = GlobalJsonLocation, Level = (uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, Message = string.Format(VSResources.MigrationBackupFile, GlobalJsonLocation, globalJsonBackedUp), Project = ProjectName }, loggedMessages[0]); Mock.Get(setup).Verify(g => g.SetupRemoval(solution, It.IsAny <IServiceProvider>(), fileSystem)); }