Пример #1
0
        public void MigrateXprojProjectFactory_GlobalJsonExists_BacksUpAndRemovesGlobalJson()
        {
            var fileSystem = CreateFileSystem(withEntries: true, withGlobalJson: true);

            var migrator = CreateInstance(ProcessRunnerFactory.CreateRunner(), fileSystem);

            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 globalJsonBackedUp = Path.Combine(BackupLocation, "global.json");

            migrator.BackupAndDeleteGlobalJson(SlnLocation, solution, BackupLocation, XprojLocation, ProjectName, logger);
            Assert.False(fileSystem.FileExists(GlobalJsonLocation));
            Assert.True(fileSystem.FileExists(globalJsonBackedUp));
            Assert.Equal(1, loggedMessages.Count);
            Assert.Equal(new LogMessage
            {
                File    = GlobalJsonLocation,
                Level   = (uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL,
                Message = string.Format(VSResources.MigrationBackupFile, GlobalJsonLocation, globalJsonBackedUp),
                Project = ProjectName
            }, loggedMessages[0]);
            Assert.NotNull(remover);
            Assert.Equal(1234u, remover.SolutionCookie);
        }
Пример #2
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);
        }