Perf Test fixing bugs and Update command (#155)

* Fixed some bugs caused by rafactoring

* Verifying a test db is created before running the tests
This commit is contained in:
Leila Lali
2016-11-30 12:56:48 -08:00
committed by GitHub
parent d1b791805a
commit 453ff9de15
19 changed files with 708 additions and 804 deletions

View File

@@ -1,682 +0,0 @@
USE [AdventureWorks2016CTP3]
GO
SELECT [SystemInformationID]
,[Database Version]
,[VersionDate]
,[ModifiedDate]
FROM [dbo].[AWBuildVersion]
GO
GO
SELECT [DatabaseLogID]
,[PostTime]
,[DatabaseUser]
,[Event]
,[Schema]
,[Object]
,[TSQL]
,[XmlEvent]
FROM [dbo].[DatabaseLog]
GO
SELECT [OrderQty]
,[ProductID]
,[SpecialOfferID]
,[OrderID]
,[LocalID]
FROM [Demo].[DemoSalesOrderDetailSeed]
GO
SELECT [DueDate]
,[CustomerID]
,[SalesPersonID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[LocalID]
FROM [Demo].[DemoSalesOrderHeaderSeed]
GO
SELECT [DepartmentID]
,[Name]
,[GroupName]
,[ModifiedDate]
FROM [HumanResources].[Department]
GO
SELECT [BusinessEntityID]
,[NationalIDNumber]
,[LoginID]
,[OrganizationNode]
,[OrganizationLevel]
,[JobTitle]
,[BirthDate]
,[MaritalStatus]
,[Gender]
,[HireDate]
,[SalariedFlag]
,[VacationHours]
,[SickLeaveHours]
,[CurrentFlag]
,[rowguid]
,[ModifiedDate]
FROM [HumanResources].[Employee]
GO
SELECT [TrackingEventID]
,[EventName]
FROM [Sales].[TrackingEvent]
GO
SELECT [SalesTaxRateID]
,[StateProvinceID]
,[TaxType]
,[TaxRate]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[SalesTaxRate]
GO
SELECT [SalesOrderID]
,[SalesOrderDetailID]
,[CarrierTrackingNumber]
,[OrderQty]
,[ProductID]
,[SpecialOfferID]
,[UnitPrice]
,[UnitPriceDiscount]
,[ModifiedDate]
FROM [Sales].[SalesOrderDetail_inmem]
GO
SELECT [SalesOrderID]
,[RevisionNumber]
,[OrderDate]
,[DueDate]
,[ShipDate]
,[Status]
,[OnlineOrderFlag]
,[SalesOrderNumber]
,[PurchaseOrderNumber]
,[AccountNumber]
,[CustomerID]
,[SalesPersonID]
,[TerritoryID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[CreditCardID]
,[CreditCardApprovalCode]
,[CurrencyRateID]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[Comment]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[SalesOrderHeader]
GO
SELECT [SalesOrderID]
,[RevisionNumber]
,[OrderDate]
,[DueDate]
,[ShipDate]
,[Status]
,[OnlineOrderFlag]
,[SalesOrderNumber]
,[PurchaseOrderNumber]
,[AccountNumber]
,[CustomerID]
,[SalesPersonID]
,[TerritoryID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[CreditCardID]
,[CreditCardApprovalCode]
,[CurrencyRateID]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[Comment]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[SalesOrder_json]
GO
SELECT [BusinessEntityID]
,[CreditCardID]
,[ModifiedDate]
FROM [Sales].[PersonCreditCard]
GO
SELECT [OrderTrackingID]
,[SalesOrderID]
,[CarrierTrackingNumber]
,[TrackingEventID]
,[EventDetails]
,[EventDateTime]
FROM [Sales].[OrderTracking]
GO
SELECT [CustomerID]
,[FirstName]
,[LastName]
,[SSN]
,[CreditCardNumber]
,[EmailAddress]
,[PhoneNumber]
,[TerritoryID]
FROM [Sales].[CustomerPII]
GO
SELECT [CustomerID]
,[PersonID]
,[StoreID]
,[TerritoryID]
,[AccountNumber]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[Customer]
GO
SELECT [CurrencyRateID]
,[CurrencyRateDate]
,[FromCurrencyCode]
,[ToCurrencyCode]
,[AverageRate]
,[EndOfDayRate]
,[ModifiedDate]
FROM [Sales].[CurrencyRate]
GO
SELECT [CurrencyCode]
,[Name]
,[ModifiedDate]
FROM [Sales].[Currency]
GO
SELECT [CreditCardID]
,[CardType]
,[CardNumber]
,[ExpMonth]
,[ExpYear]
,[ModifiedDate]
FROM [Sales].[CreditCard]
GO
SELECT [CountryRegionCode]
,[CurrencyCode]
,[ModifiedDate]
FROM [Sales].[CountryRegionCurrency]
GO
SELECT [BusinessEntityID]
,[AccountNumber]
,[Name]
,[CreditRating]
,[PreferredVendorStatus]
,[ActiveFlag]
,[PurchasingWebServiceURL]
,[ModifiedDate]
FROM [Purchasing].[Vendor]
GO
SELECT [ShipMethodID]
,[Name]
,[ShipBase]
,[ShipRate]
,[rowguid]
,[ModifiedDate]
FROM [Purchasing].[ShipMethod]
GO
SELECT [PurchaseOrderID]
,[RevisionNumber]
,[Status]
,[EmployeeID]
,[VendorID]
,[ShipMethodID]
,[OrderDate]
,[ShipDate]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[ModifiedDate]
FROM [Purchasing].[PurchaseOrderHeader]
GO
SELECT [PurchaseOrderID]
,[PurchaseOrderDetailID]
,[DueDate]
,[OrderQty]
,[ProductID]
,[UnitPrice]
,[LineTotal]
,[ReceivedQty]
,[RejectedQty]
,[StockedQty]
,[ModifiedDate]
FROM [Purchasing].[PurchaseOrderDetail]
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
SELECT [ProductID]
,[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[Color]
,[SafetyStockLevel]
,[ReorderPoint]
,[StandardCost]
,[ListPrice]
,[Size]
,[SizeUnitMeasureCode]
,[WeightUnitMeasureCode]
,[Weight]
,[DaysToManufacture]
,[ProductLine]
,[Class]
,[Style]
,[ProductSubcategoryID]
,[ProductModelID]
,[SellStartDate]
,[SellEndDate]
,[DiscontinuedDate]
,[ModifiedDate]
FROM [Production].[Product_inmem]
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]
,[ModifiedDate]
FROM [Production].[Product_ondisk]
GO
SELECT [ProductCategoryID]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductCategory]
GO
SELECT [ProductID]
,[StartDate]
,[EndDate]
,[StandardCost]
,[ModifiedDate]
FROM [Production].[ProductCostHistory]
GO
SELECT [ProductDescriptionID]
,[Description]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductDescription]
GO
SELECT [ProductID]
,[DocumentNode]
,[ModifiedDate]
FROM [Production].[ProductDocument]
GO
SELECT [ProductID]
,[LocationID]
,[Shelf]
,[Bin]
,[Quantity]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductInventory]
GO
SELECT [ProductID]
,[StartDate]
,[EndDate]
,[ListPrice]
,[ModifiedDate]
FROM [Production].[ProductListPriceHistory]
GO
SELECT [ProductModelID]
,[Name]
,[CatalogDescription]
,[Instructions]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductModel]
GO
SELECT [ProductModelID]
,[IllustrationID]
,[ModifiedDate]
FROM [Production].[ProductModelIllustration]
GO
SELECT [ProductModelID]
,[IllustrationID]
,[ModifiedDate]
FROM [Production].[ProductModelIllustration]
GO
SELECT [ProductModelID]
,[ProductDescriptionID]
,[CultureID]
,[ModifiedDate]
FROM [Production].[ProductModelProductDescriptionCulture]
GO
SELECT [ProductPhotoID]
,[ThumbNailPhoto]
,[ThumbnailPhotoFileName]
,[LargePhoto]
,[LargePhotoFileName]
,[ModifiedDate]
FROM [Production].[ProductPhoto]
GO
SELECT [ProductID]
,[ProductPhotoID]
,[Primary]
,[ModifiedDate]
FROM [Production].[ProductProductPhoto]
GO
SELECT [ProductReviewID]
,[ProductID]
,[ReviewerName]
,[ReviewDate]
,[EmailAddress]
,[Rating]
,[Comments]
,[ModifiedDate]
FROM [Production].[ProductReview]
GO
SELECT [TransactionID]
,[ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionDate]
,[TransactionType]
,[Quantity]
,[ActualCost]
,[ModifiedDate]
FROM [Production].[TransactionHistory]
GO
SELECT [TransactionID]
,[ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionDate]
,[TransactionType]
,[Quantity]
,[ActualCost]
,[ModifiedDate]
FROM [Production].[TransactionHistoryArchive]
GO
SELECT [UnitMeasureCode]
,[Name]
,[ModifiedDate]
FROM [Production].[UnitMeasure]
GO
SELECT [WorkOrderID]
,[ProductID]
,[OrderQty]
,[StockedQty]
,[ScrappedQty]
,[StartDate]
,[EndDate]
,[DueDate]
,[ScrapReasonID]
,[ModifiedDate]
FROM [Production].[WorkOrder]
GO
SELECT [WorkOrderID]
,[ProductID]
,[OperationSequence]
,[LocationID]
,[ScheduledStartDate]
,[ScheduledEndDate]
,[ActualStartDate]
,[ActualEndDate]
,[ActualResourceHrs]
,[PlannedCost]
,[ActualCost]
,[ModifiedDate]
FROM [Production].[WorkOrderRouting]
GO
SELECT [ProductID]
,[BusinessEntityID]
,[AverageLeadTime]
,[StandardPrice]
,[LastReceiptCost]
,[LastReceiptDate]
,[MinOrderQty]
,[MaxOrderQty]
,[OnOrderQty]
,[UnitMeasureCode]
,[ModifiedDate]
FROM [Purchasing].[ProductVendor]
GO
SELECT [PurchaseOrderID]
,[PurchaseOrderDetailID]
,[DueDate]
,[OrderQty]
,[ProductID]
,[UnitPrice]
,[LineTotal]
,[ReceivedQty]
,[RejectedQty]
,[StockedQty]
,[ModifiedDate]
FROM [Purchasing].[PurchaseOrderDetail]
GO
SELECT [AddressID]
,[AddressLine1]
,[AddressLine2]
,[City]
,[StateProvinceID]
,[PostalCode]
,[SpatialLocation]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Address]
GO
SELECT [AddressTypeID]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Person].[AddressType]
GO
SELECT [BusinessEntityID]
,[rowguid]
,[ModifiedDate]
FROM [Person].[BusinessEntity]
GO
SELECT [BusinessEntityID]
,[AddressID]
,[AddressTypeID]
,[rowguid]
,[ModifiedDate]
FROM [Person].[BusinessEntityAddress]
GO
SELECT [BusinessEntityID]
,[PersonID]
,[ContactTypeID]
,[rowguid]
,[ModifiedDate]
FROM [Person].[BusinessEntityContact]
GO
SELECT [ContactTypeID]
,[Name]
,[ModifiedDate]
FROM [Person].[ContactType]
GO
SELECT [CountryRegionCode]
,[Name]
,[ModifiedDate]
FROM [Person].[CountryRegion]
GO
SELECT [BusinessEntityID]
,[EmailAddressID]
,[EmailAddress]
,[rowguid]
,[ModifiedDate]
FROM [Person].[EmailAddress]
GO
SELECT [BusinessEntityID]
,[PasswordHash]
,[PasswordSalt]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Password]
GO
SELECT [BusinessEntityID]
,[PersonType]
,[NameStyle]
,[Title]
,[FirstName]
,[MiddleName]
,[LastName]
,[Suffix]
,[EmailPromotion]
,[AdditionalContactInfo]
,[Demographics]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Person]
GO
SELECT [PersonID]
,[PersonType]
,[NameStyle]
,[Title]
,[FirstName]
,[MiddleName]
,[LastName]
,[Suffix]
,[EmailPromotion]
,[AdditionalContactInfo]
,[Demographics]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Person_json]
GO
SELECT [BusinessEntityID]
,[NationalIDNumber]
,[LoginID]
,[OrganizationNode]
,[OrganizationLevel]
,[JobTitle]
,[BirthDate]
,[MaritalStatus]
,[Gender]
,[HireDate]
,[VacationHours]
,[SickLeaveHours]
,[ValidFrom]
,[ValidTo]
FROM [HumanResources].[Employee_Temporal]
GO
SELECT [BusinessEntityID]
,[DepartmentID]
,[ShiftID]
,[StartDate]
,[EndDate]
,[ModifiedDate]
FROM [HumanResources].[EmployeeDepartmentHistory]
GO
SELECT [BusinessEntityID]
,[RateChangeDate]
,[Rate]
,[PayFrequency]
,[ModifiedDate]
FROM [HumanResources].[EmployeePayHistory]
GO
SELECT [JobCandidateID]
,[BusinessEntityID]
,[Resume]
,[ModifiedDate]
FROM [HumanResources].[JobCandidate]
GO
SELECT [ShiftID]
,[Name]
,[StartTime]
,[EndTime]
,[ModifiedDate]
FROM [HumanResources].[Shift]
GO

