Skip to content

Instantly share code, notes, and snippets.

View PlagueHO's full-sized avatar
😼
Working on Game Master Copilot using Semantic Kernel, Azure OpenAI and Blazor 8

Daniel Scott-Raynsford PlagueHO

😼
Working on Game Master Copilot using Semantic Kernel, Azure OpenAI and Blazor 8
View GitHub Profile
@PlagueHO
PlagueHO / Example_DSCUnitTestsForGet-VirtualDisk.ps1
Created December 23, 2015 05:49
Example DSC Unit Tests for Get-VirtualDisk function
Describe "$($Global:DSCResourceName)\Get-VirtualDisk" {
Context 'Virtual Disk does not exist' {
Mock Get-iSCSIVirtualDisk
It 'should return null' {
$Splat = $TestVirtualDisk.Clone()
$Result = Get-VirtualDisk -Path $Splat.Path
$Result | Should Be $null
@PlagueHO
PlagueHO / Example_DSCUnitTest-Exception.ps1
Created December 23, 2015 06:03
Example DSC Unit Test an exception
Context 'Virtual Disk exists and should but has a different ParentPath' {
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) }
It 'should throw an exception' {
{ Test-TargetResource @Splat } | Should Throw
}
It 'should call expected Mocks' {
Assert-MockCalled -commandName Get-iSCSIVirtualDisk -Exactly 1
}
@PlagueHO
PlagueHO / Example_DSCCustomException.ps1
Created December 23, 2015 07:14
Example DSC Custom Exception
$errorId = 'iSCSIVirtualDiskRequiresRecreateError'
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument
$errorMessage = $($LocalizedData.iSCSIVirtualDiskRequiresRecreateError) -f $Path
$exception = New-Object -TypeName System.InvalidOperationException `
-ArgumentList $errorMessage
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
-ArgumentList $exception, $errorId, $errorCategory, $null
$PSCmdlet.ThrowTerminatingError($errorRecord)
@PlagueHO
PlagueHO / Example_DSCTestForCustomException.ps1
Created December 23, 2015 07:29
Example DSC Test for Custom Exception
Context 'Virtual Disk exists and should but has a different ParentPath' {
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) }
It 'should throw an iSCSIVirtualDiskRequiresRecreateError exception' {
$Splat = $TestVirtualDisk.Clone()
$Splat.ParentPath = 'c:\NewParent.vhdx'
$errorId = 'iSCSIVirtualDiskRequiresRecreateError'
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument
@PlagueHO
PlagueHO / Blog_ISCSIRemoveTargetPortal1.ps1
Created December 26, 2015 22:17
Example: Remove ISCSI Target Portal using TargetPortalAddress
Remove-IscsiTargetPortal -TargetPortalAddress 192.168.129.24
@PlagueHO
PlagueHO / Blog_ISCSIRemoveTargetPortalCorrect.ps1
Created December 26, 2015 22:23
Example: Correctly remove an iSCSI Target Portal
Remove-IscsiTargetPortal -TargetPortalAddress 192.168.129.24 -InitiatorPortalAddress 192.168.129.30
@PlagueHO
PlagueHO / Example_CreateNewIntegrationTestFromTemplate.ps1
Last active January 24, 2016 23:23
Create a new Integration Test from the DSC Resource integration test template
git clone https://github.com/PowerShell/DSCResources.git
Copy-Item .\DSCResources\Tests.Template\integration_config_template.ps1 .\ciSCSI\Tests\Integration\BMD_ciSCSIVirtualDisk.config.ps1
Copy-Item .\DSCResources\Tests.Template\integration_template.ps1 .\ciSCSI\Tests\Integration\BMD_ciSCSIVirtualDisk.Integration.Tests.ps1
@PlagueHO
PlagueHO / Example_DSCIntegrationTestsConfigStep1.ps1
Created January 25, 2016 00:05
Example DSC Resource Integration Tests Config Step 1
configuration 'BMD_ciSCSIVirtualDisk_config' {
Import-DscResource -Name 'BMD_ciSCSIVirtualDisk'
node localhost {
BMD_ciSCSIVirtualDisk Integration_Test {
# TODO: Fill Configuration Code Here
}
}
}
@PlagueHO
PlagueHO / Example_DSCIntegrationTestsConfigStep2.ps1
Created January 25, 2016 00:12
Example DSC Resource Integration Tests Config Step 2
$VirtualDisk = @{
Path = Join-Path -Path $ENV:Temp -ChildPath 'TestiSCSIVirtualDisk.vhdx'
Ensure = 'Present'
DiskType = 'Dynamic'
Size = 100MB
Description = 'Integration Test iSCSI Virtual Disk'
}
Configuration BMD_ciSCSIVirtualDisk_Config {
Import-DscResource -Name BMD_ciSCSIVirtualDisk_Config
@PlagueHO
PlagueHO / Example_DSCIntegrationTestsStep1.ps1
Last active January 25, 2016 00:30
Example DSC Resource Integration Tests Step 1
# Ensure that the tests can be performed on this computer
$ProductType = (Get-CimInstance Win32_OperatingSystem).ProductType
Describe 'Environment' {
Context 'Operating System' {
It 'Should be a Server OS' {
$ProductType | Should Be 3
}
}
}
if ($ProductType -ne 3)