@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
7
7
import * as sinon from 'sinon' ;
8
8
import * as should from 'should' ;
9
9
import * as path from 'path' ;
10
+ import * as vscodeMssql from 'vscode-mssql' ;
10
11
import { SqlDatabaseProjectTaskProvider } from '../../tasks/sqlDatabaseProjectTaskProvider' ;
11
12
12
13
describe ( 'Sql Database Projects Task Provider' , function ( ) : void {
@@ -33,6 +34,19 @@ describe('Sql Database Projects Task Provider', function (): void {
33
34
sandbox . stub ( vscode . workspace , 'findFiles' ) . resolves ( sqlProjUri ) ;
34
35
}
35
36
37
+ // Helper to create and stub a mock project
38
+ function stubProjectOpenWithStyle ( projectStyle : vscodeMssql . ProjectType ) {
39
+ const mockProject = {
40
+ sqlProjStyle : projectStyle ,
41
+ readProjFile : sandbox . stub ( ) . resolves ( )
42
+ } ;
43
+
44
+ const projectModule = require ( '../../models/project' ) ;
45
+ sandbox . stub ( projectModule . Project , 'openProject' ) . resolves ( mockProject ) ;
46
+
47
+ return mockProject ;
48
+ }
49
+
36
50
beforeEach ( ( ) => {
37
51
// Create a new Sinon sandbox before each test
38
52
sandbox = sinon . createSandbox ( ) ;
@@ -45,10 +59,13 @@ describe('Sql Database Projects Task Provider', function (): void {
45
59
sandbox . restore ( ) ;
46
60
} ) ;
47
61
48
- it ( 'Should create build and buildWithCodeAnalysis tasks for .sqlproj file with correct properties' , async function ( ) : Promise < void > {
62
+ it ( 'Should create build and buildWithCodeAnalysis tasks for .sqlproj file with correct properties for SDK style project ' , async function ( ) : Promise < void > {
49
63
// Define mock .sqlproj file URIs for testing
50
64
stubWorkspaceAndFiles ( [ sqlProjUris [ 0 ] ] ) ;
51
65
66
+ // Stub the project as SDK style
67
+ stubProjectOpenWithStyle ( vscodeMssql . ProjectType . SdkStyle ) ;
68
+
52
69
// Act: create tasks using the provider
53
70
const tasks = await taskProvider . createTasks ( ) ;
54
71
@@ -93,13 +110,23 @@ describe('Sql Database Projects Task Provider', function (): void {
93
110
should ( buildTask . execution . args ) . not . be . undefined ( ) ;
94
111
should ( buildTask . execution . args ) . be . Array ( ) ;
95
112
should ( buildTask . execution . args [ 0 ] ) . equal ( 'build' ) ;
113
+
114
+ const argsString = buildTask . execution . args . join ( ' ' ) ;
115
+ should ( argsString ) . containEql ( '/p:NetCoreBuild=true' ) ;
116
+ should ( argsString ) . containEql ( '/p:SystemDacpacsLocation=' ) ;
117
+ should ( argsString ) . not . containEql ( '/p:NETCoreTargetsPath=' ) ; // This should NOT be present for SDK projects
118
+ should ( argsString ) . containEql ( '-v:detailed' ) ;
119
+
96
120
}
97
121
} ) ;
98
122
99
123
it ( 'Should not create any tasks when no .sqlproj files are present in the workspace' , async function ( ) : Promise < void > {
100
124
// Define mock .sqlproj file URIs for testing
101
125
stubWorkspaceAndFiles ( [ ] ) ;
102
126
127
+ // Stub the project as SDK style
128
+ stubProjectOpenWithStyle ( vscodeMssql . ProjectType . SdkStyle ) ;
129
+
103
130
// Act: Attempt to create tasks using the provider
104
131
const tasks = await taskProvider . createTasks ( ) ;
105
132
@@ -112,6 +139,9 @@ describe('Sql Database Projects Task Provider', function (): void {
112
139
// Define mock .sqlproj file URIs for testing
113
140
stubWorkspaceAndFiles ( sqlProjUris ) ;
114
141
142
+ // Stub the project as SDK style
143
+ stubProjectOpenWithStyle ( vscodeMssql . ProjectType . SdkStyle ) ;
144
+
115
145
// Act: create tasks using the provider
116
146
const tasks = await taskProvider . createTasks ( ) ;
117
147
@@ -160,4 +190,43 @@ describe('Sql Database Projects Task Provider', function (): void {
160
190
}
161
191
}
162
192
} ) ;
193
+
194
+ it ( 'Should create tasks with correct build arguments for legacy-style project' , async function ( ) : Promise < void > {
195
+ // Define mock .sqlproj file URIs for testing
196
+ stubWorkspaceAndFiles ( [ sqlProjUris [ 0 ] ] ) ;
197
+
198
+ // Stub the project as SDK style
199
+ stubProjectOpenWithStyle ( vscodeMssql . ProjectType . LegacyStyle ) ;
200
+
201
+ // Act: create tasks using the provider
202
+ const tasks = await taskProvider . createTasks ( ) ;
203
+
204
+ // Assert: tasks should be defined and have the expected length
205
+ should ( tasks ) . not . be . undefined ( ) ;
206
+ should ( tasks ) . be . Array ( ) . and . have . length ( 2 ) ;
207
+
208
+ // Find the build task
209
+ const buildTask = tasks . find ( t => t . name === 'ProjectA.sqlproj - Build' ) ;
210
+
211
+ // Assert: build task should exist
212
+ should ( buildTask ) . not . be . undefined ( ) ;
213
+
214
+ // Assert: build task execution should contain legacy-style arguments
215
+ should ( buildTask ?. execution ) . not . be . undefined ( ) ;
216
+ if ( buildTask ?. execution instanceof vscode . ShellExecution ) {
217
+ should ( buildTask . execution . command ) . equal ( 'dotnet' ) ;
218
+ should ( buildTask . execution . args ) . not . be . undefined ( ) ;
219
+ should ( buildTask . execution . args ) . be . Array ( ) ;
220
+
221
+ // Verify it contains build command
222
+ should ( buildTask . execution . args [ 0 ] ) . equal ( 'build' ) ;
223
+
224
+ // Verify it contains legacy-style build arguments
225
+ const argsString = buildTask . execution . args . join ( ' ' ) ;
226
+ should ( argsString ) . containEql ( '/p:NetCoreBuild=true' ) ;
227
+ should ( argsString ) . containEql ( '/p:SystemDacpacsLocation=' ) ;
228
+ should ( argsString ) . containEql ( '/p:NETCoreTargetsPath=' ) ; // This is only for legacy projects
229
+ should ( argsString ) . containEql ( '-v:detailed' ) ;
230
+ }
231
+ } ) ;
163
232
} ) ;
0 commit comments