Update STS changes to be backward compatible with scmpOpen (#2031)

* Update STS changes to be backward compatible with scmpOpen

* Update cleanup code

* Fix test.
This commit is contained in:
Sakshi Sharma
2023-04-24 16:58:06 -07:00
committed by GitHub
parent 175f530403
commit 3e0135b907
4 changed files with 1090 additions and 4 deletions

View File

@@ -22,7 +22,7 @@
<PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" /> <PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" />
<PackageReference Update="Microsoft.SqlServer.Management.SmoMetadataProvider" Version="170.12.0" /> <PackageReference Update="Microsoft.SqlServer.Management.SmoMetadataProvider" Version="170.12.0" />
<PackageReference Update="Microsoft.SqlServer.DacFx" Version="162.0.15-preview" /> <PackageReference Update="Microsoft.SqlServer.DacFx" Version="162.0.34-preview" />
<PackageReference Update="Microsoft.SqlServer.DacFx.Projects" Version="162.0.32-alpha" /> <PackageReference Update="Microsoft.SqlServer.DacFx.Projects" Version="162.0.32-alpha" />
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" /> <PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4" /> <PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4" />

View File

@@ -173,9 +173,19 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
if (fs != null) if (fs != null)
{ {
DacExtractTarget extractTarget; DacExtractTarget extractTarget;
if (Enum.TryParse<DacExtractTarget>(fs.FirstOrDefault().Value, out extractTarget)) if(fs.FirstOrDefault() != null) // it is possible that this value is not set
{ {
endpointInfo.ExtractTarget = extractTarget; if (Enum.TryParse<DacExtractTarget>(fs.FirstOrDefault().Value, out extractTarget))
{
endpointInfo.ExtractTarget = extractTarget;
} else
{
endpointInfo.ExtractTarget = DacExtractTarget.SchemaObjectType; // set default but log an error
Logger.Write(TraceEventType.Error, string.Format("Schema compare open scmp operation failed during xml parsing with unknown ExtractTarget"));
}
} else
{
endpointInfo.ExtractTarget = DacExtractTarget.SchemaObjectType; // set the default if this value doesn't already exist in the scmp file
} }
} }

View File

@@ -81,6 +81,8 @@ WITH VALUES
ADD FILEGROUP [MyFileGroup] CONTAINS MEMORY_OPTIMIZED_DATA; ADD FILEGROUP [MyFileGroup] CONTAINS MEMORY_OPTIMIZED_DATA;
GO"; GO";
private string scmpFolder = Path.Combine("..", "..", "..", "SchemaCompare", "SchemaCompare");
/// <summary> /// <summary>
/// Verify the schema compare request comparing two dacpacs /// Verify the schema compare request comparing two dacpacs
/// </summary> /// </summary>
@@ -1225,7 +1227,6 @@ WITH VALUES
string filePath = Path.Combine(folderPath, string.Format("SchemaCompareOpenScmpTest{0}.scmp", DateTime.Now.ToFileTime())); string filePath = Path.Combine(folderPath, string.Format("SchemaCompareOpenScmpTest{0}.scmp", DateTime.Now.ToFileTime()));
compare.SaveToFile(filePath); compare.SaveToFile(filePath);
SchemaCompareTestUtils.VerifyAndCleanup(Directory.GetParent((targetEndpoint as SchemaCompareProjectEndpoint).ProjectFilePath).FullName);
await VerifyContentAndCleanupAsync(filePath, "<FolderStructure>ObjectType</FolderStructure>"); await VerifyContentAndCleanupAsync(filePath, "<FolderStructure>ObjectType</FolderStructure>");
} }
finally finally
@@ -1235,6 +1236,56 @@ WITH VALUES
} }
} }
/// <summary>
/// Verifies https://github.com/microsoft/azuredatastudio/issues/22728 -- Schema compare open scmp file not backward compatible
/// </summary>
[Test]
public void VerifyOpenScmpIsBackwardCompatible()
{
string testFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SchemaCompareTest", $"{TestContext.CurrentContext?.Test?.Name}_{DateTime.Now.Ticks.ToString()}");
Directory.CreateDirectory(testFolderPath);
string testScmpFileTemplate = Path.Combine(testFolderPath, "TestScmpFileTemplate.scmp");
File.Copy(Path.Combine(scmpFolder, "TestScmpFileTemplate.scmp"), testScmpFileTemplate);
string testScmpFile = LoadScmpFileTemplate(testTemplateFolderPath: scmpFolder, testWorkingFolderPath: testFolderPath, templateFileName: "TestScmpFileTemplate.scmp", fileName: "TestScmpFile.scmp");
var schemaCompareOpenScmpParams = new SchemaCompareOpenScmpParams
{
FilePath = testScmpFile
};
SchemaCompareOpenScmpOperation schemaCompareOpenScmpOperation = new SchemaCompareOpenScmpOperation(schemaCompareOpenScmpParams);
schemaCompareOpenScmpOperation.Execute(TaskExecutionMode.Execute);
Assert.NotNull(schemaCompareOpenScmpOperation.Result);
Assert.True(schemaCompareOpenScmpOperation.Result.Success);
Assert.AreEqual(schemaCompareOpenScmpOperation.Result.SourceEndpointInfo.ProjectFilePath, Path.Combine(testFolderPath, "SourceProject.sqlproj"), "Source project was expected to exist but did not");
Assert.AreEqual(schemaCompareOpenScmpOperation.Result.SourceEndpointInfo.ExtractTarget, DacExtractTarget.SchemaObjectType, $"Source project was expected to have SchemaObjectType as extract target but {schemaCompareOpenScmpOperation.Result.SourceEndpointInfo.ExtractTarget} was set instead");
Assert.AreEqual(schemaCompareOpenScmpOperation.Result.TargetEndpointInfo.ProjectFilePath, Path.Combine(testFolderPath, "TargetProject.sqlproj"), "Target project was expected to exist but did not");
Assert.AreEqual(schemaCompareOpenScmpOperation.Result.TargetEndpointInfo.ExtractTarget, DacExtractTarget.SchemaObjectType, $"Target project was expected to have SchemaObjectType as extract target but {schemaCompareOpenScmpOperation.Result.TargetEndpointInfo.ExtractTarget} was set instead");
SchemaCompareTestUtils.VerifyAndCleanup(testFolderPath);
}
private string LoadScmpFileTemplate(string testTemplateFolderPath, string testWorkingFolderPath, string templateFileName, string fileName)
{
string templatePath = Path.Combine(testTemplateFolderPath, templateFileName);
string text = File.ReadAllText(templatePath);
string sourceDummyProject = Path.Combine(testWorkingFolderPath, "SourceProject.sqlproj");
string targetDummyProject = Path.Combine(testWorkingFolderPath, "TargetProject.sqlproj");
text = text.Replace($"@@SourceProjectFilePath@@", sourceDummyProject);
text = text.Replace($"@@TargetProjectFilePath@@", targetDummyProject);
File.Create(sourceDummyProject).Close();
File.Create(targetDummyProject).Close();
string scmpPath = Path.Combine(testWorkingFolderPath, fileName);
File.WriteAllText(scmpPath, text);
return scmpPath;
}
/// <summary> /// <summary>
/// Verify the schema compare Service Calls ends to end /// Verify the schema compare Service Calls ends to end
/// </summary> /// </summary>