diff --git a/DSCResources/xSQLServerAvailabilityGroupListener/xSQLServerAvailabilityGroupListener.psm1 b/DSCResources/xSQLServerAvailabilityGroupListener/xSQLServerAvailabilityGroupListener.psm1 index d79588b7a..34376718a 100644 --- a/DSCResources/xSQLServerAvailabilityGroupListener/xSQLServerAvailabilityGroupListener.psm1 +++ b/DSCResources/xSQLServerAvailabilityGroupListener/xSQLServerAvailabilityGroupListener.psm1 @@ -39,7 +39,7 @@ function Get-TargetResource $presentIpAddress = $listener.AvailabilityGroupListenerIPAddresses - $dhcp = [bool]( $presentIpAddress | Select-Object -first 1 IsDHCP ) + $dhcp = [bool]( $presentIpAddress | Select-Object -First 1 -ExpandProperty IsDHCP ) $ipAddress = @() foreach( $currentIpAddress in $presentIpAddress ) { @@ -169,6 +169,10 @@ function Set-TargetResource throw New-TerminatingError -ErrorType AvailabilityGroupListenerIPChangeError -FormatArgs @($($IpAddress -join ', '),$($listenerState.IpAddress -join ', ')) -ErrorCategory InvalidOperation } } + + if( $($PSBoundParameters.ContainsKey('DHCP')) -and $listenerState.DHCP -ne $DHCP ) { + throw New-TerminatingError -ErrorType AvailabilityGroupListenerDHCPChangeError -FormatArgs @( $DHCP, $($listenerState.DHCP) ) -ErrorCategory InvalidOperation + } if( $listenerState.Port -ne $Port -or -not $ipAddressEqual ) { New-VerboseMessage -Message "Listener differ in configuration." @@ -193,7 +197,7 @@ function Set-TargetResource $newIpAddress = @() foreach( $currentIpAddress in $IpAddress ) { - if( -not $listenerState.IpAddress -contains $currentIpAddress ) { + if( -not ( $listenerState.IpAddress -contains $currentIpAddress ) ) { $newIpAddress += $currentIpAddress } } @@ -274,9 +278,21 @@ function Test-TargetResource } [System.Boolean] $result = $false - if( ( $Ensure -eq "" -or ( $Ensure -ne "" -and $listenerState.Ensure -eq $Ensure) ) -and ($Port -eq "" -or $listenerState.Port -eq $Port) -and $ipAddressEqual ) { - $result = $true + if( $listenerState.Ensure -eq $Ensure) { + if( $Ensure -eq 'Absent' ) { + $result = $true + } } + + if( -not $($PSBoundParameters.ContainsKey('Ensure')) -or $Ensure -eq "Present" ) { + if( ( $Port -eq "" -or $listenerState.Port -eq $Port) -and + $ipAddressEqual -and + ( -not $($PSBoundParameters.ContainsKey('DHCP')) -or $listenerState.DHCP -eq $DHCP ) ) + { + $result = $true + } + } + } else { throw New-TerminatingError -ErrorType UnexpectedErrorFromGet -ErrorCategory InvalidResult } diff --git a/README.md b/README.md index 7599b99ef..4462d0519 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,16 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased * Added resources - xSQLServerReplication +* Added tests for resources + - xSQLServerPermission + - xSQLServerEndpointState + - xSQLServerEndpointPermission + - xSQLServerAvailabilityGroupListener +* Fixes in xSQLServerAvailabilityGroupListener + - In one case the Get-method did not report that DHCP was configured. + - Now the resource will throw 'Not supported' when IP is changed between Static and DHCP. + - Fixed an issue where sometimes the listener wasn't removed. + - Fixed the issue when trying to add a static IP to a listener was ignored. ### 1.8.0.0 * Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey. diff --git a/Tests/Unit/Stubs/SMO.cs b/Tests/Unit/Stubs/SMO.cs index 6140bbc10..3926e5f24 100644 --- a/Tests/Unit/Stubs/SMO.cs +++ b/Tests/Unit/Stubs/SMO.cs @@ -3,10 +3,33 @@ namespace Microsoft.SqlServer.Management.Smo { + public class Globals + { + // Static property that is switched on or off by tests if data should be mocked (true) or not (false). + public static bool GenerateMockData = false; + } + + // Typename: Microsoft.SqlServer.Management.Smo.ObjectPermissionSet + // BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase + // Used by: + // xSQLServerEndpointPermission.Tests.ps1 + public class ObjectPermissionSet + { + public ObjectPermissionSet(){} + + public ObjectPermissionSet( + bool connect ) + { + this.Connect = connect; + } + + public bool Connect = false; + } + // TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionSet // BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase // Used by: - // xSQLServerPermission + // xSQLServerPermission.Tests.ps1 public class ServerPermissionSet { public ServerPermissionSet(){} @@ -32,7 +55,7 @@ public ServerPermissionSet( // TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionInfo // BaseType: Microsoft.SqlServer.Management.Smo.PermissionInfo // Used by: - // xSQLServerPermission + // xSQLServerPermission.Tests.ps1 public class ServerPermissionInfo { public ServerPermissionInfo() @@ -54,11 +77,9 @@ public ServerPermissionInfo( // TypeName: Microsoft.SqlServer.Management.Smo.Server // BaseType: Microsoft.SqlServer.Management.Smo.SqlSmoObject // Used by: - // xSQLServerPermission + // xSQLServerPermission.Tests.ps1 public class Server { - private bool _generateMockData = false; - public string MockGranteeName; public string Name; @@ -66,21 +87,13 @@ public class Server public string InstanceName; public bool IsHadrEnabled = false; - public Server() - { - _generateMockData = false; - } - - public Server( bool generateMockData ) - { - this._generateMockData = generateMockData; - } + public Server(){} public Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[] EnumServerPermissions( string principal, Microsoft.SqlServer.Management.Smo.ServerPermissionSet permissionSetQuery ) { List listOfServerPermissionInfo = new List(); - if( this._generateMockData ) { + if( Globals.GenerateMockData ) { Microsoft.SqlServer.Management.Smo.ServerPermissionSet[] permissionSet = { new Microsoft.SqlServer.Management.Smo.ServerPermissionSet( true, false, false, false ), new Microsoft.SqlServer.Management.Smo.ServerPermissionSet( false, true, false, false ), @@ -108,7 +121,11 @@ public void Grant( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permis public void Revoke( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string granteeName ) { - + if( granteeName != this.MockGranteeName ) + { + string errorMessage = "Expected to get granteeName == '" + this.MockGranteeName + "'. But got '" + granteeName + "'"; + throw new System.ArgumentException(errorMessage, "granteeName"); + } } } } diff --git a/Tests/Unit/Stubs/SQLPSStub.psm1 b/Tests/Unit/Stubs/SQLPSStub.psm1 new file mode 100644 index 000000000..66c8c3e06 --- /dev/null +++ b/Tests/Unit/Stubs/SQLPSStub.psm1 @@ -0,0 +1,1751 @@ +# Generated from SQL Server 2014 (build 12.0.4213.0) + +# Suppressing this rule because these functions are from an external module +# and are only being used as stubs +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUserNameAndPassWordParams', '')] +param() + +function Add-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Database}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Add-SqlAvailabilityGroupListenerStaticIp { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${StaticIp}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Add-SqlFirewallRule { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Backup-SqlDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [Parameter(ParameterSetName='ByBackupContainer')] + [Parameter(ParameterSetName='ByDBObject')] + [Parameter(ParameterSetName='ByName')] + [Parameter(ParameterSetName='ByObject')] + [ValidateNotNullOrEmpty()] + [string] + ${BackupContainer}, + + [object] + ${MirrorDevices}, + + [object] + ${BackupAction}, + + [string] + ${BackupSetName}, + + [string] + ${BackupSetDescription}, + + [object] + ${CompressionOption}, + + [switch] + ${CopyOnly}, + + [datetime] + ${ExpirationDate}, + + [switch] + ${FormatMedia}, + + [switch] + ${Incremental}, + + [switch] + ${Initialize}, + + [object] + ${LogTruncationType}, + + [string] + ${MediaDescription}, + + [ValidateRange(0, 2147483647)] + [int] + ${RetainDays}, + + [switch] + ${SkipTapeHeader}, + + [string] + ${UndoFileName}, + + [object] + ${EncryptionOption}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Database}, + + [Parameter(ParameterSetName='ByDBObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${DatabaseObject}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string[]] + ${BackupFile}, + + [ValidateNotNullOrEmpty()] + [psobject] + ${SqlCredential}, + + [ValidateNotNullOrEmpty()] + [object] + ${BackupDevice}, + + [switch] + ${PassThru}, + + [switch] + ${Checksum}, + + [switch] + ${ContinueAfterError}, + + [switch] + ${NoRewind}, + + [switch] + ${Restart}, + + [switch] + ${UnloadTapeAfter}, + + [switch] + ${NoRecovery}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFile}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFileGroup}, + + [int] + ${BlockSize}, + + [int] + ${BufferCount}, + + [int] + ${MaxTransferSize}, + + [string] + ${MediaName}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Convert-UrnToPath { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Urn} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Decode-SqlName { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SqlName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Disable-SqlAlwaysOn { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ServerInstance}, + + [switch] + ${NoServiceRestart}, + + [switch] + ${Force}, + + [pscredential] + ${Credential} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Enable-SqlAlwaysOn { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ServerInstance}, + + [switch] + ${NoServiceRestart}, + + [switch] + ${Force}, + + [pscredential] + ${Credential} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Encode-SqlName { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SqlName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByName', Mandatory=$true, Position=2, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [System.Nullable[int]] + ${ConnectionTimeout}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlInstance { + [CmdletBinding(ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${MachineName}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlSmartAdmin { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByName')] + [Parameter(Position=1)] + [Parameter(ParameterSetName='ByPath')] + [Parameter(ParameterSetName='ByObject')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ValueFromPipeline=$true)] + [Parameter(ParameterSetName='ByName')] + [psobject] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Invoke-PolicyEvaluation { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [psobject] + ${Policy}, + + [object] + ${AdHocPolicyEvaluationMode}, + + [Parameter(ParameterSetName='ConnectionProcessing', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [psobject] + ${TargetServerName}, + + [Parameter(ParameterSetName='ConnectionProcessing')] + [string] + ${TargetExpression}, + + [Parameter(ParameterSetName='ObjectProcessing', Mandatory=$true)] + [psobject[]] + ${TargetObjects}, + + [switch] + ${OutputXml} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Invoke-Sqlcmd { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline=$true)] + [psobject] + ${ServerInstance}, + + [ValidateNotNullOrEmpty()] + [string] + ${Database}, + + [switch] + ${EncryptConnection}, + + [ValidateNotNullOrEmpty()] + [string] + ${Username}, + + [ValidateNotNullOrEmpty()] + [string] + ${Password}, + + [Parameter(Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Query}, + + [int] + ${QueryTimeout}, + + [int] + ${ConnectionTimeout}, + + [ValidateRange(-1, 255)] + [int] + ${ErrorLevel}, + + [ValidateRange(-1, 25)] + [int] + ${SeverityLevel}, + + [ValidateRange(1, 2147483647)] + [int] + ${MaxCharLength}, + + [ValidateRange(1, 2147483647)] + [int] + ${MaxBinaryLength}, + + [switch] + ${AbortOnError}, + + [switch] + ${DedicatedAdministratorConnection}, + + [switch] + ${DisableVariables}, + + [switch] + ${DisableCommands}, + + [ValidateNotNullOrEmpty()] + [string] + ${HostName}, + + [string] + ${NewPassword}, + + [string[]] + ${Variable}, + + [ValidateNotNullOrEmpty()] + [string] + ${InputFile}, + + [bool] + ${OutputSqlErrors}, + + [switch] + ${IncludeSqlUserErrors}, + + [switch] + ${SuppressProviderContextWarning}, + + [switch] + ${IgnoreProviderContext} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Join-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNull()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${AvailabilityReplica}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${Database}, + + [object] + ${AutomatedBackupPreference}, + + [object] + ${FailureConditionLevel}, + + [int] + ${HealthCheckTimeout}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAvailabilityGroupListener { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [string] + ${DhcpSubnet}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${StaticIp}, + + [ValidateRange(1, 65535)] + [ValidateNotNullOrEmpty()] + [int] + ${Port}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [object] + ${AvailabilityMode}, + + [Parameter(Mandatory=$true)] + [object] + ${FailoverMode}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${EndpointUrl}, + + [int] + ${SessionTimeout}, + + [object] + ${ConnectionModeInPrimaryRole}, + + [object] + ${ConnectionModeInSecondaryRole}, + + [ValidateRange(0, 100)] + [int] + ${BackupPriority}, + + [string[]] + ${ReadOnlyRoutingList}, + + [string] + ${ReadonlyRoutingConnectionUrl}, + + [Parameter(ParameterSetName='AsTemplate')] + [switch] + ${AsTemplate}, + + [Parameter(ParameterSetName='AsTemplate')] + [ValidateNotNullOrEmpty()] + [object] + ${Version}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlBackupEncryptionOption { + [CmdletBinding()] + param( + [switch] + ${NoEncryption}, + + [ValidateNotNullOrEmpty()] + [object] + ${Algorithm}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptorType}, + + [ValidateNotNullOrEmpty()] + [string] + ${EncryptorName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Identity}, + + [ValidateNotNullOrEmpty()] + [securestring] + ${Secret}, + + [string] + ${ProviderName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlHADREndpoint { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [int] + ${Port}, + + [ValidateNotNullOrEmpty()] + [string] + ${Owner}, + + [ValidateNotNullOrEmpty()] + [string] + ${Certificate}, + + [ValidateNotNullOrEmpty()] + [ipaddress] + ${IpAddress}, + + [ValidateNotNullOrEmpty()] + [object] + ${AuthenticationOrder}, + + [ValidateNotNullOrEmpty()] + [object] + ${Encryption}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptionAlgorithm}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlFirewallRule { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Restore-SqlDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ClearSuspectPageTable}, + + [switch] + ${KeepReplication}, + + [switch] + ${Partial}, + + [switch] + ${ReplaceDatabase}, + + [switch] + ${RestrictedUser}, + + [long[]] + ${Offset}, + + [object] + ${RelocateFile}, + + [int] + ${FileNumber}, + + [object] + ${RestoreAction}, + + [string] + ${StandbyFile}, + + [string] + ${StopAtMarkAfterDate}, + + [string] + ${StopAtMarkName}, + + [string] + ${StopBeforeMarkAfterDate}, + + [string] + ${StopBeforeMarkName}, + + [string] + ${ToPointInTime}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Database}, + + [Parameter(ParameterSetName='ByDBObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${DatabaseObject}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string[]] + ${BackupFile}, + + [ValidateNotNullOrEmpty()] + [psobject] + ${SqlCredential}, + + [ValidateNotNullOrEmpty()] + [object] + ${BackupDevice}, + + [switch] + ${PassThru}, + + [switch] + ${Checksum}, + + [switch] + ${ContinueAfterError}, + + [switch] + ${NoRewind}, + + [switch] + ${Restart}, + + [switch] + ${UnloadTapeAfter}, + + [switch] + ${NoRecovery}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFile}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFileGroup}, + + [int] + ${BlockSize}, + + [int] + ${BufferCount}, + + [int] + ${MaxTransferSize}, + + [string] + ${MediaName}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Resume-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAuthenticationMode { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [object] + ${Mode}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${SqlCredential}, + + [switch] + ${ForceServiceRestart}, + + [switch] + ${NoServiceRestart}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [object] + ${AutomatedBackupPreference}, + + [object] + ${FailureConditionLevel}, + + [int] + ${HealthCheckTimeout}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAvailabilityGroupListener { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [ValidateRange(1, 65535)] + [int] + ${Port}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [object] + ${AvailabilityMode}, + + [object] + ${FailoverMode}, + + [ValidateNotNullOrEmpty()] + [string] + ${EndpointUrl}, + + [int] + ${SessionTimeout}, + + [object] + ${ConnectionModeInPrimaryRole}, + + [object] + ${ConnectionModeInSecondaryRole}, + + [ValidateRange(0, 100)] + [int] + ${BackupPriority}, + + [string[]] + ${ReadOnlyRoutingList}, + + [string] + ${ReadonlyRoutingConnectionUrl}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Identity}, + + [Parameter(Position=3)] + [ValidateNotNullOrEmpty()] + [securestring] + ${Secret}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlHADREndpoint { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [string] + ${Owner}, + + [ValidateNotNullOrEmpty()] + [string] + ${Certificate}, + + [ValidateNotNullOrEmpty()] + [ipaddress] + ${IpAddress}, + + [ValidateNotNullOrEmpty()] + [object] + ${AuthenticationOrder}, + + [ValidateNotNullOrEmpty()] + [object] + ${Encryption}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptionAlgorithm}, + + [ValidateNotNullOrEmpty()] + [int] + ${Port}, + + [ValidateNotNullOrEmpty()] + [object] + ${State}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlNetworkConfiguration { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [object] + ${Protocol}, + + [Parameter(Position=2)] + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${Port}, + + [switch] + ${Disable}, + + [switch] + ${ForceServiceRestart}, + + [switch] + ${NoServiceRestart}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlSmartAdmin { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [psobject] + ${SqlCredential}, + + [bool] + ${MasterSwitch}, + + [bool] + ${BackupEnabled}, + + [int] + ${BackupRetentionPeriodInDays}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptionOption}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Start-SqlInstance { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Stop-SqlInstance { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Suspend-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Switch-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${AllowDataLoss}, + + [switch] + ${Force}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlDatabaseReplicaState { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlSmartAdmin { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} diff --git a/Tests/Unit/Stubs/SQLServerStub.psm1 b/Tests/Unit/Stubs/SQLServerStub.psm1 new file mode 100644 index 000000000..528bdcb55 --- /dev/null +++ b/Tests/Unit/Stubs/SQLServerStub.psm1 @@ -0,0 +1,2562 @@ +# Generated from SQLServer module, module version 20.0 (SQL Server Management Studio 13.0.15600.2 - August 2016) + +# Suppressing this rule because these functions are from an external module +# and are only being used as stubs +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUserNameAndPassWordParams', '')] +param() + +function Add-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Database}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Add-SqlAvailabilityGroupListenerStaticIp { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${StaticIp}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Add-SqlAzureAuthenticationContext { + [CmdletBinding()] + param( + [Parameter(Position=0)] + [switch] + ${Interactive}, + + [Parameter(Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${ClientID}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Secret}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Tenant} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Add-SqlColumnEncryptionKeyValue { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ColumnMasterKeyName}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${EncryptedValue}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Add-SqlFirewallRule { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Backup-SqlDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByBackupContainer')] + [Parameter(ParameterSetName='ByDBObject')] + [Parameter(ParameterSetName='ByPath')] + [Parameter(ParameterSetName='ByName')] + [Parameter(ParameterSetName='ByObject')] + [ValidateNotNullOrEmpty()] + [string] + ${BackupContainer}, + + [object] + ${MirrorDevices}, + + [object] + ${BackupAction}, + + [string] + ${BackupSetName}, + + [string] + ${BackupSetDescription}, + + [object] + ${CompressionOption}, + + [switch] + ${CopyOnly}, + + [datetime] + ${ExpirationDate}, + + [switch] + ${FormatMedia}, + + [switch] + ${Incremental}, + + [switch] + ${Initialize}, + + [object] + ${LogTruncationType}, + + [string] + ${MediaDescription}, + + [ValidateRange(0, 2147483647)] + [int] + ${RetainDays}, + + [switch] + ${SkipTapeHeader}, + + [string] + ${UndoFileName}, + + [object] + ${EncryptionOption}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByName', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Database}, + + [Parameter(ParameterSetName='ByDBObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${DatabaseObject}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string[]] + ${BackupFile}, + + [ValidateNotNullOrEmpty()] + [psobject] + ${SqlCredential}, + + [ValidateNotNullOrEmpty()] + [object] + ${BackupDevice}, + + [switch] + ${PassThru}, + + [switch] + ${Checksum}, + + [switch] + ${ContinueAfterError}, + + [switch] + ${NoRewind}, + + [switch] + ${Restart}, + + [switch] + ${UnloadTapeAfter}, + + [switch] + ${NoRecovery}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFile}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFileGroup}, + + [int] + ${BlockSize}, + + [int] + ${BufferCount}, + + [int] + ${MaxTransferSize}, + + [string] + ${MediaName}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Complete-SqlColumnMasterKeyRotation { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SourceColumnMasterKeyName}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function ConvertFrom-EncodedSqlName { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SqlName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function ConvertTo-EncodedSqlName { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SqlName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Convert-UrnToPath { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Urn} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Disable-SqlAlwaysOn { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ServerInstance}, + + [switch] + ${NoServiceRestart}, + + [switch] + ${Force}, + + [pscredential] + ${Credential} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Enable-SqlAlwaysOn { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ServerInstance}, + + [switch] + ${NoServiceRestart}, + + [switch] + ${Force}, + + [pscredential] + ${Credential} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlAgent { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [Parameter(ParameterSetName='ByObject', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlAgentJob { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [Parameter(ParameterSetName='ByName', Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlAgentJobHistory { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [datetime] + ${StartRunDate}, + + [datetime] + ${EndRunDate}, + + [guid] + ${JobID}, + + [string] + ${JobName}, + + [int] + ${MinimumRetries}, + + [int] + ${MinimumRunDurationInSeconds}, + + [switch] + ${OldestFirst}, + + [object] + ${OutcomesType}, + + [int] + ${SqlMessageID}, + + [int] + ${SqlSeverity}, + + [object] + ${Since}, + + [Parameter(ParameterSetName='ByName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlAgentJobSchedule { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlAgentJobStep { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlAgentSchedule { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [Parameter(ParameterSetName='ByName', Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlColumnEncryptionKey { + [CmdletBinding()] + param( + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlColumnMasterKey { + [CmdletBinding()] + param( + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByName', Mandatory=$true, Position=2, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [System.Nullable[int]] + ${ConnectionTimeout}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlErrorLog { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [timespan] + ${Timespan}, + + [datetime] + ${Before}, + + [datetime] + ${After}, + + [object] + ${Since}, + + [switch] + ${Ascending}, + + [Parameter(ParameterSetName='ByName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlInstance { + [CmdletBinding(ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${MachineName}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Get-SqlSmartAdmin { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [Parameter(ParameterSetName='ByName')] + [Parameter(Position=1)] + [Parameter(ParameterSetName='ByObject')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [string] + ${DatabaseName}, + + [Parameter(ParameterSetName='ByName')] + [Parameter(ValueFromPipeline=$true)] + [psobject] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Invoke-PolicyEvaluation { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [psobject] + ${Policy}, + + [object] + ${AdHocPolicyEvaluationMode}, + + [Parameter(ParameterSetName='ConnectionProcessing', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [psobject] + ${TargetServerName}, + + [Parameter(ParameterSetName='ConnectionProcessing')] + [string] + ${TargetExpression}, + + [Parameter(ParameterSetName='ObjectProcessing', Mandatory=$true)] + [psobject[]] + ${TargetObjects}, + + [switch] + ${OutputXml} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Invoke-Sqlcmd { + [CmdletBinding(DefaultParameterSetName='ByConnectionParameters')] + param( + [Parameter(ParameterSetName='ByConnectionParameters', ValueFromPipeline=$true)] + [psobject] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [ValidateNotNullOrEmpty()] + [string] + ${Database}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [switch] + ${EncryptConnection}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [ValidateNotNullOrEmpty()] + [string] + ${Username}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [ValidateNotNullOrEmpty()] + [string] + ${Password}, + + [Parameter(Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Query}, + + [int] + ${QueryTimeout}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [int] + ${ConnectionTimeout}, + + [ValidateRange(-1, 255)] + [int] + ${ErrorLevel}, + + [ValidateRange(-1, 25)] + [int] + ${SeverityLevel}, + + [ValidateRange(1, 2147483647)] + [int] + ${MaxCharLength}, + + [ValidateRange(1, 2147483647)] + [int] + ${MaxBinaryLength}, + + [switch] + ${AbortOnError}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [switch] + ${DedicatedAdministratorConnection}, + + [switch] + ${DisableVariables}, + + [switch] + ${DisableCommands}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [ValidateNotNullOrEmpty()] + [string] + ${HostName}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [string] + ${NewPassword}, + + [string[]] + ${Variable}, + + [ValidateNotNullOrEmpty()] + [string] + ${InputFile}, + + [bool] + ${OutputSqlErrors}, + + [switch] + ${IncludeSqlUserErrors}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [switch] + ${SuppressProviderContextWarning}, + + [Parameter(ParameterSetName='ByConnectionParameters')] + [switch] + ${IgnoreProviderContext}, + + [Alias('As')] + [object] + ${OutputAs}, + + [Parameter(ParameterSetName='ByConnectionString', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ConnectionString} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Invoke-SqlColumnMasterKeyRotation { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SourceColumnMasterKeyName}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${TargetColumnMasterKeyName}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Join-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNull()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${AvailabilityReplica}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${Database}, + + [object] + ${AutomatedBackupPreference}, + + [object] + ${FailureConditionLevel}, + + [int] + ${HealthCheckTimeout}, + + [switch] + ${BasicAvailabilityGroup}, + + [switch] + ${DatabaseHealthTrigger}, + + [switch] + ${DtcSupportEnabled}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAvailabilityGroupListener { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [string] + ${DhcpSubnet}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${StaticIp}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(1, 65535)] + [int] + ${Port}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [object] + ${AvailabilityMode}, + + [Parameter(Mandatory=$true)] + [object] + ${FailoverMode}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${EndpointUrl}, + + [int] + ${SessionTimeout}, + + [object] + ${ConnectionModeInPrimaryRole}, + + [object] + ${ConnectionModeInSecondaryRole}, + + [ValidateRange(0, 100)] + [int] + ${BackupPriority}, + + [string[]] + ${ReadOnlyRoutingList}, + + [string] + ${ReadonlyRoutingConnectionUrl}, + + [Parameter(ParameterSetName='AsTemplate')] + [switch] + ${AsTemplate}, + + [Parameter(ParameterSetName='AsTemplate')] + [ValidateNotNullOrEmpty()] + [object] + ${Version}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlAzureKeyVaultColumnMasterKeySettings { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${KeyUrl} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlBackupEncryptionOption { + [CmdletBinding()] + param( + [switch] + ${NoEncryption}, + + [ValidateNotNullOrEmpty()] + [object] + ${Algorithm}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptorType}, + + [ValidateNotNullOrEmpty()] + [string] + ${EncryptorName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlCertificateStoreColumnMasterKeySettings { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${CertificateStoreLocation}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Thumbprint} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlCngColumnMasterKeySettings { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${CngProviderName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${KeyName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlColumnEncryptionKey { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ColumnMasterKeyName}, + + [ValidateNotNullOrEmpty()] + [string] + ${EncryptedValue}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlColumnEncryptionKeyEncryptedValue { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [object] + ${TargetColumnMasterKeySettings}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [object] + ${ColumnMasterKeySettings}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${EncryptedValue} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlColumnEncryptionSettings { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${ColumnName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${EncryptionType}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${EncryptionKey} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlColumnMasterKey { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${ColumnMasterKeySettings}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Identity}, + + [ValidateNotNullOrEmpty()] + [securestring] + ${Secret}, + + [string] + ${ProviderName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlCspColumnMasterKeySettings { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${CspProviderName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${KeyName} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function New-SqlHADREndpoint { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [int] + ${Port}, + + [ValidateNotNullOrEmpty()] + [string] + ${Owner}, + + [ValidateNotNullOrEmpty()] + [string] + ${Certificate}, + + [ValidateNotNullOrEmpty()] + [ipaddress] + ${IpAddress}, + + [ValidateNotNullOrEmpty()] + [object] + ${AuthenticationOrder}, + + [ValidateNotNullOrEmpty()] + [object] + ${Encryption}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptionAlgorithm}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlColumnEncryptionKey { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlColumnEncryptionKeyValue { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ColumnMasterKeyName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlColumnMasterKey { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Remove-SqlFirewallRule { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Restore-SqlDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ClearSuspectPageTable}, + + [switch] + ${KeepReplication}, + + [switch] + ${Partial}, + + [switch] + ${ReplaceDatabase}, + + [switch] + ${RestrictedUser}, + + [long[]] + ${Offset}, + + [object] + ${RelocateFile}, + + [int] + ${FileNumber}, + + [object] + ${RestoreAction}, + + [string] + ${StandbyFile}, + + [string] + ${StopAtMarkAfterDate}, + + [string] + ${StopAtMarkName}, + + [string] + ${StopBeforeMarkAfterDate}, + + [string] + ${StopBeforeMarkName}, + + [string] + ${ToPointInTime}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByName', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='ByPath', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Database}, + + [Parameter(ParameterSetName='ByDBObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${DatabaseObject}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string[]] + ${BackupFile}, + + [ValidateNotNullOrEmpty()] + [psobject] + ${SqlCredential}, + + [ValidateNotNullOrEmpty()] + [object] + ${BackupDevice}, + + [switch] + ${PassThru}, + + [switch] + ${Checksum}, + + [switch] + ${ContinueAfterError}, + + [switch] + ${NoRewind}, + + [switch] + ${Restart}, + + [switch] + ${UnloadTapeAfter}, + + [switch] + ${NoRecovery}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFile}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${DatabaseFileGroup}, + + [int] + ${BlockSize}, + + [int] + ${BufferCount}, + + [int] + ${MaxTransferSize}, + + [string] + ${MediaName}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Resume-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Save-SqlMigrationReport { + [CmdletBinding()] + param( + [string] + ${Server}, + + [string] + ${Database}, + + [string] + ${Schema}, + + [ValidateNotNullOrEmpty()] + [string] + ${Username}, + + [ValidateNotNullOrEmpty()] + [string] + ${Password}, + + [string] + ${Object}, + + [object] + ${InputObject}, + + [object] + ${MigrationType}, + + [ValidateNotNullOrEmpty()] + [string] + ${FolderPath} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAuthenticationMode { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [object] + ${Mode}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${SqlCredential}, + + [switch] + ${ForceServiceRestart}, + + [switch] + ${NoServiceRestart}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [object] + ${AutomatedBackupPreference}, + + [object] + ${FailureConditionLevel}, + + [int] + ${HealthCheckTimeout}, + + [bool] + ${DatabaseHealthTrigger}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAvailabilityGroupListener { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [ValidateRange(1, 65535)] + [int] + ${Port}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [object] + ${AvailabilityMode}, + + [object] + ${FailoverMode}, + + [ValidateNotNullOrEmpty()] + [string] + ${EndpointUrl}, + + [int] + ${SessionTimeout}, + + [object] + ${ConnectionModeInPrimaryRole}, + + [object] + ${ConnectionModeInSecondaryRole}, + + [ValidateRange(0, 100)] + [int] + ${BackupPriority}, + + [string[]] + ${ReadOnlyRoutingList}, + + [string] + ${ReadonlyRoutingConnectionUrl}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlColumnEncryption { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${ColumnEncryptionSettings}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlCredential { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${Identity}, + + [Parameter(Position=3)] + [ValidateNotNullOrEmpty()] + [securestring] + ${Secret}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlErrorLog { + [CmdletBinding(DefaultParameterSetName='ByPath')] + param( + [Parameter(ParameterSetName='ByName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(ParameterSetName='ByName')] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(ParameterSetName='ByName')] + [int] + ${ConnectionTimeout}, + + [ValidateRange(6, 99)] + [uint16] + ${MaxLogCount}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlHADREndpoint { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [string] + ${Owner}, + + [ValidateNotNullOrEmpty()] + [string] + ${Certificate}, + + [ValidateNotNullOrEmpty()] + [ipaddress] + ${IpAddress}, + + [ValidateNotNullOrEmpty()] + [object] + ${AuthenticationOrder}, + + [ValidateNotNullOrEmpty()] + [object] + ${Encryption}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptionAlgorithm}, + + [ValidateNotNullOrEmpty()] + [int] + ${Port}, + + [ValidateNotNullOrEmpty()] + [object] + ${State}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlNetworkConfiguration { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [object] + ${Protocol}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${Port}, + + [switch] + ${Disable}, + + [switch] + ${ForceServiceRestart}, + + [switch] + ${NoServiceRestart}, + + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Set-SqlSmartAdmin { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [ValidateNotNullOrEmpty()] + [psobject] + ${SqlCredential}, + + [bool] + ${MasterSwitch}, + + [bool] + ${BackupEnabled}, + + [int] + ${BackupRetentionPeriodInDays}, + + [ValidateNotNullOrEmpty()] + [object] + ${EncryptionOption}, + + [string] + ${DatabaseName}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Start-SqlInstance { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Stop-SqlInstance { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [Parameter(ParameterSetName='ByName', Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ServerInstance}, + + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [switch] + ${AutomaticallyAcceptUntrustedCertificates}, + + [ValidateRange(0, 2147483647)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ManagementPublicPort}, + + [ValidateNotNullOrEmpty()] + [ValidateRange(0, 2147483647)] + [System.Nullable[int]] + ${RetryTimeout} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Suspend-SqlAvailabilityDatabase { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Switch-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${AllowDataLoss}, + + [switch] + ${Force}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject}, + + [switch] + ${Script} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlAvailabilityGroup { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlAvailabilityReplica { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlDatabaseReplicaState { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +function Test-SqlSmartAdmin { + [CmdletBinding(DefaultParameterSetName='ByPath', ConfirmImpact='Medium')] + param( + [switch] + ${ShowPolicyDetails}, + + [switch] + ${AllowUserPolicies}, + + [switch] + ${NoRefresh}, + + [Parameter(ParameterSetName='ByPath', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='ByObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [object] + ${InputObject} + ) + + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} diff --git a/Tests/Unit/xSQLServerAvailabilityGroupListener.Tests.ps1 b/Tests/Unit/xSQLServerAvailabilityGroupListener.Tests.ps1 new file mode 100644 index 000000000..a07b188dc --- /dev/null +++ b/Tests/Unit/xSQLServerAvailabilityGroupListener.Tests.ps1 @@ -0,0 +1,684 @@ +$script:DSCModuleName = 'xSQLServer' +$script:DSCResourceName = 'xSQLServerAvailabilityGroupListener' + +#region HEADER + +# Unit Test Template Version: 1.1.0 +[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +# Begin Testing +try +{ + #region Pester Test Initialization + + # Loading mocked classes + Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') + + # Loading stub cmdlets + Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SQLPSStub.psm1') -Force + + # Static parameter values + $nodeName = 'localhost' + $instanceName = 'DEFAULT' + $availabilityGroup = 'AG01' + $listnerName = 'AGListner' + + $defaultParameters = @{ + InstanceName = $instanceName + NodeName = $nodeName + Name = $listnerName + AvailabilityGroup = $availabilityGroup + } + + #endregion Pester Test Initialization + + Describe "$($script:DSCResourceName)\Get-TargetResource" { + Context 'When the system is not in the desired state' { + $testParameters = $defaultParameters + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the desired state as absent' { + $result.Ensure | Should Be 'Absent' + } + + It 'Should return the same values as passed as parameters' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + $result.AvailabilityGroup | Should Be $testParameters.AvailabilityGroup + } + + It 'Should not return any IP addresses' { + $result.IpAddress | Should Be $null + } + + It 'Should not return port' { + $result.Port | Should Be 0 + } + + It 'Should return that DHCP is not used' { + $result.DHCP | Should Be $false + } + + It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Context 'When the system is in the desired state, without DHCP' { + $testParameters = $defaultParameters + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the desired state as present' { + $result.Ensure | Should Be 'Present' + } + + It 'Should return the same values as passed as parameters' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + $result.AvailabilityGroup | Should Be $testParameters.AvailabilityGroup + } + + It 'Should return correct IP address' { + $result.IpAddress | Should Be '192.168.0.1/255.255.255.0' + } + + It 'Should return correct port' { + $result.Port | Should Be 5030 + } + + It 'Should return that DHCP is not used' { + $result.DHCP | Should Be $false + } + + It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Context 'When the system is in the desired state, with DHCP' { + $testParameters = $defaultParameters + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5031 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $true -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the desired state as present' { + $result.Ensure | Should Be 'Present' + } + + It 'Should return the same values as passed as parameters' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + $result.AvailabilityGroup | Should Be $testParameters.AvailabilityGroup + } + + It 'Should return correct IP address' { + $result.IpAddress | Should Be '192.168.0.1/255.255.255.0' + } + + It 'Should return correct port' { + $result.Port | Should Be 5031 + } + + It 'Should return that DHCP is used' { + $result.DHCP | Should Be $true + } + + It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Assert-VerifiableMocks + } + + Describe "$($script:DSCResourceName)\Test-TargetResource" { + Context 'When the system is not in the desired state (for static IP)' { + It 'Should return that desired state is absent when wanted desired state is to be Present' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.10.45/255.255.252.0' + Port = 5030 + DHCP = $false + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state is absent when wanted desired state is to be Absent' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is absent when IP address is different' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.10.45/255.255.252.0' + Port = 5030 + DHCP = $false + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is absent when DHCP is absent but should be present' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + DHCP = $true + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is absent when DHCP is the only set parameter' { + $testParameters = $defaultParameters + $testParameters += @{ + DHCP = $true + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5555 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state is absent when port is different' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + DHCP = $false + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Context 'When the system is not in the desired state (for DHCP)' { + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $true -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state is absent when DHCP is present but should be absent' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.0.100/255.255.255.0' + Port = 5030 + DHCP = $false + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is absent when IP address is the only set parameter' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = '192.168.10.45/255.255.252.0' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5555 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $true -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state is absent when port is the only set parameter' { + $testParameters = $defaultParameters + $testParameters += @{ + Port = 5030 + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Context 'When the system is in the desired state (for static IP)' { + It 'Should return that desired state is present when wanted desired state is to be Absent' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + IpAddress = '192.168.10.45/255.255.252.0' + Port = 5030 + DHCP = $false + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state is present when wanted desired state is to be Present, without DHCP' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + DHCP = $false + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is present when IP address is the only set parameter' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = '192.168.0.1/255.255.255.0' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is present when port is the only set parameter' { + $testParameters = $defaultParameters + $testParameters += @{ + Port = 5030 + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Context 'When the system is in the desired state (for DHCP)' { + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $true -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state is present when wanted desired state is to be Present, with DHCP' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + DHCP = $true + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is present when DHCP is the only set parameter' { + $testParameters = $defaultParameters + $testParameters += @{ + DHCP = $true + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Assert-VerifiableMocks + } + + Describe "$($script:DSCResourceName)\Set-TargetResource" { + Mock -CommandName New-SqlAvailabilityGroupListener -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName Set-SqlAvailabilityGroupListener -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName Add-SqlAvailabilityGroupListenerStaticIp -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + + Context 'When the system is not in the desired state' { + It 'Should call the cmdlet New-SqlAvailabilityGroupListener when system is not in desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.10.45/255.255.252.0' + Port = 5030 + DHCP = $false + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + + Set-TargetResource @testParameters | Out-Null + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should throw when trying to change an existing IP address' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = '10.0.0.1/255.255.252.0' + Port = 5030 + DHCP = $false + } + + { Set-TargetResource @testParameters } | Should Throw + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should throw when trying to change from static IP to DHCP' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + DHCP = $true + } + + { Set-TargetResource @testParameters } | Should Throw + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should call the cmdlet Add-SqlAvailabilityGroupListenerStaticIp, when adding another IP address, and system is not in desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = @('192.168.0.1/255.255.255.0','10.0.0.1/255.255.252.0') + Port = 5030 + DHCP = $false + } + + Set-TargetResource @testParameters | Out-Null + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5555 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.10.45' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.252.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should call the cmdlet Set-SqlAvailabilityGroupListener when port is not in desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = '192.168.10.45/255.255.252.0' + Port = 5030 + DHCP = $false + } + + Set-TargetResource @testParameters | Out-Null + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + } + + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListener + return New-Object Object | + Add-Member NoteProperty PortNumber 5030 -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $false -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + Context 'When the system is in the desired state' { + It 'Should not call the any cmdlet *-SqlAvailability* when system is in desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + DHCP = $false + } + + Set-TargetResource @testParameters | Out-Null + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should not call the any cmdlet *-SqlAvailability* when system is in desired state (without ensure parameter)' { + $testParameters = $defaultParameters + $testParameters += @{ + IpAddress = '192.168.0.1/255.255.255.0' + Port = 5030 + } + + Set-TargetResource @testParameters | Out-Null + + Assert-MockCalled Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled New-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Set-SqlAvailabilityGroupListener -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + Assert-MockCalled Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + } + + Assert-VerifiableMocks + } +} +finally +{ + #region FOOTER + + Restore-TestEnvironment -TestEnvironment $TestEnvironment + + #endregion +} diff --git a/Tests/Unit/xSQLServerEndpointPermission.Tests.ps1 b/Tests/Unit/xSQLServerEndpointPermission.Tests.ps1 new file mode 100644 index 000000000..54f8a0561 --- /dev/null +++ b/Tests/Unit/xSQLServerEndpointPermission.Tests.ps1 @@ -0,0 +1,428 @@ +$script:DSCModuleName = 'xSQLServer' +$script:DSCResourceName = 'xSQLServerEndpointPermission' + +#region HEADER + +# Unit Test Template Version: 1.1.0 +[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +# Begin Testing +try +{ + #region Pester Test Initialization + + # Loading mocked classes + Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') + + $nodeName = 'localhost' + $instanceName = 'DEFAULT' + $principal = 'COMPANY\SqlServiceAcct' + $otherPrincipal = 'COMPANY\OtherAcct' + $endpointName = 'DefaultEndpointMirror' + + $defaultParameters = @{ + InstanceName = $instanceName + NodeName = $nodeName + Name = $endpointName + Principal = $principal + } + + #endregion Pester Test Initialization + + Describe "$($script:DSCResourceName)\Get-TargetResource" { + Context 'When the system is not in the desired state' { + $testParameters = $defaultParameters + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $otherPrincipal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the desired state as absent' { + $result.Ensure | Should Be 'Absent' + } + + It 'Should return the same values as passed as parameters' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + $result.Principal | Should Be $testParameters.Principal + } + + It 'Should not return any permissions' { + $result.Permission | Should Be '' + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Context 'When the system is in the desired state' { + $testParameters = $defaultParameters + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $principal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the desired state as present' { + $result.Ensure | Should Be 'Present' + } + + It 'Should return the same values as passed as parameters' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + $result.Principal | Should Be $testParameters.Principal + } + + It 'Should return the permissions passed as parameter' { + $result.Permission | Should Be 'CONNECT' + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Assert-VerifiableMocks + } + + Describe "$($script:DSCResourceName)\Test-TargetResource" { + Context 'When the system is not in the desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + Permission = 'CONNECT' + } + + It 'Should return that desired state is absent when wanted desired state is to be Present' { + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $otherPrincipal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + Permission = 'CONNECT' + } + + It 'Should return that desired state is absent when wanted desired state is to be Absent' { + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $principal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Context 'When the system is in the desired state' { + It 'Should return that desired state is present when wanted desired state is to be Present' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + Permission = 'CONNECT' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $principal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should return that desired state is present when wanted desired state is to be Absent' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + Permission = 'CONNECT' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $otherPrincipal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Assert-VerifiableMocks + } + + Describe "$($script:DSCResourceName)\Set-TargetResource" { + Context 'When the system is not in the desired state' { + It 'Should call the the method Grant when desired state is to be Present' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + Permission = 'CONNECT' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $otherPrincipal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru | + Add-Member ScriptMethod Grant { + param( + $permissionSet, + $principal + ) + return + } -PassThru | + Add-Member ScriptMethod Revoke { + param( + $permissionSet, + $principal + ) + throw 'Called Revoke() when it shouldn''t been called' + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should call the the method Revoke when desired state is to be Absent' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + Permission = 'CONNECT' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $principal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru | + Add-Member ScriptMethod Grant { + param( + $permissionSet, + $principal + ) + throw 'Called Grant() when it shouldn''t been called' + } -PassThru | + Add-Member ScriptMethod Revoke { + param( + $permissionSet, + $principal + ) + return + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope It + } + } + + Context 'When the system is in the desired state' { + It 'Should not throw error when desired state is already Present' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + Permission = 'CONNECT' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $principal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru | + Add-Member ScriptMethod Grant { + param( + $permissionSet, + $principal + ) + throw 'Called Grant() when it shouldn''t been called' + } -PassThru | + Add-Member ScriptMethod Revoke { + param( + $permissionSet, + $principal + ) + throw 'Called Revoke() when it shouldn''t been called' + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should not throw error when desired state is already Absent' { + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + Permission = 'CONNECT' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty Name $endpointName -PassThru | + Add-Member ScriptMethod EnumObjectPermissions { + param($permissionSet) + return @( + (New-Object Object | + Add-Member NoteProperty Grantee $otherPrincipal -PassThru | + Add-Member NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru | + Add-Member ScriptMethod Grant { + param( + $permissionSet, + $principal + ) + throw 'Called Grant() when it shouldn''t been called' + } -PassThru | + Add-Member ScriptMethod Revoke { + param( + $permissionSet, + $principal + ) + throw 'Called Revoke() when it shouldn''t been called' + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + Assert-VerifiableMocks + } +} +finally +{ + #region FOOTER + + Restore-TestEnvironment -TestEnvironment $TestEnvironment + + #endregion +} diff --git a/Tests/Unit/xSQLServerEndpointState.Tests.ps1 b/Tests/Unit/xSQLServerEndpointState.Tests.ps1 new file mode 100644 index 000000000..6f834b198 --- /dev/null +++ b/Tests/Unit/xSQLServerEndpointState.Tests.ps1 @@ -0,0 +1,370 @@ +$script:DSCModuleName = 'xSQLServer' +$script:DSCResourceName = 'xSQLServerEndPointState' + +#region HEADER + +# Unit Test Template Version: 1.1.0 +[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +# Begin Testing +try +{ + #region Pester Test Initialization + + # Loading stub cmdlets + Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SQLPSStub.psm1') -Force + + $nodeName = 'localhost' + $instanceName = 'DEFAULT' + $endpointName = 'DefaultEndpointMirror' + + $defaultParameters = @{ + InstanceName = $instanceName + NodeName = $nodeName + Name = $endpointName + } + + #endregion Pester Test Initialization + + Describe "$($script:DSCResourceName)\Get-TargetResource" { + $testParameters = $defaultParameters + + Context 'When the system is not in the desired state' { + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Stopped' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should not return the same value as expected state Started' { + $result.State | Should Not Be 'Started' + $result.State | Should Be 'Stopped' + } + + It 'Should return the same values as passed as parameters when expected state is Started' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when expected state is Started' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Started' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should not return the same value as expected state Stopped' { + $result.State | Should Not Be 'Stopped' + $result.State | Should Be 'Started' + } + + It 'Should return the same values as passed as parameters when expected state is Stopped' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when expected state is Stopped' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Context 'When the system is in the desired state' { + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Started' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the same value as expected state Started' { + $result.State | Should Not Be 'Stopped' + $result.State | Should Be 'Started' + } + + It 'Should return the same values as passed as parameters when expected state is Started' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + } + + It 'Should call the mock function Get-SQLPSInstance when expected state is Started' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Stopped' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + $result = Get-TargetResource @testParameters + + It 'Should return the same value as expected state Stopped' { + $result.State | Should Not Be 'Started' + $result.State | Should Be 'Stopped' + } + + It 'Should return the same values as passed as parameters when expected state is Stopped' { + $result.NodeName | Should Be $testParameters.NodeName + $result.InstanceName | Should Be $testParameters.InstanceName + $result.Name | Should Be $testParameters.Name + } + + It 'Should call the mock function Get-SQLPSInstance when expected state is Stopped' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Assert-VerifiableMocks + } + + Describe "$($script:DSCResourceName)\Test-TargetResource" { + Context 'When the system is not in the desired state' { + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Stopped' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state as absent when desired state is Started' { + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Started' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state of Started is absent' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Started' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state as absent when desired state is Stopped' { + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Stopped' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state of Started is absent' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Context 'When the system is in the desired state' { + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Started' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state as present when desired state is Started' { + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Started' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state of Started is present' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Stopped' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should return that desired state as present when desired state is Stopped' { + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Stopped' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state of Stopped is present' { + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope Context + } + } + + Assert-VerifiableMocks + } + + Describe "$($script:DSCResourceName)\Set-TargetResource" { + Mock Set-SqlHADREndpoint -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + + Context 'When the system is not in the desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Stopped' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Started' -PassThru | # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + Add-Member ScriptProperty Protocol { + return New-Object Object | + Add-Member ScriptProperty Tcp { + return New-Object Object | + Add-Member ScriptProperty ListenerIPAddress { + return New-Object Object | + Add-Member NoteProperty IPAddressToString '10.0.0.1' -PassThru + } -PassThru + } -PassThru + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should not throw an error when desired state is not equal to Stopped' { + { Set-TargetResource @testParameters } | Should Not Throw + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state is not equal to Stopped' { + Set-TargetResource @testParameters + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should call the mock function Set-SqlHADREndpoint when desired state is not equal to Stopped' { + Set-TargetResource @testParameters + Assert-MockCalled Set-SqlHADREndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Started' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Stopped' -PassThru | # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + Add-Member ScriptProperty Protocol { + return New-Object Object | + Add-Member ScriptProperty Tcp { + return New-Object Object | + Add-Member ScriptProperty ListenerIPAddress { + return New-Object Object | + Add-Member NoteProperty IPAddressToString '10.0.0.1' -PassThru + } -PassThru + } -PassThru + } -PassThru -Force + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should not throw an error when desired state is not equal to Started' { + { Set-TargetResource @testParameters } | Should Not Throw + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state is not equal to Started' { + Set-TargetResource @testParameters + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should call the mock function Set-SqlHADREndpoint when desired state is not equal to Started' { + Set-TargetResource @testParameters + Assert-MockCalled Set-SqlHADREndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + } + + Context 'When the system is in the desired state' { + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Stopped' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Stopped' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should not throw an error when desired state is equal to Stopped' { + { Set-TargetResource @testParameters } | Should Not Throw + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state is equal to Stopped' { + Set-TargetResource @testParameters + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should not call the mock function Set-SqlHADREndpoint when desired state is equal to Stopped' { + Set-TargetResource @testParameters + Assert-MockCalled Set-SqlHADREndpoint -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + + $testParameters = $defaultParameters + $testParameters += @{ + State = 'Started' + } + + Mock -CommandName Get-SQLAlwaysOnEndpoint -MockWith { + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + return New-Object Object | + Add-Member NoteProperty EndpointState 'Started' -PassThru -Force # TypeName: Microsoft.SqlServer.Management.Smo.EndpointState + } -ModuleName $script:DSCResourceName -Verifiable + + It 'Should not throw an error when desired state is equal to Started' { + { Set-TargetResource @testParameters } | Should Not Throw + } + + It 'Should call the mock function Get-SQLAlwaysOnEndpoint when desired state is equal to Started' { + Set-TargetResource @testParameters + Assert-MockCalled Get-SQLAlwaysOnEndpoint -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It + } + + It 'Should not call the mock function Set-SqlHADREndpoint when desired state is equal to Started' { + Set-TargetResource @testParameters + Assert-MockCalled Set-SqlHADREndpoint -Exactly -Times 0 -ModuleName $script:DSCResourceName -Scope It + } + } + + Assert-VerifiableMocks + } +} +finally +{ + #region FOOTER + + Restore-TestEnvironment -TestEnvironment $TestEnvironment + + #endregion +} diff --git a/Tests/Unit/xSQLServerPermission.Tests.ps1 b/Tests/Unit/xSQLServerPermission.Tests.ps1 index 44fa589f3..57bac0792 100644 --- a/Tests/Unit/xSQLServerPermission.Tests.ps1 +++ b/Tests/Unit/xSQLServerPermission.Tests.ps1 @@ -35,7 +35,7 @@ try #endregion Pester Test Initialization - $testParameters = @{ + $defaultParameters = @{ InstanceName = $instanceName NodeName = $nodeName Principal = $principal @@ -44,22 +44,24 @@ try Describe "$($script:DSCResourceName)\Get-TargetResource" { Context 'When the system is not in the desired state' { - BeforeAll { - Mock -CommandName Get-SQLPSInstance -MockWith { - $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList @( $false ) - $mockObjectSmoServer.Name = "$nodeName\$instanceName" - $mockObjectSmoServer.DisplayName = $instanceName - $mockObjectSmoServer.InstanceName = $instanceName - $mockObjectSmoServer.IsHadrEnabled = $False - $mockObjectSmoServer.MockGranteeName = $principal - - return $mockObjectSmoServer - } -ModuleName $script:DSCResourceName -Verifiable - } + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $false + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server + $mockObjectSmoServer.Name = "$nodeName\$instanceName" + $mockObjectSmoServer.DisplayName = $instanceName + $mockObjectSmoServer.InstanceName = $instanceName + $mockObjectSmoServer.IsHadrEnabled = $False + $mockObjectSmoServer.MockGranteeName = $principal + + return $mockObjectSmoServer + } -ModuleName $script:DSCResourceName -Verifiable + $testParameters = $defaultParameters + $result = Get-TargetResource @testParameters - It 'Should return the desired state as Absent' { + It 'Should return the desired state as absent' { $result.Ensure | Should Be 'Absent' } @@ -79,18 +81,20 @@ try } Context 'When the system is in the desired state' { - BeforeAll { - Mock -CommandName Get-SQLPSInstance -MockWith { - $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList @( $true ) - $mockObjectSmoServer.Name = "$nodeName\$instanceName" - $mockObjectSmoServer.DisplayName = $instanceName - $mockObjectSmoServer.InstanceName = $instanceName - $mockObjectSmoServer.IsHadrEnabled = $False - $mockObjectSmoServer.MockGranteeName = $principal - - return $mockObjectSmoServer - } -ModuleName $script:DSCResourceName -Verifiable - } + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $true + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server + $mockObjectSmoServer.Name = "$nodeName\$instanceName" + $mockObjectSmoServer.DisplayName = $instanceName + $mockObjectSmoServer.InstanceName = $instanceName + $mockObjectSmoServer.IsHadrEnabled = $False + $mockObjectSmoServer.MockGranteeName = $principal + + return $mockObjectSmoServer + } -ModuleName $script:DSCResourceName -Verifiable + + $testParameters = $defaultParameters $result = Get-TargetResource @testParameters @@ -125,16 +129,13 @@ try Assert-VerifiableMocks } - # This is added to the hash table after the Get method is tested, because Get method doesn't have Ensure as a parameter. - $testParameters += @{ - Ensure = 'Present' - } - Describe "$($script:DSCResourceName)\Test-TargetResource" { Context 'When the system is not in the desired state' { - BeforeAll { - Mock -CommandName Get-SQLPSInstance -MockWith { - $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList @( $false ) + It 'Should return that desired state is absent when wanted desired state is to be Present' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $false + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server $mockObjectSmoServer.Name = "$nodeName\$instanceName" $mockObjectSmoServer.DisplayName = $instanceName $mockObjectSmoServer.InstanceName = $instanceName @@ -143,22 +144,50 @@ try return $mockObjectSmoServer } -ModuleName $script:DSCResourceName -Verifiable - } + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + } - It 'Should return that desired state is absent' { $result = Test-TargetResource @testParameters $result | Should Be $false + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It } - It 'Should call the mock function Get-SQLPSInstance' { - Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + It 'Should return that desired state is absent when wanted desired state is to be Absent' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $true + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server + $mockObjectSmoServer.Name = "$nodeName\$instanceName" + $mockObjectSmoServer.DisplayName = $instanceName + $mockObjectSmoServer.InstanceName = $instanceName + $mockObjectSmoServer.IsHadrEnabled = $False + $mockObjectSmoServer.MockGranteeName = $principal + + return $mockObjectSmoServer + } -ModuleName $script:DSCResourceName -Verifiable + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $false + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It } } Context 'When the system is in the desired state' { - BeforeAll { - Mock -CommandName Get-SQLPSInstance -MockWith { - $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList @( $true ) + It 'Should return that desired state is present when wanted desired state is to be Present' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $true + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server $mockObjectSmoServer.Name = "$nodeName\$instanceName" $mockObjectSmoServer.DisplayName = $instanceName $mockObjectSmoServer.InstanceName = $instanceName @@ -167,15 +196,41 @@ try return $mockObjectSmoServer } -ModuleName $script:DSCResourceName -Verifiable - } + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + } - It 'Should return that desired state is present' { $result = Test-TargetResource @testParameters $result | Should Be $true + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It } - It 'Should call the mock function Get-SQLPSInstance' { - Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + It 'Should return that desired state is present when wanted desired state is to be Absent' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $false + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server + $mockObjectSmoServer.Name = "$nodeName\$instanceName" + $mockObjectSmoServer.DisplayName = $instanceName + $mockObjectSmoServer.InstanceName = $instanceName + $mockObjectSmoServer.IsHadrEnabled = $False + $mockObjectSmoServer.MockGranteeName = $principal + + return $mockObjectSmoServer + } -ModuleName $script:DSCResourceName -Verifiable + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + $result = Test-TargetResource @testParameters + $result | Should Be $true + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It } } @@ -184,51 +239,105 @@ try Describe "$($script:DSCResourceName)\Set-TargetResource" { Context 'When the system is not in the desired state' { - BeforeAll { - Mock -CommandName Get-SQLPSInstance -MockWith { - $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList @( $false ) + It 'Should not throw error when desired state is to be Present' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $false + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server $mockObjectSmoServer.Name = "$nodeName\$instanceName" $mockObjectSmoServer.DisplayName = $instanceName $mockObjectSmoServer.InstanceName = $instanceName $mockObjectSmoServer.IsHadrEnabled = $False - $mockObjectSmoServer.MockGranteeName = $principal + $mockObjectSmoServer.MockGranteeName = $principal return $mockObjectSmoServer } -ModuleName $script:DSCResourceName -Verifiable - } + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + } - It 'Should not throw an error' { { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope It } - It 'Should call the mock function Get-SQLPSInstance twice' { - Assert-MockCalled Get-SQLPSInstance -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope Context + It 'Should not throw error when desired state is to be Absent' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $true + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server + $mockObjectSmoServer.Name = "$nodeName\$instanceName" + $mockObjectSmoServer.DisplayName = $instanceName + $mockObjectSmoServer.InstanceName = $instanceName + $mockObjectSmoServer.IsHadrEnabled = $False + $mockObjectSmoServer.MockGranteeName = $principal + + return $mockObjectSmoServer + } -ModuleName $script:DSCResourceName -Verifiable + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 2 -ModuleName $script:DSCResourceName -Scope It } } Context 'When the system is in the desired state' { - BeforeAll { - Mock -CommandName Get-SQLPSInstance -MockWith { - $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList @( $true ) + It 'Should not throw error when desired state is to be Present' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $true + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server $mockObjectSmoServer.Name = "$nodeName\$instanceName" $mockObjectSmoServer.DisplayName = $instanceName $mockObjectSmoServer.InstanceName = $instanceName $mockObjectSmoServer.IsHadrEnabled = $False - $mockObjectSmoServer.MockGranteeName = $principal + $mockObjectSmoServer.MockGranteeName = 'Should not call Grant() or Revoke()' return $mockObjectSmoServer } -ModuleName $script:DSCResourceName -Verifiable - } + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Present' + } - It 'Should not throw an error' { { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It } - It 'Should call the mock function Get-SQLPSInstance' { - Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope Context + It 'Should not throw error when desired state is to be Absent' { + Mock -CommandName Get-SQLPSInstance -MockWith { + [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $false + + $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server + $mockObjectSmoServer.Name = "$nodeName\$instanceName" + $mockObjectSmoServer.DisplayName = $instanceName + $mockObjectSmoServer.InstanceName = $instanceName + $mockObjectSmoServer.IsHadrEnabled = $False + $mockObjectSmoServer.MockGranteeName = 'Should not call Grant() or Revoke()' + + return $mockObjectSmoServer + } -ModuleName $script:DSCResourceName -Verifiable + + $testParameters = $defaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should Not Throw + + Assert-MockCalled Get-SQLPSInstance -Exactly -Times 1 -ModuleName $script:DSCResourceName -Scope It } } - +#> Assert-VerifiableMocks } } @@ -239,6 +348,4 @@ finally Restore-TestEnvironment -TestEnvironment $TestEnvironment #endregion - - Remove-module $script:DSCResourceName -Force } diff --git a/en-US/xSQLServer.strings.psd1 b/en-US/xSQLServer.strings.psd1 index 52c9dfa1a..d099cd261 100644 --- a/en-US/xSQLServer.strings.psd1 +++ b/en-US/xSQLServer.strings.psd1 @@ -21,6 +21,7 @@ FeatureNotSupported = '{0}' is not a valid value for setting 'FEATURES'. Refer AvailabilityGroupListenerNotFound = Trying to make a change to a listener that does not exist. AvailabilityGroupListenerErrorVerifyExist = Unexpected result when trying to verify existence of listener {0}. AvailabilityGroupListenerIPChangeError = IP-address configuration mismatch. Expecting {0} found {1}. Resource does not support changing IP-address. Listener needs to be removed and then created again. +AvailabilityGroupListenerDHCPChangeError = IP-address configuration mismatch. Expecting {0} found {1}. Resource does not support changing between static IP and DHCP. Listener needs to be removed and then created again. # Endpoint EndpointNotFound = Endpoint {0} does not exist