#----------------------------------------------------------
# Un-register the SQL Server database instance.
#----------------------------------------------------------
if ($newDbId) {
$registrationURL = $baseURL + "databases/unregister-monitor"
$body = @{"databaseId" = $newDbId;
"removeMonitoringUser" = $true;
"removeDatabaseObjects" = $true;
"sysAdminUser" = "sa";
"sysAdminPassword" = "Password"} | ConvertTo-Json
Try {
Write-Host "Registering Database..."
$dpaResponseJSON = Invoke-RestMethod -Uri $registrationURL -Body $body -Method POST -Headers $dpaHeader -TimeoutSec 60
$dpaResponse = $dpaResponseJSON.data
$dpaResponse | Format-Table -AutoSize
}
Catch {
$_.Exception.ToString()
}
}
The output of above Unregister Block is below:
Unregistering Database...
databaseId result
---------- ------
70 SUCCESS
My Requirement is to write a unit test for the above PowerShell code , please help me fix it . So far what I tried is below:
Context "check correct result" {
BeforeEach {
Mock Invoke-RestMethod { return [PSCustomObject]@{
databaseId = 1
result = "Success"
}
}
Mock Write-Verbose { return $null }
$result1 = $usage
}
It "Validating output from Removing Server" {
$result1 | Should -Be 'Success'
}
}
}