# Need some help fixing - Pester Test for unregister server

**URL:** <https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060>\
**Category:** Pester\
**Created:** [April 11, 2022, 12:00pm UTC](https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060 "2022-04-11T12:00:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GVK](https://avatars.discourse-cdn.com/v4/letter/g/9de053/32.png) [@GVK](https://forums.powershell.org/u/GVK)\
**Post date:** [April 11, 2022, 12:00pm UTC](https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060/1 "2022-04-11T12:00:22Z")

</div>

```auto
#----------------------------------------------------------
# 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:

```auto
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'
     
     }

}

}

```

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [April 11, 2022, 1:52pm UTC](https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060/2 "2022-04-11T13:52:06Z")

</div>

Couple of questions,

What is the pester version here ?  
Is the above code for unregister a function ?  
Why `Format-Table` is used ?

When you use `Success` , that means you are expecting a string in the assertion here `$result1 | Should -Be 'Success'`, but your actual expression gives a formatted table as output

```auto
databaseId result
---------- ------
        70 SUCCESS

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:13pm UTC](https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060/4 "2024-05-16T21:13:23Z")

</div>


