Skip to content

Commit 802e6f9

Browse files
Merge branch 'master' into release
2 parents ba5cb86 + a7d392c commit 802e6f9

File tree

4 files changed

+118
-159
lines changed

4 files changed

+118
-159
lines changed

test/featureTests/testAssets/testAssets.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@
77
import { EventStream } from "../../../src/EventStream";
88
import { PlatformInformation } from "../../../src/platform";
99
import { OmnisharpDownloader } from "../../../src/omnisharp/OmnisharpDownloader";
10-
import { getFakeVsCode, getNullWorkspaceConfiguration } from "../../unitTests/testAssets/Fakes";
11-
import { Uri } from "../../../src/vscodeAdapter";
1210
import NetworkSettings from "../../../src/NetworkSettings";
1311

14-
1512
export function GetTestOmnisharpDownloader(sink: EventStream, platformInfo: PlatformInformation): OmnisharpDownloader {
16-
let vscode = getFakeVsCode();
17-
vscode.workspace.getConfiguration = (section?: string, resource?: Uri) => {
18-
return {
19-
...getNullWorkspaceConfiguration(),
20-
};
21-
};
22-
2313
return new OmnisharpDownloader(() => new NetworkSettings(undefined, undefined), sink, testPackageJSON, platformInfo);
2414
}
2515

test/unitTests/logging/InformationMessageObserver.test.ts

