mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:35:43 -05:00
* Minimal changes to make headers appear on empty result sets * Columns for everyone! * Updating tests - some don't pass yet * Adding some more tests to verify the changes for column/row selection * null default columns * Updates to comments as per PR comments
43 lines
2.0 KiB
C#
43 lines
2.0 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// SQL sysname supports single quotes in object names, so URN attributes need to be properly escaped
|
|
/// </summary>
|
|
[Test]
|
|
public void ToUrnEscapesAttributes()
|
|
{
|
|
var scriptingObject = new ScriptingObject() { Name = "quoted'Name", Schema = "quoted'Schema", Type = "Table" };
|
|
var urn = scriptingObject.ToUrn("server", "quoted'db");
|
|
Assert.AreEqual("Server[@Name='SERVER']/Database[@Name='quoted''db']/Table[@Name='quoted''Name' and @Schema = 'quoted''Schema']", urn.ToString(), "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')");
|
|
}
|
|
|
|
[Test]
|
|
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");
|
|
}
|
|
}
|
|
}
|