public void Can_Detect_Application_Versus_Library_Projects(ProjectType projectType, string json)
        {
            // arrange
            var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, null, null);

            Assert.AreEqual(testFileUpgradeContext.ToProjectJsonWrapper().GetProjectType(), projectType);
        }
        public void Can_Apply(string scenario, string json, string xproj)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange

                var upgradeActions = new List <IProjectUpgradeAction>();
                var testXProj      = VsProjectFactory.LoadTestProject(xproj);

                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, null);

                // updates the sdk version in global json.
                var runtimeUpgradeAction = new MigrateProjectImportsFromDnxToDotNet();
                upgradeActions.Add(runtimeUpgradeAction);

                // Apply these actions to the project.json file.
                foreach (var upgradeAction in upgradeActions)
                {
                    upgradeAction.Apply(testFileUpgradeContext);
                }

                // save the changes.
                testFileUpgradeContext.SaveChanges();

                var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile);
                Approvals.VerifyXml(projContents);


                // assert.
                //var modifiedContents = testFileUpgradeContext.ModifiedJsonContents;
                //Approvals.VerifyJson(modifiedContents);

                // Approvals.VerifyAll();
            }
        }
Beispiel #3
0
        public void Can_Rollback_If_Error(string scenario, string json, string xproj, string launchSettingsJson)
        {
            using (ApprovalResults.ForScenario(scenario + "_project_json"))
            {
                // arrange
                var testXProj = VsProjectHelper.LoadTestProject(xproj);
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, launchSettingsJson);
                var migrator = new ProjectMigrator(testFileUpgradeContext);
                var options  = new ProjectMigrationOptions(ReleaseVersion.RTM);

                // options.UpgradeToPreview1 = true; // project.json files will be updated to the preview 1 schema.
                // options.UpgradePackagesToRc2 = true; // rc1 packages will be migrated to rc2 packages, including commands (migrated to tools).
                options.AddNetStandardTargetForLibraries = true; // libraries will have the netStandard TFM added (and dependency).
                options.AddNetCoreTargetForApplications  = true; // applications will have the netCore app TFM added (and dependency)

                // add an upgrade that throws an exception..
                var additionalUpgrades = new List <IProjectUpgradeAction>();
                additionalUpgrades.Add(new ExceptionuringUpgradeAction());


                try
                {
                    // migrate
                    migrator.Apply(options, additionalUpgrades);
                    testFileUpgradeContext.SaveChanges();
                }
                catch (Exception e)
                {
                    // throw;
                }

                // assert.
                var modifiedContents = testFileUpgradeContext.ProjectJsonObject.ToString();
                Approvals.Verify(modifiedContents);

                using (ApprovalResults.ForScenario(scenario + "_xproj"))
                {
                    var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile);
                    Approvals.VerifyXml(projContents);
                }

                using (ApprovalResults.ForScenario(scenario + "_launchSettings"))
                {
                    var modifiedLaunchSettingsContents = testFileUpgradeContext.LaunchSettingsObject.ToString();
                    Approvals.Verify(modifiedLaunchSettingsContents);
                }
            }
        }
        public void Can_Apply(string scenario, string json, ReleaseVersion version)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, null, null);
                var sut = new UpgradeMicrosoftPackageVersionNumbers(version);

                // act
                sut.Apply(testFileUpgradeContext);
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedProjectJsonContents;
                Approvals.VerifyJson(modifiedContents);
            }
        }
        public void Can_Apply(string scenario, string json)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, null, null);
                var sut = new RenameAspNetPackagesToAspNetCore();

                // act
                sut.Apply(testFileUpgradeContext);
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedProjectJsonContents;
                Approvals.VerifyJson(modifiedContents);
            }
        }
Beispiel #6
0
        public void Can_Apply(string scenario, string json)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, null, null);
                // get target nuget packages for RC2, Preview1 tooling.

                var sut = new RenameCommandsToTools();

                // act
                sut.Apply(testFileUpgradeContext);
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedProjectJsonContents;
                Approvals.VerifyJson(modifiedContents);
            }
        }
        public void Can_Apply(string scenario, string json, string launchSettings)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, null, launchSettings);


                var sut = new UpdateLaunchSettings();

                // act
                sut.Apply(testFileUpgradeContext);
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedLaunchSettingsJsonContents;
                Approvals.VerifyJson(modifiedContents);
            }
        }
        public void Can_Apply(string scenario, string json)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, null, null);
                // get target nuget packages for RC2, Preview1 tooling.
                var toolPackageMigrations = ProjectMigrator.GetToolPackageMigrationList(ToolingVersion.Preview2, testFileUpgradeContext);

                var sut = new MigrateToolPackages(toolPackageMigrations);

                // act
                sut.Apply(testFileUpgradeContext);
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedProjectJsonContents;
                Approvals.VerifyJson(modifiedContents);
            }
        }
Beispiel #9
0
        public void Can_Apply(string scenario, string json, string xproj, string launchSettings, ReleaseVersion version)
        {
            using (ApprovalResults.ForScenario(scenario + "_project_json"))
            {
                // arrange
                var testXProj = VsProjectHelper.LoadTestProject(xproj);
                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, launchSettings, new [] { "appSettings.json" });

                var migrator = new ProjectMigrator(testFileUpgradeContext);
                var options  = new ProjectMigrationOptions(version);

                // options.UpgradeToPreview1 = true; // project.json files will be updated to the preview 1 schema.
                // options.UpgradePackagesToRc2 = true; // rc1 packages will be migrated to rc2 packages, including commands (migrated to tools).
                options.AddNetStandardTargetForLibraries = true; // libraries will have the netStandard TFM added (and dependency).
                options.AddNetCoreTargetForApplications  = true; // applications will have the netCore app TFM added (and dependency)

                // migrate
                migrator.Apply(options);

                // save the changes.
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedProjectJsonContents;
                Approvals.Verify(modifiedContents);
                // Approvals.VerifyJson(modifiedContents);


                using (ApprovalResults.ForScenario(scenario + "_xproj"))
                {
                    var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile);
                    Approvals.VerifyXml(projContents);
                }

                using (ApprovalResults.ForScenario(scenario + "_launchSettings"))
                {
                    var modifiedLaunchSettingsContents = testFileUpgradeContext.ModifiedLaunchSettingsJsonContents;
                    Approvals.Verify(modifiedLaunchSettingsContents);
                }
            }
        }