'Pester for Connect-NetScaler

Hey guys having trouble writing pester for this function. The function is down below. Here is a link of the code if you prefer looking on here. https://www.powershellgallery.com/packages/NetScaler/1.1.2/Content/Public%5CConnect-NetScaler.ps1

Describe 'Connect-NetScaler' {
            $Credential = New-Object PSCredential('username', (ConvertTo-SecureString -AsPlainText -Force 'password'))
            Context 'Successful Connection' {
                Mock Add-Member {
                    return @{
                        Endpoint = '10.111.33.3'
                        Scheme   = 'http'
                    }
                 }
                Mock New-Object {
                    return @{
                    Uri='http://10.111.33.3/nitro/v1';
                }
            }
                Mock ConvertTo-Json -ParameterFilter {
                    $InputObject -eq $Credential
                }
                Mock 'Invoke-RestMethod' {
                 #   $Uri | Should -BeExactly "fakename/config/login"
                   # $Credential | Should -BeOfType PSCredential
                    return [PSCustomObject]@{
                        severity = 'NONE'
                    }
                } -Verifiable
                It 'Should be able to connect'{
                    $result= Connect-NetScaler -IPAddress '10.111.33.3' -Credential $Credential
                    $result | Should -Be "Response:`n"
                }

            }
            Context 'UnSuccessful Connection' {
                Mock Add-Member {
                    return @{
                        Endpoint = '10.111.33.3'
                        Scheme   = 'http'
                    }
                 }
                Mock New-Object {
                    return @{
                    Uri='http://10.111.33.3/nitro/v1';
                }
            }
                Mock ConvertTo-Json -ParameterFilter {
                    $InputObject -eq $Credential
                }
                Mock 'Invoke-RestMethod' {
                 #   $Uri | Should -BeExactly "fakename/config/login"
                   # $Credential | Should -BeOfType PSCredential
                    return [PSCustomObject]@{
                        severity = 'ERROR'
                    }
                } -Verifiable
                It 'Should be able to connect'{
                    $result= Connect-NetScaler -IPAddress '10.111.33.3' -Credential $Credential
                    $result | Should -Throw "Error. See response: `n"
                }
            }
        } 

This is the code for the function. I am a beginner to pester so been having trouble figuring this out. Any help would be greatly appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source