Lines changed: 68 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import { InformationMessageObserver } from '../../../src/observers/InformationMessageObserver';
77
import { use as chaiUse, expect, should } from 'chai';
8-
import { vscode, Uri } from '../../../src/vscodeAdapter';
9-
import { getFakeVsCode, getNullWorkspaceConfiguration, getUnresolvedDependenices } from '../testAssets/Fakes';
8+
import { getUnresolvedDependenices, updateConfig, getVSCodeWithConfig } from '../testAssets/Fakes';
109
import { Observable } from 'rxjs/Observable';
1110
import 'rxjs/add/observable/fromPromise';
1211
import 'rxjs/add/operator/timeout';
@@ -23,36 +22,12 @@ suite("InformationMessageObserver", () => {
2322
let commandDone = new Promise<void>(resolve => {
2423
signalCommandDone = () => { resolve(); };
2524
});
26-
let vscode: vscode = getFakeVsCode();
25+
let vscode = getVsCode();
2726
let infoMessage: string;
2827
let relativePath: string;
2928
let invokedCommand: string;
3029
let observer: InformationMessageObserver = new InformationMessageObserver(vscode);
3130

32-
vscode.window.showInformationMessage = async (message: string, ...items: string[]) => {
33-
infoMessage = message;
34-
return new Promise<string>(resolve => {
35-
doClickCancel = () => {
36-
resolve(undefined);
37-
};
38-
39-
doClickOk = () => {
40-
resolve(message);
41-
};
42-
});
43-
};
44-
45-
vscode.commands.executeCommand = (command: string, ...rest: any[]) => {
46-
invokedCommand = command;
47-
signalCommandDone();
48-
return undefined;
49-
};
50-
51-
vscode.workspace.asRelativePath = (pathOrUri?: string, includeWorspaceFolder?: boolean) => {
52-
relativePath = pathOrUri;
53-
return relativePath;
54-
};
55-
5631
setup(() => {
5732
infoMessage = undefined;
5833
relativePath = undefined;
@@ -62,61 +37,77 @@ suite("InformationMessageObserver", () => {
6237
});
6338
});
6439

65-
suite('OmnisharpServerUnresolvedDependencies', () => {
66-
let event = getUnresolvedDependenices("someFile");
67-
68-
suite('Suppress Dotnet Restore Notification is true', () => {
69-
setup(() => {
70-
vscode.workspace.getConfiguration = (section?: string, resource?: Uri) => {
71-
return {
72-
...getNullWorkspaceConfiguration(),
73-
get: <T>(section: string) => {
74-
return true;// suppress the restore information
75-
}
76-
};
77-
};
40+
[
41+
{
42+
event: getUnresolvedDependenices("someFile"),
43+
expectedCommand: "dotnet.restore"
44+
}
45+
].forEach((elem) => {
46+
suite(elem.event.constructor.name, () => {
47+
suite('Suppress Dotnet Restore Notification is true', () => {
48+
setup(() => updateConfig(vscode, 'csharp', 'suppressDotnetRestoreNotification', true));
49+
50+
test('The information message is not shown', () => {
51+
observer.post(elem.event);
52+
expect(infoMessage).to.be.undefined;
53+
});
7854
});
7955

80-
test('The information message is not shown', () => {
81-
observer.post(event);
82-
expect(infoMessage).to.be.undefined;
56+
suite('Suppress Dotnet Restore Notification is false', () => {
57+
setup(() => updateConfig(vscode, 'csharp', 'suppressDotnetRestoreNotification', false));
58+
59+
test('The information message is shown', async () => {
60+
observer.post(elem.event);
61+
expect(relativePath).to.not.be.empty;
62+
expect(infoMessage).to.not.be.empty;
63+
doClickOk();
64+
await commandDone;
65+
expect(invokedCommand).to.be.equal(elem.expectedCommand);
66+
});
67+
68+
test('Given an information message if the user clicks Restore, the command is executed', async () => {
69+
observer.post(elem.event);
70+
doClickOk();
71+
await commandDone;
72+
expect(invokedCommand).to.be.equal(elem.expectedCommand);
73+
});
74+
75+
test('Given an information message if the user clicks cancel, the command is not executed', async () => {
76+
observer.post(elem.event);
77+
doClickCancel();
78+
await expect(Observable.fromPromise(commandDone).timeout(1).toPromise()).to.be.rejected;
79+
expect(invokedCommand).to.be.undefined;
80+
});
8381
});
8482
});
85-
86-
suite('Suppress Dotnet Restore Notification is false', () => {
87-
setup(() => {
88-
vscode.workspace.getConfiguration = (section?: string, resource?: Uri) => {
89-
return {
90-
...getNullWorkspaceConfiguration(),
91-
get: <T>(section: string) => {
92-
return false; // do not suppress the restore info
93-
}
94-
};
83+
});
84+
85+
function getVsCode() {
86+
let vscode = getVSCodeWithConfig();
87+
vscode.window.showInformationMessage = async (message: string, ...items: string[]) => {
88+
infoMessage = message;
89+
return new Promise<string>(resolve => {
90+
doClickCancel = () => {
91+
resolve(undefined);
9592
};
96-
});
9793

98-
test('The information message is shown', async () => {
99-
observer.post(event);
100-
expect(relativePath).to.not.be.empty;
101-
expect(infoMessage).to.not.be.empty;
102-
doClickOk();
103-
await commandDone;
104-
expect(invokedCommand).to.be.equal('dotnet.restore');
105-
});
106-
107-
test('Given an information message if the user clicks Restore, the command is executed', async () => {
108-
observer.post(event);
109-
doClickOk();
110-
await commandDone;
111-
expect(invokedCommand).to.be.equal('dotnet.restore');
112-
});
113-
114-
test('Given an information message if the user clicks cancel, the command is not executed', async () => {
115-
observer.post(event);
116-
doClickCancel();
117-
await expect(Observable.fromPromise(commandDone).timeout(1).toPromise()).to.be.rejected;
118-
expect(invokedCommand).to.be.undefined;
94+
doClickOk = () => {
95+
resolve(message);
96+
};
11997
});
120-
});
121-
});
98+
};
99+
100+
vscode.commands.executeCommand = (command: string, ...rest: any[]) => {
101+
invokedCommand = command;
102+
signalCommandDone();
103+
return undefined;
104+
};
105+
106+
vscode.workspace.asRelativePath = (pathOrUri?: string, includeWorspaceFolder?: boolean) => {
107+
relativePath = pathOrUri;
108+
return relativePath;
109+
};
110+
111+
return vscode;
112+
}
122113
});

test/unitTests/options.test.ts

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,15 @@
55

66
import { should, expect } from 'chai';
77
import { Options } from '../../src/omnisharp/options';
8-
import { getFakeVsCode, getWorkspaceConfiguration } from './testAssets/Fakes';
9-
import { WorkspaceConfiguration } from '../../src/vscodeAdapter';
10-
11-
function getVSCode(omnisharpConfig?: WorkspaceConfiguration, csharpConfig?: WorkspaceConfiguration) {
12-
const vscode = getFakeVsCode();
13-
14-
const _omnisharpConfig = omnisharpConfig || getWorkspaceConfiguration();
15-
const _csharpConfig = csharpConfig || getWorkspaceConfiguration();
16-
17-
vscode.workspace.getConfiguration = (section?, resource?) =>
18-
{
19-
if (section === 'omnisharp')
20-
{
21-
return _omnisharpConfig;
22-
}
23-
24-
if (section === 'csharp')
25-
{
26-
return _csharpConfig;
27-
}
28-
29-
return undefined;
30-
};
31-
32-
return vscode;
33-
}
8+
import { getVSCodeWithConfig, updateConfig } from './testAssets/Fakes';
349

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

3813
test('Verify defaults', () =>
3914
{
40-
const vscode = getVSCode();
15+
const vscode = getVSCodeWithConfig();
4116
const options = Options.Read(vscode);
42-
4317
expect(options.path).to.be.null;
4418
options.useGlobalMono.should.equal("auto");
4519
options.waitForDebugger.should.equal(false);
@@ -57,42 +31,38 @@ suite("Options tests", () => {
5731

5832
test('BACK-COMPAT: "omnisharp.loggingLevel": "verbose" == "omnisharp.loggingLevel": "debug"', () =>
5933
{
60-
const omnisharpConfig = getWorkspaceConfiguration();
61-
omnisharpConfig.update('loggingLevel', "verbose");
62-
const vscode = getVSCode(omnisharpConfig);
34+
const vscode = getVSCodeWithConfig();
35+
updateConfig(vscode, 'omnisharp', 'loggingLevel', "verbose");
6336

6437
const options = Options.Read(vscode);
6538

6639
options.loggingLevel.should.equal("debug");
6740
});
6841

6942
test('BACK-COMPAT: "omnisharp.useMono": true == "omnisharp.useGlobalMono": "always"', () =>
70-
{
71-
const omnisharpConfig = getWorkspaceConfiguration();
72-
omnisharpConfig.update('useMono', true);
73-
const vscode = getVSCode(omnisharpConfig);
74-
43+
{
44+
const vscode = getVSCodeWithConfig();
45+
updateConfig(vscode, 'omnisharp', 'useMono', true);
46+
7547
const options = Options.Read(vscode);
7648

7749
options.useGlobalMono.should.equal("always");
7850
});
7951

8052
test('BACK-COMPAT: "omnisharp.useMono": false == "omnisharp.useGlobalMono": "auto"', () =>
8153
{
82-
const omnisharpConfig = getWorkspaceConfiguration();
83-
omnisharpConfig.update('useMono', false);
84-
const vscode = getVSCode(omnisharpConfig);
85-
54+
const vscode = getVSCodeWithConfig();
55+
updateConfig(vscode, 'omnisharp', 'useMono', false);
56+
8657
const options = Options.Read(vscode);
8758

8859
options.useGlobalMono.should.equal("auto");
8960
});
9061

9162
test('BACK-COMPAT: "csharp.omnisharpUsesMono": true == "omnisharp.useGlobalMono": "always"', () =>
9263
{
93-
const csharpConfig = getWorkspaceConfiguration();
94-
csharpConfig.update('omnisharpUsesMono', true);
95-
const vscode = getVSCode(undefined, csharpConfig);
64+
const vscode = getVSCodeWithConfig();
65+
updateConfig(vscode, 'csharp', 'omnisharpUsesMono', true);
9666

9767
const options = Options.Read(vscode);
9868

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

10272
test('BACK-COMPAT: "csharp.omnisharpUsesMono": false == "omnisharp.useGlobalMono": "auto"', () =>
10373
{
104-
const csharpConfig = getWorkspaceConfiguration();
105-
csharpConfig.update('omnisharpUsesMono', false);
106-
const vscode = getVSCode(undefined, csharpConfig);
74+
const vscode = getVSCodeWithConfig();
75+
updateConfig(vscode, 'csharp', 'omnisharpUsesMono', false);
10776

10877
const options = Options.Read(vscode);
10978

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

11382
test('BACK-COMPAT: "csharp.omnisharp" is used if it is set and "omnisharp.path" is not', () =>
11483
{
115-
const csharpConfig = getWorkspaceConfiguration();
116-
csharpConfig.update('omnisharp', 'OldPath');
117-
const vscode = getVSCode(undefined, csharpConfig);
84+
const vscode = getVSCodeWithConfig();
85+
updateConfig(vscode, 'csharp', 'omnisharp', 'OldPath');
11886

11987
const options = Options.Read(vscode);
12088

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

12492
test('BACK-COMPAT: "csharp.omnisharp" is not used if "omnisharp.path" is set', () =>
12593
{
126-
const omnisharpConfig = getWorkspaceConfiguration();
127-
omnisharpConfig.update('path', 'NewPath');
128-
const csharpConfig = getWorkspaceConfiguration();
129-
csharpConfig.update('omnisharp', 'OldPath');
130-
const vscode = getVSCode(omnisharpConfig, csharpConfig);
94+
const vscode = getVSCodeWithConfig();
95+
updateConfig(vscode, 'omnisharp', 'path', 'NewPath');
96+
updateConfig(vscode, 'csharp', 'omnisharp', 'OldPath');
13197

13298
const options = Options.Read(vscode);
13399

test/unitTests/testAssets/Fakes.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,6 @@ export const getNullTelemetryReporter = (): ITelemetryReporter => {
3131
return reporter;
3232
};
3333

34-
export const getNullWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
35-
let configuration: vscode.WorkspaceConfiguration = {
36-
get: <T>(section: string): T | undefined => {
37-
return undefined;
38-
},
39-
has: (section: string) => { return undefined; },
40-
inspect: () => {
41-
return {
42-
key: undefined
43-
};
44-
},
45-
update: async () => { return Promise.resolve(); }
46-
};
47-
48-
return configuration;
49-
};
50-
5134
export const getWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
5235
let values: { [key: string]: any } = {};
5336

@@ -164,4 +147,33 @@ export function getWorkspaceInformationUpdated(msbuild: protocol.MsBuildWorkspac
164147
};
165148

166149
return new WorkspaceInformationUpdated(a);
167-
}
150+
}
151+
152+
export function getVSCodeWithConfig() {
153+
const vscode = getFakeVsCode();
154+
155+
const _omnisharpConfig = getWorkspaceConfiguration();
156+
const _csharpConfig = getWorkspaceConfiguration();
157+
158+
vscode.workspace.getConfiguration = (section?, resource?) =>
159+
{
160+
if (section === 'omnisharp')
161+
{
162+
return _omnisharpConfig;
163+
}
164+
165+
if (section === 'csharp')
166+
{
167+
return _csharpConfig;
168+
}
169+
170+
return undefined;
171+
};
172+
173+
return vscode;
174+
}
175+
176+
export function updateConfig(vscode: vscode.vscode, section: string, config: string, value: any) {
177+
let workspaceConfig = vscode.workspace.getConfiguration(section);
178+
workspaceConfig.update(config, value);
179+
}

0 commit comments

Comments
 (0)