mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Schema Compare tests for utils (#10759)
* Added a few tests for utils file under Schema Compare * Addressed comment- moved mock test data to a common location
This commit is contained in:
@@ -12,47 +12,12 @@ import 'mocha';
|
||||
import { SchemaCompareDialog } from './../dialogs/schemaCompareDialog';
|
||||
import { SchemaCompareMainWindow } from '../schemaCompareMainWindow';
|
||||
import { SchemaCompareTestService } from './testSchemaCompareService';
|
||||
import { mockConnectionProfile, mockDacpacEndpoint } from './testUtils';
|
||||
|
||||
// Mock test data
|
||||
const mockConnectionProfile: azdata.IConnectionProfile = {
|
||||
connectionName: 'My Connection',
|
||||
serverName: 'My Server',
|
||||
databaseName: 'My Server',
|
||||
userName: 'My User',
|
||||
password: 'My Pwd',
|
||||
authenticationType: 'SqlLogin',
|
||||
savePassword: false,
|
||||
groupFullName: 'My groupName',
|
||||
groupId: 'My GroupId',
|
||||
providerName: 'My Server',
|
||||
saveProfile: true,
|
||||
id: 'My Id',
|
||||
options: null
|
||||
};
|
||||
|
||||
const mocksource: string = 'source.dacpac';
|
||||
const mocktarget: string = 'target.dacpac';
|
||||
|
||||
const mockSourceEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
endpointType: mssql.SchemaCompareEndpointType.Dacpac,
|
||||
serverDisplayName: '',
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: mocksource,
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
const mockTargetEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
endpointType: mssql.SchemaCompareEndpointType.Dacpac,
|
||||
serverDisplayName: '',
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: mocktarget,
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
|
||||
|
||||
describe('SchemaCompareDialog.openDialog', function (): void {
|
||||
@@ -86,8 +51,13 @@ describe('SchemaCompareResult.start', function (): void {
|
||||
await promise;
|
||||
|
||||
should(result.getComparisonResult() === undefined);
|
||||
result.sourceEndpointInfo = mockSourceEndpoint;
|
||||
result.targetEndpointInfo = mockTargetEndpoint;
|
||||
|
||||
let sourceEndpointInfo : mssql.SchemaCompareEndpointInfo = {...mockDacpacEndpoint};
|
||||
let targetEndpointInfo : mssql.SchemaCompareEndpointInfo = {...mockDacpacEndpoint};
|
||||
result.sourceEndpointInfo = sourceEndpointInfo;
|
||||
result.sourceEndpointInfo.packageFilePath = mocksource;
|
||||
result.targetEndpointInfo = targetEndpointInfo;
|
||||
result.targetEndpointInfo.packageFilePath = mocktarget;
|
||||
await result.execute();
|
||||
|
||||
should(result.getComparisonResult() !== undefined);
|
||||
|
||||
55
extensions/schema-compare/src/test/testUtils.ts
Normal file
55
extensions/schema-compare/src/test/testUtils.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as mssql from '../../../mssql';
|
||||
|
||||
// Mock test data
|
||||
export const mockConnectionProfile: azdata.IConnectionProfile = {
|
||||
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',
|
||||
providerName: 'My Provider',
|
||||
saveProfile: true,
|
||||
id: 'My Id',
|
||||
options: null
|
||||
};
|
||||
|
||||
export const mockConnectionInfo = {
|
||||
options: {},
|
||||
serverName: 'My Server',
|
||||
databaseName: 'My Database',
|
||||
userName: 'My User',
|
||||
password: 'My Pwd',
|
||||
authenticationType: 'SqlLogin'
|
||||
};
|
||||
|
||||
export const mockFilePath: string = 'test.dacpac';
|
||||
|
||||
export const mockDacpacEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
endpointType: mssql.SchemaCompareEndpointType.Dacpac,
|
||||
serverDisplayName: '',
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: mockFilePath,
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
export const mockDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
endpointType: mssql.SchemaCompareEndpointType.Database,
|
||||
serverDisplayName: '',
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
55
extensions/schema-compare/src/test/utils.test.ts
Normal file
55
extensions/schema-compare/src/test/utils.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as should from 'should';
|
||||
import * as mssql from '../../../mssql';
|
||||
import {getEndpointName, verifyConnectionAndGetOwnerUri } from '../utils';
|
||||
import {mockDacpacEndpoint, mockDatabaseEndpoint, mockFilePath, mockConnectionInfo} from './testUtils';
|
||||
|
||||
describe('utils: Tests to verify getEndpointName', function (): void {
|
||||
it('Should generate correct endpoint information', async () => {
|
||||
let endpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
|
||||
should(getEndpointName(endpointInfo)).equal(' ');
|
||||
should(getEndpointName(mockDacpacEndpoint)).equal(mockFilePath);
|
||||
should(getEndpointName(mockDatabaseEndpoint)).equal(' ');
|
||||
});
|
||||
|
||||
it('Should get endpoint information from ConnectionInfo', async () => {
|
||||
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = mockDatabaseEndpoint;
|
||||
testDatabaseEndpoint.connectionDetails = mockConnectionInfo;
|
||||
|
||||
should(getEndpointName(testDatabaseEndpoint)).equal('My Server.My Database');
|
||||
});
|
||||
|
||||
it('Should get correct endpoint information from SchemaCompareEndpointInfo', async () => {
|
||||
let dbName = 'My Database';
|
||||
let serverName = 'My Server';
|
||||
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {...mockDatabaseEndpoint};
|
||||
testDatabaseEndpoint.databaseName = dbName;
|
||||
testDatabaseEndpoint.serverName = serverName;
|
||||
|
||||
should(getEndpointName(testDatabaseEndpoint)).equal('My Server.My Database');
|
||||
});
|
||||
});
|
||||
|
||||
describe('utils: Tests to verify verifyConnectionAndGetOwnerUri', function (): void {
|
||||
it('Should return undefined for endpoint as dacpac', async function (): Promise<void> {
|
||||
let ownerUri = undefined;
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(mockDacpacEndpoint, 'test');
|
||||
|
||||
should(ownerUri).equal(undefined);
|
||||
});
|
||||
|
||||
it('Should return undefined for endpoint as database and no ConnectionInfo', async function (): Promise<void> {
|
||||
let ownerUri = undefined;
|
||||
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {...mockDatabaseEndpoint};
|
||||
testDatabaseEndpoint.connectionDetails = undefined;
|
||||
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test');
|
||||
|
||||
should(ownerUri).equal(undefined);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user