This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Assert-ValueObjectAreAlike ($ReferenceObject, $DifferenceObject, $ExcludeProperty) | |
| { | |
| [string[]] $properties = ($ReferenceObject.psObject.Properties.Name + $DifferenceObject.psObject.Properties.Name ) | | |
| sort -Unique | | |
| where { $_ -notlike $ExcludeProperty } | |
| -not ( Compare-Object -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject -Property $properties ) | |
| } | |
| #usual use case |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function DoSomething | |
| { | |
| Write-Warning "problem with the server certificate" | |
| } | |
| Describe 'Test warning' { | |
| Mock Write-Warning { $Message } | |
| It 'Writes warning' { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe "DS"{ | |
| it "skipped" {} -skip | |
| it "pending" {} -Pending | |
| It "throw" { throw "sdfad" } | |
| It "assertion fail" {1 | should be 10 } | |
| It "string assertion fail" {"asdf" | should be "ffsad" } | |
| it "success" {"adsf"} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Add-MongoToPath () { | |
| $mongoPath = "C:\Program Files\MongoDB\Server\3.2\bin" | |
| if ($env:Path -notlike "*$mongoPath*") | |
| { | |
| $env:path += ";$mongoPath" | |
| } | |
| } | |
| function Start-ServerInstace ([string]$ComputerName = "localhost", [int]$Port, [string]$ReplicationSet = "rs0", [string]$DatabasePath) { | |
| $process = Start-Process Powershell.exe -PassThru -ArgumentList "-NoProfile", "-Command "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function SomeFunction ([ScriptBlock] $ScriptBlock) | |
| { | |
| Describe "Why?" { | |
| $result = &$ScriptBlock | |
| $result|Should Be 10 | |
| } | |
| } | |
| SomeFunction { 9 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add-type -TypeDefinition @" | |
| using System; | |
| public static class KeyboardEventTestUtil { | |
| public static string keybd_event(byte bVk, byte bScan, UInt32 dwFlags, System.UIntPtr dwExtraInfo) { | |
| return string.Format("{0}:{1}:{2}:{3}", bVk,bScan,dwFlags,dwExtraInfo); | |
| } | |
| } | |
| "@ | |
| describe "t" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function EnsureServiceStarted { | |
| param($Name) | |
| Start-Service -name $name | |
| $service = Get-Service -Name $name | |
| $service.Status -eq [ServiceProcess.ServiceControllerStatus]::Running | |
| } | |
| Describe "Ensure service is started" { | |
| It "Started service returns true" { | |
| mock start-service {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Test-UserName ($Name) | |
| { | |
| $Name -match "^[a-z]+$" | |
| } | |
| Test-UserName $null | |
| Test-UserName "" | |
| Test-UserName "_abc" | |
| Test-UserName "abc1" | |
| Test-UserName "abc " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $r = "c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk\VMware.VimAutomation.Sdk.Types.dll", | |
| "c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core\VMware.VimAutomation.ViCore.Types.dll" | |
| Add-Type -ReferencedAssemblies $r -typeDefinition " | |
| using VMware.VimAutomation.ViCore.Types.V1; | |
| using VMware.VimAutomation.ViCore.Types.V1.Tagging; | |
| namespace Mocks | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Should-Be { | |
| param($Expected,[Parameter(ValueFromPipeline)]$Actual) | |
| "We are comparing if two values are equal so" | |
| "when `$Expected is $($Expected.GetType()) with value '$Expected'" | |
| if ($null -eq $Actual) | |
| { | |
| "and `$Actual is `$null then the result is:" | |
| } | |
| else |
OlderNewer