Add more tests for new features (#1344)
* change create session test to use deferred promises * fix test timeout * add sqlcmd test * add file for scripting tests * added some node tests * added oe utils tests * merged master and fixed test * fix coverage path * test coverage * remove out from coverage * fix coverage site * try new coverage path * fix coverage report path * add out to ignore patterns * test new reporting style * fix test report path * remove html report * try without final json * add tests for credential store * add tree info testing * add more tests * fix test * added test for metadata * fix tests
This commit is contained in:
Родитель
f27b4a29cf
Коммит
556e3a9d2b
|
@ -2,6 +2,16 @@
|
|||
{
|
||||
"version": "0.1.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Gulp ext test",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"args": [
|
||||
"ext:test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
|
|
|
@ -180,7 +180,7 @@ export default class MainController implements vscode.Disposable {
|
|||
});
|
||||
|
||||
// initiate the scripting service
|
||||
this._scriptingService = new ScriptingService(this._connectionMgr, this._vscodeWrapper);
|
||||
this._scriptingService = new ScriptingService(this._connectionMgr);
|
||||
this._context.subscriptions.push(
|
||||
vscode.commands.registerCommand(
|
||||
Constants.cmdScriptSelect, async (node: TreeNodeInfo) => {
|
||||
|
|
|
@ -7,15 +7,13 @@ import SqlToolsServiceClient from '../languageservice/serviceclient';
|
|||
import ConnectionManager from '../controllers/connectionManager';
|
||||
import { ScriptingRequest, ScriptingParams, ScriptOperation, ScriptingObject, ScriptOptions } from '../models/contracts/scripting/scriptingRequest';
|
||||
import { TreeNodeInfo } from '../objectExplorer/treeNodeInfo';
|
||||
import VscodeWrapper from '../controllers/vscodeWrapper';
|
||||
|
||||
export class ScriptingService {
|
||||
|
||||
private _client: SqlToolsServiceClient;
|
||||
|
||||
constructor(
|
||||
private _connectionManager: ConnectionManager,
|
||||
private _vscodeWrapper: VscodeWrapper
|
||||
private _connectionManager: ConnectionManager
|
||||
) {
|
||||
this._client = this._connectionManager.client;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
export const star = '✰';
|
|
@ -28,8 +28,8 @@ gulp.task('cover:disable', () => {
|
|||
.pipe(gulp.dest("./out", {'overwrite':true}));
|
||||
});
|
||||
|
||||
gulp.task('cover:combine', () => {
|
||||
return gulp.src(['./coverage/coverage-final.json', './coverage/coverage.json'])
|
||||
gulp.task('cover:combine-json', () => {
|
||||
return gulp.src(['./coverage/coverage.json'])
|
||||
.pipe(istanbulReport({
|
||||
reporterOpts: {
|
||||
dir: './coverage'
|
||||
|
@ -41,5 +41,17 @@ gulp.task('cover:combine', () => {
|
|||
}));
|
||||
});
|
||||
|
||||
gulp.task('cover:combine-html', () => {
|
||||
return gulp.src(['**/*.html'])
|
||||
.pipe(istanbulReport({
|
||||
reporterOpts: {
|
||||
dir: './coverage'
|
||||
},
|
||||
reporters: [
|
||||
{'name': 'html'}
|
||||
]
|
||||
}));
|
||||
});
|
||||
|
||||
// for running on the jenkins build system
|
||||
gulp.task('cover:jenkins', gulp.series('cover:clean', 'cover:enableconfig', 'ext:test', 'cover:combine'));
|
||||
gulp.task('cover:jenkins', gulp.series('cover:clean', 'cover:enableconfig', 'test', 'cover:combine-json'));
|
|
@ -0,0 +1,43 @@
|
|||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
|
||||
'use strict';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as Contracts from '../src/models/contracts';
|
||||
import SqlToolsServiceClient from '../src/languageservice/serviceclient';
|
||||
import { CredentialStore } from '../src/credentialstore/credentialstore';
|
||||
import { ICredentialStore } from '../src/credentialstore/icredentialstore';
|
||||
|
||||
suite('Credential Store Tests', () => {
|
||||
|
||||
let client: TypeMoq.IMock<SqlToolsServiceClient>;
|
||||
let credentialStore: ICredentialStore;
|
||||
|
||||
setup(() => {
|
||||
client = TypeMoq.Mock.ofType(SqlToolsServiceClient, TypeMoq.MockBehavior.Loose);
|
||||
client.setup(c => c.sendRequest(Contracts.SaveCredentialRequest.type, TypeMoq.It.isAny())).returns(() => Promise.resolve(true));
|
||||
client.setup(c => c.sendRequest(Contracts.ReadCredentialRequest.type, TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
|
||||
client.setup(c => c.sendRequest(Contracts.DeleteCredentialRequest.type, TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
|
||||
credentialStore = new CredentialStore(client.object);
|
||||
});
|
||||
|
||||
test('Read credential should send a ReadCredentialRequest', () => {
|
||||
credentialStore.readCredential('test_credential').then(() => {
|
||||
client.verify(c => c.sendRequest(Contracts.ReadCredentialRequest.type, TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
test('Save credential should send a SaveCredentialRequest', () => {
|
||||
credentialStore.saveCredential('test_credential', 'test_password').then(() => {
|
||||
client.verify(c => c.sendRequest(Contracts.SaveCredentialRequest.type, TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
test('Delete credential should send a DeleteCredentialRequest', () => {
|
||||
credentialStore.deleteCredential('test_credential').then(() => {
|
||||
client.verify(c => c.sendRequest(Contracts.DeleteCredentialRequest.type, TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
});
|
|
@ -28,7 +28,7 @@ testRunner.configure(
|
|||
reporter: 'pm-mocha-jenkins-reporter',
|
||||
reporterOptions: {
|
||||
junit_report_name: 'Extension Tests',
|
||||
junit_report_path: __dirname + '../test-reports/extension_tests.xml',
|
||||
junit_report_path: __dirname + '../../test-reports/extension_tests.xml',
|
||||
junit_report_stack: 1
|
||||
},
|
||||
useColors: true // colored output from test results
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ObjectExplorerProvider } from '../src/objectExplorer/objectExplorerProvider';
|
||||
import { ObjectExplorerService } from '../src/objectExplorer/objectExplorerService';
|
||||
import ConnectionManager from '../src/controllers/connectionManager';
|
||||
import SqlToolsServiceClient from '../src/languageservice/serviceclient';
|
||||
import { expect } from 'chai';
|
||||
import { TreeNodeInfo } from '../src/objectExplorer/treeNodeInfo';
|
||||
import { ConnectionCredentials } from '../src/models/connectionCredentials';
|
||||
import { Deferred } from '../src/protocol';
|
||||
import { AddConnectionTreeNode } from '../src/objectExplorer/addConnectionTreeNode';
|
||||
import * as LocalizedConstants from '../src/constants/localizedConstants';
|
||||
import { AccountSignInTreeNode } from '../src/objectExplorer/accountSignInTreeNode';
|
||||
import { ConnectTreeNode } from '../src/objectExplorer/connectTreeNode';
|
||||
import { NodeInfo } from '../src/models/contracts/objectExplorer/nodeInfo';
|
||||
|
||||
suite('Object Explorer Provider Tests', () => {
|
||||
|
||||
let objectExplorerService: TypeMoq.IMock<ObjectExplorerService>;
|
||||
let connectionManager: TypeMoq.IMock<ConnectionManager>;
|
||||
let client: TypeMoq.IMock<SqlToolsServiceClient>;
|
||||
let objectExplorerProvider: ObjectExplorerProvider;
|
||||
|
||||
setup(() => {
|
||||
connectionManager = TypeMoq.Mock.ofType(ConnectionManager, TypeMoq.MockBehavior.Loose);
|
||||
connectionManager.setup(c => c.client).returns(() => client.object);
|
||||
client = TypeMoq.Mock.ofType(SqlToolsServiceClient, TypeMoq.MockBehavior.Loose);
|
||||
client.setup(c => c.onNotification(TypeMoq.It.isAny(), TypeMoq.It.isAny()));
|
||||
connectionManager.object.client = client.object;
|
||||
objectExplorerProvider = new ObjectExplorerProvider(connectionManager.object);
|
||||
expect(objectExplorerProvider, 'Object Explorer Provider is initialzied properly').is.not.equal(undefined);
|
||||
objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManager.object);
|
||||
objectExplorerService.setup(s => s.currentNode).returns(() => undefined);
|
||||
objectExplorerProvider.objectExplorerService = objectExplorerService.object;
|
||||
});
|
||||
|
||||
test('Test Create Session', () => {
|
||||
expect(objectExplorerService.object.currentNode, 'Current Node should be undefined').is.equal(undefined);
|
||||
expect(objectExplorerProvider.objectExplorerExists, 'Object Explorer should not exist until started').is.equal(undefined);
|
||||
const promise = new Deferred<TreeNodeInfo>();
|
||||
objectExplorerService.setup(s => s.createSession(promise, undefined)).returns(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
objectExplorerService.setup(s => s.currentNode).returns(() => TypeMoq.It.isAny());
|
||||
objectExplorerProvider.objectExplorerExists = true;
|
||||
promise.resolve(new TreeNodeInfo(undefined, undefined,
|
||||
undefined, undefined,
|
||||
undefined, undefined,
|
||||
undefined, undefined,
|
||||
undefined));
|
||||
});
|
||||
});
|
||||
objectExplorerProvider.createSession(promise, undefined).then(async () => {
|
||||
expect(objectExplorerService.object.currentNode, 'Current Node should not be undefined').is.not.equal(undefined);
|
||||
expect(objectExplorerProvider.objectExplorerExists, 'Object Explorer session should exist').is.equal(true);
|
||||
let node = await promise;
|
||||
expect(node, 'Created session node not be undefined').is.not.equal(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
test('Test Refresh Node', (done) => {
|
||||
let treeNode = TypeMoq.Mock.ofType(TreeNodeInfo, TypeMoq.MockBehavior.Loose);
|
||||
objectExplorerService.setup(s => s.refreshNode(TypeMoq.It.isAny())).returns(() => Promise.resolve(TypeMoq.It.isAny()));
|
||||
objectExplorerProvider.refreshNode(treeNode.object).then((node) => {
|
||||
expect(node, 'Refreshed node should not be undefined').is.not.equal(undefined);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
test('Test Connection Credentials', () => {
|
||||
let connectionCredentials = TypeMoq.Mock.ofType(ConnectionCredentials, TypeMoq.MockBehavior.Loose);
|
||||
objectExplorerService.setup(s => s.getConnectionCredentials(TypeMoq.It.isAnyString())).returns(() => connectionCredentials.object);
|
||||
let credentials = objectExplorerProvider.getConnectionCredentials('test_session_id');
|
||||
expect(credentials, 'Connection Credentials should not be null').is.not.equal(undefined);
|
||||
});
|
||||
|
||||
test('Test remove Object Explorer node', async () => {
|
||||
let isNodeDeleted = false;
|
||||
objectExplorerService.setup(s => s.removeObjectExplorerNode(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
|
||||
isNodeDeleted = true;
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
await objectExplorerProvider.removeObjectExplorerNode(TypeMoq.It.isAny(), TypeMoq.It.isAny());
|
||||
expect(isNodeDeleted, 'Node should be deleted').is.equal(true);
|
||||
});
|
||||
|
||||
test('Test Get Children from Object Explorer Provider', (done) => {
|
||||
const parentTreeNode = TypeMoq.Mock.ofType(TreeNodeInfo, TypeMoq.MockBehavior.Loose);
|
||||
const childTreeNode = TypeMoq.Mock.ofType(TreeNodeInfo, TypeMoq.MockBehavior.Loose);
|
||||
objectExplorerService.setup(s => s.getChildren(TypeMoq.It.isAny())).returns(() => Promise.resolve([childTreeNode.object]));
|
||||
objectExplorerProvider.getChildren(parentTreeNode.object).then((children) => {
|
||||
children.forEach((child) => expect(child, 'Children nodes should not be undefined').is.not.equal(undefined));
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
test('Test server nodes sorting mechanism', (done) => {
|
||||
const testNode = new TreeNodeInfo('testNode', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const serverTestNode = new TreeNodeInfo('serverTestNode', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const testNode2 = new TreeNodeInfo('TESTNODE', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const testNode3 = new TreeNodeInfo('', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const testNode4 = new TreeNodeInfo('1234', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
objectExplorerService.setup(s => s.rootTreeNodeArray).returns(() => [testNode, serverTestNode, testNode2, testNode3, testNode4]);
|
||||
objectExplorerService.setup(s => s.sortByServerName(objectExplorerService.object.rootTreeNodeArray)).returns(() => {
|
||||
const sortedNodeArray = objectExplorerService.object.rootTreeNodeArray.sort((a, b) => {
|
||||
return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
|
||||
});
|
||||
return sortedNodeArray;
|
||||
});
|
||||
const expectedSortedNodes = [testNode3, testNode4, serverTestNode, testNode, testNode2];
|
||||
let sortedNodes = objectExplorerService.object.sortByServerName(objectExplorerService.object.rootTreeNodeArray);
|
||||
for (let i = 0; i < sortedNodes.length; i++) {
|
||||
expect(sortedNodes[i], 'Sorted nodes should be the same as expected sorted nodes').is.equal(expectedSortedNodes[i]);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('Object Explorer Node Types Test', () => {
|
||||
|
||||
test('Test Add Connection Tree Node', () => {
|
||||
const addConnectionTreeNode = new AddConnectionTreeNode();
|
||||
expect(addConnectionTreeNode.label, 'Label should be the same as constant').is.equal(LocalizedConstants.msgAddConnection);
|
||||
expect(addConnectionTreeNode.command, 'Add Connection Tree Node has a dedicated command').is.not.equal(undefined);
|
||||
expect(addConnectionTreeNode.iconPath, 'Add Connection Tree Node has an icon').is.not.equal(undefined);
|
||||
expect(addConnectionTreeNode.collapsibleState, 'Add Connection Tree Node should have no collapsible state')
|
||||
.is.equal(vscode.TreeItemCollapsibleState.None);
|
||||
});
|
||||
|
||||
test('Test Account Sign In Tree Node', () => {
|
||||
const parentTreeNode = new TreeNodeInfo('parent', undefined, undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined);
|
||||
const accountSignInNode = new AccountSignInTreeNode(parentTreeNode);
|
||||
expect(accountSignInNode.label, 'Label should be the same as constant').is.equal(LocalizedConstants.msgConnect);
|
||||
expect(accountSignInNode.command, 'Account Sign In Node has a dedicated command').is.not.equal(undefined);
|
||||
expect(accountSignInNode.parentNode, 'Account Sign In Node should have a parent').is.not.equal(undefined);
|
||||
expect(accountSignInNode.collapsibleState, 'Account Sign In Node should have no collapsible state')
|
||||
.is.equal(vscode.TreeItemCollapsibleState.None);
|
||||
});
|
||||
|
||||
test('Test Connect Tree Node', () => {
|
||||
const parentTreeNode = new TreeNodeInfo('parent', undefined, undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined);
|
||||
const connectNode = new ConnectTreeNode(parentTreeNode);
|
||||
expect(connectNode.label, 'Label should be the same as constant').is.equal(LocalizedConstants.msgConnect);
|
||||
expect(connectNode.command, 'Connect Node has a dedicated command').is.not.equal(undefined);
|
||||
expect(connectNode.parentNode, 'Connect Node should have a parent').is.not.equal(undefined);
|
||||
expect(connectNode.collapsibleState, 'Connect Node should have no collapsible state')
|
||||
.is.equal(vscode.TreeItemCollapsibleState.None);
|
||||
});
|
||||
|
||||
test('Test getters and setters for Tree Node', () => {
|
||||
const treeNode = new TreeNodeInfo('test', 'test_value', vscode.TreeItemCollapsibleState.Collapsed, 'test_path',
|
||||
'test_status', 'Server', 'test_session', undefined, undefined);
|
||||
treeNode.nodePath = treeNode.nodePath;
|
||||
expect(treeNode.nodePath, 'Node path should be equal to expected value').is.equal('test_path');
|
||||
treeNode.nodeStatus = treeNode.nodeStatus;
|
||||
expect(treeNode.nodeStatus, 'Node status should be equal to expected value').is.equal('test_status');
|
||||
treeNode.nodeType = treeNode.nodeType;
|
||||
expect(treeNode.nodeType, 'Node type should be equal to expected value').is.equal('Server');
|
||||
treeNode.sessionId = treeNode.sessionId;
|
||||
expect(treeNode.sessionId, 'Session ID should be equal to expected value').is.equal('test_session');
|
||||
treeNode.nodeSubType = treeNode.nodeSubType;
|
||||
expect(treeNode.nodeSubType, 'Node Sub type should be equal to expected value').is.equal(undefined);
|
||||
treeNode.isLeaf = false;
|
||||
expect(treeNode.isLeaf, 'Node should not be a leaf').is.equal(false);
|
||||
treeNode.parentNode = treeNode.parentNode;
|
||||
expect(treeNode.parentNode, 'Parent node should be equal to expected value').is.equal(undefined);
|
||||
treeNode.connectionCredentials = treeNode.connectionCredentials;
|
||||
expect(treeNode.connectionCredentials, 'Connection credentials should be equal to expected value').is.equal(undefined);
|
||||
});
|
||||
|
||||
test('Test fromNodeInfo function', () => {
|
||||
const nodeInfo: NodeInfo = {
|
||||
nodePath: 'test_path',
|
||||
nodeStatus: undefined,
|
||||
nodeSubType: undefined,
|
||||
nodeType: undefined,
|
||||
label: 'test_node',
|
||||
isLeaf: false,
|
||||
errorMessage: undefined,
|
||||
metadata: undefined
|
||||
};
|
||||
const treeNodeInfo = TreeNodeInfo.fromNodeInfo(nodeInfo, 'test_session',
|
||||
undefined, undefined, undefined);
|
||||
treeNodeInfo.errorMessage = 'test_error';
|
||||
expect(treeNodeInfo.nodePath, 'Node path should be equal to expected value').is.equal(nodeInfo.nodePath);
|
||||
expect(treeNodeInfo.nodeStatus, 'Node status should be equal to expected value').is.equal(nodeInfo.nodeStatus);
|
||||
expect(treeNodeInfo.nodeType, 'Node type should be equal to expected value').is.equal(nodeInfo.nodeType);
|
||||
expect(treeNodeInfo.sessionId, 'Session ID should be equal to expected value').is.equal('test_session');
|
||||
expect(treeNodeInfo.nodeSubType, 'Node Sub type should be equal to expected value').is.equal(nodeInfo.nodeSubType);
|
||||
treeNodeInfo.isLeaf = nodeInfo.isLeaf;
|
||||
expect(treeNodeInfo.isLeaf, 'Node should not be a leaf').is.equal(nodeInfo.isLeaf);
|
||||
expect(treeNodeInfo.parentNode, 'Parent node should be equal to expected value').is.equal(undefined);
|
||||
expect(treeNodeInfo.connectionCredentials, 'Connection credentials should be equal to expected value').is.equal(undefined);
|
||||
expect(treeNodeInfo.errorMessage, 'Error message should be equal to expected value').is.equal('test_error');
|
||||
expect(treeNodeInfo.metadata, 'Node metadata should be the same as nodeInfo metadata').is.equal(nodeInfo.metadata);
|
||||
});
|
||||
});
|
|
@ -1,109 +0,0 @@
|
|||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ObjectExplorerProvider } from '../src/objectExplorer/objectExplorerProvider';
|
||||
import { ObjectExplorerService } from '../src/objectExplorer/objectExplorerService';
|
||||
import ConnectionManager from '../src/controllers/connectionManager';
|
||||
import SqlToolsServiceClient from '../src/languageservice/serviceclient';
|
||||
import { expect } from 'chai';
|
||||
import { TreeNodeInfo } from '../src/objectExplorer/treeNodeInfo';
|
||||
import { ConnectionCredentials } from '../src/models/connectionCredentials';
|
||||
|
||||
suite('Object Explorer Tests', () => {
|
||||
|
||||
let objectExplorerService: TypeMoq.IMock<ObjectExplorerService>;
|
||||
let connectionManager: TypeMoq.IMock<ConnectionManager>;
|
||||
let client: TypeMoq.IMock<SqlToolsServiceClient>;
|
||||
let objectExplorerProvider: ObjectExplorerProvider;
|
||||
|
||||
setup(() => {
|
||||
connectionManager = TypeMoq.Mock.ofType(ConnectionManager, TypeMoq.MockBehavior.Loose);
|
||||
connectionManager.setup(c => c.client).returns(() => client.object);
|
||||
client = TypeMoq.Mock.ofType(SqlToolsServiceClient, TypeMoq.MockBehavior.Loose);
|
||||
client.setup(c => c.onNotification(TypeMoq.It.isAny(), TypeMoq.It.isAny()));
|
||||
connectionManager.object.client = client.object;
|
||||
objectExplorerProvider = new ObjectExplorerProvider(connectionManager.object);
|
||||
expect(objectExplorerProvider, 'Object Explorer Provider is initialzied properly').is.not.equal(undefined);
|
||||
objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManager.object);
|
||||
objectExplorerService.setup(s => s.currentNode).returns(() => undefined);
|
||||
objectExplorerProvider.objectExplorerService = objectExplorerService.object;
|
||||
});
|
||||
|
||||
test('Test Create Session', () => {
|
||||
expect(objectExplorerService.object.currentNode, 'Current Node should be undefined').is.equal(undefined);
|
||||
expect(objectExplorerProvider.objectExplorerExists, 'Object Explorer should not exist until started').is.equal(undefined);
|
||||
objectExplorerService.setup(s => s.createSession(TypeMoq.It.isAny(), undefined)).returns(() => {
|
||||
objectExplorerService.setup(s => s.currentNode).returns(() => TypeMoq.It.isAny());
|
||||
objectExplorerProvider.objectExplorerExists = true;
|
||||
return Promise.resolve(TypeMoq.It.isAny());
|
||||
});
|
||||
objectExplorerProvider.createSession(TypeMoq.It.isAny(), undefined).then(sessionId => {
|
||||
expect(sessionId, 'Session Id should not be undefined').is.not.equal(undefined);
|
||||
expect(objectExplorerService.object.currentNode, 'Current Node should not be undefined').is.not.equal(undefined);
|
||||
expect(objectExplorerProvider.objectExplorerExists, 'Object Explorer session should exist').is.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
test('Test Refresh Node', () => {
|
||||
let treeNode = TypeMoq.Mock.ofType(TreeNodeInfo, TypeMoq.MockBehavior.Loose);
|
||||
objectExplorerService.setup(s => s.refreshNode(TypeMoq.It.isAny())).returns(() => Promise.resolve(TypeMoq.It.isAny()));
|
||||
objectExplorerProvider.refreshNode(treeNode.object).then((node) => {
|
||||
expect(node, 'Refreshed node should not be undefined').is.not.equal(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
test('Test Connection Credentials', () => {
|
||||
let connectionCredentials = TypeMoq.Mock.ofType(ConnectionCredentials, TypeMoq.MockBehavior.Loose);
|
||||
objectExplorerService.setup(s => s.getConnectionCredentials(TypeMoq.It.isAnyString())).returns(() => connectionCredentials.object);
|
||||
let credentials = objectExplorerProvider.getConnectionCredentials('test_session_id');
|
||||
expect(credentials, 'Connection Credentials should not be null').is.not.equal(undefined);
|
||||
});
|
||||
|
||||
test('Test remove Object Explorer node', async () => {
|
||||
let isNodeDeleted = false;
|
||||
objectExplorerService.setup(s => s.removeObjectExplorerNode(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
|
||||
isNodeDeleted = true;
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
objectExplorerProvider.removeObjectExplorerNode(TypeMoq.It.isAny(), TypeMoq.It.isAny());
|
||||
expect(isNodeDeleted, 'Node should be deleted').is.equal(true);
|
||||
});
|
||||
|
||||
test('Test Get Children from Object Explorer Provider', () => {
|
||||
const parentTreeNode = TypeMoq.Mock.ofType(TreeNodeInfo, TypeMoq.MockBehavior.Loose);
|
||||
const childTreeNode = TypeMoq.Mock.ofType(TreeNodeInfo, TypeMoq.MockBehavior.Loose);
|
||||
objectExplorerService.setup(s => s.getChildren(TypeMoq.It.isAny())).returns(() => Promise.resolve([childTreeNode.object]));
|
||||
objectExplorerProvider.getChildren(parentTreeNode.object).then((children) => {
|
||||
children.forEach((child) => expect(child, 'Children nodes should not be undefined').is.not.equal(undefined));
|
||||
});
|
||||
});
|
||||
|
||||
test('Test server nodes sorting mechanism', (done) => {
|
||||
const testNode = new TreeNodeInfo('testNode', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const serverTestNode = new TreeNodeInfo('serverTestNode', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const testNode2 = new TreeNodeInfo('TESTNODE', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const testNode3 = new TreeNodeInfo('', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
const testNode4 = new TreeNodeInfo('1234', undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
objectExplorerService.setup(s => s.rootTreeNodeArray).returns(() => [testNode, serverTestNode, testNode2, testNode3, testNode4]);
|
||||
objectExplorerService.setup(s => s.sortByServerName(objectExplorerService.object.rootTreeNodeArray)).returns(() => {
|
||||
const sortedNodeArray = objectExplorerService.object.rootTreeNodeArray.sort((a, b) => {
|
||||
return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
|
||||
});
|
||||
return sortedNodeArray;
|
||||
});
|
||||
const expectedSortedNodes = [testNode3, testNode4, serverTestNode, testNode, testNode2];
|
||||
let sortedNodes = objectExplorerService.object.sortByServerName(objectExplorerService.object.rootTreeNodeArray);
|
||||
for (let i = 0; i < sortedNodes.length; i++) {
|
||||
expect(sortedNodes[i], 'Sorted nodes should be the same as expected sorted nodes').is.equal(expectedSortedNodes[i]);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,67 @@
|
|||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
import * as path from 'path';
|
||||
import { ObjectExplorerUtils } from '../src/objectExplorer/objectExplorerUtils';
|
||||
import { expect } from 'chai';
|
||||
import { TreeNodeInfo } from '../src/objectExplorer/treeNodeInfo';
|
||||
import { ConnectionProfile } from '../src/models/connectionProfile';
|
||||
|
||||
suite('Object Explorer Utils Tests', () => {
|
||||
|
||||
test('Test iconPath function', () => {
|
||||
const testObjects = ['Server', 'Table', 'StoredProcedure', 'disconnectedServer'];
|
||||
const expectedPaths = ['Server_green.svg', 'Table.svg', 'StoredProcedure.svg', 'Server_red.svg'];
|
||||
for (let i = 0; i < testObjects.length; i++) {
|
||||
const iconPath = ObjectExplorerUtils.iconPath(testObjects[i]);
|
||||
const fileName = path.basename(iconPath);
|
||||
expect(fileName, 'File name should be the same as expected file name').is.equal(expectedPaths[i]);
|
||||
}
|
||||
});
|
||||
|
||||
test('Test getNodeUri function', () => {
|
||||
const disconnectedProfile = new ConnectionProfile();
|
||||
disconnectedProfile.server = 'disconnected_server';
|
||||
const testProfile = new ConnectionProfile();
|
||||
testProfile.server = 'test_server';
|
||||
testProfile.profileName = 'test_profile';
|
||||
testProfile.database = 'test_database';
|
||||
testProfile.user = 'test_user';
|
||||
const disconnectedTestNode = new TreeNodeInfo('disconnectedTest', undefined, undefined, undefined,
|
||||
undefined, 'disconnectedServer', undefined, disconnectedProfile, undefined);
|
||||
const serverTestNode = new TreeNodeInfo('serverTest', undefined, undefined, 'test_path',
|
||||
undefined, 'Server', undefined, testProfile, undefined);
|
||||
const databaseTestNode = new TreeNodeInfo('databaseTest', undefined, undefined, 'test_path',
|
||||
undefined, 'Database', undefined, testProfile, serverTestNode);
|
||||
const tableTestNode = new TreeNodeInfo('tableTest', undefined, undefined, 'test_path',
|
||||
undefined, 'Table', undefined, testProfile, databaseTestNode);
|
||||
const testNodes = [disconnectedTestNode, serverTestNode, tableTestNode];
|
||||
const expectedUris = ['disconnected_server_undefined_undefined_undefined',
|
||||
'test_server_test_database_test_user_test_profile',
|
||||
'test_server_test_database_test_user_test_profile'];
|
||||
|
||||
for (let i = 0; i < testNodes.length; i++) {
|
||||
const nodeUri = ObjectExplorerUtils.getNodeUri(testNodes[i]);
|
||||
expect(nodeUri, 'Node URI should be the same as expected Node URI').is.equal(expectedUris[i]);
|
||||
}
|
||||
});
|
||||
|
||||
test('Test getNodeUriFromProfile', () => {
|
||||
const testProfile = new ConnectionProfile();
|
||||
testProfile.server = 'test_server';
|
||||
testProfile.profileName = 'test_profile';
|
||||
testProfile.database = 'test_database';
|
||||
testProfile.user = 'test_user';
|
||||
const testProfile2 = new ConnectionProfile();
|
||||
testProfile2.server = 'test_server2';
|
||||
testProfile2.profileName = undefined;
|
||||
const testProfiles = [testProfile, testProfile2];
|
||||
const expectedProfiles = ['test_server_test_database_test_user_test_profile', 'test_server2_undefined_undefined_undefined'];
|
||||
|
||||
for (let i = 0; i < testProfiles.length; i++) {
|
||||
const uri = ObjectExplorerUtils.getNodeUriFromProfile(testProfiles[i]);
|
||||
expect(uri, 'Node URI should be the same as expected Node URI').is.equal(expectedProfiles[i]);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -29,6 +29,7 @@ import {
|
|||
} from './../src/models/interfaces';
|
||||
import * as stubs from './stubs';
|
||||
import * as vscode from 'vscode';
|
||||
import { expect } from 'chai';
|
||||
|
||||
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
||||
const standardUri: string = 'uri';
|
||||
|
@ -489,6 +490,23 @@ suite('Query Runner tests', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('Toggle SQLCMD Mode sends request', async () => {
|
||||
let queryUri = 'test_uri';
|
||||
let queryRunner = new QueryRunner(queryUri,
|
||||
queryUri,
|
||||
testStatusView.object,
|
||||
testSqlToolsServerClient.object,
|
||||
testQueryNotificationHandler.object,
|
||||
testVscodeWrapper.object);
|
||||
expect(queryRunner.isSqlCmd, 'Query Runner should have SQLCMD false be default').is.equal(false);
|
||||
testSqlToolsServerClient.setup(s => s.sendRequest(QueryExecuteContracts.QueryExecuteOptionsRequest.type, TypeMoq.It.isAny())).returns(() => {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
await queryRunner.toggleSqlCmd();
|
||||
testSqlToolsServerClient.verify(s => s.sendRequest(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
expect(queryRunner.isSqlCmd, 'SQLCMD Mode should be switched').is.equal(true);
|
||||
});
|
||||
|
||||
function setupWorkspaceConfig(configResult: {[key: string]: any}): void {
|
||||
let config = stubs.createWorkspaceConfiguration(configResult);
|
||||
testVscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import ConnectionManager from '../src/controllers/connectionManager';
|
||||
import SqlToolsServiceClient from '../src/languageservice/serviceclient';
|
||||
import { ScriptingService } from '../src/scripting/scriptingService';
|
||||
import { ScriptingRequest } from '../src/models/contracts/scripting/scriptingRequest';
|
||||
import { Script } from 'vm';
|
||||
import { TreeNodeInfo } from '../src/objectExplorer/treeNodeInfo';
|
||||
import { ServerInfo } from '../src/models/contracts/connection';
|
||||
|
||||
suite('Scripting Service Tests', () => {
|
||||
|
||||
let scriptingService: ScriptingService;
|
||||
let connectionManager: TypeMoq.IMock<ConnectionManager>;
|
||||
let client: TypeMoq.IMock<SqlToolsServiceClient>;
|
||||
|
||||
setup(() => {
|
||||
connectionManager = TypeMoq.Mock.ofType(ConnectionManager, TypeMoq.MockBehavior.Loose);
|
||||
connectionManager.setup(c => c.client).returns(() => client.object);
|
||||
client = TypeMoq.Mock.ofType(SqlToolsServiceClient, TypeMoq.MockBehavior.Loose);
|
||||
client.setup(c => c.sendRequest(ScriptingRequest.type, TypeMoq.It.isAny())).returns(() => TypeMoq.It.isAny());
|
||||
connectionManager.object.client = client.object;
|
||||
connectionManager.setup(c => c.getServerInfo(TypeMoq.It.isAny())).returns(() => {
|
||||
let serverInfo = new ServerInfo();
|
||||
serverInfo.engineEditionId = 2;
|
||||
serverInfo.serverMajorVersion = 1;
|
||||
serverInfo.isCloud = true;
|
||||
return serverInfo;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('Test Script Select', () => {
|
||||
let testNode = new TreeNodeInfo('master.dbo.test_table', undefined, undefined,
|
||||
undefined, undefined, 'Table', undefined, undefined, undefined);
|
||||
scriptingService = new ScriptingService(connectionManager.object);
|
||||
scriptingService.scriptSelect(testNode, 'test_uri');
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче