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(); } }
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, 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); } } }