View File

@@ -0,0 +1,13 @@
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

View File

@@ -0,0 +1,231 @@
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

View File

@@ -11,27 +11,55 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts
{
public class Scripts
{
public const string SimpleQuery = "SELECT * FROM sys.all_columns";
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'";
private static readonly Lazy<string> ComplexQueryInstance = new Lazy<string>(() =>
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
{
string assemblyLocation = typeof(Scripts).GetTypeInfo().Assembly.Location;
string folderName = Path.GetDirectoryName(assemblyLocation);
string filePath = Path.Combine(folderName, "Scripts/AdventureWorks.sql");
return File.ReadAllText(filePath);
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 string.Empty;
}
});
return fileContent;
}
public static string ComplexQuery { get { return ComplexQueryInstance.Value; } }
}
}

View File

@@ -0,0 +1,84 @@
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

View File

@@ -172,7 +172,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
/// <summary>
/// Returns database connection parameters for given server type
/// </summary>
public async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType)
public async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType, string databaseName)
{
ConnectionProfile connectionProfile = null;
TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType);
@@ -195,6 +195,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
}
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;

View File

@@ -41,6 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
}
catch (Exception ex)
{
Console.WriteLine("Failed to load the database connection server name settings. error: " + ex.Message);
return null;
}
}
@@ -56,6 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
}
catch (Exception ex)
{
Console.WriteLine("Failed to load the connection settings. error: " + ex.Message);
return null;
}
}

