From f99061866c161b25aa0d9ff101bc8d0b6c1f5222 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Wed, 3 Oct 2018 18:33:40 -0400 Subject: [PATCH] Upgrade SMO to 150 preview (#701) * Switch to the unified SMO NuGet so all binaries are strong named and signed. * use one AssemblyLoader instance for all loads * Revert "use one AssemblyLoader instance for all loads" This reverts commit 48c59ffd5c57152de281c87acdbcad7ddf7ab760. * Stop creating multiple AssemblyLoadContext objects during composition, per https://github.com/dotnet/coreclr/issues/19632 * restore high entropyva property * Improve the comment * Update SMO to 150 and fix scripting for objects with a single quote in their name. * restore newtonsoft reference --- Common.props | 3 +- .../Microsoft.SqlTools.CoreServices.csproj | 8 +--- .../Microsoft.SqlTools.Credentials.csproj | 6 +-- ...Microsoft.SqlTools.ResourceProvider.csproj | 3 +- .../Microsoft.SqlTools.ServiceLayer.csproj | 8 +--- .../Scripting/ScriptingExtensionMethods.cs | 6 +-- ...icrosoft.SqlTools.Hosting.UnitTests.csproj | 1 + ...Tools.ServiceLayer.IntegrationTests.csproj | 4 +- ...oft.SqlTools.ServiceLayer.PerfTests.csproj | 1 + ...t.SqlTools.ServiceLayer.Test.Common.csproj | 4 +- .../TestLogger.cs | 6 ++- ...Tools.ServiceLayer.TestDriver.Tests.csproj | 1 + ...ft.SqlTools.ServiceLayer.TestDriver.csproj | 4 +- ...SqlTools.ServiceLayer.TestEnvConfig.csproj | 1 + ...oft.SqlTools.ServiceLayer.UnitTests.csproj | 5 +-- .../ScriptingExtensionMethodsTests.cs | 39 +++++++++++++++++++ 16 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 test/Microsoft.SqlTools.ServiceLayer.UnitTests/Scripting/ScriptingExtensionMethodsTests.cs diff --git a/Common.props b/Common.props index fc28293e..1aa4820e 100644 --- a/Common.props +++ b/Common.props @@ -1,7 +1,8 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - 140.17282.0-xplat + 150.18040.0-preview true + true \ No newline at end of file diff --git a/src/Microsoft.SqlTools.CoreServices/Microsoft.SqlTools.CoreServices.csproj b/src/Microsoft.SqlTools.CoreServices/Microsoft.SqlTools.CoreServices.csproj index 1d471c4b..dea5a521 100644 --- a/src/Microsoft.SqlTools.CoreServices/Microsoft.SqlTools.CoreServices.csproj +++ b/src/Microsoft.SqlTools.CoreServices/Microsoft.SqlTools.CoreServices.csproj @@ -16,13 +16,7 @@ - - - - - - - + diff --git a/src/Microsoft.SqlTools.Credentials/Microsoft.SqlTools.Credentials.csproj b/src/Microsoft.SqlTools.Credentials/Microsoft.SqlTools.Credentials.csproj index 7a95cb08..32b8e481 100644 --- a/src/Microsoft.SqlTools.Credentials/Microsoft.SqlTools.Credentials.csproj +++ b/src/Microsoft.SqlTools.Credentials/Microsoft.SqlTools.Credentials.csproj @@ -20,13 +20,11 @@ - - - - + + diff --git a/src/Microsoft.SqlTools.ResourceProvider/Microsoft.SqlTools.ResourceProvider.csproj b/src/Microsoft.SqlTools.ResourceProvider/Microsoft.SqlTools.ResourceProvider.csproj index de5b16b0..f3611c89 100644 --- a/src/Microsoft.SqlTools.ResourceProvider/Microsoft.SqlTools.ResourceProvider.csproj +++ b/src/Microsoft.SqlTools.ResourceProvider/Microsoft.SqlTools.ResourceProvider.csproj @@ -1,4 +1,5 @@ + netcoreapp2.1 SqlToolsResourceProviderService @@ -11,7 +12,7 @@ true true portable - false + false win7-x64;win7-x86;ubuntu.14.04-x64;ubuntu.16.04-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.23-x64;opensuse.13.2-x64;osx.10.11-x64;linux-x64 diff --git a/src/Microsoft.SqlTools.ServiceLayer/Microsoft.SqlTools.ServiceLayer.csproj b/src/Microsoft.SqlTools.ServiceLayer/Microsoft.SqlTools.ServiceLayer.csproj index 66dcaf76..e54d285d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Microsoft.SqlTools.ServiceLayer.csproj +++ b/src/Microsoft.SqlTools.ServiceLayer/Microsoft.SqlTools.ServiceLayer.csproj @@ -20,13 +20,7 @@ - - - - - - - + diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingExtensionMethods.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingExtensionMethods.cs index f872d74b..df13e3e1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingExtensionMethods.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingExtensionMethods.cs @@ -103,10 +103,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting string urn = string.Format( "Server[@Name='{0}']/Database[@Name='{1}']/{2}[@Name='{3}' {4}]", server.ToUpper(), - database, + Urn.EscapeString(database), scriptingObject.Type, - scriptingObject.Name, - scriptingObject.Schema != null ? string.Format("and @Schema = '{0}'", scriptingObject.Schema) : string.Empty); + Urn.EscapeString(scriptingObject.Name), + scriptingObject.Schema != null ? string.Format("and @Schema = '{0}'", Urn.EscapeString(scriptingObject.Schema)) : string.Empty); return new Urn(urn); } diff --git a/test/Microsoft.SqlTools.Hosting.UnitTests/Microsoft.SqlTools.Hosting.UnitTests.csproj b/test/Microsoft.SqlTools.Hosting.UnitTests/Microsoft.SqlTools.Hosting.UnitTests.csproj index f28f4d44..5fe6b272 100644 --- a/test/Microsoft.SqlTools.Hosting.UnitTests/Microsoft.SqlTools.Hosting.UnitTests.csproj +++ b/test/Microsoft.SqlTools.Hosting.UnitTests/Microsoft.SqlTools.Hosting.UnitTests.csproj @@ -2,6 +2,7 @@ netcoreapp2.1 false + true diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj index 88330b73..41f266ba 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj @@ -34,9 +34,7 @@ - - - + diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Microsoft.SqlTools.ServiceLayer.PerfTests.csproj b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Microsoft.SqlTools.ServiceLayer.PerfTests.csproj index 37a930c7..f998c418 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Microsoft.SqlTools.ServiceLayer.PerfTests.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Microsoft.SqlTools.ServiceLayer.PerfTests.csproj @@ -11,6 +11,7 @@ win7-x64;win7-x86 Microsoft.SqlTools.ServiceLayer.PerfTests.Program true + true diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Microsoft.SqlTools.ServiceLayer.Test.Common.csproj b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Microsoft.SqlTools.ServiceLayer.Test.Common.csproj index 29891e27..70c955e7 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Microsoft.SqlTools.ServiceLayer.Test.Common.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Microsoft.SqlTools.ServiceLayer.Test.Common.csproj @@ -13,9 +13,7 @@ - - - + diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs index 7d1fee7a..6e7bebaf 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs @@ -97,13 +97,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common public void Verify(TraceEventType eventType, string message, string callstackMessage, bool shouldVerifyCallstack = false, bool expectLogMessage = true) { + Logger.Flush(); + // The Regex uses .* between the severity and the message to allow SMO to vary the content. 140 SMO has nothing there, 150 has a timestamp if (expectLogMessage) { - Assert.True(File.Exists(Logger.LogFileFullPath) && Regex.IsMatch(LogContents, $@"\b{eventType}:\s+\d+\s+:\s+{message}", RegexOptions.Compiled)); + Assert.True(File.Exists(Logger.LogFileFullPath) && Regex.IsMatch(LogContents, $@"\b{eventType}:.*{message}", RegexOptions.Compiled)); } else { - Assert.False(File.Exists(Logger.LogFileFullPath) && Regex.IsMatch(LogContents, $@"\b{eventType}:\s+\d+\s+:\s+{message}", RegexOptions.Compiled)); + Assert.False(File.Exists(Logger.LogFileFullPath) && Regex.IsMatch(LogContents, $@"\b{eventType}:.*{message}", RegexOptions.Compiled)); } if (shouldVerifyCallstack) { diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests.csproj b/test/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests.csproj index dc59f22b..03537ee2 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests/Microsoft.SqlTools.ServiceLayer.TestDriver.Tests.csproj @@ -10,6 +10,7 @@ false false false + true diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Microsoft.SqlTools.ServiceLayer.TestDriver.csproj b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Microsoft.SqlTools.ServiceLayer.TestDriver.csproj index be8ba2ae..f941d803 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Microsoft.SqlTools.ServiceLayer.TestDriver.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Microsoft.SqlTools.ServiceLayer.TestDriver.csproj @@ -13,9 +13,7 @@ - - - + diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj b/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj index a806d4ba..4c849532 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Microsoft.SqlTools.ServiceLayer.TestEnvConfig.csproj @@ -7,6 +7,7 @@ false false false + true diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Microsoft.SqlTools.ServiceLayer.UnitTests.csproj b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Microsoft.SqlTools.ServiceLayer.UnitTests.csproj index 36c739f5..c506b7be 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Microsoft.SqlTools.ServiceLayer.UnitTests.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Microsoft.SqlTools.ServiceLayer.UnitTests.csproj @@ -11,13 +11,12 @@ + - - - + diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Scripting/ScriptingExtensionMethodsTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Scripting/ScriptingExtensionMethodsTests.cs new file mode 100644 index 00000000..f0441a9f --- /dev/null +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Scripting/ScriptingExtensionMethodsTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.SqlServer.Management.Sdk.Sfc; +using Microsoft.SqlTools.ServiceLayer.Scripting; +using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts; +using NUnit.Framework; +using Assert = NUnit.Framework.Assert; +namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Scripting +{ + + public class ScriptingExtensionMethodsTests + { + /// + /// SQL sysname supports single quotes in object names, so URN attributes need to be properly escaped + /// + [Xunit.Fact] + public void ToUrnEscapesAttributes() + { + var scriptingObject = new ScriptingObject() { Name = "quoted'Name", Schema = "quoted'Schema", Type = "Table" }; + var urn = scriptingObject.ToUrn("server", "quoted'db"); + Assert.That(urn.ToString, Is.EqualTo("Server[@Name='SERVER']/Database[@Name='quoted''db']/Table[@Name='quoted''Name' and @Schema = 'quoted''Schema']"), "Urn should have escaped Name attributes"); + Assert.That(urn.Type, Is.EqualTo("Table"), "Urn Type"); + // These assertions are more for educational purposes than for testing, since the methods are Urn methods in SFC. + Assert.That(urn.GetNameForType("Database"), Is.EqualTo("quoted'db"), "GetNameForType('Database')"); + Assert.That(urn.GetAttribute("Schema"), Is.EqualTo("quoted'Schema"), "GetAttribute('Schema')"); + } + + [Xunit.Fact] + public void ToObjectStringUnescapesAttributes() + { + var urn = new Urn(@"Server[@Name = 'SERVER']/Database[@Name = 'quoted''db']/Table[@Name = 'quoted''Name' and @Schema = 'quoted''Schema']"); + var scriptingObject = urn.ToScriptingObject(); + Assert.That(scriptingObject.Type, Is.EqualTo("Table"), "Type"); + Assert.That(scriptingObject.Name, Is.EqualTo("quoted'Name"), "Name"); + Assert.That(scriptingObject.Schema, Is.EqualTo("quoted'Schema"), "Schema"); + } + } +}