From 92bb281cddcd3ad6b9327adedf61fb6353a717fd Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Mon, 5 Aug 2019 14:05:32 -0700 Subject: [PATCH] Ensure test file is deleted and fix test project path (#843) * Ensure test file is always deleted * Fix up project path --- sqltoolsservice.sln | 2 +- ...t.SqlTools.Test.CompletionExtension.csproj | 11 --- .../LanguageServer/LanguageServiceTests.cs | 67 ++++++++++--------- ...Tools.ServiceLayer.IntegrationTests.csproj | 2 +- .../CompletionExt.cs | 0 ...t.SqlTools.Test.CompletionExtension.csproj | 15 +++++ 6 files changed, 51 insertions(+), 46 deletions(-) delete mode 100644 test/CompletionExtSample/Microsoft.SqlTools.Test.CompletionExtension.csproj rename test/{CompletionExtSample => Microsoft.SqlTools.Test.CompletionExtension}/CompletionExt.cs (100%) create mode 100644 test/Microsoft.SqlTools.Test.CompletionExtension/Microsoft.SqlTools.Test.CompletionExtension.csproj diff --git a/sqltoolsservice.sln b/sqltoolsservice.sln index daf76b3987..db9e7fb1fd 100644 --- a/sqltoolsservice.sln +++ b/sqltoolsservice.sln @@ -95,7 +95,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.ManagedB EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.ManagedBatchParser.IntegrationTests", "test\Microsoft.SqlTools.ManagedBatchParser.IntegrationTests\Microsoft.SqlTools.ManagedBatchParser.IntegrationTests.csproj", "{D3696EFA-FB1E-4848-A726-FF7B168AFB96}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.Test.CompletionExtension", "test\CompletionExtSample\Microsoft.SqlTools.Test.CompletionExtension.csproj", "{0EC2B30C-0652-49AE-9594-85B3C3E9CA21}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlTools.Test.CompletionExtension", "test\Microsoft.SqlTools.Test.CompletionExtension\Microsoft.SqlTools.Test.CompletionExtension.csproj", "{0EC2B30C-0652-49AE-9594-85B3C3E9CA21}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/test/CompletionExtSample/Microsoft.SqlTools.Test.CompletionExtension.csproj b/test/CompletionExtSample/Microsoft.SqlTools.Test.CompletionExtension.csproj deleted file mode 100644 index f08c925b50..0000000000 --- a/test/CompletionExtSample/Microsoft.SqlTools.Test.CompletionExtension.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - netcoreapp2.2 - - - - - - - diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs index 2cb2d362cd..aecd7010ff 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs @@ -157,37 +157,42 @@ public async void AutoCompleteWithExtension() //Try to load the completion extension with new modified timestamp, expect a success var assemblyCopyPath = CopyFileWithNewModifiedTime(extensionParams.AssemblyPath); - extensionParams = new CompletionExtensionParams() + try { - AssemblyPath = assemblyCopyPath, - TypeName = "Microsoft.SqlTools.Test.CompletionExtension.CompletionExt", - Properties = new Dictionary { { "modelPath", "testModel" } } - }; - //load and initialize completion extension - await autoCompleteService.HandleCompletionExtLoadRequest(extensionParams, requestContext.Object); - - requestContext.Verify(x => x.SendResult(It.IsAny()), Times.Exactly(2)); - requestContext.Verify(x => x.SendError(It.IsAny(), 0), Times.Once); - - ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; - autoCompleteService.ParseAndBind(result.ScriptFile, result.ConnectionInfo); - scriptInfo.ConnectionKey = autoCompleteService.BindingQueue.AddConnectionContext(result.ConnectionInfo); - - //Invoke auto completion with extension enabled - var completions = autoCompleteService.GetCompletionItems( - result.TextDocumentPosition, - result.ScriptFile, - result.ConnectionInfo).Result; + extensionParams = new CompletionExtensionParams() + { + AssemblyPath = assemblyCopyPath, + TypeName = "Microsoft.SqlTools.Test.CompletionExtension.CompletionExt", + Properties = new Dictionary { { "modelPath", "testModel" } } + }; + //load and initialize completion extension + await autoCompleteService.HandleCompletionExtLoadRequest(extensionParams, requestContext.Object); - //Validate completion list is not empty - Assert.True(completions != null && completions.Length > 0, "The completion list is null or empty!"); - //Validate the first completion item in the list is preselected - Assert.True(completions[0].Preselect.HasValue && completions[0].Preselect.Value, "Preselect is not set properly in the first completion item by the completion extension!"); - //Validate the Command object attached to the completion item by the extension - Assert.True(completions[0].Command != null && completions[0].Command.CommandStr == "vsintellicode.completionItemSelected", "Command is not set properly in the first completion item by the completion extension!"); + requestContext.Verify(x => x.SendResult(It.IsAny()), Times.Exactly(2)); + requestContext.Verify(x => x.SendError(It.IsAny(), 0), Times.Once); - //clean up the temp file - File.Delete(assemblyCopyPath); + ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; + autoCompleteService.ParseAndBind(result.ScriptFile, result.ConnectionInfo); + scriptInfo.ConnectionKey = autoCompleteService.BindingQueue.AddConnectionContext(result.ConnectionInfo); + + //Invoke auto completion with extension enabled + var completions = autoCompleteService.GetCompletionItems( + result.TextDocumentPosition, + result.ScriptFile, + result.ConnectionInfo).Result; + + //Validate completion list is not empty + Assert.True(completions != null && completions.Length > 0, "The completion list is null or empty!"); + //Validate the first completion item in the list is preselected + Assert.True(completions[0].Preselect.HasValue && completions[0].Preselect.Value, "Preselect is not set properly in the first completion item by the completion extension!"); + //Validate the Command object attached to the completion item by the extension + Assert.True(completions[0].Command != null && completions[0].Command.CommandStr == "vsintellicode.completionItemSelected", "Command is not set properly in the first completion item by the completion extension!"); + } + finally + { + //clean up the temp file + File.Delete(assemblyCopyPath); + } } /// @@ -198,11 +203,7 @@ public async void AutoCompleteWithExtension() private string CopyFileWithNewModifiedTime(string filePath) { var tempPath = Path.Combine(Path.GetTempPath(), Path.GetFileName(filePath)); - if (File.Exists(tempPath)) - { - File.Delete(tempPath); - } - File.Copy(filePath, tempPath); + File.Copy(filePath, tempPath, overwrite: true); File.SetLastWriteTimeUtc(tempPath, DateTime.UtcNow); return tempPath; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj index 19db819e38..13d79d60c7 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.csproj @@ -27,7 +27,7 @@ - + diff --git a/test/CompletionExtSample/CompletionExt.cs b/test/Microsoft.SqlTools.Test.CompletionExtension/CompletionExt.cs similarity index 100% rename from test/CompletionExtSample/CompletionExt.cs rename to test/Microsoft.SqlTools.Test.CompletionExtension/CompletionExt.cs diff --git a/test/Microsoft.SqlTools.Test.CompletionExtension/Microsoft.SqlTools.Test.CompletionExtension.csproj b/test/Microsoft.SqlTools.Test.CompletionExtension/Microsoft.SqlTools.Test.CompletionExtension.csproj new file mode 100644 index 0000000000..c10fc10e27 --- /dev/null +++ b/test/Microsoft.SqlTools.Test.CompletionExtension/Microsoft.SqlTools.Test.CompletionExtension.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.2 + false + portable + Microsoft.SqlTools.Test.CompletionExtension + Microsoft.SqlTools.Test.CompletionExtension + true + $(DefineConstants);TRACE + + + + +