adding task integration with wizard and dialog framework (#1929)

* adding task integration with wizard and dialog framework
This commit is contained in:
Leila Lali
2018-07-18 16:28:36 -07:00
committed by GitHub
parent e026ab85a7
commit 6680be6a73
20 changed files with 648 additions and 92 deletions

View File

@@ -0,0 +1,107 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as sqlops from 'sqlops';
import * as assert from 'assert';
import { Mock, It, Times } from 'typemoq';
import { ExtHostBackgroundTaskManagement, TaskStatus } from 'sql/workbench/api/node/extHostBackgroundTaskManagement';
import { MainThreadBackgroundTaskManagementShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
'use strict';
suite('ExtHostBackgroundTaskManagement Tests', () => {
let extHostBackgroundTaskManagement: ExtHostBackgroundTaskManagement;
let mockProxy: Mock<MainThreadBackgroundTaskManagementShape>;
let nothing: void;
let operationId = 'operation is';
setup(() => {
mockProxy = Mock.ofInstance(<MainThreadBackgroundTaskManagementShape>{
$registerTask: (taskInfo: sqlops.TaskInfo) => nothing,
$updateTask: (taskProgressInfo: sqlops.TaskProgressInfo) => nothing
});
let mainContext = <IMainContext>{
getProxy: proxyType => mockProxy.object
};
mockProxy.setup(x => x.$registerTask(It.isAny())).callback(() => {
extHostBackgroundTaskManagement.$onTaskRegistered(operationId);
});
extHostBackgroundTaskManagement = new ExtHostBackgroundTaskManagement(mainContext);
});
test('RegisterTask should successfully create background task and update status', () => {
let operationInfo: sqlops.BackgroundOperationInfo = {
connection: undefined,
description: 'description',
displayName: 'displayName',
isCancelable: true,
operation: (op: sqlops.BackgroundOperation) => { op.updateStatus(TaskStatus.Succeeded); },
operationId: operationId
};
extHostBackgroundTaskManagement.$registerTask(operationInfo);
mockProxy.verify(x => x.$registerTask(It.is(
t => t.name === operationInfo.displayName &&
t.description === operationInfo.description &&
t.taskId === operationId &&
t.isCancelable === operationInfo.isCancelable &&
t.providerName === undefined
)), Times.once());
mockProxy.verify(x => x.$updateTask(It.is(t => t.status === TaskStatus.Succeeded)), Times.once());
extHostBackgroundTaskManagement.$removeTask(operationId);
});
test('Canceling the task should notify the extension', () => {
let operationInfo: sqlops.BackgroundOperationInfo = {
connection: undefined,
description: 'description',
displayName: 'displayName',
isCancelable: true,
operation: (op: sqlops.BackgroundOperation) => {
op.onCanceled(() => {
op.updateStatus(TaskStatus.Canceled);
})
},
operationId: operationId
};
extHostBackgroundTaskManagement.$registerTask(operationInfo);
extHostBackgroundTaskManagement.$onTaskCanceled(operationId);
mockProxy.verify(x => x.$updateTask(It.is(t => t.status === TaskStatus.Canceled)), Times.once());
extHostBackgroundTaskManagement.$removeTask(operationId);
});
test('RegisterTask should assign unique id to the operation is not assigned', () => {
let operationInfo: sqlops.BackgroundOperationInfo = {
connection: undefined,
description: 'description',
displayName: 'displayName',
isCancelable: true,
operation: (op: sqlops.BackgroundOperation) => { op.updateStatus(TaskStatus.Succeeded); },
operationId: undefined
};
extHostBackgroundTaskManagement.$registerTask(operationInfo);
mockProxy.verify(x => x.$registerTask(It.is(t => t.taskId !== undefined)), Times.once());
extHostBackgroundTaskManagement.$removeTask(operationId);
});
test('RegisterTask should fail given id of an existing operation', () => {
let operationInfo: sqlops.BackgroundOperationInfo = {
connection: undefined,
description: 'description',
displayName: 'displayName',
isCancelable: true,
operation: (op: sqlops.BackgroundOperation) => { op.updateStatus(TaskStatus.Succeeded); },
operationId: operationId
};
extHostBackgroundTaskManagement.$registerTask(operationInfo);
mockProxy.verify(x => x.$registerTask(It.is(t => t.taskId === operationId)), Times.once());
assert.throws(() => extHostBackgroundTaskManagement.$registerTask(operationInfo));
extHostBackgroundTaskManagement.$removeTask(operationId);
});
});

View File

@@ -37,7 +37,7 @@ suite('ExtHostModelViewDialog Tests', () => {
extHostModelView = Mock.ofInstance(<ExtHostModelViewShape>{
$registerProvider: (widget, handler) => undefined
});
extHostModelViewDialog = new ExtHostModelViewDialog(mainContext, extHostModelView.object);
extHostModelViewDialog = new ExtHostModelViewDialog(mainContext, extHostModelView.object, undefined);
});
test('Creating a dialog returns a dialog with initialized ok and cancel buttons and the given title', () => {

View File

@@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as sqlops from 'sqlops';
import * as assert from 'assert';
import { Mock, It, Times } from 'typemoq';
import { MainThreadBackgroundTaskManagement, TaskStatus } from 'sql/workbench/api/node/mainThreadBackgroundTaskManagement';
import { ExtHostBackgroundTaskManagementShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { ITaskService } from 'sql/parts/taskHistory/common/taskService';
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import { TaskNode } from 'sql/parts/taskHistory/common/taskNode';
import { Event, Emitter } from 'vs/base/common/event';
'use strict';
suite('MainThreadBackgroundTaskManagement Tests', () => {
let mainThreadBackgroundTaskManagement: MainThreadBackgroundTaskManagement;
let mockProxy: Mock<ExtHostBackgroundTaskManagementShape>;
let taskService: Mock<ITaskService>;
let nothing: void;
let operationId = 'operation is';
let onTaskComplete = new Emitter<TaskNode>();
setup(() => {
mockProxy = Mock.ofInstance(<ExtHostBackgroundTaskManagementShape>{
$onTaskRegistered: (operationId: string) => nothing,
$onTaskCanceled: (operationId: string) => nothing,
$registerTask: (operationInfo: sqlops.BackgroundOperationInfo) => nothing,
$removeTask: (operationId: string) => nothing,
});
taskService = Mock.ofInstance(<ITaskService>{
_serviceBrand: undefined,
onTaskComplete: undefined,
onAddNewTask: undefined,
handleNewTask: undefined,
handleTaskComplete: undefined,
getAllTasks: undefined,
getNumberOfInProgressTasks: undefined,
onNewTaskCreated: undefined,
createNewTask: (taskInfo: sqlops.TaskInfo) => nothing,
updateTask: (taskProgressInfo: sqlops.TaskProgressInfo) => nothing,
onTaskStatusChanged: undefined,
cancelTask: undefined,
registerProvider: undefined
});
let mainContext = <IExtHostContext>{
getProxy: proxyType => mockProxy.object
};
taskService.setup(x => x.onTaskComplete).returns(() => onTaskComplete.event);
mainThreadBackgroundTaskManagement = new MainThreadBackgroundTaskManagement(mainContext, taskService.object);
});
test('RegisterTask should successfully create background task', () => {
let taskInfo: sqlops.TaskInfo = {
taskId: operationId,
databaseName: undefined,
description: undefined,
isCancelable: true,
name: 'task name',
providerName: undefined,
serverName: undefined,
status: TaskStatus.NotStarted,
taskExecutionMode: 0
};
mainThreadBackgroundTaskManagement.$registerTask(taskInfo);
taskService.verify(x => x.createNewTask(It.is(t => t.status === TaskStatus.NotStarted)), Times.once());
mockProxy.verify(x => x.$onTaskRegistered(operationId), Times.once());
});
test('UpdateTask should successfully update the background task status', () => {
let taskInfo: sqlops.TaskProgressInfo = {
taskId: operationId,
status: TaskStatus.InProgress,
message: undefined,
};
mainThreadBackgroundTaskManagement.$updateTask(taskInfo);
taskService.verify(x => x.updateTask(It.is(t => t.status === TaskStatus.InProgress)), Times.once());
});
test('Canceling the task should notify the proxy', () => {
let taskInfo: sqlops.TaskProgressInfo = {
taskId: operationId,
status: TaskStatus.InProgress,
message: undefined,
};
let taskNode = new TaskNode('', '', '', operationId, undefined);
taskNode.status = TaskStatus.Canceling;
onTaskComplete.fire(taskNode);
mainThreadBackgroundTaskManagement.$updateTask(taskInfo);
mockProxy.verify(x => x.$onTaskCanceled(It.is(t => t === operationId)), Times.once());
});
});