mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
New test common project for database connections using the settings.json (#210)
* moved test driver tests and test common classes to separate projects
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// 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.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Xunit;
|
||||
|
||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
internal static int Main(string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
Console.WriteLine( "Microsoft.SqlTools.ServiceLayer.TestDriver.exe [tests]" + Environment.NewLine +
|
||||
" [tests] is a space-separated list of tests to run." + Environment.NewLine +
|
||||
" They are qualified within the Microsoft.SqlTools.ServiceLayer.TestDriver.Tests namespace" + Environment.NewLine +
|
||||
"Be sure to set the environment variable " + ServiceTestDriver.ServiceHostEnvironmentVariable + " to the full path of the sqltoolsservice executable.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Logger.Initialize("testdriver", LogLevel.Verbose);
|
||||
|
||||
int returnCode = 0;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
string testNamespace = "Microsoft.SqlTools.ServiceLayer.TestDriver.Tests.";
|
||||
foreach (var test in args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var testName = test.Contains(testNamespace) ? test.Replace(testNamespace, "") : test;
|
||||
bool containsTestName = testName.Contains(".");
|
||||
var className = containsTestName ? testName.Substring(0, testName.LastIndexOf('.')) : testName;
|
||||
var methodName = containsTestName ? testName.Substring(testName.LastIndexOf('.') + 1) : null;
|
||||
|
||||
var type = Type.GetType(testNamespace + className);
|
||||
if (type == null)
|
||||
{
|
||||
Console.WriteLine("Invalid class name");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(methodName))
|
||||
{
|
||||
var methods = type.GetMethods().Where(x => x.CustomAttributes.Any(a => a.AttributeType == typeof(FactAttribute)));
|
||||
foreach (var method in methods)
|
||||
{
|
||||
await RunTest(type, method, method.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MethodInfo methodInfo = type.GetMethod(methodName);
|
||||
await RunTest(type, methodInfo, test);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
returnCode = -1;
|
||||
}
|
||||
}
|
||||
}).Wait();
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
private static async Task RunTest(Type type, MethodInfo methodInfo, string testName)
|
||||
{
|
||||
if (methodInfo == null)
|
||||
{
|
||||
Console.WriteLine("Invalid method name");
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var typeInstance = (IDisposable)Activator.CreateInstance(type))
|
||||
{
|
||||
Console.WriteLine("Running test " + testName);
|
||||
await (Task)methodInfo.Invoke(typeInstance, null);
|
||||
Console.WriteLine("Test ran successfully: " + testName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
USE master
|
||||
GO
|
||||
|
||||
DECLARE @dbname nvarchar(128)
|
||||
SET @dbname = N'#DatabaseName#'
|
||||
|
||||
IF NOT(EXISTS (SELECT name
|
||||
FROM master.dbo.sysdatabases
|
||||
WHERE ('[' + name + ']' = @dbname
|
||||
OR name = @dbname)))
|
||||
BEGIN
|
||||
CREATE DATABASE #DatabaseName#
|
||||
END
|
||||
@@ -1,231 +0,0 @@
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Demo')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [Demo]')
|
||||
END
|
||||
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'HumanResources')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [HumanResources]')
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Person')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [Person]')
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Production')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [Production]')
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Purchasing')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [Purchasing]')
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Sales')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [Sales]')
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Security')
|
||||
BEGIN
|
||||
EXEC('CREATE SCHEMA [Security]')
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'AccountNumber')
|
||||
BEGIN
|
||||
CREATE TYPE [dbo].[AccountNumber] FROM [nvarchar](15) NULL
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'Flag')
|
||||
BEGIN
|
||||
CREATE TYPE [dbo].[Flag] FROM [bit] NOT NULL
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'Name')
|
||||
BEGIN
|
||||
CREATE TYPE [dbo].[Name] FROM [nvarchar](50) NULL
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'NameStyle')
|
||||
BEGIN
|
||||
CREATE TYPE [dbo].[NameStyle] FROM [bit] NOT NULL
|
||||
END
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'OrderNumber')
|
||||
BEGIN
|
||||
CREATE TYPE [dbo].[OrderNumber] FROM [nvarchar](25) NULL
|
||||
END
|
||||
GO
|
||||
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'Phone')
|
||||
BEGIN
|
||||
CREATE TYPE [dbo].[Phone] FROM [nvarchar](25) NULL
|
||||
END
|
||||
GO
|
||||
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Address')
|
||||
BEGIN
|
||||
CREATE TABLE [Person].[Address](
|
||||
[AddressID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
|
||||
[AddressLine1] [nvarchar](60) NOT NULL,
|
||||
[AddressLine2] [nvarchar](60) NULL,
|
||||
[City] [nvarchar](30) NOT NULL,
|
||||
[StateProvinceID] [int] NOT NULL,
|
||||
[PostalCode] [nvarchar](15) NOT NULL,
|
||||
[SpatialLocation] [geography] NULL,
|
||||
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[AddressID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'AddressType')
|
||||
BEGIN
|
||||
CREATE TABLE [Person].[AddressType](
|
||||
[AddressTypeID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[Name] [dbo].[Name] NOT NULL,
|
||||
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[AddressTypeID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
/****** Object: Table [Person].[ContactType] Script Date: 11/22/2016 9:25:52 AM ******/
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'ContactType')
|
||||
BEGIN
|
||||
CREATE TABLE [Person].[ContactType](
|
||||
[ContactTypeID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[Name] [dbo].[Name] NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_ContactType_ContactTypeID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[ContactTypeID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'EmailAddress')
|
||||
BEGIN
|
||||
CREATE TABLE [Person].[EmailAddress](
|
||||
[BusinessEntityID] [int] NOT NULL,
|
||||
[EmailAddressID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[EmailAddress] [nvarchar](50) NULL,
|
||||
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_EmailAddress_BusinessEntityID_EmailAddressID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[BusinessEntityID] ASC,
|
||||
[EmailAddressID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Person')
|
||||
BEGIN
|
||||
CREATE TABLE [Person].[Person](
|
||||
[BusinessEntityID] [int] NOT NULL,
|
||||
[PersonType] [nchar](2) NOT NULL,
|
||||
[NameStyle] [dbo].[NameStyle] NOT NULL,
|
||||
[Title] [nvarchar](8) NULL,
|
||||
[FirstName] [dbo].[Name] NOT NULL,
|
||||
[MiddleName] [dbo].[Name] NULL,
|
||||
[LastName] [dbo].[Name] NOT NULL,
|
||||
[Suffix] [nvarchar](10) NULL,
|
||||
[EmailPromotion] [int] NOT NULL,
|
||||
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_Person_BusinessEntityID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[BusinessEntityID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'PersonPhone')
|
||||
BEGIN
|
||||
CREATE TABLE [Person].[PersonPhone](
|
||||
[BusinessEntityID] [int] NOT NULL,
|
||||
[PhoneNumber] [dbo].[Phone] NOT NULL,
|
||||
[PhoneNumberTypeID] [int] NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_PersonPhone_BusinessEntityID_PhoneNumber_PhoneNumberTypeID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[BusinessEntityID] ASC,
|
||||
[PhoneNumber] ASC,
|
||||
[PhoneNumberTypeID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Location')
|
||||
BEGIN
|
||||
CREATE TABLE [Production].[Location](
|
||||
[LocationID] [smallint] IDENTITY(1,1) NOT NULL,
|
||||
[Name] [dbo].[Name] NOT NULL,
|
||||
[CostRate] [smallmoney] NOT NULL,
|
||||
[Availability] [decimal](8, 2) NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_Location_LocationID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[LocationID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Product')
|
||||
BEGIN
|
||||
CREATE TABLE [Production].[Product](
|
||||
[ProductID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[Name] [dbo].[Name] NOT NULL,
|
||||
[ProductNumber] [nvarchar](25) NOT NULL,
|
||||
[MakeFlag] [dbo].[Flag] NOT NULL,
|
||||
[FinishedGoodsFlag] [dbo].[Flag] NOT NULL,
|
||||
[Color] [nvarchar](15) NULL,
|
||||
[SafetyStockLevel] [smallint] NOT NULL,
|
||||
[ReorderPoint] [smallint] NOT NULL,
|
||||
[StandardCost] [money] NOT NULL,
|
||||
[ListPrice] [money] NOT NULL,
|
||||
[Size] [nvarchar](5) NULL,
|
||||
[SizeUnitMeasureCode] [nchar](3) NULL,
|
||||
[WeightUnitMeasureCode] [nchar](3) NULL,
|
||||
[Weight] [decimal](8, 2) NULL,
|
||||
[DaysToManufacture] [int] NOT NULL,
|
||||
[ProductLine] [nchar](2) NULL,
|
||||
[Class] [nchar](2) NULL,
|
||||
[Style] [nchar](2) NULL,
|
||||
[ProductSubcategoryID] [int] NULL,
|
||||
[ProductModelID] [int] NULL,
|
||||
[SellStartDate] [datetime] NOT NULL,
|
||||
[SellEndDate] [datetime] NULL,
|
||||
[DiscontinuedDate] [datetime] NULL,
|
||||
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
|
||||
[ModifiedDate] [datetime] NOT NULL,
|
||||
CONSTRAINT [PK_Product_ProductID] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[ProductID] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
END
|
||||
GO
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// 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.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts
|
||||
{
|
||||
public class Scripts
|
||||
{
|
||||
public const string MasterBasicQuery = "SELECT * FROM sys.all_columns"; //basic queries should return at least 10000 rows
|
||||
|
||||
public const string DelayQuery = "WAITFOR DELAY '00:01:00'";
|
||||
|
||||
public const string TestDbSimpleSelectQuery = "SELECT * FROM [Person].[Address]";
|
||||
|
||||
public const string SelectQuery = "SELECT * FROM ";
|
||||
|
||||
public static string CreateDatabaseObjectsQuery { get { return CreateDatabaseObjectsQueryInstance.Value; } }
|
||||
|
||||
public static string CreateDatabaseQuery { get { return CreateDatabaseQueryInstance.Value; } }
|
||||
|
||||
public static string TestDbComplexSelectQueries { get { return TestDbSelectQueriesInstance.Value; } }
|
||||
|
||||
private static readonly Lazy<string> CreateDatabaseObjectsQueryInstance = new Lazy<string>(() =>
|
||||
{
|
||||
return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.CreateTestDatabaseObjects.sql");
|
||||
});
|
||||
|
||||
private static readonly Lazy<string> CreateDatabaseQueryInstance = new Lazy<string>(() =>
|
||||
{
|
||||
return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.CreateTestDatabase.sql");
|
||||
});
|
||||
|
||||
private static readonly Lazy<string> TestDbSelectQueriesInstance = new Lazy<string>(() =>
|
||||
{
|
||||
return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.TestDbTableQueries.sql");
|
||||
});
|
||||
|
||||
private static string GetScriptFileContent(string fileName)
|
||||
{
|
||||
string fileContent = string.Empty;
|
||||
try
|
||||
{
|
||||
using (Stream stream = typeof(Scripts).GetTypeInfo().Assembly.GetManifestResourceStream(fileName))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
fileContent = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to load the sql script. error: {ex.Message}");
|
||||
}
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
SELECT * FROM [Person].[Address]
|
||||
|
||||
SELECT [AddressID]
|
||||
,[AddressLine1]
|
||||
,[AddressLine2]
|
||||
,[City]
|
||||
,[StateProvinceID]
|
||||
,[PostalCode]
|
||||
,[SpatialLocation]
|
||||
,[rowguid]
|
||||
,[ModifiedDate]
|
||||
FROM [Person].[Address]
|
||||
GO
|
||||
SELECT [AddressTypeID]
|
||||
,[Name]
|
||||
,[rowguid]
|
||||
,[ModifiedDate]
|
||||
FROM [Person].[AddressType]
|
||||
GO
|
||||
SELECT [ContactTypeID]
|
||||
,[Name]
|
||||
,[ModifiedDate]
|
||||
FROM [Person].[ContactType]
|
||||
GO
|
||||
SELECT [BusinessEntityID]
|
||||
,[EmailAddressID]
|
||||
,[EmailAddress]
|
||||
,[rowguid]
|
||||
,[ModifiedDate]
|
||||
FROM [Person].[EmailAddress]
|
||||
GO
|
||||
SELECT [BusinessEntityID]
|
||||
,[PersonType]
|
||||
,[NameStyle]
|
||||
,[Title]
|
||||
,[FirstName]
|
||||
,[MiddleName]
|
||||
,[LastName]
|
||||
,[Suffix]
|
||||
,[EmailPromotion]
|
||||
,[rowguid]
|
||||
,[ModifiedDate]
|
||||
FROM [Person].[Person]
|
||||
GO
|
||||
SELECT [BusinessEntityID]
|
||||
,[PhoneNumber]
|
||||
,[PhoneNumberTypeID]
|
||||
,[ModifiedDate]
|
||||
FROM [Person].[PersonPhone]
|
||||
GO
|
||||
SELECT [LocationID]
|
||||
,[Name]
|
||||
,[CostRate]
|
||||
,[Availability]
|
||||
,[ModifiedDate]
|
||||
FROM [Production].[Location]
|
||||
GO
|
||||
SELECT [ProductID]
|
||||
,[Name]
|
||||
,[ProductNumber]
|
||||
,[MakeFlag]
|
||||
,[FinishedGoodsFlag]
|
||||
,[Color]
|
||||
,[SafetyStockLevel]
|
||||
,[ReorderPoint]
|
||||
,[StandardCost]
|
||||
,[ListPrice]
|
||||
,[Size]
|
||||
,[SizeUnitMeasureCode]
|
||||
,[WeightUnitMeasureCode]
|
||||
,[Weight]
|
||||
,[DaysToManufacture]
|
||||
,[ProductLine]
|
||||
,[Class]
|
||||
,[Style]
|
||||
,[ProductSubcategoryID]
|
||||
,[ProductModelID]
|
||||
,[SellStartDate]
|
||||
,[SellEndDate]
|
||||
,[DiscontinuedDate]
|
||||
,[rowguid]
|
||||
,[ModifiedDate]
|
||||
FROM [Production].[Product]
|
||||
GO
|
||||
@@ -1,59 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Language Service end-to-end integration tests
|
||||
/// </summary>
|
||||
public class ConnectionTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Try to connect with invalid credentials
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InvalidConnection()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.InvalidConnection, 300000);
|
||||
Assert.False(connected, "Invalid connection is failed to connect");
|
||||
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.InvalidConnection, 300000);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
await testHelper.CancelConnect(queryTempFile.FilePath);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate list databases request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ListDatabasesTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection successful");
|
||||
|
||||
var listDatabaseResult = await testHelper.ListDatabases(queryTempFile.FilePath);
|
||||
Assert.True(listDatabaseResult.DatabaseNames.Length > 0);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,471 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Language Service end-to-end integration tests
|
||||
/// </summary>
|
||||
public class LanguageServiceTests
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Validate hover tooltip scenarios
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task HoverTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = "SELECT * FROM sys.objects";
|
||||
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
|
||||
Thread.Sleep(10000);
|
||||
|
||||
Hover hover = await testHelper.RequestHover(queryTempFile.FilePath, query, 0, 15);
|
||||
|
||||
Assert.True(hover != null, "Hover tooltop is null");
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validation autocompletion suggestions scenarios
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CompletionTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = "SELECT * FROM sys.objects";
|
||||
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(10000);
|
||||
|
||||
CompletionItem[] completions = await testHelper.RequestCompletion(queryTempFile.FilePath, query, 0, 15);
|
||||
|
||||
Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");
|
||||
|
||||
Thread.Sleep(50);
|
||||
|
||||
await testHelper.RequestResolveCompletion(completions[0]);
|
||||
|
||||
Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate diagnostic scenarios
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DiagnosticsTests()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
string query = "SELECT *** FROM sys.objects";
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(100);
|
||||
|
||||
var contentChanges = new TextDocumentChangeEvent[1];
|
||||
contentChanges[0] = new TextDocumentChangeEvent
|
||||
{
|
||||
Range = new Range
|
||||
{
|
||||
Start = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 5
|
||||
},
|
||||
End = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 6
|
||||
}
|
||||
},
|
||||
RangeLength = 1,
|
||||
Text = "z"
|
||||
};
|
||||
|
||||
DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams()
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier()
|
||||
{
|
||||
Version = 2,
|
||||
Uri = queryTempFile.FilePath
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestChangeTextDocumentNotification(changeParams);
|
||||
|
||||
Thread.Sleep(100);
|
||||
|
||||
contentChanges[0] = new TextDocumentChangeEvent
|
||||
{
|
||||
Range = new Range
|
||||
{
|
||||
Start = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 5
|
||||
},
|
||||
End = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 6
|
||||
}
|
||||
},
|
||||
RangeLength = 1,
|
||||
Text = "t"
|
||||
};
|
||||
|
||||
changeParams = new DidChangeTextDocumentParams
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier
|
||||
{
|
||||
Version = 3,
|
||||
Uri = queryTempFile.FilePath
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestChangeTextDocumentNotification(changeParams);
|
||||
|
||||
Thread.Sleep(2500);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Peek Definition/ Go to definition
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task DefinitionTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = "SELECT * FROM sys.objects";
|
||||
int lineNumber = 0;
|
||||
int position = 23;
|
||||
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(10000);
|
||||
// Request definition for "objects"
|
||||
Location[] locations = await testHelper.RequestDefinition(queryTempFile.FilePath, query, lineNumber, position);
|
||||
|
||||
Assert.True(locations != null, "Location is not null and not empty");
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the configuration change event
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ChangeConfigurationTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
var settings = new SqlToolsSettings();
|
||||
settings.SqlTools.IntelliSense.EnableIntellisense = false;
|
||||
DidChangeConfigurationParams<SqlToolsSettings> configParams = new DidChangeConfigurationParams<SqlToolsSettings>()
|
||||
{
|
||||
Settings = settings
|
||||
};
|
||||
|
||||
await testHelper.RequestChangeConfigurationNotification(configParams);
|
||||
|
||||
Thread.Sleep(2000);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NotificationIsSentAfterOnConnectionAutoCompleteUpdate()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
// Connect
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
|
||||
// An event signalling that IntelliSense is ready should be sent shortly thereafter
|
||||
var readyParams = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);
|
||||
Assert.NotNull(readyParams);
|
||||
Assert.Equal(queryTempFile.FilePath, readyParams.OwnerUri);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FunctionSignatureCompletionReturnsEmptySignatureHelpObjectWhenThereAreNoMatches()
|
||||
{
|
||||
string sqlText = "EXEC sys.fn_not_a_real_function ";
|
||||
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string ownerUri = tempFile.FilePath;
|
||||
File.WriteAllText(ownerUri, sqlText);
|
||||
|
||||
// Connect
|
||||
await testHelper.Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
|
||||
// Wait for intellisense to be ready
|
||||
var readyParams = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);
|
||||
Assert.NotNull(readyParams);
|
||||
Assert.Equal(ownerUri, readyParams.OwnerUri);
|
||||
|
||||
// Send a function signature help Request
|
||||
var position = new TextDocumentPosition()
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier()
|
||||
{
|
||||
Uri = ownerUri
|
||||
},
|
||||
Position = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = sqlText.Length
|
||||
}
|
||||
};
|
||||
var signatureHelp = await testHelper.Driver.SendRequest(SignatureHelpRequest.Type, position);
|
||||
|
||||
Assert.NotNull(signatureHelp);
|
||||
Assert.False(signatureHelp.ActiveSignature.HasValue);
|
||||
Assert.Null(signatureHelp.Signatures);
|
||||
|
||||
await testHelper.Disconnect(ownerUri);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FunctionSignatureCompletionReturnsCorrectFunction()
|
||||
{
|
||||
string sqlText = "EXEC sys.fn_isrolemember ";
|
||||
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string ownerUri = tempFile.FilePath;
|
||||
File.WriteAllText(ownerUri, sqlText);
|
||||
|
||||
// Connect
|
||||
await testHelper.Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
|
||||
// Wait for intellisense to be ready
|
||||
var readyParams = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);
|
||||
Assert.NotNull(readyParams);
|
||||
Assert.Equal(ownerUri, readyParams.OwnerUri);
|
||||
|
||||
// Send a function signature help Request
|
||||
var position = new TextDocumentPosition()
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier()
|
||||
{
|
||||
Uri = ownerUri
|
||||
},
|
||||
Position = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = sqlText.Length
|
||||
}
|
||||
};
|
||||
var signatureHelp = await testHelper.Driver.SendRequest(SignatureHelpRequest.Type, position);
|
||||
|
||||
Assert.NotNull(signatureHelp);
|
||||
Assert.True(signatureHelp.ActiveSignature.HasValue);
|
||||
Assert.NotEmpty(signatureHelp.Signatures);
|
||||
|
||||
var label = signatureHelp.Signatures[signatureHelp.ActiveSignature.Value].Label;
|
||||
Assert.NotNull(label);
|
||||
Assert.NotEmpty(label);
|
||||
Assert.True(label.Contains("fn_isrolemember"));
|
||||
|
||||
await testHelper.Disconnect(ownerUri);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FunctionSignatureCompletionReturnsCorrectParametersAtEachPosition()
|
||||
{
|
||||
string sqlText = "EXEC sys.fn_isrolemember 1, 'testing', 2";
|
||||
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string ownerUri = tempFile.FilePath;
|
||||
File.WriteAllText(ownerUri, sqlText);
|
||||
|
||||
// Connect
|
||||
await testHelper.Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
|
||||
// Wait for intellisense to be ready
|
||||
var readyParams = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);
|
||||
Assert.NotNull(readyParams);
|
||||
Assert.Equal(ownerUri, readyParams.OwnerUri);
|
||||
|
||||
// Verify all parameters when the cursor is inside of parameters and at separator boundaries (,)
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 25, "fn_isrolemember", 0, "@mode int");
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 26, "fn_isrolemember", 0, "@mode int");
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 27, "fn_isrolemember", 1, "@login sysname");
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 30, "fn_isrolemember", 1, "@login sysname");
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 37, "fn_isrolemember", 1, "@login sysname");
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 38, "fn_isrolemember", 2, "@tranpubid int");
|
||||
await VerifyFunctionSignatureHelpParameter(testHelper, ownerUri, 39, "fn_isrolemember", 2, "@tranpubid int");
|
||||
|
||||
await testHelper.Disconnect(ownerUri);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task VerifyFunctionSignatureHelpParameter(
|
||||
TestHelper testHelper,
|
||||
string ownerUri,
|
||||
int character,
|
||||
string expectedFunctionName,
|
||||
int expectedParameterIndex,
|
||||
string expectedParameterName)
|
||||
{
|
||||
var position = new TextDocumentPosition()
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier()
|
||||
{
|
||||
Uri = ownerUri
|
||||
},
|
||||
Position = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = character
|
||||
}
|
||||
};
|
||||
var signatureHelp = await testHelper.Driver.SendRequest(SignatureHelpRequest.Type, position);
|
||||
|
||||
Assert.NotNull(signatureHelp);
|
||||
Assert.NotNull(signatureHelp.ActiveSignature);
|
||||
Assert.True(signatureHelp.ActiveSignature.HasValue);
|
||||
Assert.NotEmpty(signatureHelp.Signatures);
|
||||
|
||||
var activeSignature = signatureHelp.Signatures[signatureHelp.ActiveSignature.Value];
|
||||
Assert.NotNull(activeSignature);
|
||||
|
||||
var label = activeSignature.Label;
|
||||
Assert.NotNull(label);
|
||||
Assert.NotEmpty(label);
|
||||
Assert.True(label.Contains(expectedFunctionName));
|
||||
|
||||
Assert.NotNull(signatureHelp.ActiveParameter);
|
||||
Assert.True(signatureHelp.ActiveParameter.HasValue);
|
||||
Assert.Equal(expectedParameterIndex, signatureHelp.ActiveParameter.Value);
|
||||
|
||||
var parameter = activeSignature.Parameters[signatureHelp.ActiveParameter.Value];
|
||||
Assert.NotNull(parameter);
|
||||
Assert.NotNull(parameter.Label);
|
||||
Assert.NotEmpty(parameter.Label);
|
||||
Assert.Equal(expectedParameterName, parameter.Label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,360 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
public class QueryExecutionTests
|
||||
{
|
||||
/* Commenting out these tests until they are fixed (12/1/16)
|
||||
[Fact]
|
||||
public async Task TestQueryCancelReliability()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.objects a CROSS JOIN sys.objects b CROSS JOIN sys.objects c";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
|
||||
// Run and cancel 100 queries
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var queryTask = testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
|
||||
var cancelResult = await testHelper.CancelQuery(queryTempFile.FilePath);
|
||||
Assert.NotNull(cancelResult);
|
||||
Assert.True(string.IsNullOrEmpty(cancelResult.Messages));
|
||||
|
||||
await queryTask;
|
||||
}
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestQueryDoesNotBlockOtherRequests()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.objects a CROSS JOIN sys.objects b CROSS JOIN sys.objects c";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
|
||||
// Start a long-running query
|
||||
var queryTask = testHelper.RunQuery(queryTempFile.FilePath, query, 60000);
|
||||
|
||||
// Interact with the service. None of these requests should time out while waiting for the query to finish
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
using (SelfCleaningTempFile queryFile2 = new SelfCleaningTempFile())
|
||||
{
|
||||
await testHelper.Connect(queryFile2.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
Assert.NotNull(await testHelper.RequestCompletion(queryFile2.FilePath, "SELECT * FROM sys.objects", 0, 10));
|
||||
await testHelper.Disconnect(queryFile2.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
await testHelper.CancelQuery(queryTempFile.FilePath);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestParallelQueryExecution()
|
||||
{
|
||||
const int queryCount = 10;
|
||||
const string query = "SELECT * FROM sys.objects";
|
||||
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
// Create n connections
|
||||
SelfCleaningTempFile[] ownerUris = new SelfCleaningTempFile[queryCount];
|
||||
for (int i = 0; i < queryCount; i++)
|
||||
{
|
||||
ownerUris[i] = new SelfCleaningTempFile();
|
||||
Assert.NotNull(await testHelper.Connect(ownerUris[i].FilePath, ConnectionTestUtils.AzureTestServerConnection));
|
||||
}
|
||||
|
||||
// Run n queries at once
|
||||
var queryTasks = new Task<QueryExecuteCompleteParams>[queryCount];
|
||||
for (int i = 0; i < queryCount; i++)
|
||||
{
|
||||
queryTasks[i] = testHelper.RunQuery(ownerUris[i].FilePath, query);
|
||||
}
|
||||
await Task.WhenAll(queryTasks);
|
||||
|
||||
// Verify that they all completed with results and Disconnect
|
||||
for (int i = 0; i < queryCount; i++)
|
||||
{
|
||||
Assert.NotNull(queryTasks[i].Result);
|
||||
Assert.NotNull(queryTasks[i].Result.BatchSummaries);
|
||||
await testHelper.Disconnect(ownerUris[i].FilePath);
|
||||
ownerUris[i].Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestSaveResultsDoesNotBlockOtherRequests()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.objects";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
|
||||
// Execute a query
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
|
||||
// Spawn several tasks to save results
|
||||
var saveTasks = new Task<SaveResultRequestResult>[100];
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
saveTasks[i] = testHelper.SaveAsCsv(queryTempFile.FilePath, System.IO.Path.GetTempFileName(), 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
saveTasks[i] = testHelper.SaveAsJson(queryTempFile.FilePath, System.IO.Path.GetTempFileName(), 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Interact with the service. None of these requests should time out while waiting for the save results tasks to finish
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
using(SelfCleaningTempFile queryFile2 = new SelfCleaningTempFile())
|
||||
{
|
||||
await testHelper.Connect(queryFile2.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
Assert.NotNull(await testHelper.RequestCompletion(queryFile2.FilePath, "SELECT * FROM sys.objects", 0, 10));
|
||||
await testHelper.Disconnect(queryFile2.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.WhenAll(saveTasks);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestQueryingSubsetDoesNotBlockOtherRequests()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.objects";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
|
||||
// Execute a query
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
|
||||
// Spawn several tasks for subset requests
|
||||
var subsetTasks = new Task<QueryExecuteSubsetResult>[100];
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
subsetTasks[i] = testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
|
||||
}
|
||||
|
||||
// Interact with the service. None of these requests should time out while waiting for the subset tasks to finish
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
using (SelfCleaningTempFile queryFile2 = new SelfCleaningTempFile())
|
||||
{
|
||||
await testHelper.Connect(queryFile2.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
Assert.NotNull(await testHelper.RequestCompletion(queryFile2.FilePath, "SELECT * FROM sys.objects", 0, 10));
|
||||
await testHelper.Disconnect(queryFile2.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.WhenAll(subsetTasks);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestCancelQueryWhileOtherOperationsAreInProgress()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.objects a CROSS JOIN sys.objects b";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
List<Task> tasks = new List<Task>();
|
||||
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
|
||||
// Execute a long-running query
|
||||
var queryTask = testHelper.RunQuery(queryTempFile.FilePath, query, 60000);
|
||||
|
||||
// Queue up some tasks that interact with the service
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
using (SelfCleaningTempFile queryFile2 = new SelfCleaningTempFile())
|
||||
{
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
await testHelper.Connect(queryFile2.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
await testHelper.RequestCompletion(queryFile2.FilePath, "SELECT * FROM sys.objects", 0, 10);
|
||||
await testHelper.RunQuery(queryFile2.FilePath, "SELECT * FROM sys.objects");
|
||||
await testHelper.Disconnect(queryFile2.FilePath);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel the long-running query
|
||||
await testHelper.CancelQuery(queryTempFile.FilePath);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteBasicQueryTest()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.all_columns c";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||
{
|
||||
TextDocument = new TextDocumentItem()
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
var queryResult = await testHelper.RunQuery(queryTempFile.FilePath, query, 10000);
|
||||
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.NotNull(queryResult.BatchSummaries);
|
||||
|
||||
foreach (var batchSummary in queryResult.BatchSummaries)
|
||||
{
|
||||
foreach (var resultSetSummary in batchSummary.ResultSetSummaries)
|
||||
{
|
||||
Assert.True(resultSetSummary.RowCount > 0);
|
||||
}
|
||||
}
|
||||
|
||||
var subsetRequest = new QueryExecuteSubsetParams()
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
BatchIndex = 0,
|
||||
ResultSetIndex = 0,
|
||||
RowsStartIndex = 0,
|
||||
RowsCount = 100,
|
||||
};
|
||||
|
||||
var querySubset = await testHelper.RequestQueryExecuteSubset(subsetRequest);
|
||||
Assert.NotNull(querySubset);
|
||||
Assert.True(querySubset.ResultSubset.RowCount == 100);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestQueryingAfterCompletionRequests()
|
||||
{
|
||||
const string query = "SELECT * FROM sys.objects";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
List<Task> tasks = new List<Task>();
|
||||
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.AzureTestServerConnection);
|
||||
|
||||
Enumerable.Range(0, 10).ToList().ForEach(arg => tasks.Add(testHelper.RequestCompletion(queryTempFile.FilePath, query, 0, 10)));
|
||||
var queryTask = testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
tasks.Add(queryTask);
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
Assert.NotNull(queryTask.Result);
|
||||
Assert.NotNull(queryTask.Result.BatchSummaries);
|
||||
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.DataToolsTelemetryAzureConnection);
|
||||
tasks.Clear();
|
||||
Enumerable.Range(0, 10).ToList().ForEach(arg => tasks.Add(testHelper.RequestCompletion(queryTempFile.FilePath, query, 0, 10)));
|
||||
queryTask = testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
tasks.Add(queryTask);
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
Assert.NotNull(queryTask.Result);
|
||||
Assert.NotNull(queryTask.Result.BatchSummaries);
|
||||
|
||||
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.SqlDataToolsAzureConnection);
|
||||
tasks.Clear();
|
||||
Enumerable.Range(0, 10).ToList().ForEach(arg => tasks.Add(testHelper.RequestCompletion(queryTempFile.FilePath, query, 0, 10)));
|
||||
queryTask = testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
tasks.Add(queryTask);
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
Assert.NotNull(queryTask.Result);
|
||||
Assert.NotNull(queryTask.Result.BatchSummaries);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
[Theory]
|
||||
[InlineData("-- no-op")]
|
||||
[InlineData("GO")]
|
||||
[InlineData("GO -- no-op")]
|
||||
public async Task NoOpQueryReturnsMessage(string query)
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
Assert.True(await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection));
|
||||
|
||||
// If: the query is executed...
|
||||
var queryResult = await testHelper.RunQueryAsync(queryTempFile.FilePath, query);
|
||||
var message = await testHelper.WaitForMessage();
|
||||
|
||||
// Then:
|
||||
// ... I expect a query result to indicate successfully started query
|
||||
Assert.NotNull(queryResult);
|
||||
|
||||
// ... I expect a non-error message to be returned without a batch associated with it
|
||||
Assert.NotNull(message);
|
||||
Assert.NotNull(message.Message);
|
||||
Assert.NotNull(message.Message.Message);
|
||||
Assert.False(message.Message.IsError);
|
||||
Assert.Null(message.Message.BatchId);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
//
|
||||
// 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.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
public class StressTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Simulate typing by a user to stress test the language service
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
public async Task TestLanguageService()
|
||||
{
|
||||
const string textToType = "SELECT * FROM sys.objects GO " +
|
||||
"CREATE TABLE MyTable(" +
|
||||
"FirstName CHAR," +
|
||||
"LastName CHAR," +
|
||||
"DateOfBirth DATETIME," +
|
||||
"CONSTRAINT MyTableConstraint UNIQUE (FirstName, LastName, DateOfBirth)) GO " +
|
||||
"INSERT INTO MyTable (FirstName, LastName, DateOfBirth) VALUES ('John', 'Doe', '19800101') GO " +
|
||||
"SELECT * FROM MyTable GO " +
|
||||
"ALTER TABLE MyTable DROP CONSTRAINT MyTableConstraint GO " +
|
||||
"DROP TABLE MyTable GO ";
|
||||
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
// Connect
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
|
||||
Thread.Sleep(10000); // Wait for intellisense to warm up
|
||||
|
||||
// Simulate typing
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
int version = 1;
|
||||
while (stopwatch.Elapsed < TimeSpan.FromMinutes(60))
|
||||
{
|
||||
for (int i = 0; i < textToType.Length; i++)
|
||||
{
|
||||
System.IO.File.WriteAllText(queryTempFile.FilePath, textToType.Substring(0, i + 1));
|
||||
|
||||
var contentChanges = new TextDocumentChangeEvent[1];
|
||||
contentChanges[0] = new TextDocumentChangeEvent()
|
||||
{
|
||||
Range = new Range()
|
||||
{
|
||||
Start = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = i
|
||||
},
|
||||
End = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = i
|
||||
}
|
||||
},
|
||||
RangeLength = 1,
|
||||
Text = textToType.Substring(i, 1)
|
||||
};
|
||||
|
||||
DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams()
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier()
|
||||
{
|
||||
Version = ++version,
|
||||
Uri = queryTempFile.FilePath
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestChangeTextDocumentNotification(changeParams);
|
||||
|
||||
Thread.Sleep(50);
|
||||
|
||||
// If we just typed a space, request/resolve completion
|
||||
if (textToType[i] == ' ')
|
||||
{
|
||||
var completions = await testHelper.RequestCompletion(queryTempFile.FilePath, textToType.Substring(0, i + 1), 0, i + 1);
|
||||
Assert.True(completions != null && completions.Length > 0, "Completion items list was null or empty");
|
||||
|
||||
Thread.Sleep(50);
|
||||
|
||||
var item = await testHelper.RequestResolveCompletion(completions[0]);
|
||||
|
||||
Assert.NotNull(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the text document
|
||||
System.IO.File.WriteAllText(queryTempFile.FilePath, "");
|
||||
|
||||
var contentChanges2 = new TextDocumentChangeEvent[1];
|
||||
contentChanges2[0] = new TextDocumentChangeEvent()
|
||||
{
|
||||
Range = new Range()
|
||||
{
|
||||
Start = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = 0
|
||||
},
|
||||
End = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = textToType.Length - 1
|
||||
}
|
||||
},
|
||||
RangeLength = textToType.Length,
|
||||
Text = ""
|
||||
};
|
||||
|
||||
DidChangeTextDocumentParams changeParams2 = new DidChangeTextDocumentParams()
|
||||
{
|
||||
ContentChanges = contentChanges2,
|
||||
TextDocument = new VersionedTextDocumentIdentifier()
|
||||
{
|
||||
Version = ++version,
|
||||
Uri = queryTempFile.FilePath
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestChangeTextDocumentNotification(changeParams2);
|
||||
}
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repeatedly execute queries to stress test the query execution service.
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
public async Task TestQueryExecutionService()
|
||||
{
|
||||
const string queryToRun = "SELECT * FROM sys.all_objects GO " +
|
||||
"SELECT * FROM sys.objects GO " +
|
||||
"SELECT * FROM sys.tables GO " +
|
||||
"SELECT COUNT(*) FROM sys.objects";
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
// Connect
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
// Run queries repeatedly
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
while (stopwatch.Elapsed < TimeSpan.FromMinutes(60))
|
||||
{
|
||||
var queryResult = await testHelper.RunQuery(queryTempFile.FilePath, queryToRun, 10000);
|
||||
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.NotNull(queryResult.BatchSummaries);
|
||||
Assert.NotEmpty(queryResult.BatchSummaries);
|
||||
Assert.NotNull(queryResult.BatchSummaries[0].ResultSetSummaries);
|
||||
Assert.NotNull(queryResult.BatchSummaries[1].ResultSetSummaries);
|
||||
Assert.NotNull(queryResult.BatchSummaries[2].ResultSetSummaries);
|
||||
Assert.NotNull(queryResult.BatchSummaries[3].ResultSetSummaries);
|
||||
|
||||
Assert.NotNull(await testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 7));
|
||||
Assert.NotNull(await testHelper.ExecuteSubset(queryTempFile.FilePath, 1, 0, 0, 7));
|
||||
Assert.NotNull(await testHelper.ExecuteSubset(queryTempFile.FilePath, 2, 0, 0, 7));
|
||||
Assert.NotNull(await testHelper.ExecuteSubset(queryTempFile.FilePath, 3, 0, 0, 1));
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repeatedly connect and disconnect to stress test the connection service.
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
public async Task TestConnectionService()
|
||||
{
|
||||
string ownerUri = "file:///my/test/file.sql";
|
||||
|
||||
var connection = ConnectionTestUtils.LocalhostConnection;
|
||||
connection.Connection.Pooling = false;
|
||||
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
// Connect/disconnect repeatedly
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
while (stopwatch.Elapsed < TimeSpan.FromMinutes(60))
|
||||
{
|
||||
// Connect
|
||||
bool connected = await testHelper.Connect(ownerUri, connection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
// Disconnect
|
||||
bool disconnected = await testHelper.Disconnect(ownerUri);
|
||||
Assert.True(disconnected, "Disconnect is successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,404 +0,0 @@
|
||||
//
|
||||
// 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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all test suites run by the test driver
|
||||
/// </summary>
|
||||
public sealed class TestHelper : IDisposable
|
||||
{
|
||||
private bool isRunning = false;
|
||||
|
||||
public TestHelper()
|
||||
{
|
||||
Driver = new ServiceTestDriver();
|
||||
Driver.Start().Wait();
|
||||
this.isRunning = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.isRunning)
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
public void WaitForExit()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.isRunning = false;
|
||||
Driver.Stop().Wait();
|
||||
Console.WriteLine("Successfully killed process.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception while waiting for service exit: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The driver object used to read/write data to the service
|
||||
/// </summary>
|
||||
public ServiceTestDriver Driver
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private object fileLock = new Object();
|
||||
|
||||
/// <summary>
|
||||
/// Request a new connection to be created
|
||||
/// </summary>
|
||||
/// <returns>True if the connection completed successfully</returns>
|
||||
public async Task<bool> Connect(string ownerUri, ConnectParams connectParams, int timeout = 15000)
|
||||
{
|
||||
connectParams.OwnerUri = ownerUri;
|
||||
var connectResult = await Driver.SendRequest(ConnectionRequest.Type, connectParams);
|
||||
if (connectResult)
|
||||
{
|
||||
var completeEvent = await Driver.WaitForEvent(ConnectionCompleteNotification.Type, timeout);
|
||||
return !string.IsNullOrEmpty(completeEvent.ConnectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a disconnect
|
||||
/// </summary>
|
||||
public async Task<bool> Disconnect(string ownerUri)
|
||||
{
|
||||
var disconnectParams = new DisconnectParams();
|
||||
disconnectParams.OwnerUri = ownerUri;
|
||||
|
||||
var disconnectResult = await Driver.SendRequest(DisconnectRequest.Type, disconnectParams);
|
||||
return disconnectResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
public async Task<bool> CancelConnect(string ownerUri)
|
||||
{
|
||||
var cancelParams = new CancelConnectParams();
|
||||
cancelParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(CancelConnectRequest.Type, cancelParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
public async Task<ListDatabasesResponse> ListDatabases(string ownerUri)
|
||||
{
|
||||
var listParams = new ListDatabasesParams();
|
||||
listParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(ListDatabasesRequest.Type, listParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteSubsetResult> RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams)
|
||||
{
|
||||
return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task RequestOpenDocumentNotification(DidOpenTextDocumentNotification openParams)
|
||||
{
|
||||
await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a configuration change notification
|
||||
/// </summary>
|
||||
public async Task RequestChangeConfigurationNotification(DidChangeConfigurationParams<SqlToolsSettings> configParams)
|
||||
{
|
||||
await Driver.SendEvent(DidChangeConfigurationNotification<SqlToolsSettings>.Type, configParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task RequestChangeTextDocumentNotification(DidChangeTextDocumentParams changeParams)
|
||||
{
|
||||
await Driver.SendEvent(DidChangeTextDocumentNotification.Type, changeParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request completion item resolve to look-up additional info
|
||||
/// </summary>
|
||||
public async Task<CompletionItem> RequestResolveCompletion(CompletionItem item)
|
||||
{
|
||||
var result = await Driver.SendRequest(CompletionResolveRequest.Type, item);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a Read Credential for given credential id
|
||||
/// </summary>
|
||||
public async Task<Credential> ReadCredential(string credentialId)
|
||||
{
|
||||
var credentialParams = new Credential();
|
||||
credentialParams.CredentialId = credentialId;
|
||||
|
||||
return await Driver.SendRequest(ReadCredentialRequest.Type, credentialParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns database connection parameters for given server type
|
||||
/// </summary>
|
||||
public async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType, string databaseName)
|
||||
{
|
||||
ConnectionProfile connectionProfile = null;
|
||||
TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType);
|
||||
if (serverIdentiry == null)
|
||||
{
|
||||
connectionProfile = ConnectionTestUtils.Setting.Connections.FirstOrDefault(x => x.ServerType == serverType);
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionProfile = ConnectionTestUtils.Setting.GetConnentProfile(serverIdentiry.ProfileName, serverIdentiry.ServerName);
|
||||
}
|
||||
|
||||
if (connectionProfile != null)
|
||||
{
|
||||
string password = connectionProfile.Password;
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
Credential credential = await ReadCredential(connectionProfile.formatCredentialId());
|
||||
password = credential.Password;
|
||||
}
|
||||
ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database,
|
||||
connectionProfile.User, password);
|
||||
if (!string.IsNullOrEmpty(databaseName))
|
||||
{
|
||||
conenctParam.Connection.DatabaseName = databaseName;
|
||||
}
|
||||
if (serverType == TestServerType.Azure)
|
||||
{
|
||||
conenctParam.Connection.ConnectTimeout = 30;
|
||||
conenctParam.Connection.Encrypt = true;
|
||||
conenctParam.Connection.TrustServerCertificate = false;
|
||||
}
|
||||
return conenctParam;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a list of completion items for a position in a block of text
|
||||
/// </summary>
|
||||
public async Task<CompletionItem[]> RequestCompletion(string ownerUri, string text, int line, int character)
|
||||
{
|
||||
// Write the text to a backing file
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, text);
|
||||
}
|
||||
|
||||
var completionParams = new TextDocumentPosition();
|
||||
completionParams.TextDocument = new TextDocumentIdentifier();
|
||||
completionParams.TextDocument.Uri = ownerUri;
|
||||
completionParams.Position = new Position();
|
||||
completionParams.Position.Line = line;
|
||||
completionParams.Position.Character = character;
|
||||
|
||||
var result = await Driver.SendRequest(CompletionRequest.Type, completionParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a a hover tooltop
|
||||
/// </summary>
|
||||
public async Task<Hover> RequestHover(string ownerUri, string text, int line, int character)
|
||||
{
|
||||
// Write the text to a backing file
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, text);
|
||||
}
|
||||
|
||||
var completionParams = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier {Uri = ownerUri},
|
||||
Position = new Position
|
||||
{
|
||||
Line = line,
|
||||
Character = character
|
||||
}
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(HoverRequest.Type, completionParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request definition( peek definition/go to definition) for a sql object in a sql string
|
||||
/// </summary>
|
||||
public async Task<Location[]> RequestDefinition(string ownerUri, string text, int line, int character)
|
||||
{
|
||||
// Write the text to a backing file
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, text);
|
||||
}
|
||||
|
||||
var definitionParams = new TextDocumentPosition();
|
||||
definitionParams.TextDocument = new TextDocumentIdentifier();
|
||||
definitionParams.TextDocument.Uri = ownerUri;
|
||||
definitionParams.Position = new Position();
|
||||
definitionParams.Position.Line = line;
|
||||
definitionParams.Position.Character = character;
|
||||
|
||||
// Send definition request
|
||||
var result = await Driver.SendRequest(DefinitionRequest.Type, definitionParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run a query using a given connection bound to a URI
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteCompleteParams> RunQuery(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
{
|
||||
// Write the query text to a backing file
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
var queryParams = new QueryExecuteParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
if (result != null)
|
||||
{
|
||||
var eventResult = await Driver.WaitForEvent(QueryExecuteCompleteEvent.Type, timeoutMilliseconds);
|
||||
return eventResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run a query using a given connection bound to a URI. This method only waits for the initial response from query
|
||||
/// execution (QueryExecuteResult). It is up to the caller to wait for the QueryExecuteCompleteEvent if they are interested.
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteResult> RunQueryAsync(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
{
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
var queryParams = new QueryExecuteParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
return await Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to cancel an executing query
|
||||
/// </summary>
|
||||
public async Task<QueryCancelResult> CancelQuery(string ownerUri)
|
||||
{
|
||||
var cancelParams = new QueryCancelParams {OwnerUri = ownerUri};
|
||||
|
||||
var result = await Driver.SendRequest(QueryCancelRequest.Type, cancelParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to save query results as CSV
|
||||
/// </summary>
|
||||
public async Task<SaveResultRequestResult> SaveAsCsv(string ownerUri, string filename, int batchIndex, int resultSetIndex)
|
||||
{
|
||||
var saveParams = new SaveResultsAsCsvRequestParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
BatchIndex = batchIndex,
|
||||
ResultSetIndex = resultSetIndex,
|
||||
FilePath = filename
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(SaveResultsAsCsvRequest.Type, saveParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to save query results as JSON
|
||||
/// </summary>
|
||||
public async Task<SaveResultRequestResult> SaveAsJson(string ownerUri, string filename, int batchIndex, int resultSetIndex)
|
||||
{
|
||||
var saveParams = new SaveResultsAsJsonRequestParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
BatchIndex = batchIndex,
|
||||
ResultSetIndex = resultSetIndex,
|
||||
FilePath = filename
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(SaveResultsAsJsonRequest.Type, saveParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a subset of results from a query
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteSubsetResult> ExecuteSubset(string ownerUri, int batchIndex, int resultSetIndex, int rowStartIndex, int rowCount)
|
||||
{
|
||||
var subsetParams = new QueryExecuteSubsetParams();
|
||||
subsetParams.OwnerUri = ownerUri;
|
||||
subsetParams.BatchIndex = batchIndex;
|
||||
subsetParams.ResultSetIndex = resultSetIndex;
|
||||
subsetParams.RowsStartIndex = rowStartIndex;
|
||||
subsetParams.RowsCount = rowCount;
|
||||
|
||||
var result = await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Waits for a message to be returned by the service
|
||||
/// </summary>
|
||||
/// <returns>A message from the service layer</returns>
|
||||
public async Task<QueryExecuteMessageParams> WaitForMessage()
|
||||
{
|
||||
return await Driver.WaitForEvent(QueryExecuteMessageEvent.Type);
|
||||
}
|
||||
|
||||
public void WriteToFile(string ownerUri, string query)
|
||||
{
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Language Service end-to-end integration tests
|
||||
/// </summary>
|
||||
public class WorkspaceTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate workspace lifecycle events
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InitializeRequestTest()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
InitializeRequest initializeRequest = new InitializeRequest()
|
||||
{
|
||||
RootPath = Path.GetTempPath(),
|
||||
Capabilities = new ClientCapabilities()
|
||||
};
|
||||
|
||||
InitializeResult result = await testHelper.Driver.SendRequest(InitializeRequest.Type, initializeRequest);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
//
|
||||
// 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.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains useful utility methods for testing connections
|
||||
/// </summary>
|
||||
public class ConnectionTestUtils
|
||||
{
|
||||
public static IEnumerable<TestServerIdentity> TestServers = InitTestServerNames();
|
||||
public static Setting Setting = InitSetting();
|
||||
|
||||
private static readonly Lazy<ConnectParams> azureTestServerConnection =
|
||||
new Lazy<ConnectParams>(() => GetConnectionFromVsCodeSettings("***REMOVED***"));
|
||||
|
||||
private static IEnumerable<TestServerIdentity> InitTestServerNames()
|
||||
{
|
||||
try
|
||||
{
|
||||
string testServerNamesFilePath = Environment.GetEnvironmentVariable("TestServerNamesFile");
|
||||
if (!string.IsNullOrEmpty(testServerNamesFilePath))
|
||||
{
|
||||
string jsonFileContent = File.ReadAllText(testServerNamesFilePath);
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<IList<TestServerIdentity>>(jsonFileContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Enumerable.Empty<TestServerIdentity>();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Failed to load the database connection server name settings. error: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Setting InitSetting()
|
||||
{
|
||||
try
|
||||
{
|
||||
string settingsFileContents = GetSettingFileContent();
|
||||
Setting setting = Newtonsoft.Json.JsonConvert.DeserializeObject<Setting>(settingsFileContents);
|
||||
|
||||
return setting;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Failed to load the connection settings. error: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ConnectParams AzureTestServerConnection
|
||||
{
|
||||
get { return azureTestServerConnection.Value; }
|
||||
}
|
||||
|
||||
public static ConnectParams LocalhostConnection
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ConnectParams()
|
||||
{
|
||||
Connection = new ConnectionDetails()
|
||||
{
|
||||
DatabaseName = "master",
|
||||
ServerName = "localhost",
|
||||
AuthenticationType = "Integrated"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static ConnectParams InvalidConnection
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ConnectParams()
|
||||
{
|
||||
Connection = new ConnectionDetails()
|
||||
{
|
||||
DatabaseName = "master",
|
||||
ServerName = "localhost",
|
||||
AuthenticationType = "SqlLogin",
|
||||
UserName = "invalid",
|
||||
Password = ".."
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Lazy<ConnectParams> sqlDataToolsAzureConnection =
|
||||
new Lazy<ConnectParams>(() => GetConnectionFromVsCodeSettings("***REMOVED***"));
|
||||
|
||||
public static ConnectParams SqlDataToolsAzureConnection
|
||||
{
|
||||
get { return sqlDataToolsAzureConnection.Value; }
|
||||
}
|
||||
|
||||
private static readonly Lazy<ConnectParams> dataToolsTelemetryAzureConnection =
|
||||
new Lazy<ConnectParams>(() => GetConnectionFromVsCodeSettings("***REMOVED***"));
|
||||
|
||||
private static string GetSettingFileContent()
|
||||
{
|
||||
string settingsFilename;
|
||||
settingsFilename = Environment.GetEnvironmentVariable("SettingsFileName");
|
||||
if (string.IsNullOrEmpty(settingsFilename))
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/Library/Application Support/Code/User/settings.json";
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json";
|
||||
}
|
||||
}
|
||||
string settingsFileContents = File.ReadAllText(settingsFilename);
|
||||
|
||||
return settingsFileContents;
|
||||
}
|
||||
|
||||
public static ConnectParams DataToolsTelemetryAzureConnection
|
||||
{
|
||||
get { return dataToolsTelemetryAzureConnection.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a connection parameters object
|
||||
/// </summary>
|
||||
public static ConnectParams CreateConnectParams(string server, string database, string username, string password)
|
||||
{
|
||||
ConnectParams connectParams = new ConnectParams();
|
||||
connectParams.Connection = new ConnectionDetails();
|
||||
connectParams.Connection.ServerName = server;
|
||||
connectParams.Connection.DatabaseName = database;
|
||||
connectParams.Connection.UserName = username;
|
||||
connectParams.Connection.Password = password;
|
||||
connectParams.Connection.AuthenticationType = "SqlLogin";
|
||||
return connectParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve connection parameters from the vscode settings file
|
||||
/// </summary>
|
||||
public static ConnectParams GetConnectionFromVsCodeSettings(string serverName)
|
||||
{
|
||||
try
|
||||
{
|
||||
string settingsFileContents = GetSettingFileContent();
|
||||
|
||||
JObject root = JObject.Parse(settingsFileContents);
|
||||
JArray connections = (JArray)root["mssql.connections"];
|
||||
|
||||
var connectionObject = connections.Where(x => x["server"].ToString() == serverName).First();
|
||||
|
||||
return CreateConnectParams( connectionObject["server"].ToString(),
|
||||
connectionObject["database"].ToString(),
|
||||
connectionObject["user"].ToString(),
|
||||
connectionObject["password"].ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Unable to load connection " + serverName + " from the vscode settings.json. Ensure the file is formatted correctly.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// 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.IO;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
public class SelfCleaningTempFile : IDisposable
|
||||
{
|
||||
private bool disposed;
|
||||
|
||||
public SelfCleaningTempFile()
|
||||
{
|
||||
FilePath = Path.GetTempFileName();
|
||||
}
|
||||
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
#region IDisposable Implementation
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed && disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(FilePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"Failed to cleanup {FilePath}");
|
||||
}
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// The model for deserializing settings.json
|
||||
/// </summary>
|
||||
public class Setting
|
||||
{
|
||||
[JsonProperty("mssql.connections")]
|
||||
public List<ConnectionProfile> Connections { get; set; }
|
||||
|
||||
public ConnectionProfile GetConnentProfile(string profilerName, string serverName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(profilerName))
|
||||
{
|
||||
var byPrfileName = Connections.FirstOrDefault(x => x.ProfileName == profilerName);
|
||||
if (byPrfileName != null)
|
||||
{
|
||||
return byPrfileName;
|
||||
}
|
||||
}
|
||||
return Connections.FirstOrDefault(x => x.ServerName == serverName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The model to deserializing the connections inside settings.json
|
||||
/// </summary>
|
||||
public class ConnectionProfile
|
||||
{
|
||||
public const string CRED_PREFIX = "Microsoft.SqlTools";
|
||||
public const string CRED_SEPARATOR = "|";
|
||||
public const string CRED_SERVER_PREFIX = "server:";
|
||||
public const string CRED_DB_PREFIX = "db:";
|
||||
public const string CRED_USER_PREFIX = "user:";
|
||||
public const string CRED_ITEMTYPE_PREFIX = "itemtype:";
|
||||
|
||||
[JsonProperty("server")]
|
||||
public string ServerName { get; set; }
|
||||
public string Database { get; set; }
|
||||
|
||||
public string User { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public string ProfileName { get; set; }
|
||||
|
||||
public TestServerType ServerType { get; set; }
|
||||
|
||||
|
||||
public string formatCredentialId(string itemType = "Profile")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ServerName))
|
||||
{
|
||||
List<string> cred = new List<string>();
|
||||
cred.Add(CRED_PREFIX);
|
||||
AddToList(itemType, CRED_ITEMTYPE_PREFIX, cred);
|
||||
AddToList(ServerName, CRED_SERVER_PREFIX, cred);
|
||||
AddToList(Database, CRED_DB_PREFIX, cred);
|
||||
AddToList(User, CRED_USER_PREFIX, cred);
|
||||
return string.Join(CRED_SEPARATOR, cred.ToArray());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private void AddToList(string item, string prefix, List<string> list)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
list.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1}", prefix, item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
public class TestResult
|
||||
{
|
||||
public double ElapsedTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// The model to deserialize the server names json
|
||||
/// </summary>
|
||||
public class TestServerIdentity
|
||||
{
|
||||
public string ServerName { get; set; }
|
||||
public string ProfileName { get; set; }
|
||||
|
||||
public TestServerType ServerType { get; set; }
|
||||
}
|
||||
|
||||
public enum TestServerType
|
||||
{
|
||||
None,
|
||||
Azure,
|
||||
OnPrem
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Timer to calculate the test run time
|
||||
/// </summary>
|
||||
public class TestTimer
|
||||
{
|
||||
private static string resultFolder = InitResultFolder();
|
||||
|
||||
private static string InitResultFolder()
|
||||
{
|
||||
string resultFodler = Environment.GetEnvironmentVariable("ResultFolder");
|
||||
if (string.IsNullOrEmpty(resultFodler))
|
||||
{
|
||||
string assemblyLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
resultFodler = Path.GetDirectoryName(assemblyLocation);
|
||||
}
|
||||
return resultFodler;
|
||||
}
|
||||
|
||||
public TestTimer()
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
||||
public bool PrintResult { get; set; }
|
||||
|
||||
public void Start()
|
||||
{
|
||||
StartDateTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
EndDateTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void EndAndPrint([CallerMemberName] string testName = "")
|
||||
{
|
||||
End();
|
||||
if (PrintResult)
|
||||
{
|
||||
var currentColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds));
|
||||
Console.ForegroundColor = currentColor;
|
||||
string resultContent = Newtonsoft.Json.JsonConvert.SerializeObject(new TestResult { ElapsedTime = TotalMilliSeconds });
|
||||
string fileName = testName + ".json";
|
||||
string resultFilePath = string.IsNullOrEmpty(resultFolder) ? fileName : Path.Combine(resultFolder, fileName);
|
||||
File.WriteAllText(resultFilePath, resultContent);
|
||||
Console.WriteLine("Result file: " + resultFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
public double TotalMilliSeconds
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EndDateTime - StartDateTime).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
public double TotalMilliSecondsUntilNow
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DateTime.UtcNow - StartDateTime).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime StartDateTime { get; private set; }
|
||||
public DateTime EndDateTime { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,7 @@
|
||||
"name": "Microsoft.SqlTools.ServiceLayer.TestDriver",
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true,
|
||||
"embed": {
|
||||
"includeFiles": [
|
||||
"Scripts/CreateTestDatabaseObjects.sql",
|
||||
"Scripts/CreateTestDatabase.sql",
|
||||
"Scripts/TestDbTableQueries.sql"
|
||||
]
|
||||
},
|
||||
"publishOptions": {
|
||||
"include": [
|
||||
"Scripts/AdventureWorks.sql"
|
||||
]
|
||||
}
|
||||
"debugType": "portable"
|
||||
},
|
||||
"dependencies": {
|
||||
"xunit": "2.1.0",
|
||||
|
||||
Reference in New Issue
Block a user