mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-25 17:24:17 -05:00
Convert most tools service tests to nunit (#1037)
* Remove xunit dependency from testdriver * swap expected/actual as needed * Convert Test.Common to nunit * port hosting unit tests to nunit * port batchparser integration tests to nunit * port testdriver.tests to nunit * fix target to copy dependency * port servicelayer unittests to nunit * more unit test fixes * port integration tests to nunit * fix test method type * try using latest windows build for PRs * reduce test memory use
This commit is contained in:
@@ -17,8 +17,8 @@ using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using NUnit.Framework;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DacFx
|
||||
{
|
||||
@@ -71,8 +71,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the export bacpac request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ExportBacpac()
|
||||
[Test]
|
||||
public async Task ExportBacpac()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxExportTest");
|
||||
@@ -102,8 +102,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the import bacpac request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ImportBacpac()
|
||||
[Test]
|
||||
public async Task ImportBacpac()
|
||||
{
|
||||
// first export a bacpac
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
@@ -150,8 +150,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the extract dacpac request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ExtractDacpac()
|
||||
[Test]
|
||||
public async Task ExtractDacpac()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxExtractTest");
|
||||
@@ -183,8 +183,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the extract request to create Sql file
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ExtractDBToFileTarget()
|
||||
[Test]
|
||||
public async Task ExtractDBToFileTarget()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, doNotCleanupDb: false, databaseName: null, query: SourceScript, dbNamePrefix: "DacFxExtractDBToFileTarget");
|
||||
@@ -217,8 +217,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the extract request to create a Flat file structure
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ExtractDBToFlatTarget()
|
||||
[Test]
|
||||
public async Task ExtractDBToFlatTarget()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, doNotCleanupDb: false, databaseName: null, query: SourceScript, dbNamePrefix: "DacFxExtractDBToFlatTarget");
|
||||
@@ -243,7 +243,7 @@ RETURN 0
|
||||
// Verify two sql files are generated in the target folder path
|
||||
// for dev-servers where there are more users/permissions present on server - the extract might have more files than just 2 expected tables, so check only for tables
|
||||
int actualCnt = Directory.GetFiles(folderPath, "table*.sql", SearchOption.AllDirectories).Length;
|
||||
Assert.Equal(2, actualCnt);
|
||||
Assert.AreEqual(2, actualCnt);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -259,8 +259,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the deploy dacpac request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void DeployDacpac()
|
||||
[Test]
|
||||
public async Task DeployDacpac()
|
||||
{
|
||||
// first extract a db to have a dacpac to import later
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
@@ -305,13 +305,14 @@ RETURN 0
|
||||
targetDb.Cleanup();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the export request being cancelled
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ExportBacpacCancellationTest()
|
||||
[Test]
|
||||
public async Task ExportBacpacCancellationTest()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxExportTest");
|
||||
@@ -353,8 +354,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the generate deploy script request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GenerateDeployScript()
|
||||
[Test]
|
||||
public async Task GenerateDeployScript()
|
||||
{
|
||||
// first extract a dacpac
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
@@ -378,8 +379,8 @@ RETURN 0
|
||||
service.PerformOperation(generateScriptOperation, TaskExecutionMode.Script);
|
||||
|
||||
// Verify script was generated
|
||||
Assert.NotEmpty(generateScriptOperation.Result.DatabaseScript);
|
||||
Assert.Contains("CREATE TABLE", generateScriptOperation.Result.DatabaseScript);
|
||||
Assert.That(generateScriptOperation.Result.DatabaseScript, Is.Not.Empty);
|
||||
Assert.That(generateScriptOperation.Result.DatabaseScript, Does.Contain("CREATE TABLE"));
|
||||
|
||||
VerifyAndCleanup(dacpacPath);
|
||||
}
|
||||
@@ -393,8 +394,8 @@ RETURN 0
|
||||
/// <summary>
|
||||
/// Verify the generate deploy plan request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GenerateDeployPlan()
|
||||
[Test]
|
||||
public async Task GenerateDeployPlan()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, SourceScript, "DacFxGenerateDeployPlanTest");
|
||||
@@ -418,9 +419,12 @@ RETURN 0
|
||||
service.PerformOperation(generateDeployPlanOperation, TaskExecutionMode.Execute);
|
||||
string report = generateDeployPlanOperation.DeployReport;
|
||||
Assert.NotNull(report);
|
||||
Assert.Contains("Create", report);
|
||||
Assert.Contains("Drop", report);
|
||||
Assert.Contains("Alter", report);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(report, Does.Contain("Create"));
|
||||
Assert.That(report, Does.Contain("Drop"));
|
||||
Assert.That(report, Does.Contain("Alter"));
|
||||
});
|
||||
|
||||
VerifyAndCleanup(dacpacPath);
|
||||
}
|
||||
@@ -437,8 +441,8 @@ RETURN 0
|
||||
// <summary>
|
||||
/// Verify that SqlCmdVars are set correctly for a deploy request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void DeployWithSqlCmdVariables()
|
||||
[Test]
|
||||
public async Task DeployWithSqlCmdVariables()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, query: storedProcScript, dbNamePrefix: "DacFxDeploySqlCmdVarsTest");
|
||||
@@ -482,8 +486,8 @@ RETURN 0
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Contains(deployParams.SqlCommandVariableValues[databaseRefVarName], deployedProc);
|
||||
Assert.Contains(deployParams.SqlCommandVariableValues[filterValueVarName], deployedProc);
|
||||
Assert.That(deployedProc, Does.Contain(deployParams.SqlCommandVariableValues[databaseRefVarName]));
|
||||
Assert.That(deployedProc, Does.Contain(deployParams.SqlCommandVariableValues[filterValueVarName]));
|
||||
|
||||
VerifyAndCleanup(dacpacPath);
|
||||
}
|
||||
@@ -500,8 +504,8 @@ RETURN 0
|
||||
// <summary>
|
||||
/// Verify that SqlCmdVars are set correctly for a generate script request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GenerateDeployScriptWithSqlCmdVariables()
|
||||
[Test]
|
||||
public async Task GenerateDeployScriptWithSqlCmdVariables()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, query: storedProcScript, dbNamePrefix: "DacFxGenerateScriptSqlCmdVarsTest");
|
||||
@@ -528,9 +532,9 @@ RETURN 0
|
||||
service.PerformOperation(generateScriptOperation, TaskExecutionMode.Script);
|
||||
|
||||
// Verify the SqlCmdVars were set correctly in the script
|
||||
Assert.NotEmpty(generateScriptOperation.Result.DatabaseScript);
|
||||
Assert.Contains($":setvar {databaseRefVarName} \"{generateScriptParams.SqlCommandVariableValues[databaseRefVarName]}\"", generateScriptOperation.Result.DatabaseScript);
|
||||
Assert.Contains($":setvar {filterValueVarName} \"{generateScriptParams.SqlCommandVariableValues[filterValueVarName]}\"", generateScriptOperation.Result.DatabaseScript);
|
||||
Assert.That(generateScriptOperation.Result.DatabaseScript, Is.Not.Empty);
|
||||
Assert.That(generateScriptOperation.Result.DatabaseScript, Does.Contain($":setvar {databaseRefVarName} \"{generateScriptParams.SqlCommandVariableValues[databaseRefVarName]}\""));
|
||||
Assert.That(generateScriptOperation.Result.DatabaseScript, Does.Contain($":setvar {filterValueVarName} \"{generateScriptParams.SqlCommandVariableValues[filterValueVarName]}\""));
|
||||
|
||||
VerifyAndCleanup(dacpacPath);
|
||||
}
|
||||
@@ -543,8 +547,8 @@ RETURN 0
|
||||
///
|
||||
/// Verify that options are set correctly for a deploy request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void DeployWithOptions()
|
||||
[Test]
|
||||
public async Task DeployWithOptions()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, query: SourceScript, dbNamePrefix: "DacFxDeployOptionsTestSource");
|
||||
@@ -607,10 +611,10 @@ RETURN 0
|
||||
{
|
||||
await conn.OpenAsync();
|
||||
var deployedResult = (string)ReliableConnectionHelper.ExecuteScalar(conn, $"SELECT TABLE_NAME FROM {targetDb.DatabaseName}.INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'table3'; ");
|
||||
Assert.Equal(expectedTableResult, deployedResult);
|
||||
Assert.AreEqual(expectedTableResult, deployedResult);
|
||||
|
||||
deployedResult = (string)ReliableConnectionHelper.ExecuteScalar(conn, $"SELECT TABLE_NAME FROM {targetDb.DatabaseName}.INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'view1'; ");
|
||||
Assert.Equal(expectedViewResult, deployedResult);
|
||||
Assert.AreEqual(expectedViewResult, deployedResult);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -622,8 +626,8 @@ RETURN 0
|
||||
// <summary>
|
||||
/// Verify that options are set correctly for a generate script request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GenerateDeployScriptWithOptions()
|
||||
[Test]
|
||||
public async Task GenerateDeployScriptWithOptions()
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, query: SourceScript, dbNamePrefix: "DacFxDeployOptionsTestSource");
|
||||
@@ -651,8 +655,8 @@ RETURN 0
|
||||
var generateScriptFalseOptionOperation = new GenerateDeployScriptOperation(generateScriptFalseOptionParams, result.ConnectionInfo);
|
||||
service.PerformOperation(generateScriptFalseOptionOperation, TaskExecutionMode.Execute);
|
||||
|
||||
Assert.DoesNotContain("table3", generateScriptFalseOptionOperation.Result.DatabaseScript);
|
||||
Assert.DoesNotContain("CREATE VIEW", generateScriptFalseOptionOperation.Result.DatabaseScript);
|
||||
Assert.That(generateScriptFalseOptionOperation.Result.DatabaseScript, Does.Not.Contain("table3"));
|
||||
Assert.That(generateScriptFalseOptionOperation.Result.DatabaseScript, Does.Not.Contain("CREATE VIEW"));
|
||||
|
||||
// try to deploy with the option set to true to make sure it works
|
||||
var generateScriptTrueOptionParams = new GenerateDeployScriptParams
|
||||
@@ -669,8 +673,8 @@ RETURN 0
|
||||
var generateScriptTrueOptionOperation = new GenerateDeployScriptOperation(generateScriptTrueOptionParams, result.ConnectionInfo);
|
||||
service.PerformOperation(generateScriptTrueOptionOperation, TaskExecutionMode.Execute);
|
||||
|
||||
Assert.Contains("DROP TABLE [dbo].[table3]", generateScriptTrueOptionOperation.Result.DatabaseScript);
|
||||
Assert.DoesNotContain("CREATE VIEW", generateScriptTrueOptionOperation.Result.DatabaseScript);
|
||||
Assert.That(generateScriptTrueOptionOperation.Result.DatabaseScript, Does.Contain("DROP TABLE [dbo].[table3]"));
|
||||
Assert.That(generateScriptTrueOptionOperation.Result.DatabaseScript, Does.Not.Contain("CREATE VIEW"));
|
||||
|
||||
// now generate script without options
|
||||
var generateScriptNoOptionsParams = new GenerateDeployScriptParams
|
||||
@@ -682,8 +686,8 @@ RETURN 0
|
||||
var generateScriptNoOptionsOperation = new GenerateDeployScriptOperation(generateScriptNoOptionsParams, result.ConnectionInfo);
|
||||
service.PerformOperation(generateScriptNoOptionsOperation, TaskExecutionMode.Execute);
|
||||
|
||||
Assert.Contains("table3", generateScriptNoOptionsOperation.Result.DatabaseScript);
|
||||
Assert.Contains("CREATE VIEW", generateScriptNoOptionsOperation.Result.DatabaseScript);
|
||||
Assert.That(generateScriptNoOptionsOperation.Result.DatabaseScript, Does.Contain("table3"));
|
||||
Assert.That(generateScriptNoOptionsOperation.Result.DatabaseScript, Does.Contain("CREATE VIEW"));
|
||||
|
||||
VerifyAndCleanup(dacpacPath);
|
||||
}
|
||||
@@ -700,8 +704,8 @@ RETURN 0
|
||||
// <summary>
|
||||
/// Verify that options can get retrieved from publish profile
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetOptionsFromProfile()
|
||||
[Test]
|
||||
public async Task GetOptionsFromProfile()
|
||||
{
|
||||
DeploymentOptions expectedResults = new DeploymentOptions()
|
||||
{
|
||||
@@ -729,8 +733,8 @@ RETURN 0
|
||||
// <summary>
|
||||
/// Verify that default options are returned if a profile doesn't specify any options
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetOptionsFromProfileWithoutOptions()
|
||||
[Test]
|
||||
public async Task GetOptionsFromProfileWithoutOptions()
|
||||
{
|
||||
DeploymentOptions expectedResults = new DeploymentOptions();
|
||||
expectedResults.ExcludeObjectTypes = null;
|
||||
|
||||
Reference in New Issue
Block a user