mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
make list databases return in their original order (#1859)
* return databases in their original order * remove using statement * fix unit tests * fix error
This commit is contained in:
@@ -9,7 +9,6 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
@@ -61,8 +60,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
abstract class ListDatabaseRequestHandler<T> : IListDatabaseRequestHandler
|
abstract class ListDatabaseRequestHandler<T> : IListDatabaseRequestHandler
|
||||||
{
|
{
|
||||||
private static readonly string[] SystemDatabases = new string[] { "master", "model", "msdb", "tempdb" };
|
|
||||||
|
|
||||||
public abstract string QueryText { get; }
|
public abstract string QueryText { get; }
|
||||||
|
|
||||||
public ListDatabasesResponse HandleRequest(ISqlConnectionFactory connectionFactory, ConnectionInfo connectionInfo)
|
public ListDatabasesResponse HandleRequest(ISqlConnectionFactory connectionFactory, ConnectionInfo connectionInfo)
|
||||||
@@ -122,9 +119,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
{
|
{
|
||||||
results.Add(this.CreateItem(reader));
|
results.Add(this.CreateItem(reader));
|
||||||
}
|
}
|
||||||
// Put system databases at the top of the list
|
|
||||||
results = results.Where(s => SystemDatabases.Any(x => this.NameMatches(x, s))).Concat(
|
|
||||||
results.Where(s => SystemDatabases.All(x => !this.NameMatches(x, s)))).ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|||||||
@@ -946,7 +946,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
|||||||
TestDbColumn[] cols = { new TestDbColumn("name") };
|
TestDbColumn[] cols = { new TestDbColumn("name") };
|
||||||
object[][] rows =
|
object[][] rows =
|
||||||
{
|
{
|
||||||
new object[] {"mydatabase"}, // this should be sorted to the end in the response
|
new object[] {"mydatabase"},
|
||||||
new object[] {"master"},
|
new object[] {"master"},
|
||||||
new object[] {"model"},
|
new object[] {"model"},
|
||||||
new object[] {"msdb"},
|
new object[] {"msdb"},
|
||||||
@@ -958,11 +958,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
|||||||
string[] databaseNames = response.DatabaseNames;
|
string[] databaseNames = response.DatabaseNames;
|
||||||
|
|
||||||
Assert.AreEqual(5, databaseNames.Length);
|
Assert.AreEqual(5, databaseNames.Length);
|
||||||
Assert.AreEqual("master", databaseNames[0]);
|
Assert.AreEqual("mydatabase", databaseNames[0]);
|
||||||
Assert.AreEqual("model", databaseNames[1]);
|
Assert.AreEqual("master", databaseNames[1]);
|
||||||
Assert.AreEqual("msdb", databaseNames[2]);
|
Assert.AreEqual("model", databaseNames[2]);
|
||||||
Assert.AreEqual("tempdb", databaseNames[3]);
|
Assert.AreEqual("msdb", databaseNames[3]);
|
||||||
Assert.AreEqual("mydatabase", databaseNames[4]);
|
Assert.AreEqual("tempdb", databaseNames[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -980,7 +980,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
|||||||
};
|
};
|
||||||
object[][] rows =
|
object[][] rows =
|
||||||
{
|
{
|
||||||
new object[] {"mydatabase", "Online", "10", "2010-01-01 11:11:11"}, // this should be sorted to the end in the response
|
new object[] {"mydatabase", "Online", "10", "2010-01-01 11:11:11"},
|
||||||
new object[] {"master", "Online", "11", "2010-01-01 11:11:12"},
|
new object[] {"master", "Online", "11", "2010-01-01 11:11:12"},
|
||||||
new object[] {"model", "Offline", "12", "2010-01-01 11:11:13"},
|
new object[] {"model", "Offline", "12", "2010-01-01 11:11:13"},
|
||||||
new object[] {"msdb", "Online", "13", "2010-01-01 11:11:14"},
|
new object[] {"msdb", "Online", "13", "2010-01-01 11:11:14"},
|
||||||
@@ -990,11 +990,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
|||||||
var response = await RunListDatabasesRequestHandler(testdata: data, includeDetails: true);
|
var response = await RunListDatabasesRequestHandler(testdata: data, includeDetails: true);
|
||||||
|
|
||||||
Assert.AreEqual(5, response.Databases.Length);
|
Assert.AreEqual(5, response.Databases.Length);
|
||||||
VerifyDatabaseDetail(rows[0], response.Databases[4]);
|
VerifyDatabaseDetail(rows[0], response.Databases[0]);
|
||||||
VerifyDatabaseDetail(rows[1], response.Databases[0]);
|
VerifyDatabaseDetail(rows[1], response.Databases[1]);
|
||||||
VerifyDatabaseDetail(rows[2], response.Databases[1]);
|
VerifyDatabaseDetail(rows[2], response.Databases[2]);
|
||||||
VerifyDatabaseDetail(rows[3], response.Databases[2]);
|
VerifyDatabaseDetail(rows[3], response.Databases[3]);
|
||||||
VerifyDatabaseDetail(rows[4], response.Databases[3]);
|
VerifyDatabaseDetail(rows[4], response.Databases[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyDatabaseDetail(object[] expected, DatabaseInfo actual)
|
private void VerifyDatabaseDetail(object[] expected, DatabaseInfo actual)
|
||||||
|
|||||||
Reference in New Issue
Block a user