//
// 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.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Moq;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
{
///
/// Tests for the ServiceHost Connection Service tests
///
public class TestObjects
{
public const string ScriptUri = "file://some/file.sql";
///
/// Creates a test connection service
///
public static ConnectionService GetTestConnectionService()
{
// use mock database connection
return new ConnectionService(new TestSqlConnectionFactory());
}
///
/// Creates a test connection info instance.
///
public static ConnectionInfo GetTestConnectionInfo()
{
return new ConnectionInfo(
new TestSqlConnectionFactory(),
ScriptUri,
GetTestConnectionDetails());
}
public static ConnectParams GetTestConnectionParams()
{
return new ConnectParams()
{
OwnerUri = ScriptUri,
Connection = GetTestConnectionDetails()
};
}
///
/// Creates a test connection details object
///
public static ConnectionDetails GetTestConnectionDetails()
{
return new ConnectionDetails()
{
UserName = "user",
Password = "password",
DatabaseName = "databaseName",
ServerName = "serverName"
};
}
///
/// Create a test language service instance
///
///
public static LanguageService GetTestLanguageService()
{
return new LanguageService();
}
///
/// Creates and returns a dummy TextDocumentPosition
///
public static TextDocumentPosition GetTestDocPosition()
{
return new TextDocumentPosition
{
TextDocument = new TextDocumentIdentifier { Uri = ScriptUri },
Position = new Position
{
Line = 0,
Character = 0
}
};
}
}
///
/// Test mock class for IDbCommand
///
public class TestSqlCommand : DbCommand
{
internal TestSqlCommand(TestResultSet[] data)
{
Data = data;
var mockParameterCollection = new Mock();
mockParameterCollection.Setup(c => c.Add(It.IsAny