Add --command command line argument (#3690)

This commit is contained in:
David Shiflet
2019-01-09 17:36:01 -05:00
committed by GitHub
parent 589b913960
commit 3d3694bb8d
6 changed files with 210 additions and 47 deletions

View File

@@ -30,7 +30,8 @@ import {
} from 'sql/parts/connection/common/connectionManagement';
import { ConnectionStore } from 'sql/parts/connection/common/connectionStore';
import { TestConnectionManagementService } from 'sqltest/stubs/connectionManagementService.test';
import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { TestCommandService } from 'vs/editor/test/browser/editorTestServices';
class TestParsedArgs implements ParsedArgs{
[arg: string]: any;
@@ -38,6 +39,7 @@ class TestParsedArgs implements ParsedArgs{
aad?: boolean;
add?: boolean;
database?:string;
command?:string;
debugBrkPluginHost?: string;
debugBrkSearch?: string;
debugId?: string;
@@ -111,7 +113,8 @@ suite('commandLineService tests', () => {
function getCommandLineService(connectionManagementService : IConnectionManagementService,
environmentService? : IEnvironmentService,
capabilitiesService? : ICapabilitiesService
capabilitiesService? : ICapabilitiesService,
commandService? : ICommandService
) : CommandLineService
{
let service= new CommandLineService(
@@ -120,7 +123,8 @@ suite('commandLineService tests', () => {
environmentService,
undefined,
undefined,
undefined
undefined,
commandService
);
return service;
}
@@ -129,14 +133,18 @@ suite('commandLineService tests', () => {
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable();
connectionManagementService.setup((c) => c.showConnectionDialog())
.returns(() => new Promise<void>((resolve, reject) => { resolve();}))
.verifiable();
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => false);
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.verifiable(TypeMoq.Times.never());
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
.verifiable(TypeMoq.Times.never());
let service = getCommandLineService(connectionManagementService.object);
service.processCommandLine();
connectionManagementService.verifyAll();
done();
service.processCommandLine().then( () => {
connectionManagementService.verifyAll();
done();
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
});
test('processCommandLine does nothing if registered servers exist and no server name is provided', done => {
@@ -146,11 +154,13 @@ suite('commandLineService tests', () => {
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true);
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.verifiable(TypeMoq.Times.never());
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
.verifiable(TypeMoq.Times.never());
let service = getCommandLineService(connectionManagementService.object);
service.processCommandLine();
connectionManagementService.verifyAll();
done();
service.processCommandLine().then( () => {
connectionManagementService.verifyAll();
done();
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
});
test('processCommandLine opens a new connection if a server name is passed', done => {
@@ -165,12 +175,88 @@ suite('commandLineService tests', () => {
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true).verifiable(TypeMoq.Times.atMostOnce());
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), 'connection', true))
.returns(() => new Promise<string>((resolve, reject) => { reject('unused');}))
.verifiable(TypeMoq.Times.once());
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
.verifiable(TypeMoq.Times.once());
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService);
service.processCommandLine();
environmentService.verifyAll();
connectionManagementService.verifyAll();
done();
service.processCommandLine().then( () => {
environmentService.verifyAll();
connectionManagementService.verifyAll();
done();
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
});
test('processCommandLine invokes a command without a profile parameter when no server is passed', done => {
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
const commandService : TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
const args : TestParsedArgs = new TestParsedArgs();
args.command = 'mycommand';
environmentService.setup(e => e.args).returns(() => args);
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true).verifiable(TypeMoq.Times.atMostOnce());
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.verifiable(TypeMoq.Times.never());
commandService.setup(c => c.executeCommand('mycommand'))
.returns(() => TPromise.wrap(1))
.verifiable(TypeMoq.Times.once());
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService, commandService.object);
service.processCommandLine().then( () => {
connectionManagementService.verifyAll();
commandService.verifyAll();
done();
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
});
test('processCommandLine invokes a command with a profile parameter when a server is passed', done => {
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
const commandService : TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
const args : TestParsedArgs = new TestParsedArgs();
args.command = 'mycommand';
args.server = 'myserver';
environmentService.setup(e => e.args).returns(() => args);
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true).verifiable(TypeMoq.Times.atMostOnce());
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.is<ConnectionProfile>( p => p.serverName === 'myserver'), 'connection', true))
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
.verifiable(TypeMoq.Times.once());
commandService.setup(c => c.executeCommand('mycommand', TypeMoq.It.is<ConnectionProfile>( p => p.serverName === 'myserver')))
.returns(() => TPromise.wrap(1))
.verifiable(TypeMoq.Times.once());
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService, commandService.object);
service.processCommandLine().then( () => {
connectionManagementService.verifyAll();
commandService.verifyAll();
done();
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
});
test('processCommandLine rejects unknown commands', done => {
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
const commandService : TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
const args : TestParsedArgs = new TestParsedArgs();
args.command = 'mycommand';
environmentService.setup(e => e.args).returns(() => args);
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true);
commandService.setup(c => c.executeCommand('mycommand'))
.returns(() => TPromise.wrapError(new Error('myerror')))
.verifiable(TypeMoq.Times.once());
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService, commandService.object);
service.processCommandLine().then( () => {
assert.fail(1,null, 'processCommandLine should reject when executeCommand errors out');
done();
}, error => {
assert.equal(error.message, 'myerror', 'unexpected error from processCommandLine ' + error);
done();
});
});
});