PROCESS{
$Session = New-PSSession -ComputerName $ComputerName -Credential $Credential
Invoke-Command -Session $Session -ScriptBlock {Import-Module WebAdministration}
if(!($PSBoundParameters.ContainsKey('Name'))){$Name = Invoke-Command -Session $Session -ScriptBlock $GetAllAppPools}
Invoke-Command -Session $Session -ScriptBlock $GetAppPoolMetaData
}
Describe 'Get-IISAppPool' {
$secpasswd = ConvertTo-SecureString 'PlainTextPassword' -AsPlainText -Force
$Cred = New-Object -TypeName PSCredential('username',$secpasswd)
Mock -CommandName New-PSSession -ModuleName IIS -MockWith {
return $true
}
Mock -CommandName Invoke-Command -ModuleName IIS -MockWith {
return $true
}
Context 'Remote AppPool' {
Get-IISAppPool -ComputerName 'Server0001' -Name 'TestAppPool' -Credential $Cred
It 'Should call New-PSSession 1 time'{
Assert-MockCalled -Exactly 1
}
}
}
[System.Runtime.Serialization.FormatterServices]::GetUninitializedObject([System.Management.Automation.Runspaces.PSSession]);
-Create instance of sealed class without getting constructor called.
System.Runtime.Serialization.FormatterServices.GetUninitializedObject(instanceType);
-Assign values to your properties / fields via reflection
YourObject.GetType().GetProperty("PropertyName").SetValue(dto, newValue, null);
YourObject.GetType().GetField("FieldName").SetValue(dto, newValue);