コード例 #1
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))));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 public void NullServiceProvider_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("serviceProvider", () => new MigrateXprojProjectFactory(
                                               ProcessRunnerFactory.CreateRunner(),
                                               new IFileSystemMock(),
                                               null,
                                               GlobalJsonSetupFactory.Create()));
 }
コード例 #4
0
        private MigrateXprojProjectFactory CreateInstance(ProcessRunner processRunner,
                                                          IFileSystem fileSystem,
                                                          IVsSolution solutionParam = null,
                                                          GlobalJsonRemover.GlobalJsonSetup globalJsonSetup = null)
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var solution        = solutionParam ?? IVsSolutionFactory.CreateWithSolutionDirectory(CreateSolutionInfo());
            var serviceProvider = IServiceProviderFactory.Create(typeof(SVsSolution), solution);
            var setup           = globalJsonSetup ?? GlobalJsonSetupFactory.Create();

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

            return(migrator);
        }
コード例 #5
0
        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));
        }