Fixed node labels, status, sub types (#338)

This commit is contained in:
Leila Lali
2017-05-09 09:33:25 -07:00
committed by GitHub
parent 5b5c5861d8
commit 0d570fa29b
25 changed files with 1975 additions and 657 deletions

View File

@@ -4,7 +4,6 @@
//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -47,6 +46,35 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
});
}
[Fact]
public async void VerifyServerLogins()
{
var query = @"If Exists (select loginname from master.dbo.syslogins
where name = 'OEServerLogin')
Begin
Drop Login [OEServerLogin]
End
CREATE LOGIN OEServerLogin WITH PASSWORD = 'SuperSecret52&&'
GO
ALTER LOGIN OEServerLogin DISABLE; ";
string databaseName = "tempdb";
await RunTest(databaseName, query, "TepmDb", async (testDbName, session) =>
{
var serverChildren = await _service.ExpandNode(session, session.Root.GetNodePath());
var securityNode = serverChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Security);
var securityChildren = await _service.ExpandNode(session, securityNode.NodePath);
var loginsNode = securityChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Logins);
var loginsChildren = await _service.ExpandNode(session, loginsNode.NodePath);
var login = loginsChildren.FirstOrDefault(x => x.Label == "OEServerLogin");
Assert.NotNull(login);
Assert.True(login.NodeStatus == "Disabled");
await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, testDbName, "Drop Login OEServerLogin");
});
}
[Fact]
public async void CreateSessionAndExpandOnTheDatabaseShouldReturnDatabaseAsTheRoot()
{
@@ -58,6 +86,92 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
});
}
[Fact]
public async void RefreshNodeShouldGetTheDataFromDatabase()
{
var query = "Create table t1 (c1 int)";
string databaseName = "#testDb#";
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
var tablesNode = await FindNodeByLabel(session.Root.ToNodeInfo(), session, SR.SchemaHierarchy_Tables);
var tableChildren = await _service.ExpandNode(session, tablesNode.NodePath);
string dropTableScript = "Drop Table t1";
Assert.True(tableChildren.Any(t => t.Label == "dbo.t1"));
await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, testDbName, dropTableScript);
tableChildren = await _service.ExpandNode(session, tablesNode.NodePath);
Assert.True(tableChildren.Any(t => t.Label == "dbo.t1"));
tableChildren = await _service.ExpandNode(session, tablesNode.NodePath, true);
Assert.False(tableChildren.Any(t => t.Label == "dbo.t1"));
});
}
[Fact]
public async void RefreshShouldCleanTheCache()
{
string query = @"Create table t1 (c1 int)
GO
Create table t2 (c1 int)
GO";
string dropTableScript1 = "Drop Table t1";
string createTableScript2 = "Create table t3 (c1 int)";
string databaseName = "#testDb#";
await RunTest(databaseName, query, "TestDb", async (testDbName, session) =>
{
var tablesNode = await FindNodeByLabel(session.Root.ToNodeInfo(), session, SR.SchemaHierarchy_Tables);
//Expand Tables node
var tableChildren = await _service.ExpandNode(session, tablesNode.NodePath);
//Expanding the tables return t1
Assert.True(tableChildren.Any(t => t.Label == "dbo.t1"));
//Delete the table from db
await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, testDbName, dropTableScript1);
//Expand Tables node
tableChildren = await _service.ExpandNode(session, tablesNode.NodePath);
//Tables still includes t1
Assert.True(tableChildren.Any(t => t.Label == "dbo.t1"));
//Verify the tables cache has items
var rootChildrenCache = session.Root.GetChildren();
var tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
Assert.True(tablesCache.Any());
await VerifyRefresh(session, tablesNode.NodePath, "dbo.t1");
//Delete the table from db
await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, testDbName, createTableScript2);
await VerifyRefresh(session, tablesNode.NodePath, "dbo.t3", false);
});
}
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);
//Verify tables cache is empty
var rootChildrenCache = session.Root.GetChildren();
var tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
Assert.False(tablesCache.Any());
//Expand Tables
var tableChildren = await _service.ExpandNode(session, tablePath, true);
//Verify table is not returned
Assert.Equal(tableChildren.Any(t => t.Label == tableName), !deleted);
//Verify tables cache has items
rootChildrenCache = session.Root.GetChildren();
tablesCache = rootChildrenCache.First(x => x.Label == SR.SchemaHierarchy_Tables).GetChildren();
Assert.True(tablesCache.Any());
}
[Fact]
public async void VerifyAllSqlObjects()
{
@@ -193,6 +307,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
var children = await _service.ExpandNode(session, node.NodePath);
foreach (var child in children)
{
//VerifyMetadata(child);
if (stringBuilder != null && child.NodeType != "Folder" && child.NodeType != "FileGroupFile")
{
stringBuilder.AppendLine($"NodeType: {child.NodeType} Label: {child.Label}");
@@ -213,33 +328,30 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
}
/// <summary>
/// Returns the children of a node with the given label
/// Returns the node with the given label
/// </summary>
private async Task<IList<NodeInfo>> FindNodeByLabel(NodeInfo node, ObjectExplorerSession session, string nodeType, bool nodeFound = false)
private async Task<NodeInfo> FindNodeByLabel(NodeInfo node, ObjectExplorerSession session, string label)
{
if (node != null && !node.IsLeaf)
if(node != null && node.Label == label)
{
return node;
}
else if (node != null && !node.IsLeaf)
{
var children = await _service.ExpandNode(session, node.NodePath);
Assert.NotNull(children);
if (!nodeFound)
foreach (var child in children)
{
foreach (var child in children)
VerifyMetadata(child);
if (child.Label == label)
{
VerifyMetadata(child);
if (child.Label == nodeType)
{
return await FindNodeByLabel(child, session, nodeType, true);
}
var result = await FindNodeByLabel(child, session, nodeType);
if (result != null)
{
return result;
}
return child;
}
var result = await FindNodeByLabel(child, session, label);
if (result != null)
{
return result;
}
}
else
{
return children;
}
}

View File

@@ -1,20 +1,52 @@
NodeType: Table Label: Employee_Temporal (System-Versioned)
NodeType: Column Label: BusinessEntityID (PK, int, not null)
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null)
NodeType: Column Label: LoginID (nvarchar(256), not null)
NodeType: Column Label: OrganizationNode (hierarchyid, null)
NodeType: Column Label: OrganizationLevel (Computed, smallint, null)
NodeType: Column Label: JobTitle (nvarchar(50), not null)
NodeType: Column Label: BirthDate (date, not null)
NodeType: Column Label: MaritalStatus (nchar(1), not null)
NodeType: Column Label: Gender (nchar(1), not null)
NodeType: Column Label: HireDate (date, not null)
NodeType: Column Label: VacationHours (smallint, not null)
NodeType: Column Label: SickLeaveHours (smallint, not null)
NodeType: Column Label: ValidFrom (datetime2, not null)
NodeType: Column Label: ValidTo (datetime2, not null)
NodeType: Key Label: PK_Employee_History_BusinessEntityID
NodeType: Statistic Label: PK_Employee_History_BusinessEntityID
NodeType: HistoryTable Label: Employee_Temporal_History (History)
NodeType: Column Label: BusinessEntityID (int, not null)
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null)
NodeType: Column Label: LoginID (nvarchar(256), not null)
NodeType: Column Label: OrganizationNode (hierarchyid, null)
NodeType: Column Label: OrganizationLevel (smallint, null)
NodeType: Column Label: JobTitle (nvarchar(50), not null)
NodeType: Column Label: BirthDate (date, not null)
NodeType: Column Label: MaritalStatus (nchar(1), not null)
NodeType: Column Label: Gender (nchar(1), not null)
NodeType: Column Label: HireDate (date, not null)
NodeType: Column Label: VacationHours (smallint, not null)
NodeType: Column Label: SickLeaveHours (smallint, not null)
NodeType: Column Label: ValidFrom (datetime2, not null)
NodeType: Column Label: ValidTo (datetime2, not null)
NodeType: Table Label: HumanResources.Employee
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: NationalIDNumber
NodeType: Column Label: LoginID
NodeType: Column Label: OrganizationNode
NodeType: Column Label: OrganizationLevel
NodeType: Column Label: JobTitle
NodeType: Column Label: BirthDate
NodeType: Column Label: MaritalStatus
NodeType: Column Label: Gender
NodeType: Column Label: HireDate
NodeType: Column Label: SalariedFlag
NodeType: Column Label: VacationHours
NodeType: Column Label: SickLeaveHours
NodeType: Column Label: CurrentFlag
NodeType: Column Label: rowguid
NodeType: Column Label: ModifiedDate
NodeType: Column Label: BusinessEntityID (PK, FK, int, not null)
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null)
NodeType: Column Label: LoginID (nvarchar(256), not null)
NodeType: Column Label: OrganizationNode (hierarchyid, null)
NodeType: Column Label: OrganizationLevel (Computed, smallint, null)
NodeType: Column Label: JobTitle (nvarchar(50), not null)
NodeType: Column Label: BirthDate (date, not null)
NodeType: Column Label: MaritalStatus (nchar(1), not null)
NodeType: Column Label: Gender (nchar(1), not null)
NodeType: Column Label: HireDate (date, not null)
NodeType: Column Label: SalariedFlag (Flag(bit), not null)
NodeType: Column Label: VacationHours (smallint, not null)
NodeType: Column Label: SickLeaveHours (smallint, not null)
NodeType: Column Label: CurrentFlag (Flag(bit), not null)
NodeType: Column Label: rowguid (uniqueidentifier, not null)
NodeType: Column Label: ModifiedDate (datetime, not null)
NodeType: Key Label: FK_Employee_Person_BusinessEntityID
NodeType: Key Label: PK_Employee_BusinessEntityID
NodeType: Constraint Label: CK_Employee_BirthDate
@@ -23,76 +55,44 @@ NodeType: Constraint Label: CK_Employee_HireDate
NodeType: Constraint Label: CK_Employee_MaritalStatus
NodeType: Constraint Label: CK_Employee_SickLeaveHours
NodeType: Constraint Label: CK_Employee_VacationHours
NodeType: Index Label: NonClusteredIndex-Login
NodeType: Index Label: NonClusteredIndex-Login (Non-Unique, Non-Clustered)
NodeType: Statistic Label: NonClusteredIndex-Login
NodeType: Statistic Label: PK_Employee_BusinessEntityID
NodeType: Table Label: HumanResources.Employee_Temporal
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: NationalIDNumber
NodeType: Column Label: LoginID
NodeType: Column Label: OrganizationNode
NodeType: Column Label: OrganizationLevel
NodeType: Column Label: JobTitle
NodeType: Column Label: BirthDate
NodeType: Column Label: MaritalStatus
NodeType: Column Label: Gender
NodeType: Column Label: HireDate
NodeType: Column Label: VacationHours
NodeType: Column Label: SickLeaveHours
NodeType: Column Label: ValidFrom
NodeType: Column Label: ValidTo
NodeType: Key Label: PK_Employee_History_BusinessEntityID
NodeType: Statistic Label: PK_Employee_History_BusinessEntityID
NodeType: HistoryTable Label: HumanResources.Employee_Temporal_History
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: NationalIDNumber
NodeType: Column Label: LoginID
NodeType: Column Label: OrganizationNode
NodeType: Column Label: OrganizationLevel
NodeType: Column Label: JobTitle
NodeType: Column Label: BirthDate
NodeType: Column Label: MaritalStatus
NodeType: Column Label: Gender
NodeType: Column Label: HireDate
NodeType: Column Label: VacationHours
NodeType: Column Label: SickLeaveHours
NodeType: Column Label: ValidFrom
NodeType: Column Label: ValidTo
NodeType: Table Label: Person.Person
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: PersonType
NodeType: Column Label: NameStyle
NodeType: Column Label: Title
NodeType: Column Label: FirstName
NodeType: Column Label: MiddleName
NodeType: Column Label: LastName
NodeType: Column Label: Suffix
NodeType: Column Label: EmailPromotion
NodeType: Column Label: AdditionalContactInfo
NodeType: Column Label: rowguid
NodeType: Column Label: ModifiedDate
NodeType: Column Label: BusinessEntityID (PK, int, not null)
NodeType: Column Label: PersonType (nchar(2), not null)
NodeType: Column Label: NameStyle (NameStyle(bit), not null)
NodeType: Column Label: Title (nvarchar(8), null)
NodeType: Column Label: FirstName (Name(nvarchar), not null)
NodeType: Column Label: MiddleName (Name(nvarchar), null)
NodeType: Column Label: LastName (Name(nvarchar), not null)
NodeType: Column Label: Suffix (nvarchar(10), null)
NodeType: Column Label: EmailPromotion (int, not null)
NodeType: Column Label: AdditionalContactInfo (AdditionalContactInfoSchemaCollection, null)
NodeType: Column Label: rowguid (uniqueidentifier, not null)
NodeType: Column Label: ModifiedDate (datetime, not null)
NodeType: Key Label: PK_Person_BusinessEntityID
NodeType: Constraint Label: CK_Person_EmailPromotion
NodeType: Constraint Label: CK_Person_PersonType
NodeType: Trigger Label: TableTrigger
NodeType: Statistic Label: PK_Person_BusinessEntityID
NodeType: View Label: HumanResources.vEmployee
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: Title
NodeType: Column Label: FirstName
NodeType: Column Label: MiddleName
NodeType: Column Label: LastName
NodeType: Column Label: Suffix
NodeType: Column Label: JobTitle
NodeType: Column Label: AdditionalContactInfo
NodeType: Column Label: BusinessEntityID (int, not null)
NodeType: Column Label: Title (nvarchar(8), null)
NodeType: Column Label: FirstName (Name(nvarchar), not null)
NodeType: Column Label: MiddleName (Name(nvarchar), null)
NodeType: Column Label: LastName (Name(nvarchar), not null)
NodeType: Column Label: Suffix (nvarchar(10), null)
NodeType: Column Label: JobTitle (nvarchar(50), not null)
NodeType: Column Label: AdditionalContactInfo (AdditionalContactInfoSchemaCollection, null)
NodeType: Synonym Label: dbo.MyProduct
NodeType: StoredProcedure Label: HumanResources.sp_GetEmployee_Person_Info_AsOf
NodeType: StoredProcedureParameter Label: @asOf
NodeType: StoredProcedureParameter Label: @asOf (datetime2, Input, Default)
NodeType: TableValuedFunction Label: dbo.ufnGetContactInformation
NodeType: TableValuedFunctionParameter Label: @PersonID
NodeType: TableValuedFunctionParameter Label: @PersonID (int, Input, No default)
NodeType: ScalarValuedFunction Label: dbo.fun1
NodeType: ScalarValuedFunction Label: dbo.ufnGetInventoryStock
NodeType: ScalarValuedFunctionParameter Label: @ProductID
NodeType: ScalarValuedFunctionParameter Label: @ProductID (int, Input, No default)
NodeType: DatabaseTrigger Label: Trigger_2
NodeType: Assembly Label: Microsoft.SqlServer.Types
NodeType: UserDefinedDataType Label: dbo.AccountNumber
@@ -102,16 +102,14 @@ NodeType: UserDefinedDataType Label: dbo.NameStyle
NodeType: UserDefinedDataType Label: dbo.OrderNumber
NodeType: UserDefinedDataType Label: dbo.Phone
NodeType: UserDefinedTableType Label: Demo.SalesOrderDetailType_inmem
NodeType: UserDefinedTableTypeColumn Label: OrderQty
NodeType: UserDefinedTableTypeColumn Label: ProductID
NodeType: UserDefinedTableTypeColumn Label: SpecialOfferID
NodeType: UserDefinedTableTypeColumn Label: OrderQty (smallint, not null)
NodeType: UserDefinedTableTypeColumn Label: ProductID (int, not null)
NodeType: UserDefinedTableTypeColumn Label: SpecialOfferID (int, not null)
NodeType: UserDefinedTableType Label: Demo.SalesOrderDetailType_ondisk
NodeType: UserDefinedTableTypeColumn Label: OrderQty
NodeType: UserDefinedTableTypeColumn Label: ProductID
NodeType: UserDefinedTableTypeColumn Label: SpecialOfferID
NodeType: UserDefinedTableTypeColumn Label: OrderQty (smallint, not null)
NodeType: UserDefinedTableTypeColumn Label: ProductID (int, not null)
NodeType: UserDefinedTableTypeColumn Label: SpecialOfferID (int, not null)
NodeType: XmlSchemaCollection Label: Person.AdditionalContactInfoSchemaCollection
NodeType: Rule Label: dbo.list_rule
NodeType: Default Label: dbo.phonedflt
NodeType: Sequence Label: Demo.ID_Seq
NodeType: FileGroup Label: PRIMARY
NodeType: FullTextCatalog Label: AW2014FullTextCatalog

View File

@@ -327,7 +327,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
smoObjectMock.SetupGet(s => s.Name).Returns(dbName);
Mock<SqlDatabaseQuerier> querierMock = new Mock<SqlDatabaseQuerier>();
querierMock.Setup(q => q.Query(It.IsAny<SmoQueryContext>(), ""))
querierMock.Setup(q => q.Query(It.IsAny<SmoQueryContext>(), "", false))
.Returns(smoObjectMock.Object.SingleItemAsEnumerable());
ServiceProvider.Register<SmoQuerier>(() => new[] { querierMock.Object });