| description | applyTo |
|---|---|
SqlServerDsc-specific guidelines for AI development. |
** |
- Never use VS Code task, always use PowerShell scripts via terminal, from repository root
- Setup build and test environment (once per
pwshsession):./build.ps1 -Tasks noop - Build project before running tests:
./build.ps1 -Tasks build - Run tests without coverage (wildcards allowed):
Invoke-PesterJob -Path '{tests filepath}' -SkipCodeCoverage - Run tests with coverage (wildcards allowed):
Invoke-PesterJob -Path '{tests filepath}' -EnableSourceLineMapping -FilterCodeCoverageResult '{pattern}' - Run QA tests:
Invoke-PesterJob -Path 'tests/QA' -SkipCodeCoverage - Never run integration tests locally
- Public commands:
{Verb}-SqlDsc{Noun}format - Private function:
{Verb}-{Noun}format
- Database Engine resources: inherit
SqlResourceBase- Add
InstanceName,ServerName, andCredentialto$this.ExcludeDscProperties SqlResourceBaseprovides:InstanceName,ServerName,Credential,Reasons,GetServerObject()- Constructor:
MyResourceName() : base () { }(no $PSScriptRoot parameter)
- Add
- Always prefer SMO over T-SQL
- Unit tests: Use SMO stub types from SMO.cs, never mock SMO types
- Run tests in new session after changing SMO.cs
- Database Engine: instance
DSCSQLTEST - Reporting Services: instance
SSRS - Power BI Report Server: instance
PBIRS
- Unit tests: Add
$env:SqlServerDscCI = $trueinBeforeAll, remove inAfterAll - Integration tests:
- Use
Connect-SqlDscDatabaseEnginefor SQL Server DB session, and always with correct CI credentials - Use
Disconnect-SqlDscDatabaseEngineafterConnect-SqlDscDatabaseEngine - Test config: tests/Integration/Commands/README.md and tests/Integration/Resources/README.md
- Integration test script files must be added to a group within the test stage in ./azure-pipelines.yml.
- Choose the appropriate group number based on the required dependencies
- Use
- When unit test tests classes or commands that contain SMO types, e.g.
[Microsoft.SqlServer.Management.Smo.*]- Ensure they are properly stubbed in SMO.cs
- Load SMO stub types from SMO.cs in unit test files, e.g.
Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs" - After changing SMO stub types, run tests in a new PowerShell session for changes to take effect.