@@ -23,10 +23,14 @@ suite(`CodeLensProvider: ${testAssetWorkspace.description}`, function () {
2323 await activateCSharpExtension ( ) ;
2424
2525 let fileName = 'Program.cs' ;
26- let projectDirectory = path . dirname ( testAssetWorkspace . projects [ 0 ] . projectDirectoryPath ) ;
26+ let projectDirectory = testAssetWorkspace . projects [ 0 ] . projectDirectoryPath ;
2727 let filePath = path . join ( projectDirectory , fileName ) ;
2828 fileUri = vscode . Uri . file ( filePath ) ;
2929
30+ let csharpConfig = vscode . workspace . getConfiguration ( 'csharp' ) ;
31+ await csharpConfig . update ( 'referencesCodeLens.enabled' , true ) ;
32+ await csharpConfig . update ( 'testsCodeLens.enabled' , true ) ;
33+
3034 await vscode . commands . executeCommand ( "vscode.open" , fileUri ) ;
3135 } ) ;
3236
@@ -56,6 +60,76 @@ suite(`CodeLensProvider: ${testAssetWorkspace.description}`, function () {
5660 } ) ;
5761} ) ;
5862
63+ suite ( `CodeLensProvider options: ${ testAssetWorkspace . description } ` , function ( ) {
64+ let fileUri : vscode . Uri ;
65+
66+ suiteSetup ( async function ( ) {
67+ should ( ) ;
68+
69+ // These tests only run on the slnWithCsproj solution
70+ if ( vscode . workspace . rootPath . split ( path . sep ) . pop ( ) !== 'slnWithCsproj' ) {
71+ this . skip ( ) ;
72+ }
73+ else
74+ {
75+ await testAssetWorkspace . restore ( ) ;
76+ await activateCSharpExtension ( ) ;
77+
78+ let fileName = 'UnitTest1.cs' ;
79+ let projectDirectory = testAssetWorkspace . projects [ 2 ] . projectDirectoryPath ;
80+ let filePath = path . join ( projectDirectory , fileName ) ;
81+ fileUri = vscode . Uri . file ( filePath ) ;
82+
83+ await vscode . commands . executeCommand ( "vscode.open" , fileUri ) ;
84+ }
85+ } ) ;
86+
87+ suiteTeardown ( async ( ) => {
88+ await testAssetWorkspace . cleanupWorkspace ( ) ;
89+ } ) ;
90+
91+ test ( "Returns no references code lenses when 'csharp.referencesCodeLens.enabled' option is set to false" , async function ( ) {
92+ let csharpConfig = vscode . workspace . getConfiguration ( 'csharp' ) ;
93+ await csharpConfig . update ( 'referencesCodeLens.enabled' , false ) ;
94+ await csharpConfig . update ( 'testsCodeLens.enabled' , true ) ;
95+
96+ let codeLenses = await GetCodeLenses ( fileUri , 100 ) ;
97+ expect ( codeLenses . length ) . to . equal ( 4 ) ;
98+
99+ for ( let codeLens of codeLenses ) {
100+ expect ( codeLens . isResolved ) . to . be . true ;
101+ expect ( codeLens . command ) . not . to . be . undefined ;
102+ expect ( codeLens . command . command ) . to . be . oneOf ( [ 'dotnet.test.run' , 'dotnet.classTests.run' , 'dotnet.test.debug' , 'dotnet.classTests.debug' ] ) ;
103+ expect ( codeLens . command . title ) . to . be . oneOf ( [ 'Run Test' , 'Run All Tests' , 'Debug Test' , 'Debug All Tests' ] ) ;
104+ }
105+ } ) ;
106+
107+ test ( "Returns no test code lenses when 'csharp.testsCodeLens.enabled' option is set to false" , async function ( ) {
108+ let csharpConfig = vscode . workspace . getConfiguration ( 'csharp' ) ;
109+ await csharpConfig . update ( 'referencesCodeLens.enabled' , true ) ;
110+ await csharpConfig . update ( 'testsCodeLens.enabled' , false ) ;
111+
112+ let codeLenses = await GetCodeLenses ( fileUri , 100 ) ;
113+ expect ( codeLenses . length ) . to . equal ( 2 ) ;
114+
115+ for ( let codeLens of codeLenses ) {
116+ expect ( codeLens . isResolved ) . to . be . true ;
117+ expect ( codeLens . command ) . not . to . be . undefined ;
118+ expect ( codeLens . command . command ) . to . be . equal ( 'editor.action.showReferences' ) ;
119+ expect ( codeLens . command . title ) . to . equal ( '0 references' ) ;
120+ }
121+ } ) ;
122+
123+ test ( "Returns no code lenses when 'csharp.referencesCodeLens.enabled' and 'csharp.testsCodeLens.enabled' options are set to false" , async function ( ) {
124+ let csharpConfig = vscode . workspace . getConfiguration ( 'csharp' ) ;
125+ await csharpConfig . update ( 'referencesCodeLens.enabled' , false ) ;
126+ await csharpConfig . update ( 'testsCodeLens.enabled' , false ) ;
127+
128+ let codeLenses = await GetCodeLenses ( fileUri , 100 ) ;
129+ expect ( codeLenses . length ) . to . equal ( 0 ) ;
130+ } ) ;
131+ } ) ;
132+
59133async function GetCodeLenses ( fileUri : vscode . Uri , resolvedItemCount ?: number ) {
60134 return < vscode . CodeLens [ ] > await vscode . commands . executeCommand ( "vscode.executeCodeLensProvider" , fileUri , resolvedItemCount ) ;
61135}
0 commit comments