Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Scripting/ScriptingExtensionMethodsTests.cs
David Shiflet 839acf67cd Convert most tools service tests to nunit (#1037)
* Remove xunit dependency from testdriver

* swap expected/actual as needed

* Convert Test.Common to nunit

* port hosting unit tests to nunit

* port batchparser integration tests to nunit

* port testdriver.tests to nunit

* fix target to copy dependency

* port servicelayer unittests to nunit

* more unit test fixes

* port integration tests to nunit

* fix test method type

* try using latest windows build for PRs

* reduce test memory use
2020-08-05 13:43:14 -04:00

40 lines
2.0 KiB
C#

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
{
/// <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.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')");
}
[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");
}
}
}