Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions test/featureTests/testAssets/testAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@
import { EventStream } from "../../../src/EventStream";
import { PlatformInformation } from "../../../src/platform";
import { OmnisharpDownloader } from "../../../src/omnisharp/OmnisharpDownloader";
import { getFakeVsCode, getNullWorkspaceConfiguration } from "../../unitTests/testAssets/Fakes";
import { Uri } from "../../../src/vscodeAdapter";
import NetworkSettings from "../../../src/NetworkSettings";


export function GetTestOmnisharpDownloader(sink: EventStream, platformInfo: PlatformInformation): OmnisharpDownloader {
let vscode = getFakeVsCode();
vscode.workspace.getConfiguration = (section?: string, resource?: Uri) => {
return {
...getNullWorkspaceConfiguration(),
};
};

return new OmnisharpDownloader(() => new NetworkSettings(undefined, undefined), sink, testPackageJSON, platformInfo);
}

Expand Down
145 changes: 68 additions & 77 deletions test/unitTests/logging/InformationMessageObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import { InformationMessageObserver } from '../../../src/observers/InformationMessageObserver';
import { use as chaiUse, expect, should } from 'chai';
import { vscode, Uri } from '../../../src/vscodeAdapter';
import { getFakeVsCode, getNullWorkspaceConfiguration, getUnresolvedDependenices } from '../testAssets/Fakes';
import { getUnresolvedDependenices, updateConfig, getVSCodeWithConfig } from '../testAssets/Fakes';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/operator/timeout';
Expand All @@ -23,36 +22,12 @@ suite("InformationMessageObserver", () => {
let commandDone = new Promise<void>(resolve => {
signalCommandDone = () => { resolve(); };
});
let vscode: vscode = getFakeVsCode();
let vscode = getVsCode();
let infoMessage: string;
let relativePath: string;
let invokedCommand: string;
let observer: InformationMessageObserver = new InformationMessageObserver(vscode);

vscode.window.showInformationMessage = async (message: string, ...items: string[]) => {
infoMessage = message;
return new Promise<string>(resolve => {
doClickCancel = () => {
resolve(undefined);
};

doClickOk = () => {
resolve(message);
};
});
};

vscode.commands.executeCommand = (command: string, ...rest: any[]) => {
invokedCommand = command;
signalCommandDone();
return undefined;
};

vscode.workspace.asRelativePath = (pathOrUri?: string, includeWorspaceFolder?: boolean) => {
relativePath = pathOrUri;
return relativePath;
};

setup(() => {
infoMessage = undefined;
relativePath = undefined;
Expand All @@ -62,61 +37,77 @@ suite("InformationMessageObserver", () => {
});
});

suite('OmnisharpServerUnresolvedDependencies', () => {
let event = getUnresolvedDependenices("someFile");

suite('Suppress Dotnet Restore Notification is true', () => {
setup(() => {
vscode.workspace.getConfiguration = (section?: string, resource?: Uri) => {
return {
...getNullWorkspaceConfiguration(),
get: <T>(section: string) => {
return true;// suppress the restore information
}
};
};
[
{
event: getUnresolvedDependenices("someFile"),
expectedCommand: "dotnet.restore"
}
].forEach((elem) => {
suite(elem.event.constructor.name, () => {
suite('Suppress Dotnet Restore Notification is true', () => {
setup(() => updateConfig(vscode, 'csharp', 'suppressDotnetRestoreNotification', true));

test('The information message is not shown', () => {
observer.post(elem.event);
expect(infoMessage).to.be.undefined;
});
});

test('The information message is not shown', () => {
observer.post(event);
expect(infoMessage).to.be.undefined;
suite('Suppress Dotnet Restore Notification is false', () => {
setup(() => updateConfig(vscode, 'csharp', 'suppressDotnetRestoreNotification', false));

test('The information message is shown', async () => {
observer.post(elem.event);
expect(relativePath).to.not.be.empty;
expect(infoMessage).to.not.be.empty;
doClickOk();
await commandDone;
expect(invokedCommand).to.be.equal(elem.expectedCommand);
});

test('Given an information message if the user clicks Restore, the command is executed', async () => {
observer.post(elem.event);
doClickOk();
await commandDone;
expect(invokedCommand).to.be.equal(elem.expectedCommand);
});

test('Given an information message if the user clicks cancel, the command is not executed', async () => {
observer.post(elem.event);
doClickCancel();
await expect(Observable.fromPromise(commandDone).timeout(1).toPromise()).to.be.rejected;
expect(invokedCommand).to.be.undefined;
});
});
});

suite('Suppress Dotnet Restore Notification is false', () => {
setup(() => {
vscode.workspace.getConfiguration = (section?: string, resource?: Uri) => {
return {
...getNullWorkspaceConfiguration(),
get: <T>(section: string) => {
return false; // do not suppress the restore info
}
};
});

function getVsCode() {
let vscode = getVSCodeWithConfig();
vscode.window.showInformationMessage = async (message: string, ...items: string[]) => {
infoMessage = message;
return new Promise<string>(resolve => {
doClickCancel = () => {
resolve(undefined);
};
});

test('The information message is shown', async () => {
observer.post(event);
expect(relativePath).to.not.be.empty;
expect(infoMessage).to.not.be.empty;
doClickOk();
await commandDone;
expect(invokedCommand).to.be.equal('dotnet.restore');
});

test('Given an information message if the user clicks Restore, the command is executed', async () => {
observer.post(event);
doClickOk();
await commandDone;
expect(invokedCommand).to.be.equal('dotnet.restore');
});

test('Given an information message if the user clicks cancel, the command is not executed', async () => {
observer.post(event);
doClickCancel();
await expect(Observable.fromPromise(commandDone).timeout(1).toPromise()).to.be.rejected;
expect(invokedCommand).to.be.undefined;
doClickOk = () => {
resolve(message);
};
});
});
});
};

vscode.commands.executeCommand = (command: string, ...rest: any[]) => {
invokedCommand = command;
signalCommandDone();
return undefined;
};

vscode.workspace.asRelativePath = (pathOrUri?: string, includeWorspaceFolder?: boolean) => {
relativePath = pathOrUri;
return relativePath;
};

return vscode;
}
});
74 changes: 20 additions & 54 deletions test/unitTests/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,15 @@

import { should, expect } from 'chai';
import { Options } from '../../src/omnisharp/options';
import { getFakeVsCode, getWorkspaceConfiguration } from './testAssets/Fakes';
import { WorkspaceConfiguration } from '../../src/vscodeAdapter';

function getVSCode(omnisharpConfig?: WorkspaceConfiguration, csharpConfig?: WorkspaceConfiguration) {
const vscode = getFakeVsCode();

const _omnisharpConfig = omnisharpConfig || getWorkspaceConfiguration();
const _csharpConfig = csharpConfig || getWorkspaceConfiguration();

vscode.workspace.getConfiguration = (section?, resource?) =>
{
if (section === 'omnisharp')
{
return _omnisharpConfig;
}

if (section === 'csharp')
{
return _csharpConfig;
}

return undefined;
};

return vscode;
}
import { getVSCodeWithConfig, updateConfig } from './testAssets/Fakes';

suite("Options tests", () => {
suiteSetup(() => should());

test('Verify defaults', () =>
{
const vscode = getVSCode();
const vscode = getVSCodeWithConfig();
const options = Options.Read(vscode);

expect(options.path).to.be.null;
options.useGlobalMono.should.equal("auto");
options.waitForDebugger.should.equal(false);
Expand All @@ -57,42 +31,38 @@ suite("Options tests", () => {

test('BACK-COMPAT: "omnisharp.loggingLevel": "verbose" == "omnisharp.loggingLevel": "debug"', () =>
{
const omnisharpConfig = getWorkspaceConfiguration();
omnisharpConfig.update('loggingLevel', "verbose");
const vscode = getVSCode(omnisharpConfig);
const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'omnisharp', 'loggingLevel', "verbose");

const options = Options.Read(vscode);

options.loggingLevel.should.equal("debug");
});

test('BACK-COMPAT: "omnisharp.useMono": true == "omnisharp.useGlobalMono": "always"', () =>
{
const omnisharpConfig = getWorkspaceConfiguration();
omnisharpConfig.update('useMono', true);
const vscode = getVSCode(omnisharpConfig);

{
const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'omnisharp', 'useMono', true);

const options = Options.Read(vscode);

options.useGlobalMono.should.equal("always");
});

test('BACK-COMPAT: "omnisharp.useMono": false == "omnisharp.useGlobalMono": "auto"', () =>
{
const omnisharpConfig = getWorkspaceConfiguration();
omnisharpConfig.update('useMono', false);
const vscode = getVSCode(omnisharpConfig);

const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'omnisharp', 'useMono', false);

const options = Options.Read(vscode);

options.useGlobalMono.should.equal("auto");
});

test('BACK-COMPAT: "csharp.omnisharpUsesMono": true == "omnisharp.useGlobalMono": "always"', () =>
{
const csharpConfig = getWorkspaceConfiguration();
csharpConfig.update('omnisharpUsesMono', true);
const vscode = getVSCode(undefined, csharpConfig);
const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'csharp', 'omnisharpUsesMono', true);

const options = Options.Read(vscode);

Expand All @@ -101,9 +71,8 @@ suite("Options tests", () => {

test('BACK-COMPAT: "csharp.omnisharpUsesMono": false == "omnisharp.useGlobalMono": "auto"', () =>
{
const csharpConfig = getWorkspaceConfiguration();
csharpConfig.update('omnisharpUsesMono', false);
const vscode = getVSCode(undefined, csharpConfig);
const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'csharp', 'omnisharpUsesMono', false);

const options = Options.Read(vscode);

Expand All @@ -112,9 +81,8 @@ suite("Options tests", () => {

test('BACK-COMPAT: "csharp.omnisharp" is used if it is set and "omnisharp.path" is not', () =>
{
const csharpConfig = getWorkspaceConfiguration();
csharpConfig.update('omnisharp', 'OldPath');
const vscode = getVSCode(undefined, csharpConfig);
const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'csharp', 'omnisharp', 'OldPath');

const options = Options.Read(vscode);

Expand All @@ -123,11 +91,9 @@ suite("Options tests", () => {

test('BACK-COMPAT: "csharp.omnisharp" is not used if "omnisharp.path" is set', () =>
{
const omnisharpConfig = getWorkspaceConfiguration();
omnisharpConfig.update('path', 'NewPath');
const csharpConfig = getWorkspaceConfiguration();
csharpConfig.update('omnisharp', 'OldPath');
const vscode = getVSCode(omnisharpConfig, csharpConfig);
const vscode = getVSCodeWithConfig();
updateConfig(vscode, 'omnisharp', 'path', 'NewPath');
updateConfig(vscode, 'csharp', 'omnisharp', 'OldPath');

const options = Options.Read(vscode);

Expand Down
48 changes: 30 additions & 18 deletions test/unitTests/testAssets/Fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@ export const getNullTelemetryReporter = (): ITelemetryReporter => {
return reporter;
};

export const getNullWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
let configuration: vscode.WorkspaceConfiguration = {
get: <T>(section: string): T | undefined => {
return undefined;
},
has: (section: string) => { return undefined; },
inspect: () => {
return {
key: undefined
};
},
update: async () => { return Promise.resolve(); }
};

return configuration;
};

export const getWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
let values: { [key: string]: any } = {};

Expand Down Expand Up @@ -164,4 +147,33 @@ export function getWorkspaceInformationUpdated(msbuild: protocol.MsBuildWorkspac
};

return new WorkspaceInformationUpdated(a);
}
}

export function getVSCodeWithConfig() {
const vscode = getFakeVsCode();

const _omnisharpConfig = getWorkspaceConfiguration();
const _csharpConfig = getWorkspaceConfiguration();

vscode.workspace.getConfiguration = (section?, resource?) =>
{
if (section === 'omnisharp')
{
return _omnisharpConfig;
}

if (section === 'csharp')
{
return _csharpConfig;
}

return undefined;
};

return vscode;
}

export function updateConfig(vscode: vscode.vscode, section: string, config: string, value: any) {
let workspaceConfig = vscode.workspace.getConfiguration(section);
workspaceConfig.update(config, value);
}