@@ -10,6 +10,9 @@ PowerShell commands that should be public should always have its separate
1010script file and the command name as the file name with the .ps1 extension,
1111these files shall always be placed in the folder source/Public.
1212
13+ All public command names must have the noun prefixed with 'SqlDsc', e.g.
14+ {Verb}-SqlDsc{Noun}.
15+
1316Public commands may use private functions to move out logic that can be
1417reused by other public commands, so move out any logic that can be deemed
1518reusable.
@@ -196,6 +199,10 @@ case (`It`-block) as possible.
196199Never test, mock or use ` Should -Invoke ` for ` Write-Verbose ` and ` Write-Debug `
197200regardless of other instructions.
198201
202+ Never use ` Should -Not -Throw ` to prepare for Pester v6 where it has been
203+ removed. By default the ` It ` block will handle any unexpected exception.
204+ Instead of ` { Command } | Should -Not -Throw ` , use ` Command ` directly.
205+
199206Unit tests should be added for all public commands, private functions and
200207class-based resources. The unit tests for class-based resources should be
201208placed in the folder tests/Unit/Classes. The unit tests for public command
@@ -206,6 +213,83 @@ they are testing, but should have the suffix .Tests.ps1. The unit tests
206213should be written to cover all possible scenarios and code paths, ensuring
207214that both edge cases and common use cases are tested.
208215
216+ All public commands should always have a test to validate parameter sets
217+ using this template. For commands with a single parameter set:
218+
219+ ``` powershell
220+ It 'Should have the correct parameters in parameter set <MockParameterSetName>' -ForEach @(
221+ @{
222+ MockParameterSetName = '__AllParameterSets'
223+ MockExpectedParameters = '[-Parameter1] <Type> [-Parameter2] <Type> [<CommonParameters>]'
224+ }
225+ ) {
226+ $result = (Get-Command -Name 'CommandName').ParameterSets |
227+ Where-Object -FilterScript {
228+ $_.Name -eq $mockParameterSetName
229+ } |
230+ Select-Object -Property @(
231+ @{
232+ Name = 'ParameterSetName'
233+ Expression = { $_.Name }
234+ },
235+ @{
236+ Name = 'ParameterListAsString'
237+ Expression = { $_.ToString() }
238+ }
239+ )
240+
241+ $result.ParameterSetName | Should -Be $MockParameterSetName
242+ $result.ParameterListAsString | Should -Be $MockExpectedParameters
243+ }
244+ ```
245+
246+ For commands with multiple parameter sets, use this pattern:
247+
248+ ``` powershell
249+ It 'Should have the correct parameters in parameter set <MockParameterSetName>' -ForEach @(
250+ @{
251+ MockParameterSetName = 'ParameterSet1'
252+ MockExpectedParameters = '-ServerObject <Server> -Name <string> -Parameter1 <string> [<CommonParameters>]'
253+ }
254+ @{
255+ MockParameterSetName = 'ParameterSet2'
256+ MockExpectedParameters = '-ServerObject <Server> -Name <string> -Parameter2 <uint> [<CommonParameters>]'
257+ }
258+ ) {
259+ $result = (Get-Command -Name 'CommandName').ParameterSets |
260+ Where-Object -FilterScript {
261+ $_.Name -eq $mockParameterSetName
262+ } |
263+ Select-Object -Property @(
264+ @{
265+ Name = 'ParameterSetName'
266+ Expression = { $_.Name }
267+ },
268+ @{
269+ Name = 'ParameterListAsString'
270+ Expression = { $_.ToString() }
271+ }
272+ )
273+
274+ $result.ParameterSetName | Should -Be $MockParameterSetName
275+ $result.ParameterListAsString | Should -Be $MockExpectedParameters
276+ }
277+ ```
278+
279+ All public commands should also include tests to validate parameter properties:
280+
281+ ``` powershell
282+ It 'Should have ParameterName as a mandatory parameter' {
283+ $parameterInfo = (Get-Command -Name 'CommandName').Parameters['ParameterName']
284+ $parameterInfo.Attributes.Mandatory | Should -Contain $true
285+ }
286+
287+ It 'Should accept ParameterName from pipeline' {
288+ $parameterInfo = (Get-Command -Name 'CommandName').Parameters['ParameterName']
289+ $parameterInfo.Attributes.ValueFromPipeline | Should -Contain $true
290+ }
291+ ```
292+
209293The ` BeforeAll ` block should be used to set up any necessary test data or mocking
210294
211295Use localized strings in the tests only when necessary. You can assign the
@@ -302,6 +386,19 @@ edge cases and common use cases are tested. The integration tests should
302386also be written to test the command in a real environment, using real
303387resources and dependencies.
304388
389+ Integration test script files for public commands must be added to a group
390+ within the 'Integration_Test_Commands_SqlServer' stage in ./azure-pipelines.yml.
391+ Choose the appropriate group number based on the dependencies of the command
392+ being tested (e.g., commands that require Database Engine should be in Group 2
393+ or later, after the Database Engine installation tests).
394+
395+ When integration tests need the computer name in CI environments, always use
396+ the Get-ComputerName command, which is available in the build pipeline.
397+
398+ For integration testing commands use the information in the
399+ tests/Integration/Commands/README.md, which describes the testing environment
400+ including available instances, users, credentials, and other configuration details.
401+
305402All integration tests must use the below code block prior to the first
306403` Describe ` -block. The following code will set up the integration test
307404environment and it will make sure the module being tested is available
@@ -343,6 +440,24 @@ The module DscResource.Test is used by the pipeline and its commands
343440are normally not used when testing public functions, private functions or
344441class-based resources.
345442
443+ ## SQL Server
444+
445+ ### SQL Server Management Objects (SMO)
446+
447+ When developing commands, private functions, class-based resources, or making
448+ modifications to existing functionality, always prefer using SQL Server
449+ Management Objects (SMO) as the primary method for interacting with SQL Server.
450+ Only use T-SQL when it is not possible to achieve the desired functionality
451+ with SMO.
452+
453+ ## Change log
454+
455+ The Unreleased section in CHANGELOG.md should always be updated when making
456+ changes to the codebase. Use the keepachangelog format and provide concrete
457+ release notes that describe the main changes made. This includes new commands,
458+ private functions, class-based resources, or significant modifications to
459+ existing functionality.
460+
346461## Style guidelines
347462
348463This project use the style guidelines from the DSC Community: https://dsccommunity.org/styleguidelines
@@ -356,6 +471,7 @@ This project use the style guidelines from the DSC Community: https://dsccommuni
356471### PowerShell files
357472
358473- All files should use UTF8 without BOM.
474+ - All files must end with a new line.
359475
360476### PowerShell code
361477
0 commit comments