View File

@@ -4,10 +4,12 @@
//
using System;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Xunit.Sdk;
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{
@@ -23,27 +25,33 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
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);
Assembly assembly = Assembly.GetEntryAssembly();
Type type = assembly.GetType(testNamespace + className);
if (type == null)
{
Console.WriteLine("Invalid class name");
}
else
{
var typeInstance = Activator.CreateInstance(type);
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);
await RunTest(typeInstance, method, method.Name);
}
}
else
{
MethodInfo methodInfo = type.GetMethod(methodName);
await RunTest(type, methodInfo, test);
await RunTest(typeInstance, methodInfo, test);
}
IDisposable disposable = typeInstance as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
}
@@ -56,21 +64,43 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
return 0;
}
private static async Task RunTest(Type type, MethodBase methodInfo, string testName)
private static async Task RunTest(object typeInstance, MethodInfo methodInfo, string testName)
{
if (methodInfo == null)
try
{
Console.WriteLine("Invalid method name");
}
else
{
using (var typeInstance = (IDisposable)Activator.CreateInstance(type))
if (methodInfo == null)
{
Console.WriteLine("Invalid method name");
}
else
{
var testAttributes = methodInfo.CustomAttributes;
BeforeAfterTestAttribute beforeAfterTestAttribute = null;
foreach (var attribute in testAttributes)
{
var args = attribute.ConstructorArguments.Select(x => x.Value as object).ToArray();
var objAttribute = Activator.CreateInstance(attribute.AttributeType, args);
beforeAfterTestAttribute = objAttribute as BeforeAfterTestAttribute;
if (beforeAfterTestAttribute != null)
{
beforeAfterTestAttribute.Before(methodInfo);
}
}
Console.WriteLine("Running test " + testName);
await (Task)methodInfo.Invoke(typeInstance, null);
if (beforeAfterTestAttribute != null)
{
beforeAfterTestAttribute.After(methodInfo);
}
Console.WriteLine("Test ran successfully: " + testName);
}
}
catch(Exception ex)
{
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Failed: {0} error: {1}", testName, ex.Message));
}
}
}
}

View File

@@ -17,7 +17,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{
private static string resultFolder = InitResultFolder();
private static string InitResultFolder()
{
string resultFodler = Environment.GetEnvironmentVariable("ResultFolder");
@@ -34,6 +33,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
Start();
}
public bool PrintResult { get; set; }
public void Start()
{
StartDateTime = DateTime.UtcNow;
@@ -47,15 +48,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
public void EndAndPrint([CallerMemberName] string testName = "")
{
End();
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);
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

View File

@@ -4,9 +4,11 @@
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"copyToOutput": {
"embed": {
"includeFiles": [
"Scripts/AdventureWorks.sql"
"Scripts/CreateTestDatabaseObjects.sql",
"Scripts/CreateTestDatabase.sql",
"Scripts/TestDbTableQueries.sql"
]
},
"publishOptions": {
@@ -27,6 +29,7 @@
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},