mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 01:25:41 -05:00
Adding schema based object folders in OE (#1849)
* Making node types automated * Adding schema based OE * added folder types in NodeTypes * Fixing stuff * Moving schema to parent and cleaning up some code * Replacing strings with nameof * Sorting nodetypes generated by tt * Adding option to put folders after nodes * Fixing folder and children order * Fixing tests * Formatting file * Formatting tt files * Fixing tt * fixing types * Update src/Microsoft.SqlTools.ServiceLayer/SqlContext/ObjectExplorerSettings.cs Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * Fixing stuff * Updating schema definitions and adding more logs * Fixing copyright * Adding Integration and Unit Tests * Fixing test --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -19,8 +19,10 @@ using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
|
||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using NUnit.Framework;
|
||||
using static Microsoft.SqlTools.ServiceLayer.ObjectExplorer.ObjectExplorerService;
|
||||
|
||||
@@ -210,6 +212,50 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GroupBySchemaisDisabled()
|
||||
{
|
||||
string query = @"Create schema t1
|
||||
GO
|
||||
Create schema t2
|
||||
GO";
|
||||
string databaseName = "#testDb#";
|
||||
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
|
||||
{
|
||||
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = false };
|
||||
var databaseNode = session.Root.ToNodeInfo();
|
||||
var databaseChildren = await _service.ExpandNode(session, databaseNode.NodePath);
|
||||
Assert.True(databaseChildren.Nodes.Any(t => t.Label == SR.SchemaHierarchy_Tables), "Tables node should be found in database node when group by schema is disabled");
|
||||
Assert.True(databaseChildren.Nodes.Any(t => t.Label == SR.SchemaHierarchy_Views), "Views node should be found in database node when group by schema is disabled");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GroupBySchemaisEnabled()
|
||||
{
|
||||
string query = @"Create schema t1
|
||||
GO
|
||||
Create schema t2
|
||||
GO";
|
||||
string databaseName = "#testDb#";
|
||||
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
|
||||
{
|
||||
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = true };
|
||||
var databaseNode = session.Root.ToNodeInfo();
|
||||
var databaseChildren = await _service.ExpandNode(session, databaseNode.NodePath);
|
||||
Assert.True(databaseChildren.Nodes.Any(t => t.Label == "t1"), "Schema node t1 should be found in database node when group by schema is enabled");
|
||||
Assert.True(databaseChildren.Nodes.Any(t => t.Label == "t2"), "Schema node t2 should be found in database node when group by schema is enabled");
|
||||
Assert.False(databaseChildren.Nodes.Any(t => t.Label == SR.SchemaHierarchy_Tables), "Tables node should not be found in database node when group by schema is enabled");
|
||||
Assert.False(databaseChildren.Nodes.Any(t => t.Label == SR.SchemaHierarchy_Views), "Views node should not be found in database node when group by schema is enabled");
|
||||
Assert.True(databaseChildren.Nodes.Any(t => t.Label == SR.SchemaHierarchy_Programmability), "Programmability node should be found in database node when group by schema is enabled");
|
||||
var lastSchemaPosition = Array.FindLastIndex(databaseChildren.Nodes, t => t.ObjectType == nameof(NodeTypes.ExpandableSchema));
|
||||
var firstNonSchemaPosition = Array.FindIndex(databaseChildren.Nodes, t => t.ObjectType != nameof(NodeTypes.ExpandableSchema));
|
||||
Assert.True(lastSchemaPosition < firstNonSchemaPosition, "Schema nodes should be before non-schema nodes");
|
||||
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = false };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private async Task VerifyRefresh(ObjectExplorerSession session, string tablePath, string tableName, bool deleted = true)
|
||||
{
|
||||
//Refresh Root
|
||||
@@ -217,7 +263,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
||||
|
||||
//Verify tables cache is empty
|
||||
var rootChildrenCache = session.Root.GetChildren();
|
||||
var tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
|
||||
var tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
|
||||
Assert.False(tablesCache.Any());
|
||||
|
||||
//Expand Tables
|
||||
@@ -292,7 +338,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
||||
ConnectionDetails details = connectParams.Connection;
|
||||
string uri = ObjectExplorerService.GenerateUri(details);
|
||||
|
||||
var session = await _service.DoCreateSession(details, uri);
|
||||
var session = await _service.DoCreateSession(details, uri);
|
||||
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "OE session created for database: {0}", databaseName));
|
||||
return session;
|
||||
}
|
||||
@@ -403,7 +449,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
||||
/// </summary>
|
||||
private async Task<NodeInfo> FindNodeByLabel(NodeInfo node, ObjectExplorerSession session, string label)
|
||||
{
|
||||
if(node != null && node.Label == label)
|
||||
if (node != null && node.Label == label)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
@@ -434,7 +480,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
||||
{
|
||||
// These are node types for which the label doesn't include a schema
|
||||
// (usually because the objects themselves aren't schema-bound)
|
||||
var schemalessLabelNodeTypes = new List<string> () {
|
||||
var schemalessLabelNodeTypes = new List<string>() {
|
||||
"Column",
|
||||
"Key",
|
||||
"Constraint",
|
||||
|
||||
Reference in New Issue
Block a user