Update SqlToolsService to netcore2.0 and fix test failures (#914)

* Upgrade and fix most tests
- Upgrade to .Net Core 2.0 in SqlToolsService
- Upgraded TypeMoq to fix multiple tests

* Fix tests broken due to TypeMoq update
- Loose vs Strict mode behavior has changed. Given we initially added strict mode to catch regressions and these are now very stable parts of the code, it seems fine to use Loose mocking and allow the passthroughs to be used.
- Other change was due to assert.equal changing. Before it would return true on deep object equality but it no longer seems to work. Added clear property-level validation in some cases to fix this.

* Fixed issue running test from cmdline locally

* Fix for AppVeyor test fail issue
- This is caused by https://github.com/Microsoft/vscode-extension-vscode/issues/64 and will be fixed in the 1.14 release of VSCode

* Attempt to fix travis build without using deprecated group value
- Investigating similar issues causing failure to find apt-get packages led to https://github.com/travis-ci/travis-ci/issues/5252. The solution may be to run apt-get update first.
This commit is contained in:
Kevin Cunnane 2017-07-10 16:04:34 -07:00 коммит произвёл GitHub
Родитель 01d7e7cece
Коммит 9c0a85ec61
22 изменённых файлов: 142 добавлений и 120 удалений

Просмотреть файл

@ -23,6 +23,7 @@ before_install:
export CHROME_BIN=/Applications/Google\ Chrome.app;
fi
- export BUILDMACHINE=true
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install xclip; fi
- npm install -g npm@4
install:

6
.vscode/launch.json поставляемый
Просмотреть файл

@ -10,7 +10,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "cover:disable"
},
{
@ -21,7 +21,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test"],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/test",
"outFiles": ["${workspaceRoot}/out/test/**/*,js"],
"preLaunchTask": "cover:disable"
},
{
@ -32,7 +32,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test"],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/test",
"outFiles": ["${workspaceRoot}/out/test/**/*,js"],
"preLaunchTask": "cover:enable"
}
]

Просмотреть файл

@ -1,5 +1,8 @@
environment:
nodejs_version: "6.9.1"
# Temporary Code version due to https://github.com/Microsoft/vscode-extension-vscode/issues/64
CODE_VERSION: 1.12.2
# safelist
branches:

Просмотреть файл

