mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
@@ -16,7 +16,6 @@ using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.Baselined;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using static Microsoft.SqlTools.ServiceLayer.ObjectExplorer.ObjectExplorerService;
|
using static Microsoft.SqlTools.ServiceLayer.ObjectExplorer.ObjectExplorerService;
|
||||||
@@ -267,8 +266,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
string msg = ex.BuildRecursiveErrorMessage();
|
string msg = ex.BuildRecursiveErrorMessage();
|
||||||
Console.WriteLine($"Failed to run OE test. uri:{uri} error:{msg} {ex.StackTrace}");
|
throw new Exception($"Failed to run OE test. uri:{uri} error:{msg} {ex.StackTrace}");
|
||||||
Assert.False(true, msg);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -297,50 +295,50 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
|||||||
|
|
||||||
private async Task<NodeInfo> ExpandServerNodeAndVerifyDatabaseHierachy(string databaseName, ObjectExplorerSession session, bool serverNode = true)
|
private async Task<NodeInfo> ExpandServerNodeAndVerifyDatabaseHierachy(string databaseName, ObjectExplorerSession session, bool serverNode = true)
|
||||||
{
|
{
|
||||||
Assert.NotNull(session);
|
Assert.That(session, Is.Not.Null, nameof(session));
|
||||||
Assert.NotNull(session.Root);
|
Assert.That(session.Root, Is.Not.Null, nameof(session.Root));
|
||||||
NodeInfo nodeInfo = session.Root.ToNodeInfo();
|
NodeInfo nodeInfo = session.Root.ToNodeInfo();
|
||||||
Assert.AreEqual(false, nodeInfo.IsLeaf);
|
Assert.That(nodeInfo.IsLeaf, Is.False, "Should not be a leaf node");
|
||||||
|
|
||||||
NodeInfo databaseNode = null;
|
NodeInfo? databaseNode = null;
|
||||||
|
|
||||||
if (serverNode)
|
if (serverNode)
|
||||||
{
|
{
|
||||||
Assert.AreEqual(nodeInfo.NodeType, NodeTypes.Server.ToString());
|
Assert.That(nodeInfo.NodeType, Is.EqualTo(NodeTypes.Server.ToString()), "Server node has incorrect type");
|
||||||
var children = session.Root.Expand(new CancellationToken());
|
var children = session.Root.Expand(new CancellationToken());
|
||||||
|
|
||||||
//All server children should be folder nodes
|
//All server children should be folder nodes
|
||||||
foreach (var item in children)
|
foreach (var item in children)
|
||||||
{
|
{
|
||||||
Assert.AreEqual("Folder", item.NodeType);
|
Assert.That(item.NodeType, Is.EqualTo(NodeTypes.Folder.ToString()), $"Node {item.Label} should be folder");
|
||||||
}
|
}
|
||||||
|
|
||||||
var databasesRoot = children.FirstOrDefault(x => x.NodeTypeId == NodeTypes.Databases);
|
var databasesRoot = children.FirstOrDefault(x => x.NodeTypeId == NodeTypes.Databases);
|
||||||
var databasesChildren = (await _service.ExpandNode(session, databasesRoot.GetNodePath())).Nodes;
|
var databasesChildren = (await _service.ExpandNode(session, databasesRoot.GetNodePath())).Nodes;
|
||||||
var databases = databasesChildren.Where(x => x.NodeType == NodeTypes.Database.ToString());
|
var databases = databasesChildren.Where(x => x.NodeType == NodeTypes.Database.ToString());
|
||||||
|
|
||||||
//Verify the test databases is in the list
|
// Verify the test databases is in the list
|
||||||
Assert.NotNull(databases);
|
|
||||||
Assert.False(databases.Any(x => x.Label == "master"));
|
Assert.False(databases.Any(x => x.Label == "master"));
|
||||||
var systemDatabasesNode = databasesChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_SystemDatabases);
|
Assert.That(databases, Has.None.Matches<NodeInfo>(n => n.Label == "master"), "master database not expected in user databases folder");
|
||||||
Assert.NotNull(systemDatabasesNode);
|
var systemDatabasesNodes = databasesChildren.Where(x => x.Label == SR.SchemaHierarchy_SystemDatabases).ToList();
|
||||||
|
Assert.That(systemDatabasesNodes, Has.Count.EqualTo(1), $"Exactly one {SR.SchemaHierarchy_SystemDatabases} node expected");
|
||||||
|
|
||||||
var systemDatabases = await _service.ExpandNode(session, systemDatabasesNode.NodePath);
|
var expandResponse = await _service.ExpandNode(session, systemDatabasesNodes.First().NodePath);
|
||||||
Assert.True(systemDatabases.Nodes.Any(x => x.Label == "master"));
|
Assert.That(expandResponse.Nodes, Has.One.Matches<NodeInfo>(n => n.Label == "master"), "master database expected in system databases folder");
|
||||||
|
|
||||||
databaseNode = databases.FirstOrDefault(d => d.Label == databaseName);
|
databaseNode = databases.FirstOrDefault(d => d.Label == databaseName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert.AreEqual(nodeInfo.NodeType, NodeTypes.Database.ToString());
|
Assert.That(nodeInfo.NodeType, Is.EqualTo(NodeTypes.Database.ToString()), $"Database node {nodeInfo.Label} has incorrect type");
|
||||||
databaseNode = session.Root.ToNodeInfo();
|
databaseNode = session.Root.ToNodeInfo();
|
||||||
Assert.True(databaseNode.Label.Contains(databaseName));
|
Assert.True(databaseNode.Label.Contains(databaseName));
|
||||||
var databasesChildren = (await _service.ExpandNode(session, databaseNode.NodePath)).Nodes;
|
var databasesChildren = (await _service.ExpandNode(session, databaseNode.NodePath)).Nodes;
|
||||||
Assert.False(databasesChildren.Any(x => x.Label == SR.SchemaHierarchy_SystemDatabases));
|
Assert.False(databasesChildren.Any(x => x.Label == SR.SchemaHierarchy_SystemDatabases));
|
||||||
|
|
||||||
}
|
}
|
||||||
Assert.NotNull(databaseNode);
|
Assert.That(databaseNode, Is.Not.Null, "Database node should not be null");
|
||||||
return databaseNode;
|
return databaseNode!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ExpandAndVerifyDatabaseNode(string databaseName, ObjectExplorerSession session)
|
private async Task ExpandAndVerifyDatabaseNode(string databaseName, ObjectExplorerSession session)
|
||||||
@@ -369,7 +367,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
|||||||
Console.WriteLine($"Session closed uri:{uri}");
|
Console.WriteLine($"Session closed uri:{uri}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ExpandTree(NodeInfo node, ObjectExplorerSession session, StringBuilder stringBuilder = null, bool verifySystemObjects = false)
|
private async Task ExpandTree(NodeInfo node, ObjectExplorerSession session, StringBuilder? stringBuilder = null, bool verifySystemObjects = false)
|
||||||
{
|
{
|
||||||
if (node != null && !node.IsLeaf)
|
if (node != null && !node.IsLeaf)
|
||||||
{
|
{
|
||||||
@@ -432,11 +430,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
|||||||
{
|
{
|
||||||
// These are node types for which the label doesn't include a schema
|
// These are node types for which the label doesn't include a schema
|
||||||
// (usually because the objects themselves aren't schema-bound)
|
// (usually because the objects themselves aren't schema-bound)
|
||||||
var schemalessLabelNodeTypes = new List<string> () {
|
var schemalessLabelNodeTypes = new List<string> () {
|
||||||
"Column",
|
"Column",
|
||||||
"Key",
|
"Key",
|
||||||
"Constraint",
|
"Constraint",
|
||||||
"Index",
|
"Index",
|
||||||
"Statistic",
|
"Statistic",
|
||||||
"Trigger",
|
"Trigger",
|
||||||
"StoredProcedureParameter",
|
"StoredProcedureParameter",
|
||||||
@@ -473,7 +471,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
|||||||
if (!string.IsNullOrEmpty(baseline))
|
if (!string.IsNullOrEmpty(baseline))
|
||||||
{
|
{
|
||||||
string actual = stringBuilder.ToString();
|
string actual = stringBuilder.ToString();
|
||||||
BaselinedTest.CompareActualWithBaseline(actual, baseline);
|
Assert.That(actual, Is.EqualTo(baseline), $"Baseline comparison for {baselineFileName} failed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -266,33 +266,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common.Baselined
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares two strings and gives appropriate output
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="actualContent">Actual string</param>
|
|
||||||
/// <param name="baselineContent">Expected string</param>
|
|
||||||
/// <remarks>Fails test if strings do not match; comparison is done using an InvariantCulture StringComparer</remarks>
|
|
||||||
public static void CompareActualWithBaseline(string actualContent, string baselineContent)
|
|
||||||
{
|
|
||||||
|
|
||||||
int _compareResult = string.Compare(actualContent, baselineContent, StringComparison.OrdinalIgnoreCase);
|
|
||||||
if (_compareResult != 0)
|
|
||||||
{
|
|
||||||
Trace.WriteLine("Debug Info:");
|
|
||||||
Trace.WriteLine("========BEGIN=EXPECTED========");
|
|
||||||
Trace.WriteLine(baselineContent);
|
|
||||||
Trace.WriteLine("=========END=EXPECTED=========");
|
|
||||||
Trace.WriteLine("=========BEGIN=ACTUAL=========");
|
|
||||||
Trace.WriteLine(actualContent);
|
|
||||||
Trace.WriteLine("==========END=ACTUAL==========");
|
|
||||||
Assert.True(false, string.Format("Comparison failed! (actualContent {0} baselineContent)", (_compareResult < 0 ? "<" : ">"))); //we already know it is not equal
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Trace.WriteLine("Compare match! All is fine...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the testscript with the provided name
|
/// Gets the name of the testscript with the provided name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
{
|
{
|
||||||
uri = queryTempFile.FilePath;
|
uri = queryTempFile.FilePath;
|
||||||
|
|
||||||
ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, uri);
|
ConnectionInfo connInfo = await InitLiveConnectionInfo(serverType, databaseName, uri);
|
||||||
Query query = new Query(queryText, connInfo, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory());
|
Query query = new Query(queryText, connInfo, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory());
|
||||||
query.Execute();
|
query.Execute();
|
||||||
await query.ExecutionTask;
|
await query.ExecutionTask;
|
||||||
@@ -132,23 +132,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConnectionInfo InitLiveConnectionInfo(TestServerType serverType, string databaseName, string scriptFilePath)
|
private async Task<ConnectionInfo> InitLiveConnectionInfo(TestServerType serverType, string databaseName, string scriptFilePath)
|
||||||
{
|
{
|
||||||
ConnectParams connectParams = ConnectionProfileService.GetConnectionParameters(serverType, databaseName);
|
ConnectParams connectParams = ConnectionProfileService.GetConnectionParameters(serverType, databaseName);
|
||||||
|
|
||||||
string ownerUri = scriptFilePath;
|
string ownerUri = scriptFilePath;
|
||||||
var connectionService = ConnectionService.Instance;
|
var connectionService = ConnectionService.Instance;
|
||||||
var connectionResult = connectionService.Connect(new ConnectParams()
|
var connectionResult = await connectionService.Connect(new ConnectParams()
|
||||||
{
|
{
|
||||||
OwnerUri = ownerUri,
|
OwnerUri = ownerUri,
|
||||||
Connection = connectParams.Connection
|
Connection = connectParams.Connection
|
||||||
});
|
});
|
||||||
|
|
||||||
connectionResult.Wait();
|
if(!string.IsNullOrEmpty(connectionResult.ErrorMessage))
|
||||||
|
{
|
||||||
ConnectionInfo connInfo = null;
|
throw new Exception($"Error creating live connection to {connectParams.Connection.ServerName} (Type={serverType}). Error: {connectionResult.ErrorMessage}");
|
||||||
|
}
|
||||||
|
ConnectionInfo? connInfo = null;
|
||||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||||
Assert.NotNull(connInfo);
|
Assert.That(connInfo, Is.Not.Null, $"Could not find connection {ownerUri} when creating live connection");
|
||||||
return connInfo;
|
return connInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,39 +5,9 @@
|
|||||||
<UserId>[user name for SQL authentication]</UserId>
|
<UserId>[user name for SQL authentication]</UserId>
|
||||||
<Password>[password for SQL authentication]</Password>
|
<Password>[password for SQL authentication]</Password>
|
||||||
</Instance>
|
</Instance>
|
||||||
<Instance VersionKey="defaultSql2016">
|
|
||||||
<DataSource>[server name]</DataSource>
|
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
|
||||||
<Password>[password for SQL authentication]</Password>
|
|
||||||
</Instance>
|
|
||||||
<Instance VersionKey="defaultSqlAzureV12">
|
<Instance VersionKey="defaultSqlAzureV12">
|
||||||
<DataSource>[server name]</DataSource>
|
<DataSource>[server name]</DataSource>
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
<UserId>[user name for SQL authentication]</UserId>
|
||||||
<Password>[password for SQL authentication]</Password>
|
<Password>[password for SQL authentication]</Password>
|
||||||
</Instance>
|
</Instance>
|
||||||
<Instance VersionKey="defaultSql2005">
|
|
||||||
<DataSource>[server name]</DataSource>
|
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
|
||||||
<Password>[password for SQL authentication]</Password>
|
|
||||||
</Instance>
|
|
||||||
<Instance VersionKey="defaultSql2008">
|
|
||||||
<DataSource>[server name]</DataSource>
|
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
|
||||||
<Password>[password for SQL authentication]</Password>
|
|
||||||
</Instance>
|
|
||||||
<Instance VersionKey="defaultSql2011">
|
|
||||||
<DataSource>[server name]</DataSource>
|
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
|
||||||
<Password>[password for SQL authentication]</Password>
|
|
||||||
</Instance>
|
|
||||||
<Instance VersionKey="defaultSqlAzure">
|
|
||||||
<DataSource>[server name]</DataSource>
|
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
|
||||||
<Password>[password for SQL authentication]</Password>
|
|
||||||
</Instance>
|
|
||||||
<Instance VersionKey="defaultSql2014">
|
|
||||||
<DataSource>[server name]</DataSource>
|
|
||||||
<UserId>[user name for SQL authentication]</UserId>
|
|
||||||
<Password>[password for SQL authentication]</Password>
|
|
||||||
</Instance>
|
|
||||||
</Instances>
|
</Instances>
|
||||||
|
|||||||
Reference in New Issue
Block a user