Creating a new Sql Core project that stores OE classes. (#2165)

* init

* More fixes

* moving filters from contracts to core OE classes

* Fixing some tests

* More fixes and added doc comments

* Fixing tests

* Quick refactoring

* more cleanups

* cleanup

* Adding stateless OE

* Adding null checks

* Making group by schema independent of settings

* Fixing tests

* Removing node info from core oe code

* Fixing tests and moving OE code to its own project

* moving oe to own project

* Removing changes to Kusto

* Removing azure access token from service layer

* Fixing project description and title

* Fixing file name typo

* Removing unused  strings from service layer

* Fixing localized strings in tests
Adding comments to stateless OE

* Fixing stuff

* Update src/Microsoft.SqlTools.SqlCore/Microsoft.SqlTools.SqlCore.csproj

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Fixing project nesting

* Fixing more stuff and removing OE class

* Cleanup

* Code cleanup

* fixing oe service provider

* Fixing test name

* Remove using

* Update src/Microsoft.SqlTools.SqlCore/ObjectExplorer/SmoModel/SmoQueryContext.cs

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Fixing syntax error

* Adding project to locproject

* Fixing stuff

* Fixing errors

* sorting usings

---------

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
Aasim Khan
2023-08-17 05:11:35 +00:00
committed by GitHub
parent 4ae9534ac8
commit 73c2a75fba
98 changed files with 6755 additions and 6116 deletions

View File

@@ -21,6 +21,7 @@ using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
using Microsoft.SqlTools.SqlCore.Metadata;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Metadata
{

View File

@@ -18,7 +18,7 @@ using System.Threading.Tasks;
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.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
@@ -70,9 +70,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
await RunTest(databaseName, query, "TepmDb", async (testDbName, session) =>
{
var serverChildren = (await _service.ExpandNode(session, session.Root.GetNodePath())).Nodes;
var securityNode = serverChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Security);
var securityNode = serverChildren.FirstOrDefault(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Security);
var securityChildren = (await _service.ExpandNode(session, securityNode.NodePath)).Nodes;
var loginsNode = securityChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Logins);
var loginsNode = securityChildren.FirstOrDefault(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Logins);
var loginsChildren = (await _service.ExpandNode(session, loginsNode.NodePath)).Nodes;
var login = loginsChildren.FirstOrDefault(x => x.Label == "OEServerLogin");
Assert.NotNull(login);
@@ -106,9 +106,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
await RunTest(databaseName, query, "TepmDb", async (testDbName, session) =>
{
var serverChildren = (await _service.ExpandNode(session, session.Root.GetNodePath())).Nodes;
var serverObjectsNode = serverChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_ServerObjects);
var serverObjectsNode = serverChildren.FirstOrDefault(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_ServerObjects);
var serverObjectsChildren = (await _service.ExpandNode(session, serverObjectsNode.NodePath)).Nodes;
var triggersNode = serverObjectsChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Triggers);
var triggersNode = serverObjectsChildren.FirstOrDefault(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Triggers);
var triggersChildren = await _service.ExpandNode(session, triggersNode.NodePath);
var trigger = triggersChildren.Nodes.FirstOrDefault(x => x.Label == "OE_ddl_trig_database");
Assert.NotNull(trigger);
@@ -134,7 +134,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
string databaseName = "#testDb#";
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
var tablesNode = await FindNodeByLabel(session.Root.ToNodeInfo(), session, SR.SchemaHierarchy_Tables);
var tablesNode = await FindNodeByLabel(new NodeInfo(session.Root), session, SqlTools.SqlCore.SR.SchemaHierarchy_Tables);
var tableChildren = (await _service.ExpandNode(session, tablesNode.NodePath)).Nodes;
string dropTableScript = "Drop Table t1";
Assert.True(tableChildren.Any(t => t.Label == "dbo.t1"));
@@ -161,7 +161,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
var databaseNode = await ExpandServerNodeAndVerifyDatabaseHierachy(testDbName, session);
var response = await _service.ExpandNode(session, databaseNode.NodePath);
Assert.True(response.ErrorMessage.Contains(string.Format(CultureInfo.InvariantCulture, SR.DatabaseNotAccessible, testDbName)));
Assert.True(response.ErrorMessage.Contains(string.Format(CultureInfo.InvariantCulture, SqlTools.SqlCore.SR.DatabaseNotAccessible, testDbName)));
});
}
@@ -178,7 +178,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
string databaseName = "#testDb#";
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
var tablesNode = await FindNodeByLabel(session.Root.ToNodeInfo(), session, SR.SchemaHierarchy_Tables);
var tablesNode = await FindNodeByLabel(new NodeInfo(session.Root), session, SqlTools.SqlCore.SR.SchemaHierarchy_Tables);
//Expand Tables node
var tableChildren = await _service.ExpandNode(session, tablesNode.NodePath);
@@ -198,7 +198,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
//Verify the tables cache has items
var rootChildrenCache = session.Root.GetChildren();
var tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
var tablesCache = rootChildrenCache.First(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Tables).GetChildren();
Assert.True(tablesCache.Any());
await VerifyRefresh(session, tablesNode.NodePath, "dbo.t1");
@@ -220,10 +220,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = false };
var databaseNode = session.Root.ToNodeInfo();
var databaseNode = new NodeInfo(session.Root);
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");
Assert.True(databaseChildren.Nodes.Any(t => t.Label == SqlTools.SqlCore.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 == SqlTools.SqlCore.SR.SchemaHierarchy_Views), "Views node should be found in database node when group by schema is disabled");
});
}
@@ -238,13 +238,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = true };
var databaseNode = session.Root.ToNodeInfo();
var databaseNode = new NodeInfo(session.Root);
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");
Assert.False(databaseChildren.Nodes.Any(t => t.Label == SqlTools.SqlCore.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 == SqlTools.SqlCore.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 == SqlTools.SqlCore.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");
@@ -263,7 +263,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = true };
var databaseNode = session.Root.ToNodeInfo();
var databaseNode = new NodeInfo(session.Root);
var databaseChildren = await _service.ExpandNode(session, databaseNode.NodePath);
Assert.True(databaseChildren.Nodes.Any(t => t.Label == "t1"), "Non legacy schema node t1 should be found in database node when group by schema is enabled");
Assert.True(databaseChildren.Nodes.Any(t => t.Label == "t2"), "Non legacy schema node t2 should be found in database node when group by schema is enabled");
@@ -283,7 +283,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
Assert.That(legacySchemas, Does.Not.Contain(nodes.Label), "Legacy schema node should not be found in database node when group by schema is enabled");
}
var legacySchemasNode = databaseChildren.Nodes.First(t => t.Label == SR.SchemaHierarchy_BuiltInSchema);
var legacySchemasNode = databaseChildren.Nodes.First(t => t.Label == SqlTools.SqlCore.SR.SchemaHierarchy_BuiltInSchema);
var legacySchemasChildren = await _service.ExpandNode(session, legacySchemasNode.NodePath);
foreach (var nodes in legacySchemasChildren.Nodes)
{
@@ -306,10 +306,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
string databaseName = "#testDb#";
await RunTest(databaseName, query, "Testdb", async (testDbName, session) =>
{
var databaseNode = session.Root.ToNodeInfo();
var databaseNode = new NodeInfo(session.Root);
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");
var tablesNode = databaseChildren.Nodes.First(t => t.Label == SR.SchemaHierarchy_Tables);
Assert.True(databaseChildren.Nodes.Any(t => t.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Tables), "Tables node should be found in database node");
var tablesNode = databaseChildren.Nodes.First(t => t.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Tables);
var NameProperty = tablesNode.FilterableProperties.First(t => t.Name == "Name");
Assert.True(NameProperty != null, "Name property should be found in tables node");
@@ -385,11 +385,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
private async Task VerifyRefresh(ObjectExplorerSession session, string tablePath, string tableName, bool deleted = true)
{
//Refresh Root
var rootChildren = await _service.ExpandNode(session, session.Root.ToNodeInfo().NodePath, true);
var rootChildren = await _service.ExpandNode(session, new NodeInfo(session.Root).NodePath, true);
//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 == SqlTools.SqlCore.SR.SchemaHierarchy_Tables).GetChildren();
Assert.False(tablesCache.Any());
//Expand Tables
@@ -400,7 +400,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
//Verify tables cache has items
rootChildrenCache = session.Root.GetChildren();
tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
tablesCache = rootChildrenCache.First(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Tables).GetChildren();
Assert.True(tablesCache.Any());
}
@@ -473,7 +473,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
Assert.That(session, Is.Not.Null, nameof(session));
Assert.That(session.Root, Is.Not.Null, nameof(session.Root));
var nodeInfo = session.Root.ToNodeInfo();
var nodeInfo = new NodeInfo(session.Root);
Assert.That(nodeInfo.IsLeaf, Is.False, "Should not be a leaf node");
NodeInfo databaseNode = null;
@@ -496,8 +496,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
// Verify the test databases is in the list
Assert.False(databases.Any(x => x.Label == "master"));
Assert.That(databases, Has.None.Matches<NodeInfo>(n => n.Label == "master"), "master database not expected in user databases folder");
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 systemDatabasesNodes = databasesChildren.Where(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_SystemDatabases).ToList();
Assert.That(systemDatabasesNodes, Has.Count.EqualTo(1), $"Exactly one {SqlTools.SqlCore.SR.SchemaHierarchy_SystemDatabases} node expected");
var expandResponse = await _service.ExpandNode(session, systemDatabasesNodes.First().NodePath);
Assert.That(expandResponse.Nodes, Has.One.Matches<NodeInfo>(n => n.Label == "master"), "master database expected in system databases folder");
@@ -507,10 +507,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
else
{
Assert.That(nodeInfo.NodeType, Is.EqualTo(NodeTypes.Database.ToString()), $"Database node {nodeInfo.Label} has incorrect type");
databaseNode = session.Root.ToNodeInfo();
databaseNode = new NodeInfo(session.Root);
Assert.True(databaseNode.Label.Contains(databaseName));
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 == SqlTools.SqlCore.SR.SchemaHierarchy_SystemDatabases));
}
Assert.That(databaseNode, Is.Not.Null, "Database node should not be null");
@@ -521,7 +521,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
Assert.NotNull(session);
Assert.NotNull(session.Root);
var nodeInfo = session.Root.ToNodeInfo();
var nodeInfo = new NodeInfo(session.Root);
Assert.AreEqual(false, nodeInfo.IsLeaf);
Assert.AreEqual(nodeInfo.NodeType, NodeTypes.Database.ToString());
Assert.True(nodeInfo.Label.Contains(databaseName));
@@ -533,7 +533,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
Assert.AreEqual("Folder", item.NodeType);
}
var tablesRoot = children.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Tables);
var tablesRoot = children.FirstOrDefault(x => x.Label == SqlTools.SqlCore.SR.SchemaHierarchy_Tables);
Assert.NotNull(tablesRoot);
}
@@ -555,10 +555,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
stringBuilder.Append($"NodeType: {child.NodeType} Label: {child.Label} SubType:{child.NodeSubType} Status:{child.NodeStatus}{Environment.NewLine}");
}
if (!verifySystemObjects && (child.Label == SR.SchemaHierarchy_SystemStoredProcedures ||
child.Label == SR.SchemaHierarchy_SystemViews ||
child.Label == SR.SchemaHierarchy_SystemFunctions ||
child.Label == SR.SchemaHierarchy_SystemDataTypes))
if (!verifySystemObjects && (child.Label == SqlTools.SqlCore.SR.SchemaHierarchy_SystemStoredProcedures ||
child.Label == SqlTools.SqlCore.SR.SchemaHierarchy_SystemViews ||
child.Label == SqlTools.SqlCore.SR.SchemaHierarchy_SystemFunctions ||
child.Label == SqlTools.SqlCore.SR.SchemaHierarchy_SystemDataTypes))
{
// don't expand the system folders because then the test will take for ever
}
@@ -642,7 +642,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
await RunTest(databaseName, query, testDbPrefix, async (testDbName, session) =>
{
await ExpandServerNodeAndVerifyDatabaseHierachy(testDbName, session, false);
await ExpandTree(session.Root.ToNodeInfo(), session, stringBuilder, verifySystemObjects);
await ExpandTree(new NodeInfo(session.Root), session, stringBuilder, verifySystemObjects);
string baseline = string.IsNullOrEmpty(baselineFileName) ? string.Empty : LoadBaseLine(baselineFileName);
if (!string.IsNullOrEmpty(baseline))
{

View File

@@ -0,0 +1,84 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.CoreSql.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
using System.Linq;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
public class StatelessObjectExplorerServiceTests
{
string databaseName = "tempdb";
ObjectExplorerServerInfo serverInfo = new ObjectExplorerServerInfo()
{
DatabaseName = "tempdb",
ServerName = "testserver",
UserName = "testuser",
IsCloud = true,
isDefaultOrSystemDatabase = false
};
ObjectExplorerOptions options = new ObjectExplorerOptions()
{
GroupBySchemaFlagGetter = () => true,
OperationTimeoutSeconds = 10000,
};
[Test]
[TestCase("", "dbo")]
[TestCase("testserver/{0}/dbo", "Tables")]
[TestCase("testserver/{0}/dbo/Tables", "dbo.t1")]
[TestCase("testserver/{0}/dbo/Tables", "dbo.t2")]
public async Task ExpandingPathShouldReturnCorrectNodes(string oePath, string childLabel)
{
var query = @"Create table t1 (c1 int)
GO
Create table t2 (c1 int)
GO";
await RunTest(databaseName, query, "testdb", async (testdbName, connectionString) =>
{
serverInfo.DatabaseName = testdbName;
var pathWithDb = string.Format(oePath, testdbName);
var nodes = StatelessObjectExplorer.Expand(connectionString, null, pathWithDb, serverInfo, options);
Assert.True(nodes.Any(node => node.Label == childLabel), $"Expansion result for {pathWithDb} does not contain node {childLabel}");
});
}
private async Task RunTest(string databaseName, string query, string testDbPrefix, Func<string, string, Task> test)
{
SqlTestDb? testDb = null;
try
{
testDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, query, testDbPrefix);
if (databaseName == "#testDb#")
{
databaseName = testDb.DatabaseName;
}
await test(testDb.DatabaseName, testDb.ConnectionString);
}
catch (Exception ex)
{
string msg = ex.BuildRecursiveErrorMessage();
throw new Exception($"Failed to run OE test. error:{msg} {ex.StackTrace}");
}
finally
{
if (testDb != null)
{
await testDb.CleanupAsync();
}
}
}
}
}

View File

@@ -34,6 +34,7 @@
<ProjectReference Include="../../src/Microsoft.SqlTools.ResourceProvider.Core/Microsoft.SqlTools.ResourceProvider.Core.csproj" />
<ProjectReference Include="../../src/Microsoft.SqlTools.ResourceProvider.DefaultImpl/Microsoft.SqlTools.ResourceProvider.DefaultImpl.csproj" />
<ProjectReference Include="../../test/Microsoft.SqlTools.ServiceLayer.Test.Common/Microsoft.SqlTools.ServiceLayer.Test.Common.csproj" />
<ProjectReference Include="../../src/Microsoft.SqlTools.SqlCore/Microsoft.SqlTools.SqlCore.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />

View File

@@ -4,13 +4,17 @@
//
using System;
using System.Linq;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Workspace;
using Moq;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
@@ -19,23 +23,31 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
Mock<DatabaseChildFactory> factory;
Mock<TreeNode> node;
Mock<SmoQueryContext> context;
bool enableGroupBySchema = false;
[SetUp]
public void init()
{
factory = new Mock<DatabaseChildFactory>();
factory.SetupGet(c => c.ChildQuerierTypes).Returns(null as Type[]);
factory.Setup(c => c.CreateChild(It.IsAny<TreeNode>(), It.IsAny<SqlSmoObject>())).Returns((TreeNode node, Schema obj) => {
return new TreeNode(){
factory.Setup(c => c.CreateChild(It.IsAny<TreeNode>(), It.IsAny<SqlSmoObject>())).Returns((TreeNode node, Schema obj) =>
{
return new TreeNode()
{
Label = obj.Name,
NodeType = nameof(NodeTypes.Schemas)
};
});
factory.CallBase = true;
Mock<SmoQueryContext> context = new Mock<SmoQueryContext>(new Server(), null);
context = new Mock<SmoQueryContext>(new Server(), ExtensionServiceProvider.CreateDefaultServiceProvider(), () =>
{
return enableGroupBySchema;
});
context.CallBase = true;
context.Object.ValidFor = ValidForFlag.None;
node = new Mock<TreeNode>();
node.Setup(n => n.GetContext()).Returns(context.Object);
}
@@ -43,7 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
[Test]
public void SchemaBasedFoldersExcludedWhenGroupBySchemaIsEnabled()
{
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = true };
enableGroupBySchema = true;
var children = factory.Object.Expand(node.Object, true, "TestDB", true, new System.Threading.CancellationToken());
Assert.False(children.Any(c => c.Label == "Tables"), "Tables subfolder in database should be excluded when group by schema is enabled");
Assert.False(children.Any(c => c.Label == "Views"), "Views subfolder in database should be excluded when group by schema is enabled");
@@ -53,6 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
[Test]
public void SchemaBasedFoldersIncludedWhenGroupBySchemaIsDisabled()
{
enableGroupBySchema = false;
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.SqlTools.ObjectExplorer = new ObjectExplorerSettings() { GroupBySchema = false };
var children = factory.Object.Expand(node.Object, true, "TestDB", true, new System.Threading.CancellationToken());
Assert.True(children.Any(c => c.Label == "Tables"), "Tables subfolder in database should be included when group by schema is disabled");
@@ -60,7 +73,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
Assert.True(children.Any(c => c.Label == "Synonyms"), "Synonyms subfolder in database should be included when group by schema is disabled");
}
}
}

View File

@@ -9,9 +9,9 @@ using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
@@ -908,7 +908,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
[TestCaseSource("ConvertExpandNodeFilterToNodeFilterTestCases")]
public void TestConvertExpandNodeFilterToNodeFilter(NodeFilter filter, NodeFilterProperty prop, INodeFilter expectedParsedFilter)
{
INodeFilter actualParsedFilter = ObjectExplorerUtils.ConvertExpandNodeFilterToNodeFilter(filter, prop);
INodeFilter actualParsedFilter = filter.ToINodeFilter(prop);
Assert.That(
JsonConvert.SerializeObject(actualParsedFilter),
Is.EqualTo(JsonConvert.SerializeObject(expectedParsedFilter)),

View File

@@ -7,8 +7,8 @@
using System.Collections.Generic;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
@@ -29,7 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
NodeValue = serverName
};
serverSession = new ObjectExplorerService.ObjectExplorerSession("serverUri", serverRoot, null, null);
serverSession = new ObjectExplorerService.ObjectExplorerSession("serverUri", serverRoot);
var databaseRoot = new TreeNode
{
@@ -38,7 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
Parent = serverRoot
};
databaseSession = new ObjectExplorerService.ObjectExplorerSession("databaseUri", databaseRoot, null, null);
databaseSession = new ObjectExplorerService.ObjectExplorerSession("databaseUri", databaseRoot);
}
[Test]

View File

@@ -4,24 +4,28 @@
//
#nullable disable
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Threading;
using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.Connection;
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.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
using Moq;
using NUnit.Framework;
using Microsoft.SqlTools.ServiceLayer.Connection;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
@@ -31,16 +35,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
public class NodeTests : ObjectExplorerTestBase
{
private string defaultOwnerUri = "objectexplorer://myserver";
private ServerInfo defaultServerInfo;
private ObjectExplorerServerInfo oeServerInfo = null;
private ConnectionDetails defaultConnectionDetails;
private ConnectionCompleteParams defaultConnParams;
private string fakeConnectionString = "Data Source=server;Initial Catalog=database;Integrated Security=False;User Id=user";
private ServerConnection serverConnection = null;
[SetUp]
public void InitNodeTests()
{
defaultServerInfo = TestObjects.GetTestServerInfo();
var defaultServerInfo = TestObjects.GetTestServerInfo();
serverConnection = new ServerConnection(new SqlConnection(fakeConnectionString));
defaultConnectionDetails = new ConnectionDetails()
@@ -53,31 +58,41 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
defaultConnParams = new ConnectionCompleteParams()
{
ServerInfo = defaultServerInfo,
ConnectionSummary = defaultConnectionDetails != null ? ((IConnectionSummary)defaultConnectionDetails).Clone(): null,
ConnectionSummary = defaultConnectionDetails != null ? ((IConnectionSummary)defaultConnectionDetails).Clone() : null,
OwnerUri = defaultOwnerUri
};
oeServerInfo = new ObjectExplorerServerInfo()
{
ServerName = defaultConnectionDetails.ServerName,
DatabaseName = defaultConnectionDetails.DatabaseName,
UserName = defaultConnectionDetails.UserName,
ServerVersion = defaultServerInfo.ServerVersion,
EngineEditionId = defaultServerInfo.EngineEditionId,
IsCloud = defaultServerInfo.IsCloud
};
var smoquery = typeof(SqlCore.ObjectExplorer.SmoModel.SmoQuerier).Assembly;
// TODO can all tests use the standard service provider?
ServiceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
ServiceProvider = ExtensionServiceProvider.CreateFromAssembliesInDirectory(Path.GetDirectoryName(smoquery.Location),new string[] { Path.GetFileName(smoquery.Location) });
}
[Test]
public void ServerNodeConstructorValidatesFields()
{
Assert.Throws<ArgumentNullException>(() => new ServerNode(null, ServiceProvider, serverConnection));
Assert.Throws<ArgumentNullException>(() => new ServerNode(defaultConnParams, null, serverConnection));
Assert.Throws<ArgumentNullException>(() => new ServerNode(null, serverConnection, ServiceProvider));
}
[Test]
public void ServerNodeConstructorShouldSetValuesCorrectly()
{
// Given a server node with valid inputs
ServerNode node = new ServerNode(defaultConnParams, ServiceProvider, serverConnection);
ServerNode node = new ServerNode(oeServerInfo, serverConnection, ServiceProvider);
// Then expect all fields set correctly
Assert.False(node.IsAlwaysLeaf, "Server node should never be a leaf");
Assert.AreEqual(defaultConnectionDetails.ServerName, node.NodeValue);
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + " - "
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + oeServerInfo.ServerVersion + " - "
+ defaultConnectionDetails.UserName + ")";
Assert.AreEqual(expectedLabel, node.Label);
@@ -91,55 +106,43 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
public void ServerNodeLabelShouldIgnoreUserNameIfEmptyOrNull()
{
// Given no username set
ConnectionSummary integratedAuthSummary = new ConnectionSummary()
{
DatabaseName = defaultConnectionDetails.DatabaseName,
ServerName = defaultConnectionDetails.ServerName,
UserName = null
};
ConnectionCompleteParams connParams = new ConnectionCompleteParams()
{
ConnectionSummary = integratedAuthSummary,
ServerInfo = defaultServerInfo,
OwnerUri = defaultOwnerUri
};
oeServerInfo.UserName = null;
// When querying label
string label = new ServerNode(connParams, ServiceProvider, serverConnection).Label;
string label = new ServerNode(oeServerInfo, serverConnection, ServiceProvider).Label;
// Then only server name and version shown
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + ")";
string expectedLabel = oeServerInfo.ServerName + " (SQL Server " + oeServerInfo.ServerVersion + ")";
Assert.AreEqual(expectedLabel, label);
}
[Test]
public void ServerNodeConstructorShouldShowDbNameForCloud()
{
defaultServerInfo.IsCloud = true;
oeServerInfo.IsCloud = true;
// Given a server node for a cloud DB, with master name
ServerNode node = new ServerNode(defaultConnParams, ServiceProvider, serverConnection);
ServerNode node = new ServerNode(oeServerInfo, serverConnection);
// Then expect label to not include db name
string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + " - "
+ defaultConnectionDetails.UserName + ")";
string expectedLabel = oeServerInfo.ServerName + " (SQL Server " + oeServerInfo.ServerVersion + " - "
+ oeServerInfo.UserName + ")";
Assert.AreEqual(expectedLabel, node.Label);
// But given a server node for a cloud DB that's not master
defaultConnectionDetails.DatabaseName = "NotMaster";
defaultConnParams.ConnectionSummary.DatabaseName = defaultConnectionDetails.DatabaseName;
node = new ServerNode(defaultConnParams, ServiceProvider, serverConnection);
oeServerInfo.DatabaseName = "NotMaster";
node = new ServerNode(oeServerInfo, serverConnection, ServiceProvider);
// Then expect label to include db name
expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + " - "
+ defaultConnectionDetails.UserName + ", " + defaultConnectionDetails.DatabaseName + ")";
expectedLabel = oeServerInfo.ServerName + " (SQL Server " + oeServerInfo.ServerVersion + " - "
+ oeServerInfo.UserName + ", " + oeServerInfo.DatabaseName + ")";
Assert.AreEqual(expectedLabel, node.Label);
}
[Test]
public void ToNodeInfoIncludeAllFields()
public void NodeInfoConstructorPopulatesAllFieldsFromTreeNode()
{
// Given a server connection
ServerNode node = new ServerNode(defaultConnParams, ServiceProvider, serverConnection);
ServerNode node = new ServerNode(oeServerInfo, serverConnection, ServiceProvider);
// When converting to NodeInfo
NodeInfo info = node.ToNodeInfo();
NodeInfo info = new NodeInfo(node);
// Then all fields should match
Assert.AreEqual(node.IsAlwaysLeaf, info.IsLeaf);
Assert.AreEqual(node.Label, info.Label);
@@ -192,21 +195,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
public void MultiLevelTreeShouldFormatPath()
{
TreeNode root = new TreeNode("root");
Assert.AreEqual("root" , root.GetNodePath());
Assert.AreEqual("root", root.GetNodePath());
TreeNode level1Child1 = new TreeNode("L1C1 (with extra info)");
level1Child1.NodePathName = "L1C1";
TreeNode level1Child2 = new TreeNode("L1C2");
root.AddChild(level1Child1);
root.AddChild(level1Child2);
Assert.AreEqual("root/L1C1" , level1Child1.GetNodePath());
Assert.AreEqual("root/L1C1", level1Child1.GetNodePath());
Assert.AreEqual("root/L1C2", level1Child2.GetNodePath());
TreeNode level2Child1 = new TreeNode("L2C2");
level1Child1.AddChild(level2Child1);
Assert.AreEqual("root/L1C1/L2C2", level2Child1.GetNodePath());
}
[Test]
public void ServerNodeContextShouldIncludeServer()
{
@@ -254,7 +257,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then I expect it to be in an error state
Assert.Null(context);
Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, SR.TreeNodeError, expectedMsg),
string.Format(CultureInfo.CurrentCulture, SqlTools.SqlCore.SR.TreeNodeError, expectedMsg),
node.ErrorStateMessage);
}
@@ -272,19 +275,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then I expect it to be in an error state
Assert.Null(context);
Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, SR.TreeNodeError, expectedMsg),
string.Format(CultureInfo.CurrentCulture, SqlTools.SqlCore.SR.TreeNodeError, expectedMsg),
node.ErrorStateMessage);
}
[Test]
public void QueryContextShouldNotCallOpenOnAlreadyOpenConnection()
{
// given a server connection that will state its connection is open
Server smoServer = new Server(new ServerConnection(new SqlConnection(fakeConnectionString)));
Mock<SmoWrapper> wrapper = SetupSmoWrapperForIsOpenTest(smoServer, isOpen: true);
SmoQueryContext context = new SmoQueryContext(smoServer, ServiceProvider, wrapper.Object);
// when I access the Server property
Server actualServer = context.Server;
@@ -313,9 +316,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// given a server connection that will state its connection is closed
Server smoServer = new Server(new ServerConnection(new SqlConnection(fakeConnectionString)));
Mock<SmoWrapper> wrapper = SetupSmoWrapperForIsOpenTest(smoServer, isOpen: false);
SmoQueryContext context = new SmoQueryContext(smoServer, ServiceProvider, wrapper.Object);
// when I access the Server property
Server actualServer = context.Server;
@@ -330,7 +333,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// given a server connection that will state its connection is closed
Server smoServer = new Server(new ServerConnection(new SqlConnection(fakeConnectionString)));
Mock<SmoWrapper> wrapper = SetupSmoWrapperForIsOpenTest(smoServer, isOpen: false);
SmoQueryContext context = new SmoQueryContext(smoServer, ServiceProvider, wrapper.Object);
context.Parent = smoServer;
// when I access the Parent property
@@ -378,7 +381,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
private ServerNode SetupServerNodeWithCreator(SmoWrapper creator)
{
ServerNode node = new ServerNode(defaultConnParams, ServiceProvider, new ServerConnection(new SqlConnection(fakeConnectionString)));
ServerNode node = new ServerNode(oeServerInfo, new ServerConnection(new SqlConnection(fakeConnectionString)), ServiceProvider, () => false);
node.SmoWrapper = creator;
return node;
}
@@ -408,20 +411,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
// Then I expect it to contain server-level folders
Assert.AreEqual(3, children.Count);
VerifyTreeNode<FolderNode>(children[0], "Folder", SR.SchemaHierarchy_Databases);
VerifyTreeNode<FolderNode>(children[1], "Folder", SR.SchemaHierarchy_Security);
VerifyTreeNode<FolderNode>(children[2], "Folder", SR.SchemaHierarchy_ServerObjects);
VerifyTreeNode<FolderNode>(children[0], "Folder", SqlTools.SqlCore.SR.SchemaHierarchy_Databases);
VerifyTreeNode<FolderNode>(children[1], "Folder", SqlTools.SqlCore.SR.SchemaHierarchy_Security);
VerifyTreeNode<FolderNode>(children[2], "Folder", SqlTools.SqlCore.SR.SchemaHierarchy_ServerObjects);
// And the database is contained under it
TreeNode databases = children[0];
IList<TreeNode> dbChildren = databases.Expand(new CancellationToken());
Assert.AreEqual(2, dbChildren.Count);
Assert.AreEqual(SR.SchemaHierarchy_SystemDatabases, dbChildren[0].NodeValue);
Assert.AreEqual(SqlTools.SqlCore.SR.SchemaHierarchy_SystemDatabases, dbChildren[0].NodeValue);
TreeNode dbNode = dbChildren[1];
Assert.AreEqual(dbName, dbNode.NodeValue);
Assert.AreEqual(dbName, dbNode.Label);
Assert.False(dbNode.IsAlwaysLeaf);
// Note: would like to verify Database in the context, but cannot since it's a Sealed class and isn't easily mockable
}

