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
# This example shows three versions of behavior, in the first the data binding only | |
# picks up the property that is defined on the type, in the second it picks up ever | |
# powershell adapted property Name (alias property), and in the third it picks up | |
# all properties even though they are all powershell properties and not on the PSObjectType | |
# is there some special handling for PSObject regarding WPF in Windows PowerShell? | |
Add-Type -AssemblyName PresentationFramework | |
[string]$xaml = @" |
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
# GOOD: | |
# shares data among tests without polluting | |
# the script scope | |
Describe "I share data" { | |
$container = @{ Value = 1 } | |
It "I give data" { | |
$container.Value = 5 | |
} |
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 Import-Script { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[String] $Path, | |
[Hashtable] $Parameters = @{}, | |
[Object[]] $Arguments = @(), | |
[String] $EntryPoint = 'Main' | |
) |
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 Get-Banner { | |
param ( | |
[Parameter(Mandatory)] | |
[String] $Text | |
) | |
if (-not $fonts) { | |
$fonts = (Invoke-RestMethod -Method GET -Uri 'http://artii.herokuapp.com/fonts_list') -split "`n" | |
} | |
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 getOrUpdateValue { | |
[CmdletBinding()] | |
param( | |
$Hashtable, | |
$Key, | |
$DefaultValue | |
) | |
if ($Hashtable.ContainsKey($Key)) { | |
# do not enumerate so we get the same thing back |
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 a () { } | |
describe "b" { mock a {} | |
context "b" { | |
describe "a" { | |
a | |
context "b" { | |
a | |
it "c" { |
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
get-module m,n,p | remove-module | |
# some tested code | |
New-Module m -ScriptBlock { | |
New-Module n -ScriptBlock { | |
function a { Write-Error "error abcd" } | |
} | Import-Module | |
function b { |
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 "path trimmer" { | |
it "does correct stuff" -TestCases @( | |
@{ Actual = "c:\"; Expected = "c:\" } | |
@{ Actual = "c:\abc"; Expected = "c:\abc" } | |
@{ Actual = "c:\abc\"; Expected = "c:\abc" } | |
@{ Actual = "\\abc\def"; Expected = "\\abc\def" } | |
@{ Actual = "\\abc\def\"; Expected = "\\abc\def" } | |
@{ Actual = "\\abc\def\gef\"; Expected = "\\abc\def\gef" } | |
@{ Actual = "\"; Expected = "\" } | |
) { |
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
$arr = 1..100 | |
$repe = 1..100 | |
Measure-Command { | |
foreach ($i in $repe) { | |
$l = New-Object 'System.Collections.Generic.List[Object]' | |
foreach ($ii in $arr) { | |
$l.Add($ii) | |
} | |
} | |
$l.count -eq $arr.count |
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
Get-Module Pester | Remove-Module | |
Import-Module ./Pester.psd1 | |
$sb = { | |
Add-Dependency { | |
Start-Sleep -Seconds 10 | |
} | |
Describe "integration test" { |