Skip to content

Commit 0302243

Browse files
committed
move dotnet test logic to its own file
1 parent fe2e7a4 commit 0302243

File tree

2 files changed

+60
-31
lines changed

2 files changed

+60
-31
lines changed

src/features/commands.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as fs from 'fs-extra-promise';
1313
import * as path from 'path';
1414
import * as protocol from '../protocol';
1515
import * as vscode from 'vscode';
16+
import * as dotnetTest from './dotnetTest'
1617

1718
let channel = vscode.window.createOutputChannel('.NET');
1819

@@ -27,37 +28,8 @@ export default function registerCommands(server: OmnisharpServer, extensionPath:
2728
let d5 = vscode.commands.registerCommand('csharp.downloadDebugger', () => { });
2829

2930
return vscode.Disposable.from(d1, d2, d3, d4, d5,
30-
vscode.commands.registerCommand('dotnet.test.run', (testMethod, fileName) => runDotnetTest(testMethod, fileName, server)),
31-
vscode.commands.registerCommand('dotnet.test.debug', (testMethod, fileName) => debugDotnetTest(testMethod, fileName, server)));
32-
}
33-
34-
// Run test through dotnet-test command. This function can be moved to a separate structure
35-
function runDotnetTest(testMethod: string, fileName: string, server: OmnisharpServer) {
36-
serverUtils.runDotNetTest(server, { FileName: fileName, MethodName: testMethod }).then(response => {
37-
if (response.Pass) {
38-
vscode.window.showInformationMessage('Test passed');
39-
}
40-
else {
41-
vscode.window.showErrorMessage('Test failed');
42-
}
43-
});
44-
}
45-
46-
// Run test through dotnet-test command with debugger attached
47-
function debugDotnetTest(testMethod: string, fileName: string, server: OmnisharpServer) {
48-
serverUtils.getTestStartInfo(server, { FileName: fileName, MethodName: testMethod }).then(response => {
49-
vscode.commands.executeCommand(
50-
'vscode.startDebug', {
51-
"name": ".NET test launch",
52-
"type": "coreclr",
53-
"request": "launch",
54-
"program": response.Executable,
55-
"args": response.Argument.split(' '),
56-
"cwd": "${workspaceRoot}",
57-
"stopAtEntry": false
58-
}
59-
);
60-
});
31+
dotnetTest.registerDotNetTestRunCommand(server),
32+
dotnetTest.registerDotNetTestDebugCommand(server));
6133
}
6234

6335
function pickProjectAndStart(server: OmnisharpServer) {

src/features/dotnetTest.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import {OmnisharpServer} from '../omnisharpServer';
9+
import * as vscode from 'vscode';
10+
import * as serverUtils from "../omnisharpUtils";
11+
12+
export function registerDotNetTestRunCommand(server: OmnisharpServer): vscode.Disposable {
13+
return vscode.commands.registerCommand(
14+
'dotnet.test.run',
15+
(testMethod, fileName) => runDotnetTest(testMethod, fileName, server));
16+
}
17+
18+
export function registerDotNetTestDebugCommand(server: OmnisharpServer): vscode.Disposable {
19+
return vscode.commands.registerCommand(
20+
'dotnet.test.debug',
21+
(testMethod, fileName) => debugDotnetTest(testMethod, fileName, server));
22+
}
23+
24+
// Run test through dotnet-test command. This function can be moved to a separate structure
25+
export function runDotnetTest(testMethod: string, fileName: string, server: OmnisharpServer) {
26+
serverUtils
27+
.runDotNetTest(server, { FileName: fileName, MethodName: testMethod })
28+
.then(
29+
response => {
30+
if (response.Pass) {
31+
vscode.window.showInformationMessage('Test passed');
32+
}
33+
else {
34+
vscode.window.showErrorMessage('Test failed');
35+
}
36+
},
37+
reason => {
38+
vscode.window.showErrorMessage('Fail to run test because ' + reason + '.');
39+
});
40+
}
41+
42+
// Run test through dotnet-test command with debugger attached
43+
export function debugDotnetTest(testMethod: string, fileName: string, server: OmnisharpServer) {
44+
serverUtils.getTestStartInfo(server, { FileName: fileName, MethodName: testMethod }).then(response => {
45+
vscode.commands.executeCommand(
46+
'vscode.startDebug', {
47+
"name": ".NET test launch",
48+
"type": "coreclr",
49+
"request": "launch",
50+
"program": response.Executable,
51+
"args": response.Argument.split(' '),
52+
"cwd": "${workspaceRoot}",
53+
"stopAtEntry": false
54+
}
55+
).then(undefined, reason => { vscode.window.showErrorMessage('Failed to debug test because ' + reason + '.') });
56+
});
57+
}

0 commit comments

Comments
 (0)