From e86b0bc87fac596d5ff7cc8edd42384f46f5e378 Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Thu, 26 May 2022 13:08:53 -0700 Subject: [PATCH] Fix some integration tests (#1516) * Fix integration test cases * More test fixes * Dacfx test fix * Make master default test db is none specified --- .../Connection/ConnectionServiceTests.cs | 30 +++++++++++-------- .../DacFx/DacFxServiceTests.cs | 8 +++-- .../Utility/LiveConnectionHelper.cs | 6 +++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ConnectionServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ConnectionServiceTests.cs index 8267c1b1..c7e286e4 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ConnectionServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ConnectionServiceTests.cs @@ -174,23 +174,29 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection /// Using connection details to build connection string /// [Test] - public async Task GetCurrentConnectionStringTestwithConnectionDetails() + public async Task GetCurrentConnectionStringTestWithConnectionDetails() { // If we make a connection to a live database ConnectionService service = ConnectionService.Instance; - var result = LiveConnectionHelper.InitLiveConnectionInfo(); - var resultConnectionDetails = result.ConnectionInfo.ConnectionDetails; - var requestContext = new Mock>(); - - requestContext.Setup(x => x.SendResult(It.Is((connectionString) => connectionString.Contains(resultConnectionDetails.ToString())))) - .Returns(Task.FromResult(new object())); - var requestParams = new GetConnectionStringParams() + var requestParams = new GetConnectionStringParams(); + requestParams.OwnerUri = null; + requestParams.ConnectionDetails = new ConnectionDetails() { - OwnerUri = null, - ConnectionDetails = {ServerName = "testServer", DatabaseName = "testDatabase", UserName = "sa", Password = "password", ApplicationName = "TestApp"}, - IncludePassword = true, - IncludeApplicationName = true + ServerName = "testServer", + DatabaseName = "testDatabase", + UserName = "sa", + Password = "[placeholder]", + ApplicationName = "sqlops-connection-string" }; + requestParams.IncludePassword = true; + requestParams.IncludeApplicationName = true; + + // get the expected connection string from the connection details being passed to ConnectionService + string expectedConnectionString = ConnectionService.CreateConnectionStringBuilder(requestParams.ConnectionDetails).ToString(); + + var requestContext = new Mock>(); + requestContext.Setup(x => x.SendResult(It.Is((connectionString) => connectionString.Contains(expectedConnectionString)))) + .Returns(Task.FromResult(new object())); await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object); requestContext.VerifyAll(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs index 762c172e..2ad0f393 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs @@ -731,6 +731,7 @@ FROM MissingEdgeHubInputStream'"; expectedResults.BlockOnPossibleDataLoss = new DeploymentOptionProperty(true); expectedResults.AllowIncompatiblePlatform = new DeploymentOptionProperty(true); expectedResults.DisableIndexesForDataPhase = new DeploymentOptionProperty(false); + expectedResults.IgnoreTableOptions = new DeploymentOptionProperty(false); var dacfxRequestContext = new Mock>(); dacfxRequestContext.Setup((RequestContext x) => x.SendResult(It.Is((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object())); @@ -756,6 +757,7 @@ FROM MissingEdgeHubInputStream'"; DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions(); expectedResults.ExcludeObjectTypes = null; expectedResults.DisableIndexesForDataPhase = new DeploymentOptionProperty(false); + expectedResults.IgnoreTableOptions = new DeploymentOptionProperty(false); var dacfxRequestContext = new Mock>(); dacfxRequestContext.Setup((RequestContext x) => x.SendResult(It.Is((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object())); @@ -779,6 +781,7 @@ FROM MissingEdgeHubInputStream'"; public async Task ValidateGetDefaultPublishOptionsCallFromService() { DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions(); + expectedResults.IgnoreTableOptions = new DeploymentOptionProperty(false); var dacfxRequestContext = new Mock>(); dacfxRequestContext.Setup((RequestContext x) => x.SendResult(It.Is((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object())); @@ -855,10 +858,11 @@ Streaming query statement contains a reference to missing output stream 'Missing } else { - // Verifying expected and actual deployment options properties are equal + //Verifying expected and actual deployment options properties are equal Assert.True((defaultP == null && actualP == null) || (defaultP == null && String.IsNullOrEmpty(actualP as string)) - || defaultP.Equals(actualP) + // check the type of the properties, the descriptions will not match when overriding defaults + || defaultP.GetType().Equals(actualP.GetType()) , $"Actual Property from Service is not equal to default property for {v.Name}, Actual property: {actualP} and Default property: {defaultP}"); // Verifying expected and actual deployment options property values are equal diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs index cb14e44d..0d5b209b 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs @@ -65,7 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility return new TestConnectionResult() { ConnectionInfo = connInfo, ScriptFile = scriptFile }; } - public static async Task InitLiveConnectionInfoAsync(string databaseName = null, string ownerUri = null, + public static async Task InitLiveConnectionInfoAsync(string databaseName = "master", string ownerUri = null, string connectionType = ServiceLayer.Connection.ConnectionType.Default, TestServerType serverType = TestServerType.OnPrem) { ScriptFile scriptFile = null; @@ -75,6 +75,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri); ownerUri = scriptFile.ClientUri; } + if (string.IsNullOrEmpty(databaseName)) + { + databaseName = "master"; + } ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(serverType, databaseName); var connectionService = GetLiveTestConnectionService();