fixed db trigger, system types and oe tests (#331)

* fixed db trigger, system types and oe tests
This commit is contained in:
Leila Lali
2017-04-28 09:44:45 -07:00
committed by GitHub
parent c4227c2e24
commit c46032c71f
13 changed files with 690 additions and 565 deletions

View File

@@ -272,7 +272,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common.Baselined
/// <param name="actualContent">Actual string</param>
/// <param name="baselineContent">Expected string</param>
/// <remarks>Fails test if strings do not match; comparison is done using an InvariantCulture StringComparer</remarks>
public void CompareActualWithBaseline(string actualContent, string baselineContent)
public static void CompareActualWithBaseline(string actualContent, string baselineContent)
{
int _compareResult = string.Compare(actualContent, baselineContent, StringComparison.OrdinalIgnoreCase);

View File

@@ -54,29 +54,26 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
/// Create the test db if not already exists
/// </summary>
public static SqlTestDb CreateNew(
TestServerType serverType,
bool doNotCleanupDb = false,
string databaseName = null,
string query = null,
TestServerType serverType,
bool doNotCleanupDb = false,
string databaseName = null,
string query = null,
string dbNamePrefix = null)
{
SqlTestDb testDb = new SqlTestDb();
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
databaseName = databaseName ?? GetUniqueDBName(dbNamePrefix);
string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
TestServiceProvider.Instance.RunQuery(serverType, MasterDatabaseName, createDatabaseQuery);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' is created", databaseName));
if (!string.IsNullOrEmpty(query))
{
databaseName = databaseName ?? GetUniqueDBName(dbNamePrefix);
string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
TestServiceProvider.Instance.RunQuery(serverType, MasterDatabaseName, createDatabaseQuery);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' is created", databaseName));
if (!string.IsNullOrEmpty(query))
{
TestServiceProvider.Instance.RunQuery(serverType, databaseName, query);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' SQL types are created", databaseName));
}
testDb.DatabaseName = databaseName;
testDb.ServerType = serverType;
testDb.DoNotCleanupDb = doNotCleanupDb;
TestServiceProvider.Instance.RunQuery(serverType, databaseName, query);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' SQL types are created", databaseName));
}
testDb.DatabaseName = databaseName;
testDb.ServerType = serverType;
testDb.DoNotCleanupDb = doNotCleanupDb;
return testDb;
}
@@ -111,13 +108,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
public void Cleanup()
{
if (!DoNotCleanupDb)
try
{
string dropDatabaseQuery = string.Format(CultureInfo.InvariantCulture,
(ServerType == TestServerType.Azure ? Scripts.DropDatabaseIfExistAzure : Scripts.DropDatabaseIfExist), DatabaseName);
if (!DoNotCleanupDb)
{
string dropDatabaseQuery = string.Format(CultureInfo.InvariantCulture,
(ServerType == TestServerType.Azure ? Scripts.DropDatabaseIfExistAzure : Scripts.DropDatabaseIfExist), DatabaseName);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Cleaning up database {0}", DatabaseName));
TestServiceProvider.Instance.RunQuery(ServerType, MasterDatabaseName, dropDatabaseQuery);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Cleaning up database {0}", DatabaseName));
TestServiceProvider.Instance.RunQuery(ServerType, MasterDatabaseName, dropDatabaseQuery);
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Failed to cleanup database: {0} error:{1}", DatabaseName, ex.Message));
}
}

View File

@@ -0,0 +1,136 @@
NodeType: Table Label: HumanResources.Employee
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: NationalIDNumber
NodeType: Column Label: LoginID
NodeType: Column Label: OrganizationNode
NodeType: Column Label: OrganizationLevel
NodeType: Column Label: JobTitle
NodeType: Column Label: BirthDate
NodeType: Column Label: MaritalStatus
NodeType: Column Label: Gender
NodeType: Column Label: HireDate
NodeType: Column Label: SalariedFlag
NodeType: Column Label: VacationHours
NodeType: Column Label: SickLeaveHours
NodeType: Column Label: CurrentFlag
NodeType: Column Label: rowguid
NodeType: Column Label: ModifiedDate
NodeType: Key Label: FK_Employee_Person_BusinessEntityID
NodeType: Key Label: PK_Employee_BusinessEntityID
NodeType: Constraint Label: CK_Employee_BirthDate
NodeType: Constraint Label: CK_Employee_Gender
NodeType: Constraint Label: CK_Employee_HireDate
NodeType: Constraint Label: CK_Employee_MaritalStatus
NodeType: Constraint Label: CK_Employee_SickLeaveHours
NodeType: Constraint Label: CK_Employee_VacationHours
NodeType: Index Label: NonClusteredIndex-Login
NodeType: Statistic Label: NonClusteredIndex-Login
NodeType: Statistic Label: PK_Employee_BusinessEntityID
NodeType: Table Label: HumanResources.Employee_Temporal
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: NationalIDNumber
NodeType: Column Label: LoginID
NodeType: Column Label: OrganizationNode
NodeType: Column Label: OrganizationLevel
NodeType: Column Label: JobTitle
NodeType: Column Label: BirthDate
NodeType: Column Label: MaritalStatus
NodeType: Column Label: Gender
NodeType: Column Label: HireDate
NodeType: Column Label: VacationHours
NodeType: Column Label: SickLeaveHours
NodeType: Column Label: ValidFrom
NodeType: Column Label: ValidTo
NodeType: Key Label: PK_Employee_History_BusinessEntityID
NodeType: Statistic Label: PK_Employee_History_BusinessEntityID
NodeType: Table Label: Person.Person
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: PersonType
NodeType: Column Label: NameStyle
NodeType: Column Label: Title
NodeType: Column Label: FirstName
NodeType: Column Label: MiddleName
NodeType: Column Label: LastName
NodeType: Column Label: Suffix
NodeType: Column Label: EmailPromotion
NodeType: Column Label: AdditionalContactInfo
NodeType: Column Label: rowguid
NodeType: Column Label: ModifiedDate
NodeType: Key Label: PK_Person_BusinessEntityID
NodeType: Constraint Label: CK_Person_EmailPromotion
NodeType: Constraint Label: CK_Person_PersonType
NodeType: Trigger Label: TableTrigger
NodeType: Statistic Label: PK_Person_BusinessEntityID
NodeType: View Label: HumanResources.vEmployee
NodeType: Column Label: BusinessEntityID
NodeType: Column Label: Title
NodeType: Column Label: FirstName
NodeType: Column Label: MiddleName
NodeType: Column Label: LastName
NodeType: Column Label: Suffix
NodeType: Column Label: JobTitle
NodeType: Column Label: AdditionalContactInfo
NodeType: Synonym Label: dbo.MyProduct
NodeType: StoredProcedure Label: HumanResources.sp_GetEmployee_Person_Info_AsOf
NodeType: StoredProcedureParameter Label: @asOf
NodeType: TableValuedFunction Label: dbo.ufnGetContactInformation
NodeType: TableValuedFunctionParameter Label: @PersonID
NodeType: ScalarValuedFunction Label: dbo.fun1
NodeType: ScalarValuedFunction Label: dbo.ufnGetInventoryStock
NodeType: ScalarValuedFunctionParameter Label: @ProductID
NodeType: DatabaseTrigger Label: Trigger_2
NodeType: Assembly Label: Microsoft.SqlServer.Types
NodeType: UserDefinedDataType Label: dbo.AccountNumber
NodeType: UserDefinedDataType Label: dbo.Flag
NodeType: UserDefinedDataType Label: dbo.Name
NodeType: UserDefinedDataType Label: dbo.NameStyle
NodeType: UserDefinedDataType Label: dbo.OrderNumber
NodeType: UserDefinedDataType Label: dbo.Phone
NodeType: UserDefinedTableType Label: Demo.SalesOrderDetailType_inmem
NodeType: UserDefinedTableTypeColumn Label: OrderQty
NodeType: UserDefinedTableTypeColumn Label: ProductID
NodeType: UserDefinedTableTypeColumn Label: SpecialOfferID
NodeType: UserDefinedTableType Label: Demo.SalesOrderDetailType_ondisk
NodeType: UserDefinedTableTypeColumn Label: OrderQty
NodeType: UserDefinedTableTypeColumn Label: ProductID
NodeType: UserDefinedTableTypeColumn Label: SpecialOfferID
NodeType: XmlSchemaCollection Label: Person.AdditionalContactInfoSchemaCollection
NodeType: Rule Label: dbo.list_rule
NodeType: Default Label: dbo.phonedflt
NodeType: Sequence Label: Demo.ID_Seq
NodeType: FileGroup Label: PRIMARY
NodeType: FullTextCatalog Label: AW2014FullTextCatalog
NodeType: User Label: amy0
NodeType: User Label: dbo
NodeType: User Label: guest
NodeType: User Label: INFORMATION_SCHEMA
NodeType: User Label: sys
NodeType: DatabaseRole Label: db_accessadmin
NodeType: DatabaseRole Label: db_backupoperator
NodeType: DatabaseRole Label: db_datareader
NodeType: DatabaseRole Label: db_datawriter
NodeType: DatabaseRole Label: db_ddladmin
NodeType: DatabaseRole Label: db_denydatareader
NodeType: DatabaseRole Label: db_denydatawriter
NodeType: DatabaseRole Label: db_owner
NodeType: DatabaseRole Label: db_securityadmin
NodeType: DatabaseRole Label: public
NodeType: DatabaseRole Label: SalesManagers
NodeType: DatabaseRole Label: SalesPersons
NodeType: Schema Label: dbo
NodeType: Schema Label: db_accessadmin
NodeType: Schema Label: db_backupoperator
NodeType: Schema Label: db_datareader
NodeType: Schema Label: db_datawriter
NodeType: Schema Label: db_ddladmin
NodeType: Schema Label: db_denydatareader
NodeType: Schema Label: db_denydatawriter
NodeType: Schema Label: db_owner
NodeType: Schema Label: db_securityadmin
NodeType: Schema Label: Demo
NodeType: Schema Label: guest
NodeType: Schema Label: HumanResources
NodeType: Schema Label: INFORMATION_SCHEMA
NodeType: Schema Label: Person
NodeType: Schema Label: sys
NodeType: DatabaseEncryptionKey Label:

View File

@@ -6,6 +6,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.SqlTools.Credentials;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
@@ -78,9 +80,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
/// </summary>
public void RunQuery(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false)
{
string uri = "";
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, queryTempFile.FilePath);
uri = queryTempFile.FilePath;
ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, uri);
Query query = new Query(queryText, connInfo, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory());
query.Execute();
query.ExecutionTask.Wait();
@@ -96,7 +101,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
string.Join(Environment.NewLine, errorBatches.Select(b => b.BatchText))));
}
}
DisconnectConnection(uri);
}
}
public static async Task<T> CalculateRunTime<T>(Func<Task<T>> testToRun, bool printResult, [CallerMemberName] string testName = "")
{
TestTimer timer = new TestTimer() { PrintResult = printResult };
T result = await testToRun();
timer.EndAndPrint(testName);
return result;
}
private ConnectionInfo InitLiveConnectionInfo(TestServerType serverType, string databaseName, string scriptFilePath)
@@ -119,6 +135,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
return connInfo;
}
private void DisconnectConnection(string uri)
{
ConnectionService.Instance.Disconnect(new DisconnectParams
{
OwnerUri = uri,
Type = ConnectionType.Default
});
}
private static bool hasInitServices = false;
private static void InitializeTestServices()