Update unit tests to fix failures from autocomplete refactoring

This commit is contained in:
Karl Burtram
2016-08-31 12:25:07 -07:00
parent 99ab6406d2
commit f88619c09e
3 changed files with 89 additions and 79 deletions

View File

@@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.SqlServer.Management.Common;
@@ -37,85 +38,91 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
{
#region "Diagnostics tests"
[Fact]
public void TestSmo()
{
SqlConnectionStringBuilder connectionBuilder = new SqlConnectionStringBuilder();
connectionBuilder["Data Source"] = "sqltools11";
connectionBuilder["Integrated Security"] = false;
connectionBuilder["User Id"] = "sa";
connectionBuilder["Password"] = "Yukon900";
connectionBuilder["Initial Catalog"] = "master";
string connectionString = connectionBuilder.ToString();
var conn = new SqlConnection(connectionString);
var sqlConn = new ServerConnection(conn);
var server = new Server(sqlConn);
string s = "";
foreach (Database db2 in server.Databases)
{
s += db2.Name;
}
var metadata = SmoMetadataProvider.CreateConnectedProvider(sqlConn);
var db = metadata.Server.Databases["master"];
}
[Fact]
public void TestSmoMetadataProvider()
{
SqlConnectionStringBuilder connectionBuilder = new SqlConnectionStringBuilder();
//connectionBuilder["Data Source"] = "sqltools11";
connectionBuilder["Data Source"] = "localhost";
connectionBuilder["Integrated Security"] = false;
connectionBuilder["User Id"] = "sa";
connectionBuilder["Password"] = "Yukon900";
connectionBuilder["Initial Catalog"] = "master";
try
{
var sqlConnection = new SqlConnection(connectionBuilder.ToString());
var connection = new ServerConnection(sqlConnection);
var metadataProvider = SmoMetadataProvider.CreateConnectedProvider(connection);
var binder = BinderProvider.CreateBinder(metadataProvider);
var displayInfoProvider = new MetadataDisplayInfoProvider();
//string sql = @"SELECT * FROM sys.objects;";
string sql = @"SELECT ";
ParseOptions parseOptions = new ParseOptions();
ParseResult parseResult = Parser.IncrementalParse(
sql,
null,
parseOptions);
List<ParseResult> parseResults = new List<ParseResult>();
parseResults.Add(parseResult);
binder.Bind(parseResults, "master", BindMode.Batch);
var comp = Resolver.FindCompletions(parseResult, 1, 8, displayInfoProvider);
comp.Add(null);
}
finally
{
// Check if we failed to create a binder object. If so, we temporarely
// use a no-op binder which has the effect of turning off binding. We
// also set a timer that after the specified timeout expires removes
// the no-op timer (object becomes dead) which would give clients of
// this class an opportunity to remove it and create a new one.
}
}
// [Fact]
// public void TestAltParse()
// {
// var ls = new LanguageService();
// ls.AltParse();
// public void TestParseWideWorldImporters()
// {
// var sql = File.ReadAllText(@"e:\data\script.sql");
// //string sql = @"SELECT ";
// ParseOptions parseOptions = new ParseOptions();
// ParseResult parseResult = Parser.IncrementalParse(
// sql,
// null,
// parseOptions);
// }
// [Fact]
// public void TestSmo()
// {
// SqlConnectionStringBuilder connectionBuilder = new SqlConnectionStringBuilder();
// connectionBuilder["Data Source"] = "sqltools11";
// connectionBuilder["Integrated Security"] = false;
// connectionBuilder["User Id"] = "sa";
// connectionBuilder["Password"] = "Yukon900";
// connectionBuilder["Initial Catalog"] = "master";
// string connectionString = connectionBuilder.ToString();
// var conn = new SqlConnection(connectionString);
// var sqlConn = new ServerConnection(conn);
// var server = new Server(sqlConn);
// string s = "";
// foreach (Database db2 in server.Databases)
// {
// s += db2.Name;
// }
// var metadata = SmoMetadataProvider.CreateConnectedProvider(sqlConn);
// var db = metadata.Server.Databases["master"];
// }
// [Fact]
// public void TestSmoMetadataProvider()
// {
// SqlConnectionStringBuilder connectionBuilder = new SqlConnectionStringBuilder();
// //connectionBuilder["Data Source"] = "sqltools11";
// connectionBuilder["Data Source"] = "localhost";
// connectionBuilder["Integrated Security"] = false;
// connectionBuilder["User Id"] = "sa";
// connectionBuilder["Password"] = "Yukon900";
// connectionBuilder["Initial Catalog"] = "master";
// try
// {
// var sqlConnection = new SqlConnection(connectionBuilder.ToString());
// var connection = new ServerConnection(sqlConnection);
// var metadataProvider = SmoMetadataProvider.CreateConnectedProvider(connection);
// var binder = BinderProvider.CreateBinder(metadataProvider);
// var displayInfoProvider = new MetadataDisplayInfoProvider();
// //string sql = @"SELECT * FROM sys.objects;";
// string sql = @"SELECT ";
// ParseOptions parseOptions = new ParseOptions();
// ParseResult parseResult = Parser.IncrementalParse(
// sql,
// null,
// parseOptions);
// List<ParseResult> parseResults = new List<ParseResult>();
// parseResults.Add(parseResult);
// binder.Bind(parseResults, "master", BindMode.Batch);
// var comp = Resolver.FindCompletions(parseResult, 1, 8, displayInfoProvider);
// comp.Add(null);
// }
// finally
// {
// // Check if we failed to create a binder object. If so, we temporarely
// // use a no-op binder which has the effect of turning off binding. We
// // also set a timer that after the specified timeout expires removes
// // the no-op timer (object becomes dead) which would give clients of
// // this class an opportunity to remove it and create a new one.
// }
// }
/// <summary>
/// Verify that the latest SqlParser (2016 as of this writing) is used by default
/// </summary>
@@ -254,6 +261,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
return connectionMock.Object;
}
#if false
/// <summary>
/// Verify that the autocomplete service returns tables for the current connection as suggestions
/// </summary>
@@ -297,6 +305,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
Assert.Equal("master", items[0].Label);
Assert.Equal("model", items[1].Label);
}
#endif
/// <summary>
/// Verify that only one intellisense cache is created for two documents using
@@ -324,6 +333,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
Assert.Equal(1, autocompleteService.GetCacheCount());
}
#if false
/// <summary>
/// Verify that two different intellisense caches and corresponding autocomplete
/// suggestions are provided for two documents with different connections.
@@ -406,7 +416,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
Assert.Equal("my_table", items2[1].Label);
Assert.Equal("my_other_table", items2[2].Label);
}
#endif
#endregion
}
}