Fix service dependency startup warning (#14180)

* Fix service dependency startup warning

* fix tests
This commit is contained in:
Charles Gagnon
2021-02-06 15:01:16 -08:00
committed by GitHub
parent 63f9be6b5f
commit 86aa24e198
13 changed files with 84 additions and 58 deletions

View File

@@ -77,8 +77,6 @@ suite('Notebook Editor Model', function (): void {
testinstantiationService.stub(IStorageService, new TestStorageService());
testinstantiationService.stub(IProductService, { quality: 'stable' });
const queryConnectionService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose,
undefined, // connection store
undefined, // connection status manager
undefined, // connection dialog service
testinstantiationService, // instantiation service
undefined, // editor service

View File

@@ -28,8 +28,6 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
let instantiationService = new TestInstantiationService();
instantiationService.stub(IStorageService, new TestStorageService());
let mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
undefined, //connection store
undefined, // connectionstatusmanager
undefined, // connectiondialog service
instantiationService, // instantiation service
undefined, // editor service

View File

@@ -93,8 +93,6 @@ suite('SQL QueryEditor Tests', () => {
let testinstantiationService = new TestInstantiationService();
testinstantiationService.stub(IStorageService, new TestStorageService());
connectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose,
undefined, // connection store
undefined, // connection status manager
undefined, // connection dialog service
testinstantiationService, // instantiation service
undefined, // editor service
@@ -267,8 +265,6 @@ suite('SQL QueryEditor Tests', () => {
let testinstantiationService = new TestInstantiationService();
testinstantiationService.stub(IStorageService, new TestStorageService());
connectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose,
undefined, // connection store
undefined, // connection status manager
undefined, // connection dialog service
testinstantiationService, // instantiation service
undefined, // editor service

View File

@@ -50,7 +50,6 @@ export class AccountManagementService implements IAccountManagementService {
// CONSTRUCTOR /////////////////////////////////////////////////////////
constructor(
private _mementoObj: object,
@IInstantiationService private _instantiationService: IInstantiationService,
@IStorageService private _storageService: IStorageService,
@IClipboardService private _clipboardService: IClipboardService,
@@ -58,12 +57,9 @@ export class AccountManagementService implements IAccountManagementService {
@ILogService private readonly _logService: ILogService,
@INotificationService private readonly _notificationService: INotificationService
) {
// Create the account store
if (!this._mementoObj) {
this._mementoContext = new Memento(AccountManagementService.ACCOUNT_MEMENTO, this._storageService);
this._mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL);
}
this._accountStore = this._instantiationService.createInstance(AccountStore, this._mementoObj);
this._mementoContext = new Memento(AccountManagementService.ACCOUNT_MEMENTO, this._storageService);
const mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL);
this._accountStore = this._instantiationService.createInstance(AccountStore, mementoObj);
// Setup the event emitters
this._addAccountProviderEmitter = new Emitter<AccountProviderAddedEventParams>();

View File

@@ -214,7 +214,7 @@ suite('Account Management Service Tests:', () => {
// If: I add an account when the provider doesn't exist
// Then: It should not resolve
return Promise.race([
new Promise((resolve, reject) => setTimeout(() => resolve(), 100)),
new Promise<void>((resolve, reject) => setTimeout(() => resolve(), 100)),
ams.addAccount('doesNotExist').then(() => { throw new Error('Promise resolved when the provider did not exist'); })
]);
});
@@ -283,7 +283,7 @@ suite('Account Management Service Tests:', () => {
// If: I get accounts when the provider doesn't exist
// Then: It should not resolve
return Promise.race([
new Promise((resolve, reject) => setTimeout(() => resolve(), 100)),
new Promise<void>((resolve, reject) => setTimeout(() => resolve(), 100)),
ams.getAccountsForProvider('doesNotExist').then(() => { throw new Error('Promise resolved when the provider did not exist'); })
]);
});
@@ -529,13 +529,10 @@ function getTestState(): AccountManagementState {
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(AccountStore), TypeMoq.It.isAny()))
.returns(() => mockAccountStore.object);
// Create mock memento
let mockMemento = {};
const testNotificationService = new TestNotificationService();
// Create the account management service
let ams = new AccountManagementService(mockMemento, mockInstantiationService.object, new TestStorageService(), undefined!, undefined!, undefined!, testNotificationService);
let ams = new AccountManagementService(mockInstantiationService.object, new TestStorageService(), undefined!, undefined!, undefined!, testNotificationService);
// Wire up event handlers
let evUpdate = new EventVerifierSingle<UpdateAccountListEventParams>();

View File

@@ -41,8 +41,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ILogService } from 'vs/platform/log/common/log';
import * as interfaces from 'sql/platform/connection/common/interfaces';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { Memento } from 'vs/workbench/common/memento';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { entries } from 'sql/base/common/collections';
import { values } from 'vs/base/common/collections';
@@ -70,14 +69,15 @@ export class ConnectionManagementService extends Disposable implements IConnecti
private _connectionGlobalStatus = new ConnectionGlobalStatus(this._notificationService);
private _mementoContext: Memento;
private _mementoObj: any;
private _mementoObj: MementoObject;
private _connectionStore: ConnectionStore;
private _connectionStatusManager: ConnectionStatusManager;
private static readonly CONNECTION_MEMENTO = 'ConnectionManagement';
private static readonly _azureResources: AzureResource[] =
[AzureResource.ResourceManagement, AzureResource.Sql, AzureResource.OssRdbms];
constructor(
private _connectionStore: ConnectionStore,
private _connectionStatusManager: ConnectionStatusManager,
@IConnectionDialogService private _connectionDialogService: IConnectionDialogService,
@IInstantiationService private _instantiationService: IInstantiationService,
@IEditorService private _editorService: IEditorService,
@@ -91,18 +91,12 @@ export class ConnectionManagementService extends Disposable implements IConnecti
@IAccountManagementService private _accountManagementService: IAccountManagementService,
@ILogService private _logService: ILogService,
@IStorageService private _storageService: IStorageService,
@IEnvironmentService private _environmentService: IEnvironmentService,
@IExtensionService private readonly extensionService: IExtensionService
) {
super();
if (!this._connectionStore) {
this._connectionStore = _instantiationService.createInstance(ConnectionStore);
}
if (!this._connectionStatusManager) {
this._connectionStatusManager = new ConnectionStatusManager(this._capabilitiesService, this._logService, this._environmentService, this._notificationService);
}
this._connectionStore = _instantiationService.createInstance(ConnectionStore);
this._connectionStatusManager = _instantiationService.createInstance(ConnectionStatusManager);
if (this._storageService) {
this._mementoContext = new Memento(ConnectionManagementService.CONNECTION_MEMENTO, this._storageService);
this._mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL);

View File

@@ -90,8 +90,6 @@ suite('ConnectionDialogService tests', () => {
let errorMessageService = getMockErrorMessageService();
let capabilitiesService = new TestCapabilitiesService();
mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
undefined, // connection store
undefined, // connection status manager
undefined, // connection dialog service
testInstantiationService, // instantiation service
undefined, // editor service

View File

@@ -57,8 +57,6 @@ suite('ConnectionDialogWidget tests', () => {
cmInstantiationService.stub(IContextKeyService, new MockContextKeyService());
mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
undefined, // connection store
undefined, // connection status manager
undefined, // connection dialog service
cmInstantiationService, // instantiation service
undefined, // editor service

View File

@@ -25,18 +25,22 @@ import * as azdata from 'azdata';
import * as assert from 'assert';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { TestAccountManagementService } from 'sql/platform/accounts/test/common/testAccountManagementService';
import { TestEnvironmentService, TestEditorService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { NullLogService } from 'vs/platform/log/common/log';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { assign } from 'vs/base/common/objects';
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IQueryEditorConfiguration } from 'sql/platform/query/common/query';
import { TestInstantiationService } from 'sql/platform/instantiation/test/common/instantiationServiceMock';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
suite('SQL ConnectionManagementService tests', () => {
@@ -156,11 +160,16 @@ suite('SQL ConnectionManagementService tests', () => {
});
function createConnectionManagementService(): ConnectionManagementService {
const testInstantiationService = new TestInstantiationService();
const testLogService = new NullLogService();
testInstantiationService.stub(IStorageService, new TestStorageService());
testInstantiationService.stub(ICapabilitiesService, capabilitiesService);
testInstantiationService.stub(ILogService, testLogService);
testInstantiationService.stubCreateInstance(ConnectionStore, connectionStore.object);
let connectionManagementService = new ConnectionManagementService(
connectionStore.object,
undefined,
connectionDialogService.object,
undefined, // IInstantiationService
testInstantiationService,
workbenchEditorService.object,
new NullAdsTelemetryService(), // ITelemetryService
workspaceConfigurationServiceMock.object,
@@ -170,9 +179,8 @@ suite('SQL ConnectionManagementService tests', () => {
resourceProviderStubMock.object,
undefined, // IAngularEventingService
accountManagementService.object,
new NullLogService(), // ILogService
testLogService, // ILogService
undefined, // IStorageService
TestEnvironmentService,
getBasicExtensionService()
);
return connectionManagementService;
@@ -1556,7 +1564,10 @@ suite('SQL ConnectionManagementService tests', () => {
profile.password = test_password;
return { profile: profile, savedCred: true };
});
const connectionManagementService = new ConnectionManagementService(connectionStoreMock.object, undefined, undefined, undefined, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
const testInstantiationService = new TestInstantiationService();
testInstantiationService.stub(IStorageService, new TestStorageService());
testInstantiationService.stubCreateInstance(ConnectionStore, connectionStoreMock.object);
const connectionManagementService = new ConnectionManagementService(undefined, testInstantiationService, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
assert.equal(profile.password, '', 'Profile should not have password initially');
assert.equal(profile.options['password'], '', 'Profile options should not have password initially');
// Check for invalid profile id
@@ -1582,7 +1593,11 @@ suite('SQL ConnectionManagementService tests', () => {
profile.password = test_password;
return { profile: profile, savedCred: true };
});
const connectionManagementService = new ConnectionManagementService(connectionStoreMock.object, undefined, undefined, undefined, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
const testInstantiationService = new TestInstantiationService();
testInstantiationService.stub(IStorageService, new TestStorageService());
testInstantiationService.stubCreateInstance(ConnectionStore, connectionStoreMock.object);
const connectionManagementService = new ConnectionManagementService(undefined, testInstantiationService, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
assert.equal(profile.password, '', 'Profile should not have password initially');
assert.equal(profile.options['password'], '', 'Profile options should not have password initially');
let credentials = await connectionManagementService.getConnectionCredentials(profile.id);
@@ -1734,7 +1749,6 @@ suite('SQL ConnectionManagementService tests', () => {
test('getConnections test', () => {
const connectionStatusManagerMock = TypeMoq.Mock.ofType(ConnectionStatusManager, TypeMoq.MockBehavior.Loose);
const connectionStoreMock = TypeMoq.Mock.ofType(ConnectionStore, TypeMoq.MockBehavior.Loose, new TestStorageService());
connectionStatusManagerMock.setup(x => x.getActiveConnectionProfiles(undefined)).returns(() => {
return [createConnectionProfile('1'), createConnectionProfile('2')];
});
@@ -1750,7 +1764,13 @@ suite('SQL ConnectionManagementService tests', () => {
connectionStoreMock.setup(x => x.getConnectionProfileGroups(TypeMoq.It.isAny(), undefined)).returns(() => {
return [group1];
});
const connectionManagementService = new ConnectionManagementService(connectionStoreMock.object, connectionStatusManagerMock.object, undefined, undefined, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
const testInstantiationService = new TestInstantiationService();
const createInstanceStub = sinon.stub(testInstantiationService, 'createInstance');
createInstanceStub.withArgs(ConnectionStore).returns(connectionStoreMock.object);
createInstanceStub.withArgs(ConnectionStatusManager).returns(connectionStatusManagerMock.object);
const connectionManagementService = new ConnectionManagementService(undefined, testInstantiationService, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
// dupe connections have been seeded the numbers below already reflected the de-duped results
@@ -1774,20 +1794,21 @@ suite('SQL ConnectionManagementService tests', () => {
});
test('isRecent should evaluate whether a profile was recently connected or not', () => {
const connectionStatusManagerMock = TypeMoq.Mock.ofType(ConnectionStatusManager, TypeMoq.MockBehavior.Loose);
const connectionStoreMock = TypeMoq.Mock.ofType(ConnectionStore, TypeMoq.MockBehavior.Loose, new TestStorageService());
const testInstantiationService = new TestInstantiationService();
testInstantiationService.stub(IStorageService, new TestStorageService());
sinon.stub(testInstantiationService, 'createInstance').withArgs(ConnectionStore).returns(connectionStoreMock.object);
connectionStoreMock.setup(x => x.getRecentlyUsedConnections()).returns(() => {
return [createConnectionProfile('1')];
});
let profile1 = createConnectionProfile('1');
let profile2 = createConnectionProfile('2');
const connectionManagementService = new ConnectionManagementService(connectionStoreMock.object, connectionStatusManagerMock.object, undefined, undefined, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
const connectionManagementService = new ConnectionManagementService(undefined, testInstantiationService, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
assert(connectionManagementService.isRecent(profile1));
assert(!connectionManagementService.isRecent(profile2));
});
test('clearRecentConnection and ConnectionsList should call connectionStore functions', () => {
const connectionStatusManagerMock = TypeMoq.Mock.ofType(ConnectionStatusManager, TypeMoq.MockBehavior.Loose);
const connectionStoreMock = TypeMoq.Mock.ofType(ConnectionStore, TypeMoq.MockBehavior.Loose, new TestStorageService());
let called = false;
connectionStoreMock.setup(x => x.clearRecentlyUsed()).returns(() => {
@@ -1796,8 +1817,11 @@ test('clearRecentConnection and ConnectionsList should call connectionStore func
connectionStoreMock.setup(x => x.removeRecentConnection(TypeMoq.It.isAny())).returns(() => {
called = true;
});
const testInstantiationService = new TestInstantiationService();
testInstantiationService.stub(IStorageService, new TestStorageService());
sinon.stub(testInstantiationService, 'createInstance').withArgs(ConnectionStore).returns(connectionStoreMock.object);
let profile1 = createConnectionProfile('1');
const connectionManagementService = new ConnectionManagementService(connectionStoreMock.object, connectionStatusManagerMock.object, undefined, undefined, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
const connectionManagementService = new ConnectionManagementService(undefined, testInstantiationService, undefined, undefined, undefined, new TestCapabilitiesService(), undefined, undefined, undefined, undefined, undefined, undefined, undefined, getBasicExtensionService());
connectionManagementService.clearRecentConnection(profile1);
assert(called);
called = false;

View File

@@ -45,8 +45,6 @@ suite('Insights Dialog Controller Tests', () => {
let testinstantiationService = new TestInstantiationService();
testinstantiationService.stub(IStorageService, new TestStorageService());
let connMoq = Mock.ofType(ConnectionManagementService, MockBehavior.Strict,
undefined, // connection store
undefined, // connection status manager
undefined, // connection dialog service
testinstantiationService, // instantiation service
undefined, // editor service

View File

@@ -54,8 +54,6 @@ suite('AsyncServerTreeDragAndDrop', () => {
let instantiationService = new TestInstantiationService();
instantiationService.stub(IStorageService, new TestStorageService());
let mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
undefined, //connection store
undefined, // connectionstatusmanager
undefined, // connectiondialog service
instantiationService, // instantiation service
undefined, // editor service

View File

@@ -59,8 +59,6 @@ suite('SQL Drag And Drop Controller tests', () => {
let instantiationService = new TestInstantiationService();
instantiationService.stub(IStorageService, new TestStorageService());
let mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
undefined, //connection store
undefined, // connectionstatusmanager
undefined, // connectiondialog service
instantiationService, // instantiation service
undefined, // editor service