mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 01:25:36 -05:00
Swapping vscode calls for ApiWrapper for testability (#10267)
* swapping vscode calls for apiwrapper for testability * Adding mainController tests * Adding unit tests for input validation * Adding project controller tests, reorganizing error handling * Removing commented-out code
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as xmldom from 'xmldom';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
import { Uri } from 'vscode';
|
||||
import { promises as fs } from 'fs';
|
||||
import { DataSource } from './dataSources/dataSources';
|
||||
import { getErrorMessage } from '../common/utils';
|
||||
|
||||
/**
|
||||
* Class representing a Project, and providing functions for operating on it
|
||||
@@ -35,14 +34,7 @@ export class Project {
|
||||
*/
|
||||
public async readProjFile() {
|
||||
const projFileText = await fs.readFile(this.projectFilePath);
|
||||
|
||||
try {
|
||||
this.projFileXmlDoc = new xmldom.DOMParser().parseFromString(projFileText.toString());
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(err);
|
||||
return;
|
||||
}
|
||||
this.projFileXmlDoc = new xmldom.DOMParser().parseFromString(projFileText.toString());
|
||||
|
||||
// find all folders and files to include
|
||||
|
||||
@@ -93,7 +85,7 @@ export class Project {
|
||||
}
|
||||
|
||||
private createProjectEntry(relativePath: string, entryType: EntryType): ProjectEntry {
|
||||
return new ProjectEntry(vscode.Uri.file(path.join(this.projectFolderPath, relativePath)), relativePath, entryType);
|
||||
return new ProjectEntry(Uri.file(path.join(this.projectFolderPath, relativePath)), relativePath, entryType);
|
||||
}
|
||||
|
||||
private findOrCreateItemGroup(containedTag?: string): any {
|
||||
@@ -134,21 +126,15 @@ export class Project {
|
||||
}
|
||||
|
||||
private async addToProjFile(entry: ProjectEntry) {
|
||||
try {
|
||||
switch (entry.type) {
|
||||
case EntryType.File:
|
||||
this.addFileToProjFile(entry.relativePath);
|
||||
break;
|
||||
case EntryType.Folder:
|
||||
this.addFolderToProjFile(entry.relativePath);
|
||||
}
|
||||
switch (entry.type) {
|
||||
case EntryType.File:
|
||||
this.addFileToProjFile(entry.relativePath);
|
||||
break;
|
||||
case EntryType.Folder:
|
||||
this.addFolderToProjFile(entry.relativePath);
|
||||
}
|
||||
|
||||
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
return;
|
||||
}
|
||||
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||
}
|
||||
|
||||
private async serializeToProjFile(projFileContents: any) {
|
||||
@@ -165,11 +151,11 @@ export class ProjectEntry {
|
||||
/**
|
||||
* Absolute file system URI
|
||||
*/
|
||||
fsUri: vscode.Uri;
|
||||
fsUri: Uri;
|
||||
relativePath: string;
|
||||
type: EntryType;
|
||||
|
||||
constructor(uri: vscode.Uri, relativePath: string, type: EntryType) {
|
||||
constructor(uri: Uri, relativePath: string, type: EntryType) {
|
||||
this.fsUri = uri;
|
||||
this.relativePath = relativePath;
|
||||
this.type = type;
|
||||
|
||||
Reference in New Issue
Block a user