Avoid throwing exception in LangageService for OE connections (#361)

* Ensure connection open for OE queries and fix connection disposal
- Dispose connection in Metadata service, to ensure we cleanly dispose and don't rely on garbage colleciton
- Fixed issue where if the connection was closed, expanding databases in the Server would fail. This is because SMO doesn't always reopen the connection, certainly not for Server level queries. The solution is to always check if open and reopen.
- Added unit tests for this, which required mocking the relevant IsOpen / OpenConnection methods. Refactored SMO wrapper calls into a dedicated class file to handle this

* Avoid throwing exception in LangageService for OE connections
- Handle non-File URIs by skipping language service binding in those cases. Added test for this

- VSCode passes untitled:, git: and other paths, often without a '/'. Updated logic to handle this.

* Handle windows file paths
This commit is contained in:
Kevin Cunnane
2017-05-26 13:11:26 -07:00
committed by GitHub
parent bbd0972dde
commit a4c630d5d3
4 changed files with 96 additions and 19 deletions

View File

@@ -196,5 +196,37 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Workspace
// verify the file is being tracked by workspace
Assert.True(workspaceService.Workspace.ContainsFile(TestObjects.ScriptUri));
}
[Fact]
public void DontBindToObjectExplorerConnectEvents()
{
// when I ask for a non-file object in the workspace, it should return null
var workspace = new ServiceLayer.Workspace.Workspace();
ScriptFile file = workspace.GetFile("objectexplorer://server;database=database;user=user");
Assert.Null(file);
// when I ask for a file, it should return the file
string tempFile = Path.GetTempFileName();
string fileContents = "hello world";
File.WriteAllText(tempFile, fileContents);
file = workspace.GetFile(tempFile);
Assert.Equal(fileContents, file.Contents);
if (tempFile.StartsWith("/"))
{
tempFile = tempFile.Substring(1);
}
file = workspace.GetFile("file://" + tempFile);
Assert.Equal(fileContents, file.Contents);
file = workspace.GetFileBuffer("untitled://"+ tempFile, fileContents);
Assert.Equal(fileContents, file.Contents);
// For windows files, just check scheme is null since it's hard to mock file contents in these
Assert.Null(ServiceLayer.Workspace.Workspace.GetScheme(@"C:\myfile.sql"));
Assert.Null(ServiceLayer.Workspace.Workspace.GetScheme(@"\\myfile.sql"));
}
}
}