mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
* Initial code for binding queue * Fix-up some of the timeout wait code * Add some initial test code * Add missing test file * Update the binding queue tests * Add more test coverage and refactor a bit. Disable reliabile connection until we can fix it..it's holding an open data reader connection. * A few more test updates * Initial integrate queue with language service. * Hook up the connected binding queue into al binding calls. * Cleanup comments and remove dead code * More missing comments * Fix build break. Reenable ReliabileConnection. * Revert all changes to SqlConnectionFactory * Resolve merge conflicts * Cleanup some more of the timeouts and sync code * Address code review feedback * Address more code review feedback
213 lines
6.1 KiB
C#
213 lines
6.1 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
//#define USE_LIVE_CONNECTION
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
|
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
|
|
|
namespace Microsoft.SqlTools.Test.Utility
|
|
{
|
|
/// <summary>
|
|
/// Tests for the ServiceHost Connection Service tests
|
|
/// </summary>
|
|
public class TestObjects
|
|
{
|
|
public const string ScriptUri = "file://some/file.sql";
|
|
|
|
/// <summary>
|
|
/// Creates a test connection service
|
|
/// </summary>
|
|
public static ConnectionService GetTestConnectionService()
|
|
{
|
|
#if !USE_LIVE_CONNECTION
|
|
// use mock database connection
|
|
return new ConnectionService(new TestSqlConnectionFactory());
|
|
#else
|
|
// connect to a real server instance
|
|
return ConnectionService.Instance;
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a test connection info instance.
|
|
/// </summary>
|
|
public static ConnectionInfo GetTestConnectionInfo()
|
|
{
|
|
return new ConnectionInfo(
|
|
GetTestSqlConnectionFactory(),
|
|
ScriptUri,
|
|
GetTestConnectionDetails());
|
|
}
|
|
|
|
public static ConnectParams GetTestConnectionParams()
|
|
{
|
|
return new ConnectParams()
|
|
{
|
|
OwnerUri = ScriptUri,
|
|
Connection = GetTestConnectionDetails()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a test connection details object
|
|
/// </summary>
|
|
public static ConnectionDetails GetTestConnectionDetails()
|
|
{
|
|
return new ConnectionDetails()
|
|
{
|
|
UserName = "sa",
|
|
Password = "Yukon900",
|
|
DatabaseName = "AdventureWorks2016CTP3_2",
|
|
ServerName = "sqltools11"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a test language service instance
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static LanguageService GetTestLanguageService()
|
|
{
|
|
return new LanguageService();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a test sql connection factory instance
|
|
/// </summary>
|
|
public static ISqlConnectionFactory GetTestSqlConnectionFactory()
|
|
{
|
|
#if !USE_LIVE_CONNECTION
|
|
// use mock database connection
|
|
return new TestSqlConnectionFactory();
|
|
#else
|
|
// connect to a real server instance
|
|
return ConnectionService.Instance.ConnectionFactory;
|
|
#endif
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test mock class for IDbCommand
|
|
/// </summary>
|
|
public class TestSqlCommand : DbCommand
|
|
{
|
|
internal TestSqlCommand(Dictionary<string, string>[][] data)
|
|
{
|
|
Data = data;
|
|
}
|
|
|
|
internal Dictionary<string, string>[][] Data { get; set; }
|
|
|
|
public override void Cancel()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override int ExecuteNonQuery()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override object ExecuteScalar()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void Prepare()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override string CommandText { get; set; }
|
|
public override int CommandTimeout { get; set; }
|
|
public override CommandType CommandType { get; set; }
|
|
public override UpdateRowSource UpdatedRowSource { get; set; }
|
|
protected override DbConnection DbConnection { get; set; }
|
|
protected override DbParameterCollection DbParameterCollection { get; }
|
|
protected override DbTransaction DbTransaction { get; set; }
|
|
public override bool DesignTimeVisible { get; set; }
|
|
|
|
protected override DbParameter CreateDbParameter()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
|
|
{
|
|
return new TestDbDataReader(Data);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test mock class for SqlConnection wrapper
|
|
/// </summary>
|
|
public class TestSqlConnection : DbConnection
|
|
{
|
|
internal TestSqlConnection(Dictionary<string, string>[][] data)
|
|
{
|
|
Data = data;
|
|
}
|
|
|
|
internal Dictionary<string, string>[][] Data { get; set; }
|
|
|
|
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
// No Op
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
// No Op, unless credentials are bad
|
|
if(ConnectionString.Contains("invalidUsername"))
|
|
{
|
|
throw new Exception("Invalid credentials provided");
|
|
}
|
|
}
|
|
|
|
public override string ConnectionString { get; set; }
|
|
public override string Database { get; }
|
|
public override ConnectionState State { get; }
|
|
public override string DataSource { get; }
|
|
public override string ServerVersion { get; }
|
|
|
|
protected override DbCommand CreateDbCommand()
|
|
{
|
|
return new TestSqlCommand(Data);
|
|
}
|
|
|
|
public override void ChangeDatabase(string databaseName)
|
|
{
|
|
// No Op
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test mock class for SqlConnection factory
|
|
/// </summary>
|
|
public class TestSqlConnectionFactory : ISqlConnectionFactory
|
|
{
|
|
public DbConnection CreateSqlConnection(string connectionString)
|
|
{
|
|
return new TestSqlConnection(null)
|
|
{
|
|
ConnectionString = connectionString
|
|
};
|
|
}
|
|
}
|
|
}
|