View File

@@ -16,7 +16,7 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
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.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Moq.Protected;
@@ -282,7 +282,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
var foundNodes = service.FindNodes(session.SessionId, "Server", null, null, null);
Assert.AreEqual(1, foundNodes.Count);
Assert.AreEqual("Server", foundNodes[0].NodeType);
Assert.AreEqual(session.RootNode.NodePath, foundNodes[0].ToNodeInfo().NodePath);
Assert.AreEqual(session.RootNode.NodePath, new NodeInfo(foundNodes[0]).NodePath);
}
[Test]
@@ -298,7 +298,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
public void FindNodeCanExpandParentNodes()
{
var mockTreeNode = new Mock<TreeNode>();
object[] populateChildrenArguments = { ItExpr.Is<bool>(x => x == false), ItExpr.IsNull<string>(), new CancellationToken(), ItExpr.IsNull<string>(), ItExpr.IsNull<IEnumerable<NodeFilter>>() };
object[] populateChildrenArguments = { ItExpr.Is<bool>(x => x == false), ItExpr.IsNull<string>(), new CancellationToken(), ItExpr.IsNull<string>(), ItExpr.IsNull<IEnumerable<INodeFilter>>() };
mockTreeNode.Protected().Setup("PopulateChildren", populateChildrenArguments);
mockTreeNode.Object.IsAlwaysLeaf = false;

View File

@@ -8,8 +8,8 @@
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.Nodes;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{

View File

@@ -5,8 +5,7 @@
#nullable disable
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
@@ -59,7 +58,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
[TestCase("16.1.2.3", SqlServerType.Sql2022)]
public void CalculateServerTypeShouldReturnExpectedValue(string serverVersion, SqlServerType expectedServerType)
{
ServerInfo serverInfo = new ServerInfo
ObjectExplorerServerInfo serverInfo = new ObjectExplorerServerInfo
{
ServerVersion = serverVersion
};
@@ -128,7 +127,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
private void VerifyCalculateServerTypeForEngineEdition(int engineEdition, SqlServerType expected)
{
ServerInfo serverInfo = new ServerInfo
ObjectExplorerServerInfo serverInfo = new ObjectExplorerServerInfo
{
EngineEditionId = engineEdition
};

View File

@@ -6,24 +6,32 @@
#nullable disable
using System;
using System.IO;
using System.Linq;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.Nodes;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class SmoQueryModelTests
{
IMultiServiceProvider serviceProvider;
[SetUp]
public void Setup()
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
var assembly = typeof(SmoQuerier).Assembly;
serviceProvider = ExtensionServiceProvider.CreateFromAssembliesInDirectory(Path.GetDirectoryName(assembly.Location), new string[] { Path.GetFileName(assembly.Location) });
}
[Test]
public void ShouldFindDatabaseQuerierFromRealPath()
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
// When I request a database compatible querier
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database)));
// Then I expect to get back the SqlDatabaseQuerier
@@ -87,8 +95,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
private SmoQuerier GetSmoQuerier(Type querierType)
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
// When I request a compatible querier
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(querierType));
// Then I expect to get back the Querier

View File

@@ -6,7 +6,7 @@
#nullable disable
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Microsoft.SqlTools.SqlCore.ObjectExplorer.SmoModel;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer