@@ -27,22 +27,25 @@ BeforeAll {
2727 $script :moduleName = ' SqlServerDsc'
2828
2929 Import-Module - Name $script :moduleName - Force - ErrorAction ' Stop'
30+ }
3031
31- # Import the SMO module to ensure real SMO types are available
32- Import-SqlDscPreferredModule
32+ Describe ' Add-SqlDscDataFile' - Tag @ (' Integration_SQL2017' , ' Integration_SQL2019' , ' Integration_SQL2022' ) {
33+ BeforeAll {
34+ $script :mockInstanceName = ' DSCSQLTEST'
35+ $script :mockComputerName = Get-ComputerName
3336
34- $ script :mockInstanceName = ' DSCSQLTEST '
35- $ script :mockComputerName = Get-ComputerName
37+ $mockSqlAdministratorUserName = ' SqlAdmin ' # Using computer name as NetBIOS name throw exception.
38+ $mockSqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1 ' - AsPlainText - Force
3639
37- $mockSqlAdministratorUserName = ' SqlAdmin' # Using computer name as NetBIOS name throw exception.
38- $mockSqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
40+ $script :mockSqlAdminCredential = [System.Management.Automation.PSCredential ]::new($mockSqlAdministratorUserName , $mockSqlAdministratorPassword )
3941
40- $script :mockSqlAdminCredential = [System.Management.Automation.PSCredential ]::new($mockSqlAdministratorUserName , $mockSqlAdministratorPassword )
42+ $script :serverObject = Connect-SqlDscDatabaseEngine - InstanceName $script :mockInstanceName - Credential $script :mockSqlAdminCredential - ErrorAction ' Stop'
43+ }
4144
42- $script :serverObject = Connect-SqlDscDatabaseEngine - InstanceName $script :mockInstanceName - Credential $script :mockSqlAdminCredential - ErrorAction ' Stop'
43- }
45+ AfterAll {
46+ Disconnect-SqlDscDatabaseEngine - ServerObject $script :serverObject
47+ }
4448
45- Describe ' Add-SqlDscDataFile' - Tag @ (' Integration_SQL2017' , ' Integration_SQL2019' , ' Integration_SQL2022' ) {
4649 Context ' When adding a DataFile to a FileGroup with real SMO types' {
4750 BeforeEach {
4851 # Create real SMO Database and FileGroup objects
@@ -103,25 +106,4 @@ Describe 'Add-SqlDscDataFile' -Tag @('Integration_SQL2017', 'Integration_SQL2019
103106 $result [1 ] | Should - Be $dataFile2
104107 }
105108 }
106-
107- Context ' When verifying DataFile parent relationship' {
108- BeforeEach {
109- $script :testDatabase = [Microsoft.SqlServer.Management.Smo.Database ]::new()
110- $script :testDatabase.Name = ' TestDatabase'
111- $script :testDatabase.Parent = $script :serverObject
112-
113- $script :testFileGroup = New-SqlDscFileGroup - Database $script :testDatabase - Name ' TestFileGroup' - Confirm:$false
114- $script :testDataFile = New-SqlDscDataFile - FileGroup $script :testFileGroup - Name ' TestDataFile' - FileName ' C:\Data\TestDataFile.ndf' - Confirm:$false
115- }
116-
117- It ' Should update DataFile parent reference when added to FileGroup' {
118- $script :testDataFile.Parent | Should - BeNullOrEmpty
119-
120- Add-SqlDscDataFile - FileGroup $script :testFileGroup - DataFile $script :testDataFile
121-
122- # Note: The parent may or may not be updated depending on SMO implementation
123- # This test verifies the DataFile is in the collection
124- $script :testFileGroup.Files [$script :testDataFile.Name ] | Should - Be $script :testDataFile
125- }
126- }
127109}
0 commit comments