mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add more tests for duplicate database references (#13292)
* Add test for duplicate project reference * add test for different slashes that caused problem before * split up duplicate database reference tests
This commit is contained in:
@@ -15,6 +15,7 @@ import { promises as fs } from 'fs';
|
|||||||
import { Project, EntryType, SystemDatabase, SystemDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry } from '../models/project';
|
import { Project, EntryType, SystemDatabase, SystemDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry } from '../models/project';
|
||||||
import { exists, convertSlashesForSqlProj } from '../common/utils';
|
import { exists, convertSlashesForSqlProj } from '../common/utils';
|
||||||
import { Uri, window } from 'vscode';
|
import { Uri, window } from 'vscode';
|
||||||
|
import { IDacpacReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings';
|
||||||
|
|
||||||
let projFilePath: string;
|
let projFilePath: string;
|
||||||
|
|
||||||
@@ -369,26 +370,79 @@ describe('Project: sqlproj content operations', function (): void {
|
|||||||
should(projFileText).containEql('<DefaultValue>otherServerName</DefaultValue>');
|
should(projFileText).containEql('<DefaultValue>otherServerName</DefaultValue>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not allow adding duplicate database references', async function (): Promise<void> {
|
it('Should not allow adding duplicate dacpac references', async function (): Promise<void> {
|
||||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||||
const project = await Project.openProject(projFilePath);
|
const project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
should(project.databaseReferences.length).equal(0, 'There should be no database references to start with');
|
should(project.databaseReferences.length).equal(0, 'There should be no database references to start with');
|
||||||
await project.addSystemDatabaseReference({ databaseName: 'master', systemDb: SystemDatabase.master, suppressMissingDependenciesErrors: false });
|
|
||||||
|
const dacpacReference: IDacpacReferenceSettings = { dacpacFileLocation: Uri.file('test.dacpac'), suppressMissingDependenciesErrors: false };
|
||||||
|
await project.addDatabaseReference(dacpacReference);
|
||||||
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after adding a reference to test.dacpac');
|
||||||
|
should(project.databaseReferences[0].databaseName).equal('test', 'project.databaseReferences[0].databaseName should be test');
|
||||||
|
|
||||||
|
// try to add reference to test.dacpac again
|
||||||
|
await testUtils.shouldThrowSpecificError(async () => await project.addDatabaseReference(dacpacReference), constants.databaseReferenceAlreadyExists);
|
||||||
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after trying to add a reference to test.dacpac again');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should not allow adding duplicate system database references', async function (): Promise<void> {
|
||||||
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||||
|
const project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
|
should(project.databaseReferences.length).equal(0, 'There should be no database references to start with');
|
||||||
|
|
||||||
|
const systemDbReference: ISystemDatabaseReferenceSettings = { databaseName: 'master', systemDb: SystemDatabase.master, suppressMissingDependenciesErrors: false };
|
||||||
|
await project.addSystemDatabaseReference(systemDbReference);
|
||||||
should(project.databaseReferences.length).equal(1, 'There should be one database reference after adding a reference to master');
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after adding a reference to master');
|
||||||
should(project.databaseReferences[0].databaseName).equal(constants.master, 'project.databaseReferences[0].databaseName should be master');
|
should(project.databaseReferences[0].databaseName).equal(constants.master, 'project.databaseReferences[0].databaseName should be master');
|
||||||
|
|
||||||
// try to add reference to master again
|
// try to add reference to master again
|
||||||
await testUtils.shouldThrowSpecificError(async () => await project.addSystemDatabaseReference({ databaseName: 'master', systemDb: SystemDatabase.master, suppressMissingDependenciesErrors: false }), constants.databaseReferenceAlreadyExists);
|
await testUtils.shouldThrowSpecificError(async () => await project.addSystemDatabaseReference(systemDbReference), constants.databaseReferenceAlreadyExists);
|
||||||
should(project.databaseReferences.length).equal(1, 'There should only be one database reference after trying to add a reference to master again');
|
should(project.databaseReferences.length).equal(1, 'There should only be one database reference after trying to add a reference to master again');
|
||||||
|
});
|
||||||
|
|
||||||
await project.addDatabaseReference({ dacpacFileLocation: Uri.file('test.dacpac'), suppressMissingDependenciesErrors: false });
|
it('Should not allow adding duplicate project references', async function (): Promise<void> {
|
||||||
should(project.databaseReferences.length).equal(2, 'There should be two database references after adding a reference to test.dacpac');
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||||
should(project.databaseReferences[1].databaseName).equal('test', 'project.databaseReferences[1].databaseName should be test');
|
const project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
// try to add reference to test.dacpac again
|
should(project.databaseReferences.length).equal(0, 'There should be no database references to start with');
|
||||||
await testUtils.shouldThrowSpecificError(async () => await project.addDatabaseReference({ dacpacFileLocation: Uri.file('test.dacpac'), suppressMissingDependenciesErrors: false }), constants.databaseReferenceAlreadyExists);
|
|
||||||
should(project.databaseReferences.length).equal(2, 'There should be two database references after trying to add a reference to test.dacpac again');
|
const projectReference: IProjectReferenceSettings = {
|
||||||
|
projectName: 'testProject',
|
||||||
|
projectGuid: '',
|
||||||
|
projectRelativePath: Uri.file('testProject.sqlproj'),
|
||||||
|
suppressMissingDependenciesErrors: false
|
||||||
|
};
|
||||||
|
await project.addProjectReference(projectReference);
|
||||||
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after adding a reference to testProject.sqlproj');
|
||||||
|
should(project.databaseReferences[0].databaseName).equal('testProject', 'project.databaseReferences[0].databaseName should be testProject');
|
||||||
|
|
||||||
|
// try to add reference to testProject again
|
||||||
|
await testUtils.shouldThrowSpecificError(async () => await project.addProjectReference(projectReference), constants.databaseReferenceAlreadyExists);
|
||||||
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after trying to add a reference to testProject again');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should handle trying to add duplicate database references when slashes are different direction', async function (): Promise<void> {
|
||||||
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||||
|
const project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
|
should(project.databaseReferences.length).equal(0, 'There should be no database references to start with');
|
||||||
|
|
||||||
|
const projectReference: IProjectReferenceSettings = {
|
||||||
|
projectName: 'testProject',
|
||||||
|
projectGuid: '',
|
||||||
|
projectRelativePath: Uri.file('testFolder/testProject.sqlproj'),
|
||||||
|
suppressMissingDependenciesErrors: false
|
||||||
|
};
|
||||||
|
await project.addProjectReference(projectReference);
|
||||||
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after adding a reference to testProject.sqlproj');
|
||||||
|
should(project.databaseReferences[0].databaseName).equal('testProject', 'project.databaseReferences[0].databaseName should be testProject');
|
||||||
|
|
||||||
|
// try to add reference to testProject again with slashes in the other direction
|
||||||
|
projectReference.projectRelativePath = Uri.file('testFolder\\testProject.sqlproj');
|
||||||
|
await testUtils.shouldThrowSpecificError(async () => await project.addProjectReference(projectReference), constants.databaseReferenceAlreadyExists);
|
||||||
|
should(project.databaseReferences.length).equal(1, 'There should be one database reference after trying to add a reference to testProject again');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should update sqlcmd variable values if value changes', async function (): Promise<void> {
|
it('Should update sqlcmd variable values if value changes', async function (): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user