mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
cleanup dacpac and schema compare to use createConnectionProfile() from ads-test (#19942)
* cleanup dacpac and schema compare to use createConnectionProfile() from ads-test * typo * reuse mockConnectionInfo
This commit is contained in:
@@ -9,11 +9,13 @@ import * as TypeMoq from 'typemoq';
|
||||
import * as loc from '../localizedConstants';
|
||||
import * as sinon from 'sinon';
|
||||
import * as azdata from 'azdata';
|
||||
import * as azdataTest from '@microsoft/azdata-test';
|
||||
|
||||
import 'mocha';
|
||||
import { ConnectionDropdownValue, SchemaCompareDialog } from './../dialogs/schemaCompareDialog';
|
||||
import { SchemaCompareMainWindow } from '../schemaCompareMainWindow';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
import { mockConnectionProfile, mockConnectionProfile2, setDacpacEndpointInfo } from './testUtils';
|
||||
import { setDacpacEndpointInfo } from './testUtils';
|
||||
import { SchemaCompareMainWindowTest } from './testSchemaCompareMainWindow';
|
||||
import { SchemaCompareDialogTest } from './testSchemaCompareDialog';
|
||||
|
||||
@@ -75,9 +77,10 @@ describe('SchemaCompareDialog.openDialog @DacFx@', function (): void {
|
||||
});
|
||||
|
||||
it('Verify server dropdown gets populated appropriately', async function (): Promise<void> {
|
||||
const getConnectionsResults: azdata.connection.ConnectionProfile[] = [{ ...mockConnectionProfile }];
|
||||
const connectionProfile = azdataTest.stubs.connectionProfile.createConnectionProfile();
|
||||
const getConnectionsResults: azdata.connection.ConnectionProfile[] = [{ ...connectionProfile }];
|
||||
sinon.stub(azdata.connection, 'getCurrentConnection').resolves(undefined);
|
||||
sinon.stub(azdata.connection, 'openConnectionDialog').resolves(<any>Promise.resolve(mockConnectionProfile));
|
||||
sinon.stub(azdata.connection, 'openConnectionDialog').resolves(<any>Promise.resolve(connectionProfile));
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves(<any>Promise.resolve(getConnectionsResults));
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves(['My Database']);
|
||||
|
||||
@@ -95,17 +98,20 @@ describe('SchemaCompareDialog.openDialog @DacFx@', function (): void {
|
||||
|
||||
// Confirm source server dropdown has the new connection as its value
|
||||
should.notEqual(dialog.getSourceServerDropdownValue(), undefined);
|
||||
should((dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(mockConnectionProfile, `SourceDropdownValue: (Actual) ${(dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${mockConnectionProfile}`);
|
||||
should((dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(connectionProfile, `SourceDropdownValue: (Actual) ${(dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${connectionProfile}`);
|
||||
|
||||
// Target server dropdown passively populated with the new connection, since it wasn't pre-populated
|
||||
should.notEqual(dialog.getTargetServerDropdownValue(), undefined);
|
||||
should((dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(mockConnectionProfile, `TargetDropdownValue: (Actual) ${(dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${mockConnectionProfile}`);
|
||||
should((dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(connectionProfile, `TargetDropdownValue: (Actual) ${(dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${connectionProfile}`);
|
||||
});
|
||||
|
||||
it('Verify source server dropdown does not get updated when target server is updated', async function (): Promise<void> {
|
||||
sinon.stub(azdata.connection, 'getCurrentConnection').resolves({ ...mockConnectionProfile });
|
||||
sinon.stub(azdata.connection, 'openConnectionDialog').resolves(<any>Promise.resolve(mockConnectionProfile2));
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves(<any>Promise.resolve([{ ...mockConnectionProfile }, { ...mockConnectionProfile2 }]));
|
||||
const connectionProfile1 = azdataTest.stubs.connectionProfile.createConnectionProfile({ connectionName: 'connection1', connectionId: 'testId1', databaseName: 'db1'});
|
||||
const connectionProfile2 = azdataTest.stubs.connectionProfile.createConnectionProfile({ connectionName: 'connection2', connectionId: 'testId2', databaseName: 'db2'});
|
||||
|
||||
sinon.stub(azdata.connection, 'getCurrentConnection').resolves({ ...connectionProfile1 });
|
||||
sinon.stub(azdata.connection, 'openConnectionDialog').resolves(<any>Promise.resolve(connectionProfile2));
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves(<any>Promise.resolve([{ ...connectionProfile1 }, { ...connectionProfile2 }]));
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves(['My Database']);
|
||||
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(undefined, mockExtensionContext.object);
|
||||
@@ -122,10 +128,10 @@ describe('SchemaCompareDialog.openDialog @DacFx@', function (): void {
|
||||
|
||||
// Confirm source server dropdown has the current connection (from getCurrentConnection) as its value (and doesn't get updated to what target server is)
|
||||
should.notEqual(dialog.getSourceServerDropdownValue(), undefined);
|
||||
should((dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(mockConnectionProfile, `SourceDropdownValue: (Actual) ${(dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${mockConnectionProfile}`);
|
||||
should((dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(connectionProfile1, `SourceDropdownValue: (Actual) ${(dialog.getSourceServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${connectionProfile1}`);
|
||||
|
||||
// Confirm target server dropdown has the new connection (from openConnectionDialog) as its value
|
||||
should.notEqual(dialog.getTargetServerDropdownValue(), undefined);
|
||||
should((dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(mockConnectionProfile2, `TargetDropdownValue: (Actual) ${(dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${mockConnectionProfile2}`);
|
||||
should((dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection).deepEqual(connectionProfile2, `TargetDropdownValue: (Actual) ${(dialog.getTargetServerDropdownValue() as ConnectionDropdownValue).connection} (Expected) ${connectionProfile2}`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,50 +25,6 @@ export const mockIConnectionProfile: azdata.IConnectionProfile = {
|
||||
options: null
|
||||
};
|
||||
|
||||
export const mockConnectionProfile: azdata.connection.ConnectionProfile = {
|
||||
providerId: 'My Provider',
|
||||
connectionId: 'My Id',
|
||||
connectionName: 'My Connection',
|
||||
serverName: 'My Server',
|
||||
databaseName: 'My Database',
|
||||
userName: 'My User',
|
||||
password: 'My Pwd',
|
||||
authenticationType: 'SqlLogin',
|
||||
savePassword: false,
|
||||
groupFullName: 'My groupName',
|
||||
groupId: 'My GroupId',
|
||||
saveProfile: true,
|
||||
options: {
|
||||
server: 'My Server',
|
||||
database: 'My Database',
|
||||
user: 'My User',
|
||||
password: 'My Pwd',
|
||||
authenticationType: 'SqlLogin'
|
||||
}
|
||||
};
|
||||
|
||||
export const mockConnectionProfile2: azdata.connection.ConnectionProfile = {
|
||||
providerId: 'My Provider2',
|
||||
connectionId: 'My Id2',
|
||||
connectionName: 'My Connection2',
|
||||
serverName: 'My Server2',
|
||||
databaseName: 'My Database2',
|
||||
userName: 'My User2',
|
||||
password: 'My Pwd2',
|
||||
authenticationType: 'SqlLogin',
|
||||
savePassword: false,
|
||||
groupFullName: 'My groupName2',
|
||||
groupId: 'My GroupId2',
|
||||
saveProfile: true,
|
||||
options: {
|
||||
server: 'My Server2',
|
||||
database: 'My Database2',
|
||||
user: 'My User2',
|
||||
password: 'My Pwd2',
|
||||
authenticationType: 'SqlLogin'
|
||||
}
|
||||
};
|
||||
|
||||
export const mockConnectionResult: azdata.ConnectionResult = {
|
||||
connected: false,
|
||||
connectionId: undefined,
|
||||
|
||||
@@ -8,13 +8,14 @@ import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as mssql from 'mssql';
|
||||
import * as loc from '../localizedConstants';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as path from 'path';
|
||||
import * as uuid from 'uuid';
|
||||
import * as os from 'os';
|
||||
import * as azdataTest from '@microsoft/azdata-test';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import { getEndpointName, verifyConnectionAndGetOwnerUri, exists } from '../utils';
|
||||
import { mockDacpacEndpoint, mockDatabaseEndpoint, mockFilePath, mockConnectionInfo, shouldThrowSpecificError, mockConnectionResult, mockConnectionProfile } from './testUtils';
|
||||
import { mockDacpacEndpoint, mockDatabaseEndpoint, mockFilePath, mockConnectionInfo, shouldThrowSpecificError, mockConnectionResult } from './testUtils';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
@@ -115,7 +116,16 @@ describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', funct
|
||||
});
|
||||
|
||||
it('Should throw an error for login failure', async function (): Promise<void> {
|
||||
const getConnectionsResults: azdata.connection.ConnectionProfile[] = [{ ...mockConnectionProfile }];
|
||||
const connectionProfile = azdataTest.stubs.connectionProfile.createConnectionProfile({
|
||||
// these need to match what's in mockConnectionInfo in testUtils.ts
|
||||
options: {
|
||||
server: mockConnectionInfo.serverName,
|
||||
database: mockConnectionInfo.databaseName,
|
||||
user: mockConnectionInfo.userName,
|
||||
authenticationType: mockConnectionInfo.authenticationType
|
||||
}
|
||||
});
|
||||
const getConnectionsResults: azdata.connection.ConnectionProfile[] = [{ ...connectionProfile }];
|
||||
const connection = { ...mockConnectionResult };
|
||||
const testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = { ...mockDatabaseEndpoint };
|
||||
testDatabaseEndpoint.connectionDetails = { ...mockConnectionInfo };
|
||||
|
||||
Reference in New Issue
Block a user