Schema Compare test coverage (#11042)

* Few tests for Schema Compare

* Addressed comment- removed wait in test

* Split setEndpointInfo for database and dacpac
This commit is contained in:
Sakshi Sharma
2020-06-24 14:03:02 -07:00
committed by GitHub
parent 561b881200
commit de263eacd1
5 changed files with 331 additions and 162 deletions

View File

@@ -4,16 +4,16 @@
*--------------------------------------------------------------------------------------------*/
import * as should from 'should';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as mssql from '../../../mssql';
import * as TypeMoq from 'typemoq';
import * as loc from '../localizedConstants';
import 'mocha';
import { SchemaCompareDialog } from './../dialogs/schemaCompareDialog';
import { SchemaCompareMainWindow } from '../schemaCompareMainWindow';
import { SchemaCompareTestService } from './testSchemaCompareService';
import { SchemaCompareTestService, testStateScmp } from './testSchemaCompareService';
import { createContext, TestContext } from './testContext';
import { mockIConnectionProfile, mockDacpacEndpoint, mockFilePath } from './testUtils';
import { mockIConnectionProfile, mockFilePath, setDacpacEndpointInfo, setDatabaseEndpointInfo, shouldThrowSpecificError } from './testUtils';
// Mock test data
const mocksource: string = 'source.dacpac';
@@ -26,7 +26,7 @@ before(async function (): Promise<void> {
testContext = createContext();
});
describe('SchemaCompareDialog.openDialog', function (): void {
beforeEach(() => {
before(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
});
@@ -42,27 +42,22 @@ describe('SchemaCompareDialog.openDialog', function (): void {
});
});
describe('SchemaCompareResult.start', function (): void {
beforeEach(() => {
describe('SchemaCompareMainWindow.start', function (): void {
before(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
});
it('Should be correct when created.', async function (): Promise<void> {
let sc = new SchemaCompareTestService();
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start(null);
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should(result.getComparisonResult() === undefined);
let sourceEndpointInfo : mssql.SchemaCompareEndpointInfo = {...mockDacpacEndpoint};
let targetEndpointInfo : mssql.SchemaCompareEndpointInfo = {...mockDacpacEndpoint};
result.sourceEndpointInfo = sourceEndpointInfo;
result.sourceEndpointInfo.packageFilePath = mocksource;
result.targetEndpointInfo = targetEndpointInfo;
result.targetEndpointInfo.packageFilePath = mocktarget;
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
await result.execute();
should(result.getComparisonResult() !== undefined);
@@ -74,8 +69,6 @@ describe('SchemaCompareResult.start', function (): void {
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start(undefined);
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should.equal(result.sourceEndpointInfo, undefined);
should.equal(result.targetEndpointInfo, undefined);
@@ -86,8 +79,6 @@ describe('SchemaCompareResult.start', function (): void {
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start({connectionProfile: mockIConnectionProfile});
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should.notEqual(result.sourceEndpointInfo, undefined);
should.equal(result.sourceEndpointInfo.endpointType, mssql.SchemaCompareEndpointType.Database);
@@ -102,8 +93,6 @@ describe('SchemaCompareResult.start', function (): void {
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
const dacpacPath = mockFilePath;
await result.start(dacpacPath);
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should.notEqual(result.sourceEndpointInfo, undefined);
should.equal(result.sourceEndpointInfo.endpointType, mssql.SchemaCompareEndpointType.Dacpac);
@@ -111,3 +100,86 @@ describe('SchemaCompareResult.start', function (): void {
should.equal(result.targetEndpointInfo, undefined);
});
});
describe('SchemaCompareMainWindow.execute', function (): void {
before(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
testContext = createContext();
});
beforeEach(async function (): Promise<void> {
testContext.apiWrapper.reset();
});
it('Should fail for failing Schema Compare service', async function (): Promise<void> {
let sc = new SchemaCompareTestService(testStateScmp.FAILURE);
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start(null);
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
await shouldThrowSpecificError(async () => await result.execute(), loc.compareErrorMessage('Test failure'));
});
it('Should exit for failing Schema Compare service', async function (): Promise<void> {
let sc = new SchemaCompareTestService(testStateScmp.FAILURE);
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns(() => Promise.resolve(''));
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start(null);
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
await result.execute();
testContext.apiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
it('Should disable script button and apply button for Schema Compare service for dacpac', async function (): Promise<void> {
let sc = new SchemaCompareTestService(testStateScmp.SUCCESS_NOT_EQUAL);
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start(null);
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
await result.execute();
//Generate script button and apply button should be disabled for dacpac comparison
should(result.verifyButtonsState(false, false)).equal(true);
});
it('Should disable script button and apply button for Schema Compare service for database', async function (): Promise<void> {
let sc = new SchemaCompareTestService(testStateScmp.SUCCESS_NOT_EQUAL);
let result = new SchemaCompareMainWindow(testContext.apiWrapper.object, sc, mockExtensionContext.object);
await result.start(null);
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDatabaseEndpointInfo();
await result.execute();
//Generate script button and apply button should be enabled for database comparison
should(result.verifyButtonsState(true, true)).equal(true);
});
});