mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 02:58:31 -05:00
Split up NotebookProvider into separate providers for handling file serialization and cell execution. (#17176)
This commit is contained in:
@@ -22,14 +22,14 @@ import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { Separator } from 'vs/base/common/actions';
|
||||
import { INotebookModelOptions } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookEditorContentLoader } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ModelFactory } from 'sql/workbench/services/notebook/browser/models/modelFactory';
|
||||
import { CellTypes } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { nb } from 'azdata';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, SerializationManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
|
||||
suite('CellToolbarActions', function (): void {
|
||||
suite('removeDuplicatedAndStartingSeparators', function (): void {
|
||||
@@ -202,13 +202,14 @@ export async function createandLoadNotebookModel(codeContent?: nb.INotebookConte
|
||||
|
||||
let serviceCollection = new ServiceCollection();
|
||||
let instantiationService = new InstantiationService(serviceCollection, true);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(codeContent ? codeContent : defaultCodeContent));
|
||||
let defaultModelOptions: INotebookModelOptions = {
|
||||
notebookUri: URI.file('/some/path.ipynb'),
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers: [new NotebookManagerStub()],
|
||||
contentManager: mockContentManager.object,
|
||||
serializationManagers: [new SerializationManagerStub()],
|
||||
executeManagers: [new ExecuteManagerStub()],
|
||||
contentLoader: mockContentManager.object,
|
||||
notificationService: undefined,
|
||||
connectionService: undefined,
|
||||
providerId: 'SQL',
|
||||
|
||||
@@ -17,10 +17,11 @@ import { NodeStub, NotebookServiceStub } from 'sql/workbench/contrib/notebook/te
|
||||
import { basenameOrAuthority } from 'vs/base/common/resources';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { IExtensionService, NullExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { INotebookService, IProviderInfo } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { INotebookService, IProviderInfo, ISerializationManager } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { EditorInputCapabilities } from 'vs/workbench/common/editor';
|
||||
import { LocalContentManager } from 'sql/workbench/services/notebook/common/localContentManager';
|
||||
|
||||
suite('Notebook Input', function (): void {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
@@ -39,9 +40,14 @@ suite('Notebook Input', function (): void {
|
||||
name: 'TestName',
|
||||
displayName: 'TestDisplayName',
|
||||
connectionProviderIds: ['TestId'],
|
||||
notebookProvider: 'TestProvider'
|
||||
notebookProvider: testProvider
|
||||
}];
|
||||
});
|
||||
let testManager: ISerializationManager = {
|
||||
providerId: testProvider,
|
||||
contentManager: instantiationService.createInstance(LocalContentManager)
|
||||
};
|
||||
mockNotebookService.setup(s => s.getOrCreateSerializationManager(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(testManager));
|
||||
|
||||
(instantiationService as TestInstantiationService).stub(INotebookService, mockNotebookService.object);
|
||||
|
||||
@@ -87,11 +93,11 @@ suite('Notebook Input', function (): void {
|
||||
// Notebook URI
|
||||
assert.deepStrictEqual(untitledNotebookInput.notebookUri, untitledUri);
|
||||
|
||||
// Content Manager
|
||||
// Notebook editor timestamp
|
||||
assert.notStrictEqual(untitledNotebookInput.editorOpenedTimestamp, undefined);
|
||||
|
||||
// Notebook editor timestamp
|
||||
assert.notStrictEqual(untitledNotebookInput.contentManager, undefined);
|
||||
// Content Loader
|
||||
assert.notStrictEqual(untitledNotebookInput.contentLoader, undefined);
|
||||
|
||||
// Layout changed event
|
||||
assert.notStrictEqual(untitledNotebookInput.layoutChanged, undefined);
|
||||
|
||||
@@ -12,10 +12,10 @@ import { NotebookModelStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { NotebookEditorStub } from 'sql/workbench/contrib/notebook/test/testCommon';
|
||||
import { notebookConstants } from 'sql/workbench/services/notebook/browser/interfaces';
|
||||
import { ICellModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { INavigationProvider, INotebookEditor, INotebookManager, INotebookParams, INotebookProvider, NavigationProviders, SQL_NOTEBOOK_PROVIDER, unsavedBooksContextKey } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { FailToSaveTrustState, NotebookService, NotebookServiceNoProviderRegistered, NotebookUriNotDefined, ProviderDescriptor } from 'sql/workbench/services/notebook/browser/notebookServiceImpl';
|
||||
import { INavigationProvider, INotebookEditor, IExecuteManager, INotebookParams, IExecuteProvider, NavigationProviders, SQL_NOTEBOOK_PROVIDER, unsavedBooksContextKey, ISerializationProvider, ISerializationManager } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { FailToSaveTrustState, NotebookService, NotebookServiceNoProviderRegistered, NotebookUriNotDefined, ExecuteProviderDescriptor, SerializationProviderDescriptor } from 'sql/workbench/services/notebook/browser/notebookServiceImpl';
|
||||
import { NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { Extensions, INotebookProviderRegistry, NotebookProviderRegistration } from 'sql/workbench/services/notebook/common/notebookRegistry';
|
||||
import { INotebookProviderRegistry, NotebookProviderRegistryId, ProviderDescriptionRegistration } from 'sql/workbench/services/notebook/common/notebookRegistry';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { errorHandler, onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
@@ -36,9 +36,15 @@ import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/commo
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
|
||||
/**
|
||||
* class to mock azdata.nb.ServerManager object
|
||||
*/
|
||||
class TestContentManager implements azdata.nb.ContentManager {
|
||||
deserializeNotebook(contents: string): Thenable<azdata.nb.INotebookContents> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
serializeNotebook(notebook: azdata.nb.INotebookContents): Thenable<string> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
|
||||
class TestServerManager implements azdata.nb.ServerManager {
|
||||
isStarted: boolean = true; //by default our mock creates ServerManager in started mode.
|
||||
onServerStarted: Event<void>;
|
||||
@@ -48,14 +54,16 @@ class TestServerManager implements azdata.nb.ServerManager {
|
||||
async stopServer(): Promise<void> {
|
||||
this.isStarted = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TestNotebookManager - creates a NotebookManager object that helps keep track of state needed by testing
|
||||
*/
|
||||
class TestNotebookManager implements INotebookManager {
|
||||
contentManager: undefined;
|
||||
class TestSerializationManager implements ISerializationManager {
|
||||
constructor(
|
||||
public providerId: string = 'providerId1',
|
||||
public contentManager: TestContentManager = new TestContentManager()
|
||||
) { }
|
||||
}
|
||||
|
||||
class TestExecuteManager implements IExecuteManager {
|
||||
sessionManager: undefined;
|
||||
constructor(
|
||||
public providerId: string = 'providerId1',
|
||||
@@ -63,16 +71,24 @@ class TestNotebookManager implements INotebookManager {
|
||||
) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* * TestNotebookProvider - creates a NotebookManager object that helps keep track of state needed by testing
|
||||
*/
|
||||
class TestNotebookProvider implements INotebookProvider {
|
||||
class TestSerializationProvider implements ISerializationProvider {
|
||||
constructor(
|
||||
public providerId: string = 'providerId1',
|
||||
public manager: TestNotebookManager = new TestNotebookManager(providerId)
|
||||
public manager: TestSerializationManager = new TestSerializationManager(providerId)
|
||||
) { }
|
||||
|
||||
getNotebookManager(uri: URI): Thenable<INotebookManager> {
|
||||
getSerializationManager(notebookUri: URI): Thenable<ISerializationManager> {
|
||||
return Promise.resolve(this.manager);
|
||||
}
|
||||
}
|
||||
|
||||
class TestExecuteProvider implements IExecuteProvider {
|
||||
constructor(
|
||||
public providerId: string = 'providerId1',
|
||||
public manager: TestExecuteManager = new TestExecuteManager(providerId)
|
||||
) { }
|
||||
|
||||
getExecuteManager(uri: URI): Thenable<IExecuteManager> {
|
||||
return Promise.resolve(this.manager);
|
||||
}
|
||||
|
||||
@@ -82,9 +98,11 @@ class TestNotebookProvider implements INotebookProvider {
|
||||
}
|
||||
|
||||
suite('ProviderDescriptor:', () => {
|
||||
test('Verifies varies getter setters of Provider Descriptor', async () => {
|
||||
const notebookProvider = <INotebookProvider>{};
|
||||
const providerDescriptor = new ProviderDescriptor(notebookProvider);
|
||||
test('Verifies various getters & setters for Serialization Provider Descriptor', async () => {
|
||||
const providerId = 'TestId';
|
||||
const notebookProvider = <ISerializationProvider>{};
|
||||
const providerDescriptor = new SerializationProviderDescriptor(providerId, notebookProvider);
|
||||
assert.strictEqual(providerDescriptor.providerId, providerId, 'providerDescriptor providerId should return correct provider ID');
|
||||
assert.strictEqual(providerDescriptor.instance, notebookProvider, `providerDescriptor instance should be the value passed into the constructor`);
|
||||
const providerInstancePromise = providerDescriptor.instanceReady;
|
||||
assert.notStrictEqual(providerInstancePromise, undefined, `providerDescriptor instanceReady should not return an undefined promise object`);
|
||||
@@ -92,9 +110,26 @@ suite('ProviderDescriptor:', () => {
|
||||
assert.strictEqual(result, notebookProvider, `instanceReady property of the providerDescriptor should resolve with notebookProvider object that it was constructed with`);
|
||||
|
||||
providerDescriptor.instance = undefined;
|
||||
assert.strictEqual(providerDescriptor.instance, undefined, `provider.Descriptor instance should be undefined when we set it explicitly to undefined`);
|
||||
assert.strictEqual(providerDescriptor.instance, undefined, `providerDescriptor instance should be undefined when we set it explicitly to undefined`);
|
||||
providerDescriptor.instance = notebookProvider;
|
||||
assert.strictEqual(providerDescriptor.instance, notebookProvider, `provider.Descriptor instance should be instance: ${notebookProvider} that we explicitly set it to`);
|
||||
assert.strictEqual(providerDescriptor.instance, notebookProvider, `providerDescriptor instance should be instance: ${notebookProvider} that we explicitly set it to`);
|
||||
});
|
||||
|
||||
test('Verifies various getters & setters for Execute Provider Descriptor', async () => {
|
||||
const providerId = 'TestId';
|
||||
const notebookProvider = <IExecuteProvider>{};
|
||||
const providerDescriptor = new ExecuteProviderDescriptor(providerId, notebookProvider);
|
||||
assert.strictEqual(providerDescriptor.providerId, providerId, 'providerDescriptor providerId should return correct provider ID');
|
||||
assert.strictEqual(providerDescriptor.instance, notebookProvider, `providerDescriptor instance should be the value passed into the constructor`);
|
||||
const providerInstancePromise = providerDescriptor.instanceReady;
|
||||
assert.notStrictEqual(providerInstancePromise, undefined, `providerDescriptor instanceReady should not return an undefined promise object`);
|
||||
const result = await providerInstancePromise;
|
||||
assert.strictEqual(result, notebookProvider, `instanceReady property of the providerDescriptor should resolve with notebookProvider object that it was constructed with`);
|
||||
|
||||
providerDescriptor.instance = undefined;
|
||||
assert.strictEqual(providerDescriptor.instance, undefined, `providerDescriptor instance should be undefined when we set it explicitly to undefined`);
|
||||
providerDescriptor.instance = notebookProvider;
|
||||
assert.strictEqual(providerDescriptor.instance, notebookProvider, `providerDescriptor instance should be instance: ${notebookProvider} that we explicitly set it to`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -198,7 +233,7 @@ suite.skip('NotebookService:', function (): void {
|
||||
await notebookService.registrationComplete;
|
||||
assert.deepStrictEqual(notebookService.getProvidersForFileType('ipynb'), ['sql'], 'sql provider should be registered for ipynb extension');
|
||||
|
||||
const otherProviderRegistration: NotebookProviderRegistration = {
|
||||
const otherProviderRegistration: ProviderDescriptionRegistration = {
|
||||
fileExtensions: 'ipynb',
|
||||
standardKernels: {
|
||||
name: 'kernel1',
|
||||
@@ -208,8 +243,8 @@ suite.skip('NotebookService:', function (): void {
|
||||
provider: 'otherProvider'
|
||||
};
|
||||
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(Extensions.NotebookProviderContribution);
|
||||
notebookRegistry.registerNotebookProvider(otherProviderRegistration);
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(NotebookProviderRegistryId);
|
||||
notebookRegistry.registerProviderDescription(otherProviderRegistration);
|
||||
|
||||
assert.deepStrictEqual(notebookService.getProvidersForFileType('ipynb'), ['sql', 'otherProvider'], 'otherProvider should also be registered for ipynb extension');
|
||||
assert.deepStrictEqual(notebookService.getSupportedFileExtensions(), ['IPYNB'], 'Only IPYNB should be registered as supported file extension');
|
||||
@@ -223,10 +258,10 @@ suite.skip('NotebookService:', function (): void {
|
||||
assert.strictEqual(notebookService['_store']['_isDisposed'], true, `underlying disposable store object should be disposed state`);
|
||||
});
|
||||
|
||||
test('verify that getOrCreateNotebookManager does not throw when extensionService.whenInstalledExtensionRegistered() throws', async () => {
|
||||
test('verify that getOrCreateSerializationManager does not throw when extensionService.whenInstalledExtensionRegistered() throws', async () => {
|
||||
const providerId = 'providerId1';
|
||||
createRegisteredProviderWithManager({ notebookService, providerId });
|
||||
notebookService.registerProvider(providerId, undefined);
|
||||
createExecuteProviderWithManager({ notebookService, providerId });
|
||||
notebookService.registerSerializationProvider(providerId, undefined);
|
||||
//verify method under test logs error and does not throw when extensionService.whenInstalledExtensionRegistered() throws
|
||||
const error: Error = new Error('Extension Registration Failed');
|
||||
extensionServiceMock.setup(x => x.whenInstalledExtensionsRegistered()).throws(error);
|
||||
@@ -236,18 +271,34 @@ suite.skip('NotebookService:', function (): void {
|
||||
assert.strictEqual(_error, error, `error object passed to logService.error call must be the one thrown from whenInstalledExtensionsRegistered call`);
|
||||
})
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
await notebookService.getOrCreateNotebookManager(providerId, URI.parse('untitled:uri1'));
|
||||
await notebookService.getOrCreateSerializationManager(providerId, URI.parse('untitled:uri1'));
|
||||
logServiceMock.verifyAll();
|
||||
});
|
||||
|
||||
test('verify that getOrCreateExecuteManager does not throw when extensionService.whenInstalledExtensionRegistered() throws', async () => {
|
||||
const providerId = 'providerId1';
|
||||
createExecuteProviderWithManager({ notebookService, providerId });
|
||||
notebookService.registerExecuteProvider(providerId, undefined);
|
||||
//verify method under test logs error and does not throw when extensionService.whenInstalledExtensionRegistered() throws
|
||||
const error: Error = new Error('Extension Registration Failed');
|
||||
extensionServiceMock.setup(x => x.whenInstalledExtensionsRegistered()).throws(error);
|
||||
|
||||
test('verify that getOrCreateNotebookManager throws when no providers are registered', async () => {
|
||||
const methodName = 'getOrCreateNotebookManager';
|
||||
logServiceMock.setup(x => x.error(TypeMoq.It.isAny()))
|
||||
.returns((_error: string | Error, ...args: any[]) => {
|
||||
assert.strictEqual(_error, error, `error object passed to logService.error call must be the one thrown from whenInstalledExtensionsRegistered call`);
|
||||
})
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
await notebookService.getOrCreateExecuteManager(providerId, URI.parse('untitled:uri1'));
|
||||
logServiceMock.verifyAll();
|
||||
});
|
||||
|
||||
test('verify that getOrCreateSerializationManager throws when no providers are registered', async () => {
|
||||
const methodName = 'getOrCreateSerializationManager';
|
||||
|
||||
// register the builtin sql provider to be undefined
|
||||
notebookService.registerProvider(SQL_NOTEBOOK_PROVIDER, undefined);
|
||||
notebookService.registerSerializationProvider(SQL_NOTEBOOK_PROVIDER, undefined);
|
||||
try {
|
||||
await notebookService.getOrCreateNotebookManager('test', URI.parse('untitled:uri1'));
|
||||
await notebookService.getOrCreateSerializationManager('test', URI.parse('untitled:uri1'));
|
||||
throw Error(`${methodName} did not throw as was expected`);
|
||||
} catch (error) {
|
||||
assert.strictEqual((error as Error).message, NotebookServiceNoProviderRegistered, `${methodName} should throw error with message:${NotebookServiceNoProviderRegistered}' when no providers are registered`);
|
||||
@@ -256,7 +307,29 @@ suite.skip('NotebookService:', function (): void {
|
||||
// when even the default provider is not registered, method under test throws exception
|
||||
unRegisterProviders(notebookService);
|
||||
try {
|
||||
await notebookService.getOrCreateNotebookManager(SQL_NOTEBOOK_PROVIDER, URI.parse('untitled:uri1'));
|
||||
await notebookService.getOrCreateSerializationManager(SQL_NOTEBOOK_PROVIDER, URI.parse('untitled:uri1'));
|
||||
throw Error(`${methodName} did not throw as was expected`);
|
||||
} catch (error) {
|
||||
assert.strictEqual((error as Error).message, NotebookServiceNoProviderRegistered, `${methodName} should throw error with message:${NotebookServiceNoProviderRegistered}' when no providers are registered`);
|
||||
}
|
||||
});
|
||||
|
||||
test('verify that getOrCreateExecuteManager throws when no providers are registered', async () => {
|
||||
const methodName = 'getOrCreateExecuteManager';
|
||||
|
||||
// register the builtin sql provider to be undefined
|
||||
notebookService.registerExecuteProvider(SQL_NOTEBOOK_PROVIDER, undefined);
|
||||
try {
|
||||
await notebookService.getOrCreateExecuteManager('test', URI.parse('untitled:uri1'));
|
||||
throw Error(`${methodName} did not throw as was expected`);
|
||||
} catch (error) {
|
||||
assert.strictEqual((error as Error).message, NotebookServiceNoProviderRegistered, `${methodName} should throw error with message:${NotebookServiceNoProviderRegistered}' when no providers are registered`);
|
||||
}
|
||||
|
||||
// when even the default provider is not registered, method under test throws exception
|
||||
unRegisterProviders(notebookService);
|
||||
try {
|
||||
await notebookService.getOrCreateExecuteManager(SQL_NOTEBOOK_PROVIDER, URI.parse('untitled:uri1'));
|
||||
throw Error(`${methodName} did not throw as was expected`);
|
||||
} catch (error) {
|
||||
assert.strictEqual((error as Error).message, NotebookServiceNoProviderRegistered, `${methodName} should throw error with message:${NotebookServiceNoProviderRegistered}' when no providers are registered`);
|
||||
@@ -282,27 +355,50 @@ suite.skip('NotebookService:', function (): void {
|
||||
assert.strictEqual(result, provider1, `${methodName} must return the provider that we registered with netbookService for the provider id: ${provider1.providerId}`);
|
||||
});
|
||||
|
||||
test('verifies return value of getOrCreateNotebookManager', async () => {
|
||||
test('verifies return value of getOrCreateSerializationManager', async () => {
|
||||
await notebookService.registrationComplete;
|
||||
try {
|
||||
await notebookService.getOrCreateNotebookManager(SQL_NOTEBOOK_PROVIDER, undefined);
|
||||
await notebookService.getOrCreateSerializationManager(SQL_NOTEBOOK_PROVIDER, undefined);
|
||||
throw new Error('expected exception was not thrown');
|
||||
} catch (error) {
|
||||
assert.strictEqual((error as Error).message, NotebookUriNotDefined, `getOrCreateNotebookManager must throw with UriNotDefined error, when a valid uri is not provided`);
|
||||
assert.strictEqual((error as Error).message, NotebookUriNotDefined, `getOrCreateSerializationManager must throw with UriNotDefined error, when a valid uri is not provided`);
|
||||
}
|
||||
const provider1Id = SQL_NOTEBOOK_PROVIDER;
|
||||
const { providerId: provider2Id, manager: provider2Manager } = createRegisteredProviderWithManager({ providerId: 'provider2Id', notebookService });
|
||||
const { providerId: provider2Id, manager: provider2Manager } = createExecuteProviderWithManager({ providerId: 'provider2Id', notebookService });
|
||||
|
||||
const uri1: URI = URI.parse(`untitled:test1`);
|
||||
const uri2: URI = URI.parse(`untitled:test2`);
|
||||
const result1 = await notebookService.getOrCreateNotebookManager(provider1Id, uri1);
|
||||
const result2 = await notebookService.getOrCreateNotebookManager(provider2Id, uri2);
|
||||
const result1Again = await notebookService.getOrCreateNotebookManager(provider1Id, uri1);
|
||||
assert.strictEqual(result2, provider2Manager, `the notebook manager for the provider must be the one returned by getNotebookManager of the provider`);
|
||||
assert.notStrictEqual(result1, result2, `different notebookManagers should be returned for different uris`);
|
||||
assert.strictEqual(result1, result1Again, `same notebookManagers should be returned for same uri for builtin providers`);
|
||||
const result2Again = await notebookService.getOrCreateNotebookManager(provider2Id, uri2);
|
||||
assert.strictEqual(result2, result2Again, `same notebookManagers should be returned for same uri for custom providers`);
|
||||
const result1 = await notebookService.getOrCreateSerializationManager(provider1Id, uri1);
|
||||
const result2 = await notebookService.getOrCreateSerializationManager(provider2Id, uri2);
|
||||
const result1Again = await notebookService.getOrCreateSerializationManager(provider1Id, uri1);
|
||||
assert.strictEqual(result2, provider2Manager, `the serialization manager for the provider must be the one returned by getSerializationManager of the provider`);
|
||||
assert.notStrictEqual(result1, result2, `different serialization managers should be returned for different uris`);
|
||||
assert.strictEqual(result1, result1Again, `same serialization managers should be returned for same uri for builtin providers`);
|
||||
const result2Again = await notebookService.getOrCreateSerializationManager(provider2Id, uri2);
|
||||
assert.strictEqual(result2, result2Again, `same serialization managers should be returned for same uri for custom providers`);
|
||||
});
|
||||
|
||||
test('verifies return value of getOrCreateExecuteManager', async () => {
|
||||
await notebookService.registrationComplete;
|
||||
try {
|
||||
await notebookService.getOrCreateExecuteManager(SQL_NOTEBOOK_PROVIDER, undefined);
|
||||
throw new Error('expected exception was not thrown');
|
||||
} catch (error) {
|
||||
assert.strictEqual((error as Error).message, NotebookUriNotDefined, `getOrCreateExecuteManager must throw with UriNotDefined error, when a valid uri is not provided`);
|
||||
}
|
||||
const provider1Id = SQL_NOTEBOOK_PROVIDER;
|
||||
const { providerId: provider2Id, manager: provider2Manager } = createExecuteProviderWithManager({ providerId: 'provider2Id', notebookService });
|
||||
|
||||
const uri1: URI = URI.parse(`untitled:test1`);
|
||||
const uri2: URI = URI.parse(`untitled:test2`);
|
||||
const result1 = await notebookService.getOrCreateExecuteManager(provider1Id, uri1);
|
||||
const result2 = await notebookService.getOrCreateExecuteManager(provider2Id, uri2);
|
||||
const result1Again = await notebookService.getOrCreateExecuteManager(provider1Id, uri1);
|
||||
assert.strictEqual(result2, provider2Manager, `the execute manager for the provider must be the one returned by getExecuteManager of the provider`);
|
||||
assert.notStrictEqual(result1, result2, `different execute managers should be returned for different uris`);
|
||||
assert.strictEqual(result1, result1Again, `same execute managers should be returned for same uri for builtin providers`);
|
||||
const result2Again = await notebookService.getOrCreateExecuteManager(provider2Id, uri2);
|
||||
assert.strictEqual(result2, result2Again, `same execute managers should be returned for same uri for custom providers`);
|
||||
});
|
||||
|
||||
test('verifies add/remove/find/list/renameNotebookEditor methods and corresponding events', async () => {
|
||||
@@ -360,24 +456,43 @@ suite.skip('NotebookService:', function (): void {
|
||||
assert.strictEqual(editorsRemoved, 1, `onNotebookEditorRemove should have been called that increments editorsRemoved value`);
|
||||
});
|
||||
|
||||
test('test registration of a new provider with multiple filetypes & kernels and verify that corresponding manager is returned by getOrCreateNotebookManager', async () => {
|
||||
test('test registration of a new serialization provider with multiple filetypes & kernels and verify that corresponding manager is returned by getOrCreateSerializationManager methods', async () => {
|
||||
const providerId = 'Jpeg';
|
||||
const notebookProviderRegistration = <NotebookProviderRegistration>{
|
||||
const notebookProviderRegistration = <ProviderDescriptionRegistration>{
|
||||
provider: providerId,
|
||||
fileExtensions: ['jpeg', 'jpg'],
|
||||
standardKernels: [<azdata.nb.IStandardKernel>{ name: 'kernel1' }, <azdata.nb.IStandardKernel>{ name: 'kernel2' }]
|
||||
};
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(Extensions.NotebookProviderContribution);
|
||||
notebookRegistry.registerNotebookProvider(notebookProviderRegistration);
|
||||
const managerPromise = notebookService.getOrCreateNotebookManager(providerId, URI.parse('untitled:jpg'));
|
||||
const providerInstance = createRegisteredProviderWithManager({ notebookService, providerId });
|
||||
notebookService.registerProvider(providerId, providerInstance);
|
||||
const result = await managerPromise;
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(NotebookProviderRegistryId);
|
||||
notebookRegistry.registerProviderDescription(notebookProviderRegistration);
|
||||
|
||||
const serializationManagerPromise = notebookService.getOrCreateSerializationManager(providerId, URI.parse('untitled:jpg'));
|
||||
const serializationProviderInstance = createSerializationProviderWithManager({ notebookService, providerId });
|
||||
notebookService.registerSerializationProvider(providerId, serializationProviderInstance);
|
||||
const serializationResult = await serializationManagerPromise;
|
||||
|
||||
// verify result
|
||||
assert.strictEqual(result, providerInstance.manager, `createRegisteredProviderWithManager must return the manager corresponding to INotebookProvider that we registered`);
|
||||
assert.strictEqual(serializationResult, serializationProviderInstance.manager, `createSerializationProviderWithManager must return the serialization manager corresponding to ISerializationProvider that we registered`);
|
||||
});
|
||||
|
||||
test('test registration of a new execute provider with multiple filetypes & kernels and verify that corresponding manager is returned by getOrCreateExecuteManager methods', async () => {
|
||||
const providerId = 'Jpeg';
|
||||
const notebookProviderRegistration = <ProviderDescriptionRegistration>{
|
||||
provider: providerId,
|
||||
fileExtensions: ['jpeg', 'jpg'],
|
||||
standardKernels: [<azdata.nb.IStandardKernel>{ name: 'kernel1' }, <azdata.nb.IStandardKernel>{ name: 'kernel2' }]
|
||||
};
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(NotebookProviderRegistryId);
|
||||
notebookRegistry.registerProviderDescription(notebookProviderRegistration);
|
||||
|
||||
const executeManagerPromise = notebookService.getOrCreateExecuteManager(providerId, URI.parse('untitled:jpg'));
|
||||
const executeProviderInstance = createExecuteProviderWithManager({ notebookService, providerId });
|
||||
notebookService.registerExecuteProvider(providerId, executeProviderInstance);
|
||||
const executeResult = await executeManagerPromise;
|
||||
|
||||
// verify result
|
||||
assert.strictEqual(executeResult, executeProviderInstance.manager, `createExecuteProviderWithManager must return the execute manager corresponding to IExecuteProvider that we registered`);
|
||||
});
|
||||
|
||||
test('verify that firing of extensionService.onDidUninstallExtension event calls removeContributedProvidersFromCache', async () => {
|
||||
const methodName = 'removeContributedProvidersFromCache';
|
||||
@@ -480,7 +595,7 @@ suite.skip('NotebookService:', function (): void {
|
||||
}
|
||||
});
|
||||
|
||||
suite(`serialization tests`, () => {
|
||||
suite(`serialization state tests`, () => {
|
||||
for (const isTrusted of [true, false, undefined]) {
|
||||
for (const isModelTrusted of [true, false]) {
|
||||
if (isTrusted !== undefined && !isModelTrusted) {
|
||||
@@ -576,10 +691,11 @@ suite.skip('NotebookService:', function (): void {
|
||||
});
|
||||
|
||||
function unRegisterProviders(notebookService: NotebookService) {
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(Extensions.NotebookProviderContribution);
|
||||
const notebookRegistry = Registry.as<INotebookProviderRegistry>(NotebookProviderRegistryId);
|
||||
// unregister all builtin providers
|
||||
for (const providerContribution of notebookRegistry.providers) {
|
||||
notebookService.unregisterProvider(providerContribution.provider);
|
||||
for (const providerContribution of notebookRegistry.providerDescriptions) {
|
||||
notebookService.unregisterSerializationProvider(providerContribution.provider);
|
||||
notebookService.unregisterExecuteProvider(providerContribution.provider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,21 +711,32 @@ function setTrustedSetup(notebookService: NotebookService) {
|
||||
return notebookUri;
|
||||
}
|
||||
|
||||
function createRegisteredProviderWithManager({ notebookService, providerId = 'providerId', testProviderManagers = undefined }: { providerId?: string; notebookService: NotebookService; testProviderManagers?: TestNotebookProvider[] }): TestNotebookProvider {
|
||||
const provider = new TestNotebookProvider(providerId);
|
||||
notebookService.registerProvider(providerId, provider);
|
||||
function createSerializationProviderWithManager({ notebookService, providerId = 'providerId', testProviderManagers = undefined }: { providerId?: string; notebookService: NotebookService; testProviderManagers?: TestSerializationProvider[] }): TestSerializationProvider {
|
||||
const provider = new TestSerializationProvider(providerId);
|
||||
notebookService.registerSerializationProvider(providerId, provider);
|
||||
if (testProviderManagers !== undefined) {
|
||||
testProviderManagers.push(provider);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
async function addManagers({ notebookService, prefix = 'providerId', uriPrefix = 'id', count = 1 }: { notebookService: NotebookService; prefix?: string; uriPrefix?: string; count?: number; }): Promise<TestNotebookProvider[]> {
|
||||
function createExecuteProviderWithManager({ notebookService, providerId = 'providerId', testProviderManagers = undefined }: { providerId?: string; notebookService: NotebookService; testProviderManagers?: TestExecuteProvider[] }): TestExecuteProvider {
|
||||
const provider = new TestExecuteProvider(providerId);
|
||||
notebookService.registerExecuteProvider(providerId, provider);
|
||||
if (testProviderManagers !== undefined) {
|
||||
testProviderManagers.push(provider);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
async function addManagers({ notebookService, prefix = 'providerId', uriPrefix = 'id', count = 1 }: { notebookService: NotebookService; prefix?: string; uriPrefix?: string; count?: number; }): Promise<TestExecuteProvider[]> {
|
||||
const testProviderManagers = [];
|
||||
for (let i: number = 1; i <= count; i++) {
|
||||
const providerId = `${prefix}${i}`;
|
||||
createRegisteredProviderWithManager({ providerId, notebookService, testProviderManagers });
|
||||
await notebookService.getOrCreateNotebookManager(providerId, URI.parse(`${uriPrefix}${i}`));
|
||||
createSerializationProviderWithManager({ providerId, notebookService, testProviderManagers });
|
||||
createExecuteProviderWithManager({ providerId, notebookService, testProviderManagers });
|
||||
await notebookService.getOrCreateSerializationManager(providerId, URI.parse(`${uriPrefix}${i}`));
|
||||
await notebookService.getOrCreateExecuteManager(providerId, URI.parse(`${uriPrefix}${i}`));
|
||||
}
|
||||
return testProviderManagers;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, SerializationManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
import { ModelFactory } from 'sql/workbench/services/notebook/browser/models/modelFactory';
|
||||
import { INotebookModelOptions } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
@@ -24,7 +24,7 @@ import { InstantiationService } from 'vs/platform/instantiation/common/instantia
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
|
||||
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookEditorContentLoader } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { SessionManager } from 'sql/workbench/contrib/notebook/test/emptySessionClasses';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
import { CellTypes } from 'sql/workbench/services/notebook/common/contracts';
|
||||
@@ -79,7 +79,8 @@ let configurationService: IConfigurationService;
|
||||
|
||||
suite('NotebookViewModel', function (): void {
|
||||
let defaultViewName = 'Default New View';
|
||||
let notebookManagers = [new NotebookManagerStub()];
|
||||
let serializationManagers = [new SerializationManagerStub()];
|
||||
let executeManagers = [new ExecuteManagerStub()];
|
||||
let mockSessionManager: TypeMoq.Mock<nb.SessionManager>;
|
||||
let memento: TypeMoq.Mock<Memento>;
|
||||
let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>;
|
||||
@@ -239,7 +240,7 @@ suite('NotebookViewModel', function (): void {
|
||||
|
||||
function setupServices() {
|
||||
mockSessionManager = TypeMoq.Mock.ofType(SessionManager);
|
||||
notebookManagers[0].sessionManager = mockSessionManager.object;
|
||||
executeManagers[0].sessionManager = mockSessionManager.object;
|
||||
notificationService = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService, TypeMoq.MockBehavior.Loose);
|
||||
capabilitiesService = TypeMoq.Mock.ofType<ICapabilitiesService>(TestCapabilitiesService);
|
||||
memento = TypeMoq.Mock.ofType(Memento, TypeMoq.MockBehavior.Loose, '');
|
||||
@@ -252,8 +253,9 @@ suite('NotebookViewModel', function (): void {
|
||||
defaultModelOptions = {
|
||||
notebookUri: defaultUri,
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers,
|
||||
contentManager: undefined,
|
||||
serializationManagers: serializationManagers,
|
||||
executeManagers: executeManagers,
|
||||
contentLoader: undefined,
|
||||
notificationService: notificationService.object,
|
||||
connectionService: queryConnectionService.object,
|
||||
providerId: 'SQL',
|
||||
@@ -265,9 +267,9 @@ suite('NotebookViewModel', function (): void {
|
||||
}
|
||||
|
||||
async function initializeNotebookViewsExtension(contents: nb.INotebookContents): Promise<NotebookViewsExtension> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
|
||||
@@ -8,10 +8,10 @@ import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilit
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookEditorContentLoader } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { DeleteViewAction, InsertCellAction } from 'sql/workbench/contrib/notebook/browser/notebookViews/notebookViewsActions';
|
||||
import { SessionManager } from 'sql/workbench/contrib/notebook/test/emptySessionClasses';
|
||||
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, SerializationManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ModelFactory } from 'sql/workbench/services/notebook/browser/models/modelFactory';
|
||||
import { ICellModel, INotebookModelOptions, ViewMode } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
@@ -58,7 +58,8 @@ let initialNotebookContent: nb.INotebookContents = {
|
||||
|
||||
suite('Notebook Views Actions', function (): void {
|
||||
let defaultViewName = 'Default New View';
|
||||
let notebookManagers = [new NotebookManagerStub()];
|
||||
let serializationManagers = [new SerializationManagerStub()];
|
||||
let executeManagers = [new ExecuteManagerStub()];
|
||||
let mockSessionManager: TypeMoq.Mock<nb.SessionManager>;
|
||||
let memento: TypeMoq.Mock<Memento>;
|
||||
let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>;
|
||||
@@ -164,7 +165,7 @@ suite('Notebook Views Actions', function (): void {
|
||||
|
||||
function setupServices() {
|
||||
mockSessionManager = TypeMoq.Mock.ofType(SessionManager);
|
||||
notebookManagers[0].sessionManager = mockSessionManager.object;
|
||||
executeManagers[0].sessionManager = mockSessionManager.object;
|
||||
notificationService = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService, TypeMoq.MockBehavior.Loose);
|
||||
capabilitiesService = TypeMoq.Mock.ofType<ICapabilitiesService>(TestCapabilitiesService);
|
||||
memento = TypeMoq.Mock.ofType(Memento, TypeMoq.MockBehavior.Loose, '');
|
||||
@@ -177,8 +178,9 @@ suite('Notebook Views Actions', function (): void {
|
||||
defaultModelOptions = {
|
||||
notebookUri: defaultUri,
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers,
|
||||
contentManager: undefined,
|
||||
serializationManagers: serializationManagers,
|
||||
executeManagers: executeManagers,
|
||||
contentLoader: undefined,
|
||||
notificationService: notificationService.object,
|
||||
connectionService: queryConnectionService.object,
|
||||
providerId: 'SQL',
|
||||
@@ -190,9 +192,9 @@ suite('Notebook Views Actions', function (): void {
|
||||
}
|
||||
|
||||
async function initializeNotebookViewsExtension(contents: nb.INotebookContents): Promise<NotebookViewsExtension> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
|
||||
@@ -11,7 +11,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, SerializationManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
import { ModelFactory } from 'sql/workbench/services/notebook/browser/models/modelFactory';
|
||||
import { INotebookModelOptions } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
@@ -24,7 +24,7 @@ import { InstantiationService } from 'vs/platform/instantiation/common/instantia
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
|
||||
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookEditorContentLoader } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { SessionManager } from 'sql/workbench/contrib/notebook/test/emptySessionClasses';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
import { CellTypes } from 'sql/workbench/services/notebook/common/contracts';
|
||||
@@ -62,7 +62,8 @@ let configurationService: IConfigurationService;
|
||||
|
||||
suite('NotebookViews', function (): void {
|
||||
let defaultViewName = 'Default New View';
|
||||
let notebookManagers = [new NotebookManagerStub()];
|
||||
let serializationManagers = [new SerializationManagerStub()];
|
||||
let executeManagers = [new ExecuteManagerStub()];
|
||||
let mockSessionManager: TypeMoq.Mock<nb.SessionManager>;
|
||||
let memento: TypeMoq.Mock<Memento>;
|
||||
let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>;
|
||||
@@ -131,7 +132,7 @@ suite('NotebookViews', function (): void {
|
||||
|
||||
function setupServices() {
|
||||
mockSessionManager = TypeMoq.Mock.ofType(SessionManager);
|
||||
notebookManagers[0].sessionManager = mockSessionManager.object;
|
||||
executeManagers[0].sessionManager = mockSessionManager.object;
|
||||
notificationService = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService, TypeMoq.MockBehavior.Loose);
|
||||
capabilitiesService = TypeMoq.Mock.ofType<ICapabilitiesService>(TestCapabilitiesService);
|
||||
memento = TypeMoq.Mock.ofType(Memento, TypeMoq.MockBehavior.Loose, '');
|
||||
@@ -144,8 +145,9 @@ suite('NotebookViews', function (): void {
|
||||
defaultModelOptions = {
|
||||
notebookUri: defaultUri,
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers,
|
||||
contentManager: undefined,
|
||||
serializationManagers: serializationManagers,
|
||||
executeManagers: executeManagers,
|
||||
contentLoader: undefined,
|
||||
notificationService: notificationService.object,
|
||||
connectionService: queryConnectionService.object,
|
||||
providerId: 'SQL',
|
||||
@@ -157,9 +159,9 @@ suite('NotebookViews', function (): void {
|
||||
}
|
||||
|
||||
async function initializeExtension(): Promise<NotebookViewsExtension> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(initialNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
|
||||
@@ -13,12 +13,12 @@ import { URI } from 'vs/base/common/uri';
|
||||
|
||||
import { ClientSession } from 'sql/workbench/services/notebook/browser/models/clientSession';
|
||||
import { SessionManager, EmptySession } from 'sql/workbench/contrib/notebook/test/emptySessionClasses';
|
||||
import { NotebookManagerStub, ServerManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, ServerManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
|
||||
suite('Client Session', function (): void {
|
||||
let path = URI.file('my/notebook.ipynb');
|
||||
let notebookManager: NotebookManagerStub;
|
||||
let notebookManager: ExecuteManagerStub;
|
||||
let serverManager: ServerManagerStub;
|
||||
let mockSessionManager: TypeMoq.Mock<nb.SessionManager>;
|
||||
let notificationService: TypeMoq.Mock<INotificationService>;
|
||||
@@ -27,19 +27,19 @@ suite('Client Session', function (): void {
|
||||
setup(() => {
|
||||
serverManager = new ServerManagerStub();
|
||||
mockSessionManager = TypeMoq.Mock.ofType(SessionManager);
|
||||
notebookManager = new NotebookManagerStub();
|
||||
notebookManager = new ExecuteManagerStub();
|
||||
notebookManager.serverManager = serverManager;
|
||||
notebookManager.sessionManager = mockSessionManager.object;
|
||||
notificationService = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService, TypeMoq.MockBehavior.Loose);
|
||||
|
||||
session = new ClientSession({
|
||||
notebookManager: notebookManager,
|
||||
executeManager: notebookManager,
|
||||
notebookUri: path,
|
||||
notificationService: notificationService.object,
|
||||
kernelSpec: { name: 'python', display_name: 'Python 3', language: 'python' }
|
||||
});
|
||||
|
||||
let serverlessNotebookManager = new NotebookManagerStub();
|
||||
let serverlessNotebookManager = new ExecuteManagerStub();
|
||||
serverlessNotebookManager.sessionManager = mockSessionManager.object;
|
||||
});
|
||||
|
||||
@@ -169,7 +169,7 @@ suite('Client Session', function (): void {
|
||||
|
||||
let remoteSession = new ClientSession({
|
||||
kernelSpec: { name: 'python', display_name: 'Python 3', language: 'python' },
|
||||
notebookManager: newNotebookManager,
|
||||
executeManager: newNotebookManager,
|
||||
notebookUri: path,
|
||||
notificationService: notificationService.object
|
||||
});
|
||||
|
||||
@@ -10,14 +10,12 @@ import * as fs from 'fs';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as tempWrite from 'temp-write';
|
||||
import { LocalContentManager } from 'sql/workbench/services/notebook/common/localContentManager';
|
||||
import { CellTypes } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { TestFileService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { IFileService, IReadFileOptions, IFileContent, IWriteFileOptions, IFileStatWithMetadata } from 'vs/platform/files/common/files';
|
||||
import { VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
|
||||
import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { promisify } from 'util';
|
||||
|
||||
let expectedNotebookContent: nb.INotebookContents = {
|
||||
@@ -69,34 +67,15 @@ suite('Local Content Manager', function (): void {
|
||||
contentManager = instantiationService.createInstance(LocalContentManager);
|
||||
});
|
||||
|
||||
test('Should return undefined if path is undefined', async function (): Promise<void> {
|
||||
let content = await contentManager.getNotebookContents(undefined);
|
||||
assert(isUndefinedOrNull(content));
|
||||
// tslint:disable-next-line:no-null-keyword
|
||||
content = await contentManager.getNotebookContents(null);
|
||||
assert(isUndefinedOrNull(content));
|
||||
});
|
||||
|
||||
test('Should throw if file does not exist', async function (): Promise<void> {
|
||||
try {
|
||||
await contentManager.getNotebookContents(URI.file('/path/doesnot/exist.ipynb'));
|
||||
assert.fail('expected to throw');
|
||||
} catch (e) { }
|
||||
});
|
||||
test('Should return notebook contents parsed as INotebook when valid notebook file parsed', async function (): Promise<void> {
|
||||
// Given a file containing a valid notebook
|
||||
let localFile = tempWrite.sync(notebookContentString, 'notebook.ipynb');
|
||||
// when I read the content
|
||||
let notebook = await contentManager.getNotebookContents(URI.file(localFile));
|
||||
let notebook = await contentManager.deserializeNotebook(notebookContentString);
|
||||
// then I expect notebook format to match
|
||||
verifyMatchesExpectedNotebook(notebook);
|
||||
});
|
||||
test('Should ignore invalid content in the notebook file', async function (): Promise<void> {
|
||||
// Given a file containing a notebook with some garbage properties
|
||||
let invalidContent = notebookContentString + '\\nasddfdsafasdf';
|
||||
let localFile = tempWrite.sync(invalidContent, 'notebook.ipynb');
|
||||
// when I read the content
|
||||
let notebook = await contentManager.getNotebookContents(URI.file(localFile));
|
||||
let notebook = await contentManager.deserializeNotebook(invalidContent);
|
||||
// then I expect notebook format to still be valid
|
||||
verifyMatchesExpectedNotebook(notebook);
|
||||
});
|
||||
@@ -130,10 +109,8 @@ suite('Local Content Manager', function (): void {
|
||||
nbformat_minor: 2
|
||||
};
|
||||
let mimeContentString = JSON.stringify(mimeNotebook);
|
||||
// Given a file containing a valid notebook with multiline mime type
|
||||
let localFile = tempWrite.sync(mimeContentString, 'notebook.ipynb');
|
||||
// when I read the content
|
||||
let notebook = await contentManager.getNotebookContents(URI.file(localFile));
|
||||
let notebook = await contentManager.deserializeNotebook(mimeContentString);
|
||||
// then I expect output to have been normalized into a single string
|
||||
let displayOutput = <nb.IDisplayData>notebook.cells[0].outputs[0];
|
||||
assert.strictEqual(displayOutput.data['text/html'], '<div></div>');
|
||||
@@ -141,7 +118,7 @@ suite('Local Content Manager', function (): void {
|
||||
|
||||
test('Should create a new empty notebook if content is undefined', async function (): Promise<void> {
|
||||
// verify that when loading content from an empty string, a new notebook is created.
|
||||
let content = await contentManager.loadFromContentString(undefined);
|
||||
let content = await contentManager.deserializeNotebook(undefined);
|
||||
assert.strictEqual(content.metadata, undefined, 'Verify that metadata is undefined');
|
||||
// verify that the notebook is empty
|
||||
assert.strictEqual(content.cells.length, 0, 'Notebook should be empty, so the number of cells should be 0');
|
||||
@@ -149,12 +126,22 @@ suite('Local Content Manager', function (): void {
|
||||
|
||||
test('Should create a new empty notebook if content is an empty string', async function (): Promise<void> {
|
||||
// verify that when loading content from an empty string, a new notebook is created.
|
||||
let content = await contentManager.loadFromContentString('');
|
||||
let content = await contentManager.deserializeNotebook('');
|
||||
assert.strictEqual(content.metadata, undefined, 'Verify that metadata is undefined');
|
||||
// verify that the notebook is empty
|
||||
assert.strictEqual(content.cells.length, 0, 'Notebook should be empty, so the number of cells should be 0');
|
||||
});
|
||||
|
||||
test('Should return undefined if notebook contents are undefined', async function (): Promise<void> {
|
||||
let strContent = await contentManager.serializeNotebook(undefined);
|
||||
assert.strictEqual(strContent, undefined);
|
||||
});
|
||||
|
||||
test('Should return stringified version of notebook contents', async function (): Promise<void> {
|
||||
let strContent = await contentManager.serializeNotebook(expectedNotebookContent);
|
||||
assert.strictEqual(strContent, JSON.stringify(expectedNotebookContent, undefined, ' '));
|
||||
});
|
||||
|
||||
test('Should create a markdown cell', async function (): Promise<void> {
|
||||
let expectedNotebookMarkdownContent: nb.INotebookContents = {
|
||||
cells: [{
|
||||
@@ -173,7 +160,7 @@ suite('Local Content Manager', function (): void {
|
||||
};
|
||||
let markdownNotebookContent = JSON.stringify(expectedNotebookMarkdownContent);
|
||||
// verify that notebooks support markdown cells
|
||||
let notebook = await contentManager.loadFromContentString(markdownNotebookContent);
|
||||
let notebook = await contentManager.deserializeNotebook(markdownNotebookContent);
|
||||
// assert that markdown cell is supported by
|
||||
// verifying the notebook matches the expectedNotebookMarkdownContent format
|
||||
assert.strictEqual(notebook.cells.length, 1, 'The number of cells should be equal to 1');
|
||||
@@ -207,7 +194,7 @@ suite('Local Content Manager', function (): void {
|
||||
};
|
||||
let streamOutputContent = JSON.stringify(expectedNotebookStreamOutputContent);
|
||||
// Verify that the stream output type is supported
|
||||
let notebook = await contentManager.loadFromContentString(streamOutputContent);
|
||||
let notebook = await contentManager.deserializeNotebook(streamOutputContent);
|
||||
assert.strictEqual(notebook.cells[0].outputs[0].output_type, 'stream', 'Cell output from notebook should be stream');
|
||||
assert.strictEqual(notebook.cells[0].cell_type, expectedNotebookStreamOutputContent.cells[0].cell_type, 'Cell type of notebook should match the expectedNotebookStreamOutputContent');
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ import { TestLifecycleService, TestTextFileService, workbenchInstantiationServic
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { nb } from 'azdata';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { INotebookEditor, INotebookManager } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { INotebookEditor, IExecuteManager, ISerializationManager } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
@@ -50,9 +50,13 @@ class ServiceAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
class NotebookManagerStub implements INotebookManager {
|
||||
class SerializationManagerStub implements ISerializationManager {
|
||||
providerId: string;
|
||||
contentManager: nb.ContentManager;
|
||||
}
|
||||
|
||||
class ExecuteManagerStub implements IExecuteManager {
|
||||
providerId: string;
|
||||
sessionManager: nb.SessionManager;
|
||||
serverManager: nb.ServerManager;
|
||||
}
|
||||
@@ -62,7 +66,8 @@ let defaultUri = URI.file('/some/path.ipynb');
|
||||
// Note: these tests are intentionally written to be extremely brittle and break on any changes to notebook/cell serialization changes.
|
||||
// If any of these tests fail, it is likely that notebook editor rehydration will fail with cryptic JSON messages.
|
||||
suite('Notebook Editor Model', function (): void {
|
||||
let notebookManagers = [new NotebookManagerStub()];
|
||||
let serializationManagers = [new SerializationManagerStub()];
|
||||
let executeManagers = [new ExecuteManagerStub()];
|
||||
let notebookModel: NotebookModel;
|
||||
const instantiationService: IInstantiationService = workbenchInstantiationService();
|
||||
let accessor: ServiceAccessor;
|
||||
@@ -156,8 +161,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
defaultModelOptions = {
|
||||
notebookUri: defaultUri,
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers,
|
||||
contentManager: undefined,
|
||||
serializationManagers: serializationManagers,
|
||||
executeManagers: executeManagers,
|
||||
contentLoader: undefined,
|
||||
notificationService: notificationService.object,
|
||||
connectionService: queryConnectionService.object,
|
||||
providerId: 'SQL',
|
||||
@@ -197,7 +203,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
@@ -221,7 +227,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(25), ' "execution_count": null');
|
||||
@@ -233,7 +239,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"');
|
||||
@@ -250,7 +256,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(25), ' "execution_count": 10');
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
@@ -261,7 +267,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(25), ' "execution_count": 15');
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
@@ -272,7 +278,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellExecuted);
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(25), ' "execution_count": 105');
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
});
|
||||
@@ -289,7 +295,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -300,7 +306,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputCleared);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputCleared);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"');
|
||||
@@ -323,7 +329,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -342,7 +348,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "This is a test\\n",');
|
||||
@@ -369,7 +375,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -388,7 +394,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "This is a test"');
|
||||
@@ -413,7 +419,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -427,7 +433,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
modelContentChangedEvent: undefined
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
|
||||
assert(!notebookEditorModel.lastEditFullReplacement, 'should not do a full replacement for a source update');
|
||||
|
||||
@@ -453,7 +459,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -467,7 +473,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
modelContentChangedEvent: undefined
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
|
||||
assert(!notebookEditorModel.lastEditFullReplacement, 'should not do a full replacement for a source update');
|
||||
|
||||
@@ -494,7 +500,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
@@ -516,7 +522,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
contentChange = {
|
||||
@@ -533,7 +539,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' ""');
|
||||
@@ -558,7 +564,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
|
||||
@@ -576,7 +582,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
@@ -600,7 +606,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
@@ -630,7 +636,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [cell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
}
|
||||
|
||||
@@ -647,7 +653,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
assert(!notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
@@ -677,7 +683,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -689,7 +695,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell]
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"');
|
||||
@@ -714,7 +720,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell],
|
||||
cellIndex: 0
|
||||
};
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
|
||||
@@ -728,7 +734,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell]
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"');
|
||||
@@ -750,7 +756,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell]
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(32), ' "text": "test test test"');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(33), ' }');
|
||||
@@ -779,7 +785,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [],');
|
||||
@@ -792,7 +798,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
cells: [newCell]
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellOutputUpdated);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"');
|
||||
@@ -810,9 +816,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '"This text is in quotes"');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '"This text is in quotes"');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\\"This text is in quotes\\""');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -825,9 +831,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '""""""""""');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '""""""""""');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\\"\\"\\"\\"\\"\\"\\"\\"\\"\\""');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -840,9 +846,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '\\\\\\\\\\');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '\\\\\\\\\\');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\\\\\\\\\\\\\\\\\\\\\"');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -855,9 +861,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '\"\"\"\"\"\"\"\"\"\"');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '\"\"\"\"\"\"\"\"\"\"');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\""');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -870,9 +876,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, 'this is a long line in a cell test. Everything should serialize correctly! # Comments here: adding more tests is fun?');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, 'this is a long line in a cell test. Everything should serialize correctly! # Comments here: adding more tests is fun?');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "this is a long line in a cell test. Everything should serialize correctly! # Comments here: adding more tests is fun?"');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -885,9 +891,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}\\|;:",<.>/?\'');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}\\|;:",<.>/?\'');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}\\\\|;:\\",<.>/?\'"');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -900,9 +906,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '\'\'\'\'');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '\'\'\'\'');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\'\'\'\'"');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -915,9 +921,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' ""');
|
||||
|
||||
ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel, newCell);
|
||||
@@ -930,9 +936,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '"test"' + os.EOL + 'test""');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '"test"' + os.EOL + 'test""');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\\"test\\"\\n",');
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
@@ -952,9 +958,9 @@ suite('Notebook Editor Model', function (): void {
|
||||
notebookEditorModel.replaceEntireTextEditorModel(notebookModel, undefined);
|
||||
|
||||
let newCell = notebookModel.addCell(CellTypes.Code);
|
||||
setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
await setupTextEditorModelWithEmptyOutputs(notebookEditorModel, newCell);
|
||||
|
||||
addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '"""""test"' + os.EOL + '"""""""test\\""');
|
||||
await addTextToBeginningOfTextEditorModel(notebookEditorModel, newCell, '"""""test"' + os.EOL + '"""""""test\\""');
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(9), ' "\\"\\"\\"\\"\\"test\\"\\n",');
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
|
||||
@@ -983,7 +989,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, testResourcePropertiesService);
|
||||
}
|
||||
|
||||
function setupTextEditorModelWithEmptyOutputs(notebookEditorModel: NotebookEditorModel, newCell: ICellModel) {
|
||||
async function setupTextEditorModelWithEmptyOutputs(notebookEditorModel: NotebookEditorModel, newCell: ICellModel) {
|
||||
// clear outputs
|
||||
newCell[<any>'_outputs'] = [];
|
||||
|
||||
@@ -993,13 +999,13 @@ suite('Notebook Editor Model', function (): void {
|
||||
cellIndex: 0
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellsModified);
|
||||
assert(notebookEditorModel.lastEditFullReplacement);
|
||||
|
||||
assert.strictEqual(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [],');
|
||||
}
|
||||
|
||||
function addTextToBeginningOfTextEditorModel(notebookEditorModel: NotebookEditorModel, newCell: ICellModel, textToAdd: string) {
|
||||
async function addTextToBeginningOfTextEditorModel(notebookEditorModel: NotebookEditorModel, newCell: ICellModel, textToAdd: string) {
|
||||
let contentChange: NotebookContentChange = {
|
||||
changeType: NotebookChangeType.CellSourceUpdated,
|
||||
cells: [newCell],
|
||||
@@ -1014,7 +1020,7 @@ suite('Notebook Editor Model', function (): void {
|
||||
}
|
||||
};
|
||||
|
||||
notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
await notebookEditorModel.updateModel(contentChange, NotebookChangeType.CellSourceUpdated);
|
||||
}
|
||||
|
||||
function ensureStaticContentInOneLineCellIsCorrect(notebookEditorModel: NotebookEditorModel, newCell: ICellModel) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { nb } from 'azdata';
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, SerializationManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { CellTypes } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { IClientSession, INotebookModelOptions } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
@@ -26,7 +26,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { ClientSession } from 'sql/workbench/services/notebook/browser/models/clientSession';
|
||||
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookEditorContentLoader } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookRange } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { NotebookMarkdownRenderer } from 'sql/workbench/contrib/notebook/browser/outputs/notebookMarkdown';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
@@ -67,8 +67,8 @@ let instantiationService: IInstantiationService;
|
||||
let serviceCollection = new ServiceCollection();
|
||||
|
||||
suite('Notebook Find Model', function (): void {
|
||||
|
||||
let notebookManagers = [new NotebookManagerStub()];
|
||||
let serializationManagers = [new SerializationManagerStub()];
|
||||
let executeManagers = [new ExecuteManagerStub()];
|
||||
let memento: TypeMoq.Mock<Memento>;
|
||||
let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>;
|
||||
let defaultModelOptions: INotebookModelOptions;
|
||||
@@ -92,8 +92,9 @@ suite('Notebook Find Model', function (): void {
|
||||
defaultModelOptions = {
|
||||
notebookUri: defaultUri,
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers,
|
||||
contentManager: undefined,
|
||||
serializationManagers: serializationManagers,
|
||||
executeManagers: executeManagers,
|
||||
contentLoader: undefined,
|
||||
notificationService: notificationService.object,
|
||||
connectionService: queryConnectionService.object,
|
||||
providerId: 'SQL',
|
||||
@@ -434,9 +435,9 @@ suite('Notebook Find Model', function (): void {
|
||||
|
||||
|
||||
async function initNotebookModel(contents: nb.INotebookContents): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
// Initialize the model
|
||||
model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
|
||||
@@ -12,7 +12,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { ExecuteManagerStub, SerializationManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||
import { ModelFactory } from 'sql/workbench/services/notebook/browser/models/modelFactory';
|
||||
import { IClientSession, INotebookModelOptions, NotebookContentChange, IClientSessionOptions, ICellModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
@@ -29,7 +29,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
|
||||
import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { NotebookEditorContentLoader } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
|
||||
import { SessionManager } from 'sql/workbench/contrib/notebook/test/emptySessionClasses';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
@@ -138,7 +138,8 @@ let instantiationService: IInstantiationService;
|
||||
let configurationService: IConfigurationService;
|
||||
|
||||
suite('notebook model', function (): void {
|
||||
let notebookManagers = [new NotebookManagerStub()];
|
||||
let serializationManagers = [new SerializationManagerStub()];
|
||||
let executeManagers = [new ExecuteManagerStub()];
|
||||
let mockSessionManager: TypeMoq.Mock<nb.SessionManager>;
|
||||
let memento: TypeMoq.Mock<Memento>;
|
||||
let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>;
|
||||
@@ -146,7 +147,7 @@ suite('notebook model', function (): void {
|
||||
const logService = new NullLogService();
|
||||
setup(() => {
|
||||
mockSessionManager = TypeMoq.Mock.ofType(SessionManager);
|
||||
notebookManagers[0].sessionManager = mockSessionManager.object;
|
||||
executeManagers[0].sessionManager = mockSessionManager.object;
|
||||
sessionReady = new Deferred<void>();
|
||||
notificationService = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService, TypeMoq.MockBehavior.Loose);
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
@@ -160,8 +161,9 @@ suite('notebook model', function (): void {
|
||||
defaultModelOptions = {
|
||||
notebookUri: defaultUri,
|
||||
factory: new ModelFactory(instantiationService),
|
||||
notebookManagers,
|
||||
contentManager: undefined,
|
||||
serializationManagers: serializationManagers,
|
||||
executeManagers: executeManagers,
|
||||
contentLoader: undefined,
|
||||
notificationService: notificationService.object,
|
||||
connectionService: queryConnectionService.object,
|
||||
providerId: 'SQL',
|
||||
@@ -171,7 +173,7 @@ suite('notebook model', function (): void {
|
||||
capabilitiesService: capabilitiesService
|
||||
};
|
||||
clientSessionOptions = {
|
||||
notebookManager: defaultModelOptions.notebookManagers[0],
|
||||
executeManager: defaultModelOptions.executeManagers[0],
|
||||
notebookUri: defaultModelOptions.notebookUri,
|
||||
notificationService: notificationService.object,
|
||||
kernelSpec: defaultModelOptions.defaultKernel
|
||||
@@ -200,9 +202,9 @@ suite('notebook model', function (): void {
|
||||
nbformat_minor: 5
|
||||
};
|
||||
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(emptyNotebook));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
@@ -216,9 +218,9 @@ suite('notebook model', function (): void {
|
||||
|
||||
test('Should use trusted state set in model load', async function (): Promise<void> {
|
||||
// Given a notebook
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents(true);
|
||||
@@ -231,9 +233,9 @@ suite('notebook model', function (): void {
|
||||
test('Should throw if model load fails', async function (): Promise<void> {
|
||||
// Given a call to get Contents fails
|
||||
let error = new Error('File not found');
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.reject(error));//.throws(error);
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initalize the model
|
||||
// Then it should throw
|
||||
@@ -245,9 +247,9 @@ suite('notebook model', function (): void {
|
||||
|
||||
test('Should convert cell info to CellModels', async function (): Promise<void> {
|
||||
// Given a notebook with 2 cells
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initalize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -261,18 +263,18 @@ suite('notebook model', function (): void {
|
||||
|
||||
test('Should handle multiple notebook managers', async function (): Promise<void> {
|
||||
// Given a notebook with 2 cells
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
let defaultNotebookManager = new NotebookManagerStub();
|
||||
let defaultNotebookManager = new ExecuteManagerStub();
|
||||
defaultNotebookManager.providerId = 'SQL';
|
||||
|
||||
let jupyterNotebookManager = new NotebookManagerStub();
|
||||
let jupyterNotebookManager = new ExecuteManagerStub();
|
||||
jupyterNotebookManager.providerId = 'jupyter';
|
||||
|
||||
// Setup 2 notebook managers
|
||||
defaultModelOptions.notebookManagers = [defaultNotebookManager, jupyterNotebookManager];
|
||||
defaultModelOptions.executeManagers = [defaultNotebookManager, jupyterNotebookManager];
|
||||
|
||||
// Change default notebook provider id to jupyter
|
||||
defaultModelOptions.providerId = 'jupyter';
|
||||
@@ -282,7 +284,7 @@ suite('notebook model', function (): void {
|
||||
await model.loadContents();
|
||||
|
||||
// I expect the default provider to be jupyter
|
||||
assert.strictEqual(model.notebookManager.providerId, 'jupyter', 'Notebook manager provider id incorrect');
|
||||
assert.strictEqual(model.executeManager.providerId, 'jupyter', 'Notebook manager provider id incorrect');
|
||||
|
||||
// Similarly, change default notebook provider id to SQL
|
||||
defaultModelOptions.providerId = 'SQL';
|
||||
@@ -292,13 +294,13 @@ suite('notebook model', function (): void {
|
||||
await model.loadContents();
|
||||
|
||||
// I expect the default provider to be SQL
|
||||
assert.strictEqual(model.notebookManager.providerId, 'SQL', 'Notebook manager provider id incorrect after 2nd model load');
|
||||
assert.strictEqual(model.executeManager.providerId, 'SQL', 'Notebook manager provider id incorrect after 2nd model load');
|
||||
|
||||
// Check that the getters return the correct values
|
||||
assert.strictEqual(model.notebookManagers.length, 2, 'There should be 2 notebook managers');
|
||||
assert(!isUndefinedOrNull(model.getNotebookManager('SQL')), 'SQL notebook manager is not defined');
|
||||
assert(!isUndefinedOrNull(model.getNotebookManager('jupyter')), 'Jupyter notebook manager is not defined');
|
||||
assert(isUndefinedOrNull(model.getNotebookManager('foo')), 'foo notebook manager is incorrectly defined');
|
||||
assert.strictEqual(model.executeManagers.length, 2, 'There should be 2 notebook managers');
|
||||
assert(!isUndefinedOrNull(model.getExecuteManager('SQL')), 'SQL notebook manager is not defined');
|
||||
assert(!isUndefinedOrNull(model.getExecuteManager('jupyter')), 'Jupyter notebook manager is not defined');
|
||||
assert(isUndefinedOrNull(model.getExecuteManager('foo')), 'foo notebook manager is incorrectly defined');
|
||||
|
||||
// Check other properties to ensure that they're returning as expected
|
||||
// No server manager was passed into the notebook manager stub, so expect hasServerManager to return false
|
||||
@@ -308,9 +310,9 @@ suite('notebook model', function (): void {
|
||||
|
||||
test('Should set active cell correctly', async function (): Promise<void> {
|
||||
// Given a notebook with 2 cells
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initalize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -364,10 +366,10 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should set notebook parameter and injected parameter cell correctly', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedParameterizedNotebookContent));
|
||||
defaultModelOptions.notebookUri = defaultUri;
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -392,10 +394,10 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should set notebookUri parameters to new cell correctly', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContentOneCell));
|
||||
defaultModelOptions.notebookUri = notebookUriParams;
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -412,14 +414,14 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should set notebookUri parameters to new cell after parameters cell correctly', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
let expectedNotebookContentParameterCell = expectedNotebookContentOneCell;
|
||||
//Set the cell to be tagged as parameter cell
|
||||
expectedNotebookContentParameterCell.cells[0].metadata.tags = ['parameters'];
|
||||
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContentParameterCell));
|
||||
defaultModelOptions.notebookUri = notebookUriParams;
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -436,11 +438,11 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should set notebookUri parameters to new cell after injected parameters cell correctly', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedParameterizedNotebookContent));
|
||||
defaultModelOptions.notebookUri = notebookUriParams;
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -457,9 +459,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should move first cell below second cell correctly', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -477,9 +479,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should move second cell up above the first cell correctly', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -498,9 +500,9 @@ suite('notebook model', function (): void {
|
||||
|
||||
test('Should delete cells correctly', async function (): Promise<void> {
|
||||
// Given a notebook with 2 cells
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initalize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -549,9 +551,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should notify cell on metadata change', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initalize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -566,9 +568,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should set cell language correctly after cell type conversion', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
@@ -594,9 +596,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should load contents but then go to error state if client session startup fails', async function (): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContentOneCell));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// Given I have a session that fails to start
|
||||
sessionReady.resolve();
|
||||
@@ -608,7 +610,7 @@ suite('notebook model', function (): void {
|
||||
await model.requestModelLoad();
|
||||
// starting client session fails at startSessionInstance due to:
|
||||
// Cannot set property 'defaultKernelLoaded' of undefined
|
||||
await assert.rejects(async () => { await model.startSession(notebookManagers[0]); });
|
||||
await assert.rejects(async () => { await model.startSession(executeManagers[0]); });
|
||||
// Then I expect load to succeed
|
||||
assert.strictEqual(model.cells.length, 1);
|
||||
assert(model.clientSession);
|
||||
@@ -623,15 +625,15 @@ suite('notebook model', function (): void {
|
||||
let model = await loadModelAndStartClientSession(expectedNotebookContent);
|
||||
|
||||
assert.strictEqual(model.inErrorState, false);
|
||||
assert.strictEqual(model.notebookManagers.length, 1);
|
||||
assert.strictEqual(model.executeManagers.length, 1);
|
||||
assert.deepStrictEqual(model.clientSession, mockClientSession);
|
||||
});
|
||||
|
||||
test('Should notify on trust set', async function () {
|
||||
// Given a notebook that's been loaded
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
await model.requestModelLoad();
|
||||
|
||||
@@ -697,9 +699,9 @@ suite('notebook model', function (): void {
|
||||
expectedNotebookContent.metadata['custom-object'] = { prop1: 'value1', prop2: 'value2' };
|
||||
|
||||
// Given a notebook
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined, queryConnectionService.object, configurationService);
|
||||
await model.loadContents();
|
||||
@@ -808,9 +810,9 @@ suite('notebook model', function (): void {
|
||||
nbformat: 4,
|
||||
nbformat_minor: 5
|
||||
};
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(notebook));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// And a matching connection profile
|
||||
let expectedConnectionProfile = <ConnectionProfile>{
|
||||
@@ -858,9 +860,9 @@ suite('notebook model', function (): void {
|
||||
nbformat: 4,
|
||||
nbformat_minor: 5
|
||||
};
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(notebook));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
// When I initialize the model
|
||||
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
||||
@@ -885,9 +887,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
test('Should keep kernel alias as language info kernel alias name even if kernel spec is seralized as SQL', async function () {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedKernelAliasNotebookContentOneCell));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
queryConnectionService.setup(c => c.getActiveConnections(TypeMoq.It.isAny())).returns(() => null);
|
||||
|
||||
@@ -904,9 +906,9 @@ suite('notebook model', function (): void {
|
||||
});
|
||||
|
||||
async function loadModelAndStartClientSession(notebookContent: nb.INotebookContents): Promise<NotebookModel> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(notebookContent));
|
||||
defaultModelOptions.contentManager = mockContentManager.object;
|
||||
defaultModelOptions.contentLoader = mockContentManager.object;
|
||||
|
||||
queryConnectionService.setup(c => c.getActiveConnections(TypeMoq.It.isAny())).returns(() => null);
|
||||
|
||||
@@ -921,7 +923,7 @@ suite('notebook model', function (): void {
|
||||
|
||||
await model.requestModelLoad();
|
||||
|
||||
await model.startSession(notebookManagers[0]);
|
||||
await model.startSession(executeManagers[0]);
|
||||
|
||||
// Then I expect load to succeed
|
||||
assert(!isUndefinedOrNull(model.clientSession), 'clientSession should exist after session is started');
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as vsEvent from 'vs/base/common/event';
|
||||
import { INotebookModel, ICellModel, IClientSession, NotebookContentChange, ISingleNotebookEditOperation, MoveDirection, ViewMode } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { INotebookFindModel } from 'sql/workbench/contrib/notebook/browser/models/notebookFindModel';
|
||||
import { NotebookChangeType, CellType } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { INotebookManager, INotebookService, INotebookEditor, ILanguageMagic, INotebookProvider, INavigationProvider, INotebookParams, INotebookSection, ICellEditorProvider, NotebookRange } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { IExecuteManager, INotebookService, INotebookEditor, ILanguageMagic, IExecuteProvider, INavigationProvider, INotebookParams, INotebookSection, ICellEditorProvider, NotebookRange, ISerializationProvider, ISerializationManager } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
||||
import { IModelDecorationsChangeAccessor } from 'vs/editor/common/model';
|
||||
import { NotebookFindMatch } from 'sql/workbench/contrib/notebook/browser/find/notebookFindDecorations';
|
||||
@@ -47,7 +47,10 @@ export class NotebookModelStub implements INotebookModel {
|
||||
get sessionLoadFinished(): Promise<void> {
|
||||
throw new Error('method not implemented.');
|
||||
}
|
||||
get notebookManagers(): INotebookManager[] {
|
||||
get serializationManager(): ISerializationManager {
|
||||
throw new Error('method not implemented.');
|
||||
}
|
||||
get executeManagers(): IExecuteManager[] {
|
||||
throw new Error('method not implemented.');
|
||||
}
|
||||
get kernelChanged(): vsEvent.Event<nb.IKernelChangedArgs> {
|
||||
@@ -197,9 +200,13 @@ export class NotebookFindModelStub implements INotebookFindModel {
|
||||
}
|
||||
}
|
||||
|
||||
export class NotebookManagerStub implements INotebookManager {
|
||||
export class SerializationManagerStub implements ISerializationManager {
|
||||
providerId: string;
|
||||
contentManager: nb.ContentManager;
|
||||
}
|
||||
|
||||
export class ExecuteManagerStub implements IExecuteManager {
|
||||
providerId: string;
|
||||
sessionManager: nb.SessionManager;
|
||||
serverManager: nb.ServerManager;
|
||||
}
|
||||
@@ -245,10 +252,16 @@ export class NotebookServiceStub implements INotebookService {
|
||||
setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
registerProvider(providerId: string, provider: INotebookProvider): void {
|
||||
registerSerializationProvider(providerId: string, provider: ISerializationProvider): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
unregisterProvider(providerId: string): void {
|
||||
registerExecuteProvider(providerId: string, provider: IExecuteProvider): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
unregisterSerializationProvider(providerId: string): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
unregisterExecuteProvider(providerId: string): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
registerNavigationProvider(provider: INavigationProvider): void {
|
||||
@@ -266,7 +279,10 @@ export class NotebookServiceStub implements INotebookService {
|
||||
getStandardKernelsForProvider(provider: string): nb.IStandardKernel[] {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getOrCreateNotebookManager(providerId: string, uri: URI): Thenable<INotebookManager> {
|
||||
getOrCreateSerializationManager(providerId: string, uri: URI): Promise<ISerializationManager> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getOrCreateExecuteManager(providerId: string, uri: URI): Thenable<IExecuteManager> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
addNotebookEditor(editor: INotebookEditor): void {
|
||||
|
||||
Reference in New Issue
Block a user