Public api changes to namespace accounts & connection. (#2383)

* 1.Added following functions to namespace accounts
function getAllAccounts(): Thenable<AccountWithProviderHandle[]>;
function getSecurityToken(account: AccountWithProviderHandle): Thenable<{}>;
2.Added class AccountWithProviderHandle as the wrapper for Account
3.Changed function openConnectionDialog of namespace connection to allow connection dialog initialized with specified parameters, i.e., server name, database name, etc.
function openConnectionDialog(provider?: string[], initialConnectionProfile?: IConnectionProfile): Thenable<connection.Connection>;

* Added unit tests for ExtHostAccountManagement.$getAllAccounts
This commit is contained in:
Vincent Feng
2018-09-03 11:48:00 +08:00
committed by GitHub
parent b27f69aace
commit 8600dbb04e
9 changed files with 170 additions and 9 deletions

View File

@@ -256,6 +256,91 @@ suite('ExtHostAccountManagement', () => {
})
.then(() => done(), (err) => done(err));
});
// GETALLACCOUNTS TESTS ///////////////////////////////////////////////////////
test('GetAllAccounts - Success', (done) => {
let mockAccountProviderMetadata = {
id: 'azure',
displayName: 'Azure'
};
let mockAccount1 = {
key: {
providerId: mockAccountProviderMetadata.id,
accountId: 'azure_account_1'
},
displayInfo: {
contextualDisplayName: 'Microsoft Account',
accountType: 'microsoft',
displayName: 'Azure Account 1'
},
properties: [],
isStale: false
};
let mockAccount2 = {
key: {
providerId: mockAccountProviderMetadata.id,
accountId: 'azure_account_2'
},
displayInfo: {
contextualDisplayName: 'Work/School Account',
accountType: 'microsoft',
displayName: 'Azure Account 2'
},
properties: [],
isStale: false
};
let mockAccounts = [mockAccount1, mockAccount2];
let expectedAccounts = [
{
account: mockAccount1,
providerHandle: 0
},
{
account: mockAccount2,
providerHandle: 0
}
];
let mockAccountManagementService = getMockAccountManagementService(mockAccounts);
instantiationService.stub(IAccountManagementService, mockAccountManagementService.object);
let accountManagementService = instantiationService.createInstance(MainThreadAccountManagement);
threadService.set(SqlMainContext.MainThreadAccountManagement, accountManagementService);
// Setup: Create ext host account management with registered account provider
let extHost = new ExtHostAccountManagement(threadService);
extHost.$registerAccountProvider(mockAccountProviderMetadata, new AccountProviderStub());
// If: I get all accounts
extHost.$getAllAccounts()
.then((accounts) => {
// Then: The call should have been passed to the account management service
mockAccountManagementService.verify(
(obj) => obj.getAccountsForProvider(TypeMoq.It.isAny()),
TypeMoq.Times.once()
);
assert.ok(Array.isArray(accounts));
assert.equal(accounts.length, expectedAccounts.length);
assert.deepStrictEqual(accounts, expectedAccounts);
})
.then(() => done(), (err) => done(err));
});
test('GetAllAccounts - No account providers', (done) => {
// Setup: Create ext host account management with no registered account providers
let extHost = new ExtHostAccountManagement(threadService);
// If: I get all accounts
// Then: It should throw
assert.throws(
() => extHost.$getAllAccounts(),
(error) => {
return error.message === 'No account providers registered.';
});
done();
});
});
function getMockAccountProvider(): TypeMoq.Mock<sqlops.AccountProvider> {
@@ -271,3 +356,12 @@ function getMockAccountProvider(): TypeMoq.Mock<sqlops.AccountProvider> {
return mock;
}
function getMockAccountManagementService(accounts: sqlops.Account[]): TypeMoq.Mock<AccountManagementTestService> {
let mockAccountManagementService = TypeMoq.Mock.ofType(AccountManagementTestService);
mockAccountManagementService.setup(x => x.getAccountsForProvider(TypeMoq.It.isAny()))
.returns(() => Promise.resolve(accounts));
return mockAccountManagementService;
}