@ -126,6 +126,9 @@ gulp.task('ext:build', gulp.series('ext:localization', 'ext:lint', 'ext:compile'
gulp.task('ext:test', (done) => {
let workspace = process.env['WORKSPACE'];
if (!workspace) {
workspace = process.cwd();
}
process.env.JUNIT_REPORT_PATH = workspace + '/test-reports/ext_xunit.xml';
cproc.exec(`code --extensionDevelopmentPath="${workspace}" --extensionTestsPath="${workspace}/out/test" --verbose`, (error, stdout, stderr) => {
if (error) {

Просмотреть файл

@ -1,7 +1,7 @@
{
"name": "mssql",
"displayName": "mssql",
"version": "1.0.0",
"version": "1.1.0",
"description": "Develop Microsoft SQL Server, Azure SQL Database and SQL Data Warehouse everywhere",
"publisher": "ms-mssql",
"preview": false,
@ -82,8 +82,8 @@
"remap-istanbul": "^0.6.4",
"systemjs-builder": "^0.15.32",
"tslint": "^3.14.0",
"typemoq": "^0.3.2",
"typescript": "^2.1.5",
"typemoq": "^1.7.0",
"typescript": "2.3.4",
"uglify-js": "mishoo/UglifyJS2#harmony-v2.8.22",
"vscode": "^1.0.5",
"vscode-nls-dev": "https://github.com/Raymondd/vscode-nls-dev/releases/download/2.0.2/build.tar.gz",

Просмотреть файл

@ -1,20 +1,20 @@
{
"service": {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.45",
"downloadFileNames": {
"Windows_7_86": "win-x86-netcoreapp1.0.zip",
"Windows_7_64": "win-x64-netcoreapp1.0.zip",
"OSX_10_11_64": "osx-x64-netcoreapp1.0.tar.gz",
"CentOS_7": "centos-x64-netcoreapp1.0.tar.gz",
"Debian_8": "debian-x64-netcoreapp1.0.tar.gz",
"Fedora_23": "fedora-x64-netcoreapp1.0.tar.gz",
"OpenSUSE_13_2": "opensuse-x64-netcoreapp1.0.tar.gz",
"RHEL_7": "rhel-x64-netcoreapp1.0.tar.gz",
"Ubuntu_14": "ubuntu14-x64-netcoreapp1.0.tar.gz",
"Ubuntu_16": "ubuntu16-x64-netcoreapp1.0.tar.gz"
"Windows_7_86": "win-x86-netcoreapp2.0.zip",
"Windows_7_64": "win-x64-netcoreapp2.0.zip",
"OSX_10_11_64": "osx-x64-netcoreapp2.0.tar.gz",
"CentOS_7": "centos-x64-netcoreapp2.0.tar.gz",
"Debian_8": "debian-x64-netcoreapp2.0.tar.gz",
"Fedora_23": "fedora-x64-netcoreapp2.0.tar.gz",
"OpenSUSE_13_2": "opensuse-x64-netcoreapp2.0.tar.gz",
"RHEL_7": "rhel-x64-netcoreapp2.0.tar.gz",
"Ubuntu_14": "ubuntu14-x64-netcoreapp2.0.tar.gz",
"Ubuntu_16": "ubuntu16-x64-netcoreapp2.0.tar.gz"
},
"installDir": "../sqltoolsservice/{#version#}/{#platform#}",
"executableFiles": ["Microsoft.SqlTools.ServiceLayer.exe", "Microsoft.SqlTools.ServiceLayer", "Microsoft.SqlTools.ServiceLayer.dll"]
"executableFiles": ["MicrosoftSqlToolsServiceLayer.exe", "MicrosoftSqlToolsServiceLayer", "MicrosoftSqlToolsServiceLayer.dll"]
}
}

Просмотреть файл

@ -1,20 +1,20 @@
{
"service": {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.45",
"downloadFileNames": {
"Windows_7_86": "win-x86-netcoreapp1.0.zip",
"Windows_7_64": "win-x64-netcoreapp1.0.zip",
"OSX_10_11_64": "osx-x64-netcoreapp1.0.tar.gz",
"CentOS_7": "centos-x64-netcoreapp1.0.tar.gz",
"Debian_8": "debian-x64-netcoreapp1.0.tar.gz",
"Fedora_23": "fedora-x64-netcoreapp1.0.tar.gz",
"OpenSUSE_13_2": "opensuse-x64-netcoreapp1.0.tar.gz",
"RHEL_7": "rhel-x64-netcoreapp1.0.tar.gz",
"Ubuntu_14": "ubuntu14-x64-netcoreapp1.0.tar.gz",
"Ubuntu_16": "ubuntu16-x64-netcoreapp1.0.tar.gz"
"Windows_7_86": "win-x86-netcoreapp2.0.zip",
"Windows_7_64": "win-x64-netcoreapp2.0.zip",
"OSX_10_11_64": "osx-x64-netcoreapp2.0.tar.gz",
"CentOS_7": "centos-x64-netcoreapp2.0.tar.gz",
"Debian_8": "debian-x64-netcoreapp2.0.tar.gz",
"Fedora_23": "fedora-x64-netcoreapp2.0.tar.gz",
"OpenSUSE_13_2": "opensuse-x64-netcoreapp2.0.tar.gz",
"RHEL_7": "rhel-x64-netcoreapp2.0.tar.gz",
"Ubuntu_14": "ubuntu14-x64-netcoreapp2.0.tar.gz",
"Ubuntu_16": "ubuntu16-x64-netcoreapp2.0.tar.gz"
},
"installDir": "../sqltoolsservice/{#version#}/{#platform#}",
"executableFiles": ["Microsoft.SqlTools.ServiceLayer.exe", "Microsoft.SqlTools.ServiceLayer", "Microsoft.SqlTools.ServiceLayer.dll"]
"executableFiles": ["MicrosoftSqlToolsServiceLayer.exe", "MicrosoftSqlToolsServiceLayer", "MicrosoftSqlToolsServiceLayer.dll"]
}
}

Просмотреть файл

@ -20,11 +20,11 @@ import assert = require('assert');
suite('ConnectionCredentials Tests', () => {
let defaultProfile: interfaces.IConnectionProfile;
let prompter: TypeMoq.Mock<IPrompter>;
let context: TypeMoq.Mock<vscode.ExtensionContext>;
let credentialStore: TypeMoq.Mock<CredentialStore>;
let vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let connectionStore: TypeMoq.Mock<ConnectionStore>;
let prompter: TypeMoq.IMock<IPrompter>;
let context: TypeMoq.IMock<vscode.ExtensionContext>;
let credentialStore: TypeMoq.IMock<CredentialStore>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
let connectionStore: TypeMoq.IMock<ConnectionStore>;
setup(() => {
defaultProfile = Object.assign(new ConnectionProfile(), {

Просмотреть файл

@ -57,7 +57,7 @@ suite('Connection Profile tests', () => {
test('CreateProfile should ask questions in correct order', done => {
// Given
let prompter: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let prompter: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let answers: {[key: string]: string} = {};
let profileQuestions: IQuestion[];
let profileReturned: IConnectionProfile;
@ -99,7 +99,7 @@ suite('Connection Profile tests', () => {
test('CreateProfile - SqlPassword should be default auth type', done => {
// Given
let prompter: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let prompter: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let answers: {[key: string]: string} = {};
let profileQuestions: IQuestion[];
let profileReturned: IConnectionProfile;
@ -126,7 +126,7 @@ suite('Connection Profile tests', () => {
test('CreateProfile - Integrated auth support', done => {
// Given
let prompter: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let prompter: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let answers: {[key: string]: string} = {};
let profileQuestions: IQuestion[];
let profileReturned: IConnectionProfile;
@ -211,13 +211,13 @@ suite('Connection Profile tests', () => {
});
test('Profile is connected to and validated prior to saving', done => {
let connectionManagerMock: TypeMoq.Mock<ConnectionManager> = TypeMoq.Mock.ofType(ConnectionManager);
let connectionManagerMock: TypeMoq.IMock<ConnectionManager> = TypeMoq.Mock.ofType(ConnectionManager);
connectionManagerMock.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(true));
let connectionStoreMock = TypeMoq.Mock.ofType(ConnectionStore);
connectionStoreMock.setup(x => x.saveProfile(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
let prompter: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let prompter: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
prompter.setup(x => x.prompt(TypeMoq.It.isAny()))
.returns(questions => {
let answers: {[key: string]: string} = {};
@ -254,13 +254,13 @@ suite('Connection Profile tests', () => {
});
test('Profile is not saved when connection validation fails', done => {
let connectionManagerMock: TypeMoq.Mock<ConnectionManager> = TypeMoq.Mock.ofType(ConnectionManager);
let connectionManagerMock: TypeMoq.IMock<ConnectionManager> = TypeMoq.Mock.ofType(ConnectionManager);
connectionManagerMock.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(false));
let connectionStoreMock = TypeMoq.Mock.ofType(ConnectionStore);
connectionStoreMock.setup(x => x.saveProfile(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
let prompter: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let prompter: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
prompter.setup(x => x.prompt(TypeMoq.It.isAny()))
.returns(questions => {
let answers: {[key: string]: string} = {};
@ -302,7 +302,7 @@ suite('Connection Profile tests', () => {
answers[LocalizedConstants.serverPrompt] = 'Server=my-server';
// Set up the prompter to answer the server prompt with the connection string
let prompter: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let prompter: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
prompter.setup(x => x.prompt(TypeMoq.It.isAny())).returns(questions => {
questions.filter(question => question.name === LocalizedConstants.serverPrompt)[0].onAnswered(answers[LocalizedConstants.serverPrompt]);
questions.filter(question => question.name !== LocalizedConstants.serverPrompt && question.name !== LocalizedConstants.profileNamePrompt)

Просмотреть файл

@ -19,11 +19,11 @@ import assert = require('assert');
suite('ConnectionStore tests', () => {
let defaultNamedProfile: interfaces.IConnectionProfile;
let defaultUnnamedProfile: interfaces.IConnectionProfile;
let context: TypeMoq.Mock<vscode.ExtensionContext>;
let globalstate: TypeMoq.Mock<vscode.Memento>;
let credentialStore: TypeMoq.Mock<CredentialStore>;
let vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let connectionConfig: TypeMoq.Mock<ConnectionConfig>;
let context: TypeMoq.IMock<vscode.ExtensionContext>;
let globalstate: TypeMoq.IMock<vscode.Memento>;
let credentialStore: TypeMoq.IMock<CredentialStore>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
let connectionConfig: TypeMoq.IMock<ConnectionConfig>;
setup(() => {
defaultNamedProfile = Object.assign(new ConnectionProfile(), {

Просмотреть файл

@ -20,15 +20,15 @@ interface IFixture {
}
suite('ServiceDownloadProvider Tests', () => {
let config: TypeMoq.Mock<IConfig>;
let testStatusView: TypeMoq.Mock<IStatusView>;
let testHttpClient: TypeMoq.Mock<IHttpClient>;
let testDecompressProvider: TypeMoq.Mock<IDecompressProvider>;
let testLogger: TypeMoq.Mock<ILogger>;
let config: TypeMoq.IMock<IConfig>;
let testStatusView: TypeMoq.IMock<IStatusView>;
let testHttpClient: TypeMoq.IMock<IHttpClient>;
let testDecompressProvider: TypeMoq.IMock<IDecompressProvider>;
let testLogger: TypeMoq.IMock<ILogger>;
setup(() => {
config = TypeMoq.Mock.ofType(Config, TypeMoq.MockBehavior.Strict);
testStatusView = TypeMoq.Mock.ofType(ServerStatusView, TypeMoq.MockBehavior.Strict);
testStatusView = TypeMoq.Mock.ofType(ServerStatusView, TypeMoq.MockBehavior.Loose);
testHttpClient = TypeMoq.Mock.ofType(HttpClient, TypeMoq.MockBehavior.Strict);
testDecompressProvider = TypeMoq.Mock.ofType(DecompressProvider);
testLogger = TypeMoq.Mock.ofType(Logger);

Просмотреть файл

@ -7,9 +7,9 @@ import ExtConfig from '../src/configurations/extConfig';
import Config from '../src/configurations/config';
suite('ExtConfig Tests', () => {
let config: TypeMoq.Mock<IConfig>;
let extensionConfig: TypeMoq.Mock<WorkspaceConfiguration>;
let workspaceConfig: TypeMoq.Mock<WorkspaceConfiguration>;
let config: TypeMoq.IMock<IConfig>;
let extensionConfig: TypeMoq.IMock<WorkspaceConfiguration>;
let workspaceConfig: TypeMoq.IMock<WorkspaceConfiguration>;
let fromConfig: string = 'fromConfig';
let fromExtensionConfig: string = 'fromExtensionConfig';

Просмотреть файл

@ -16,8 +16,8 @@ suite('MainController Tests', () => {
let document: vscode.TextDocument;
let newDocument: vscode.TextDocument;
let mainController: MainController;
let connectionManager: TypeMoq.Mock<ConnectionManager>;
let untitledSqlDocumentService: TypeMoq.Mock<UntitledSqlDocumentService>;
let connectionManager: TypeMoq.IMock<ConnectionManager>;
let untitledSqlDocumentService: TypeMoq.IMock<UntitledSqlDocumentService>;
let docUri: string;
let newDocUri: string;
let docUriCallback: string;
@ -184,8 +184,8 @@ suite('MainController Tests', () => {
});
test('TextDocument Events should handle non-initialized connection manager' , done => {
let contextMock: TypeMoq.Mock<vscode.ExtensionContext> = TypeMoq.Mock.ofType(TestExtensionContext);
let vscodeWrapperMock: TypeMoq.Mock<VscodeWrapper> = TypeMoq.Mock.ofType(VscodeWrapper);
let contextMock: TypeMoq.IMock<vscode.ExtensionContext> = TypeMoq.Mock.ofType(TestExtensionContext);
let vscodeWrapperMock: TypeMoq.IMock<VscodeWrapper> = TypeMoq.Mock.ofType(VscodeWrapper);
let controller: MainController = new MainController(contextMock.object,
undefined, // ConnectionManager
vscodeWrapperMock.object);

Просмотреть файл

@ -67,8 +67,8 @@ function createTestConnectionManager(
statusView?: StatusView,
connectionStore?: ConnectionStore): ConnectionManager {
let contextMock: TypeMoq.Mock<ExtensionContext> = TypeMoq.Mock.ofType(TestExtensionContext);
let prompterMock: TypeMoq.Mock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
let contextMock: TypeMoq.IMock<ExtensionContext> = TypeMoq.Mock.ofType(TestExtensionContext);
let prompterMock: TypeMoq.IMock<IPrompter> = TypeMoq.Mock.ofType(TestPrompter);
if (!statusView) {
statusView = TypeMoq.Mock.ofType(StatusView).object;
}
@ -102,7 +102,7 @@ suite('Per File Connection Tests', () => {
let manager: ConnectionManager = createTestConnectionManager();
// Setup mocking
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, createTestConnectionResult(params.ownerUri));
@ -141,7 +141,7 @@ suite('Per File Connection Tests', () => {
let manager: ConnectionManager = createTestConnectionManager();
// Setup mocking
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isValue(ConnectionContracts.ConnectionRequest.type), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, createTestConnectionResult(params.ownerUri));
@ -195,7 +195,7 @@ suite('Per File Connection Tests', () => {
let manager: ConnectionManager = createTestConnectionManager();
// Setup mocking
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isValue(ConnectionContracts.ConnectionRequest.type), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, createTestConnectionResult(params.ownerUri));
@ -260,7 +260,7 @@ suite('Per File Connection Tests', () => {
let manager: ConnectionManager = createTestConnectionManager();
// Setup mocking
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isValue(ConnectionContracts.ConnectionRequest.type), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, createTestConnectionResult(params.ownerUri));
@ -282,7 +282,7 @@ suite('Per File Connection Tests', () => {
quickPickItemType: Interfaces.CredentialsQuickPickItemType.Mru
};
let vscodeWrapperMock: TypeMoq.Mock<VscodeWrapper> = TypeMoq.Mock.ofType(VscodeWrapper);
let vscodeWrapperMock: TypeMoq.IMock<VscodeWrapper> = TypeMoq.Mock.ofType(VscodeWrapper);
vscodeWrapperMock.callBase = true;
vscodeWrapperMock.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(newDatabaseChoice));
@ -326,11 +326,11 @@ suite('Per File Connection Tests', () => {
test('Prompts for new connection before running query if disconnected', () => {
// Setup mocking
let contextMock: TypeMoq.Mock<ExtensionContext> = TypeMoq.Mock.ofType(TestExtensionContext);
let vscodeWrapperMock: TypeMoq.Mock<VscodeWrapper> = TypeMoq.Mock.ofType(VscodeWrapper);
let contextMock: TypeMoq.IMock<ExtensionContext> = TypeMoq.Mock.ofType(TestExtensionContext);
let vscodeWrapperMock: TypeMoq.IMock<VscodeWrapper> = TypeMoq.Mock.ofType(VscodeWrapper);
vscodeWrapperMock.setup(x => x.isEditingSqlFile).returns(() => true);
vscodeWrapperMock.setup(x => x.activeTextEditorUri).returns(() => 'file://my/test/file.sql');
let connectionManagerMock: TypeMoq.Mock<ConnectionManager> = TypeMoq.Mock.ofType(ConnectionManager);
let connectionManagerMock: TypeMoq.IMock<ConnectionManager> = TypeMoq.Mock.ofType(ConnectionManager);
connectionManagerMock.setup(x => x.isConnected(TypeMoq.It.isAny())).returns(() => false);
connectionManagerMock.setup(x => x.isConnected(TypeMoq.It.isAny())).returns(() => true);
connectionManagerMock.setup(x => x.onNewConnection()).returns(() => Promise.resolve(false));
@ -350,7 +350,7 @@ suite('Per File Connection Tests', () => {
let connectionManager: ConnectionManager = createTestConnectionManager();
// Setup mocking
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isValue(ConnectionContracts.ConnectionRequest.type), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
connectionManager.handleConnectionCompleteNotification().call(connectionManager, createTestConnectionResult(params.ownerUri));
@ -401,14 +401,14 @@ suite('Per File Connection Tests', () => {
let myResult = createConnectionResultForCreds(connectionCreds, expectedDbName);
myResult.ownerUri = testFile;
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, myResult);
})
.returns(() => Promise.resolve(true));
let statusViewMock: TypeMoq.Mock<StatusView> = TypeMoq.Mock.ofType(StatusView);
let statusViewMock: TypeMoq.IMock<StatusView> = TypeMoq.Mock.ofType(StatusView);
let actualDbName = undefined;
statusViewMock.setup(x => x.connectSuccess(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((fileUri, creds: IConnectionCredentials, server: ConnectionContracts.ServerInfo) => {
@ -460,14 +460,14 @@ suite('Per File Connection Tests', () => {
let myResult = createConnectionResultForCreds(connectionCreds, expectedDbName);
myResult.ownerUri = testFile;
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, myResult);
})
.returns(() => Promise.resolve(true));
let statusViewMock: TypeMoq.Mock<StatusView> = TypeMoq.Mock.ofType(StatusView);
let statusViewMock: TypeMoq.IMock<StatusView> = TypeMoq.Mock.ofType(StatusView);
let actualDbName = undefined;
statusViewMock.setup(x => x.connectSuccess(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((fileUri, creds: IConnectionCredentials) => {
@ -503,8 +503,8 @@ suite('Per File Connection Tests', () => {
const testFile = 'file:///my/test/file.sql';
let manager: ConnectionManager = createTestConnectionManager();
let statusViewMock: TypeMoq.Mock<StatusView> = TypeMoq.Mock.ofType(StatusView);
let serviceClientMock: TypeMoq.Mock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
let statusViewMock: TypeMoq.IMock<StatusView> = TypeMoq.Mock.ofType(StatusView);
let serviceClientMock: TypeMoq.IMock<SqlToolsServiceClient> = TypeMoq.Mock.ofType(SqlToolsServiceClient);
serviceClientMock.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((type, params: ConnectionContracts.ConnectParams) => {
manager.handleConnectionCompleteNotification().call(manager, createTestConnectionResult(params.ownerUri));

Просмотреть файл

@ -9,7 +9,7 @@ suite('QueryNotificationHandler tests', () => {
let notificationHandler: QueryNotificationHandler;
let eventData: any;
let runnerMock: TypeMoq.Mock<QueryRunner>;
let runnerMock: TypeMoq.IMock<QueryRunner>;
let batchStartHandlerCalled: boolean;
let messageHandlerCalled: boolean;
@ -29,8 +29,7 @@ suite('QueryNotificationHandler tests', () => {
// Setup mock - Use the same QueryRunner for the whole test - this tests if it can be reused
runnerMock = TypeMoq.Mock.ofType(QueryRunner, TypeMoq.MockBehavior.Loose);
runnerMock.setup(x => x.hasCompleted).callBase();
runnerMock.setup(x => x._setHasCompleted()).callBase();
runnerMock.callBase = true;
runnerMock.setup(x => x.handleBatchStart(TypeMoq.It.isAny())).callback((event) => {
batchStartHandlerCalled = true;
});
@ -92,7 +91,7 @@ suite('QueryNotificationHandler tests', () => {
done();
});
test('QueryNotificationHandler handles registerRunner in the middle of th event flow', done => {
test('QueryNotificationHandler handles registerRunner in the middle of the event flow', done => {
resetBools();
// If some notifications are fired before registerRunner

Просмотреть файл

@ -34,18 +34,18 @@ const standardSelection: ISelectionData = {startLine: 0, endLine: 0, startColumn
// TESTS //////////////////////////////////////////////////////////////////////////////////////////
suite('Query Runner tests', () => {
let testSqlOutputContentProvider: TypeMoq.Mock<SqlOutputContentProvider>;
let testSqlToolsServerClient: TypeMoq.Mock<SqlToolsServerClient>;
let testQueryNotificationHandler: TypeMoq.Mock<QueryNotificationHandler>;
let testVscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let testStatusView: TypeMoq.Mock<StatusView>;
let testSqlOutputContentProvider: TypeMoq.IMock<SqlOutputContentProvider>;
let testSqlToolsServerClient: TypeMoq.IMock<SqlToolsServerClient>;
let testQueryNotificationHandler: TypeMoq.IMock<QueryNotificationHandler>;
let testVscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
let testStatusView: TypeMoq.IMock<StatusView>;
setup(() => {
testSqlOutputContentProvider = TypeMoq.Mock.ofType(SqlOutputContentProvider, TypeMoq.MockBehavior.Strict, {extensionPath: ''});
testSqlToolsServerClient = TypeMoq.Mock.ofType(SqlToolsServerClient, TypeMoq.MockBehavior.Strict);
testQueryNotificationHandler = TypeMoq.Mock.ofType(QueryNotificationHandler, TypeMoq.MockBehavior.Strict);
testVscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper, TypeMoq.MockBehavior.Strict);
testStatusView = TypeMoq.Mock.ofType(StatusView, TypeMoq.MockBehavior.Strict);
testSqlOutputContentProvider = TypeMoq.Mock.ofType(SqlOutputContentProvider, TypeMoq.MockBehavior.Loose, {extensionPath: ''});
testSqlToolsServerClient = TypeMoq.Mock.ofType(SqlToolsServerClient, TypeMoq.MockBehavior.Loose);
testQueryNotificationHandler = TypeMoq.Mock.ofType(QueryNotificationHandler, TypeMoq.MockBehavior.Loose);
testVscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper, TypeMoq.MockBehavior.Loose);
testStatusView = TypeMoq.Mock.ofType(StatusView, TypeMoq.MockBehavior.Loose);
});
@ -63,7 +63,7 @@ suite('Query Runner tests', () => {
test('Handles Query Request Result Properly', () => {
// Setup:
// ... Standard service to handle a execute request, standard query notification
setupStandardQueryRequestServiceMock(testSqlToolsServerClient, () => { return Promise.resolve(new QueryExecuteContracts.QueryExecuteResult); });
setupStandardQueryRequestServiceMock(testSqlToolsServerClient, () => { return Promise.resolve(new QueryExecuteContracts.QueryExecuteResult()); });
setupStandardQueryNotificationHandlerMock(testQueryNotificationHandler);
// ... Mock up the view and VSCode wrapper to handle requests to update view
@ -71,7 +71,7 @@ suite('Query Runner tests', () => {
testVscodeWrapper.setup( x => x.logToOutputChannel(TypeMoq.It.isAnyString()));
// ... Mock up a event emitter to accept a start event (only)
let mockEventEmitter = TypeMoq.Mock.ofType(EventEmitter, TypeMoq.MockBehavior.Strict);
let mockEventEmitter = TypeMoq.Mock.ofType(EventEmitter, TypeMoq.MockBehavior.Loose);
mockEventEmitter.setup(x => x.emit('start'));
// If:
@ -636,18 +636,21 @@ suite('Query Runner tests', () => {
* @param returnCallback Function to execute when query execute request is called
*/
function setupStandardQueryRequestServiceMock(
testSqlToolsServerClient: TypeMoq.Mock<SqlToolsServerClient>,
testSqlToolsServerClient: TypeMoq.IMock<SqlToolsServerClient>,
returnCallback: (...x: any[]) => Thenable<QueryDisposeContracts.QueryDisposeResult>
): void {
testSqlToolsServerClient.setup(x => x.sendRequest(TypeMoq.It.isValue(QueryExecuteContracts.QueryExecuteRequest.type), TypeMoq.It.isAny()))
.callback((type, details: QueryExecuteParams) => {
assert.equal(details.ownerUri, standardUri);
assert.equal(details.querySelection, standardSelection);
assert.equal(details.querySelection.startLine, standardSelection.startLine);
assert.equal(details.querySelection.startColumn, standardSelection.startColumn);
assert.equal(details.querySelection.endLine, standardSelection.endLine);
assert.equal(details.querySelection.endColumn, standardSelection.endColumn);
})
.returns(returnCallback);
}
function setupStandardQueryNotificationHandlerMock(testQueryNotificationHandler: TypeMoq.Mock<QueryNotificationHandler>): void {
function setupStandardQueryNotificationHandlerMock(testQueryNotificationHandler: TypeMoq.IMock<QueryNotificationHandler>): void {
testQueryNotificationHandler.setup(x => x.registerRunner(TypeMoq.It.isAny(), TypeMoq.It.isAnyString()))
.callback((qr, u: string) => {
assert.equal(u, standardUri);

Просмотреть файл

@ -14,9 +14,9 @@ suite('save results tests', () => {
const testFile = 'file:///my/test/file.sql';
let filePath = '';
let serverClient: TypeMoq.Mock<SqlToolsServerClient>;
let prompter: TypeMoq.Mock<IPrompter>;
let vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let serverClient: TypeMoq.IMock<SqlToolsServerClient>;
let prompter: TypeMoq.IMock<IPrompter>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
setup(() => {
@ -141,6 +141,12 @@ suite('save results tests', () => {
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
serverClient.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => {
// This will come back as null from the service layer, but tslinter doesn't like that
@ -216,7 +222,7 @@ suite('save results tests', () => {
vscodeWrapper.setup(x => x.openTextDocument(TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny())).returns(() => {
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
serverClient.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
@ -255,7 +261,7 @@ suite('save results tests', () => {
vscodeWrapper.setup(x => x.openTextDocument(TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny())).returns(() => {
vscodeWrapper.setup(x => x.showTextDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
return Promise.resolve(undefined);
});
serverClient.setup(x => x.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()))

Просмотреть файл

@ -16,9 +16,9 @@ interface IFixture {
suite('Server tests', () => {
let testDownloadProvider: TypeMoq.Mock<ServiceDownloadProvider>;
let testStatusView: TypeMoq.Mock<IStatusView>;
let testConfig: TypeMoq.Mock<IConfig>;
let testDownloadProvider: TypeMoq.IMock<ServiceDownloadProvider>;
let testStatusView: TypeMoq.IMock<IStatusView>;
let testConfig: TypeMoq.IMock<IConfig>;
setup(() => {
testDownloadProvider = TypeMoq.Mock.ofType(ServiceDownloadProvider, TypeMoq.MockBehavior.Strict);

Просмотреть файл

@ -15,9 +15,9 @@ interface IFixture {
suite('Service Client tests', () => {
let testServiceProvider: TypeMoq.Mock<ServerProvider>;
let testServiceProvider: TypeMoq.IMock<ServerProvider>;
let logger = new Logger(text => console.log(text));
let testStatusView: TypeMoq.Mock<StatusView>;
let testStatusView: TypeMoq.IMock<StatusView>;
setup(() => {
testServiceProvider = TypeMoq.Mock.ofType(ServerProvider, TypeMoq.MockBehavior.Strict);

Просмотреть файл

@ -12,10 +12,10 @@ import { ISelectionData } from '../src/models/interfaces';
suite('SqlOutputProvider Tests', () => {
let vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
let contentProvider: SqlOutputContentProvider;
let context: TypeMoq.Mock<vscode.ExtensionContext>;
let statusView: TypeMoq.Mock<StatusView>;
let context: TypeMoq.IMock<vscode.ExtensionContext>;
let statusView: TypeMoq.IMock<StatusView>;
let setSplitPaneSelectionConfig: (value: string) => void;
let setCurrentEditorColumn: (column: number) => void;

Просмотреть файл

@ -6,7 +6,7 @@ import VscodeWrapper from '../src/controllers/vscodeWrapper';
interface IFixture {
openDocResult: Promise<vscode.TextDocument>;
showDocResult: Promise<vscode.TextEditor>;
vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
service: UntitledSqlDocumentService;
textDocuments: vscode.TextDocument[];
}
@ -34,7 +34,7 @@ suite('UntitledSqlDocumentService Tests', () => {
}
function createUntitledSqlDocumentService(fixture: IFixture): IFixture {
let vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
vscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper);
vscodeWrapper.setup(x => x.textDocuments).returns(() => { return fixture.textDocuments; });

Просмотреть файл

@ -4,7 +4,7 @@ import { SqlOutputContentProvider } from '../src/models/SqlOutputContentProvider
import VscodeWrapper from '../src/controllers/vscodeWrapper';
import QueryRunner from '../src/controllers/QueryRunner';
import { ISelectionData } from '../src/models/interfaces';
import { QueryExecuteSubsetResult } from '../src/models/contracts/queryExecute';
import { QueryExecuteSubsetResult, ResultSetSubset } from '../src/models/contracts/queryExecute';
import StatusView from '../src/views/statusView';
import * as stubs from './stubs';
import vscode = require('vscode');
@ -12,12 +12,12 @@ import * as TypeMoq from 'typemoq';
import assert = require('assert');
suite('Web Service Request Handler Tests', () => {
let vscodeWrapper: TypeMoq.Mock<VscodeWrapper>;
let vscodeWrapper: TypeMoq.IMock<VscodeWrapper>;
let contentProvider: SqlOutputContentProvider;
let context: TypeMoq.Mock<vscode.ExtensionContext>;
let statusView: TypeMoq.Mock<StatusView>;
let result: TypeMoq.Mock<stubs.ExpressResult>;
let queryRunner: TypeMoq.Mock<QueryRunner>;
let context: TypeMoq.IMock<vscode.ExtensionContext>;
let statusView: TypeMoq.IMock<StatusView>;
let result: TypeMoq.IMock<stubs.ExpressResult>;
let queryRunner: TypeMoq.IMock<QueryRunner>;
setup(() => {
@ -99,7 +99,11 @@ suite('Web Service Request Handler Tests', () => {
.returns( () => {
return new Promise<QueryExecuteSubsetResult>((reject, resolve) => {
// returning a blank resultSubset Message
resolve({message: '', resultSubset: {rowCount: 0, rows: [[]]}});
let subsetResult = new QueryExecuteSubsetResult();
subsetResult.resultSubset = new ResultSetSubset();
subsetResult.resultSubset.rowCount = 0;
subsetResult.resultSubset.rows = [[]];
resolve(subsetResult);
});
});
@ -185,7 +189,10 @@ suite('Web Service Request Handler Tests', () => {
queryRunner.setup(x => x.copyResults(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((selection: any, batchId: any, resultId: any, includeHeaders: any) => {
// assert that input data has properly propogated
assert.equal(selection, request.body);
assert.equal(selection.fromCell, request.body.fromCell);
assert.equal(selection.toCell, request.body.toCell);
assert.equal(selection.fromRow, request.body.fromRow);
assert.equal(selection.toRow, request.body.toRow);
assert.equal(includeHeaders, testQuery.includeHeaders);
assert.equal(batchId, testQuery.batchId);
assert.equal(resultId, testQuery.resultId);