function BeAwesome($ActualValue, [switch] $Negate)
{
[bool] $succeeded = $ActualValue -eq 'Awesome'
if ($Negate) { $succeeded = -not $succeeded }
if (-not $succeeded)
{
if ($Negate)
{
$failureMessage = "{$ActualValue} is Awesome"
}
else
{
$failureMessage = "{$ActualValue} is not Awesome"
}
}
return New-Object psobject -Property @{
Succeeded = $succeeded
FailureMessage = $failureMessage
}
}
Add-ShouldOperator -Name BeAwesome `
-Test $function:BeAwesome `
-Alias 'BA'
PS C:\> "bad" | should -BeAwesome
{bad} is not Awesome
Describe "Validate important file" {
BeforeAll {
$samplePath = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid()).txt"
Write-Host $samplePath
1..100 | Set-Content -Path $samplePath
}
It "File Contains 100 lines" {
@(Get-Content $samplePath).Count | Should -Be 100
}
It "First ten lines should be 1 -\> 10" {
@(Get-Content $samplePath -TotalCount 10) | Should -Be @(1..10)
}
AfterAll {
Remove-Item -Path $samplePath
}
}
Describe "Testing export formats" {
BeforeAll {
$filePath = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid())"
}
It "Test Export-CSV" {
Get-ChildItem | Export-CSV -Path $filePath -NoTypeInformation
$dir = Import-CSV -Path $filePath
# ...
}
It "Test Export-Clixml" {
Get-ChildItem | Export-Clixml -Path $filePath
$dir = Import-Clixml -Path $filePath
# ...
}
AfterEach {
if (Test-Path $file) {
Remove-Item $file -Force
}
}
}
Fix pseudo code: add 4-char white-space to the first matching line without indentation (except for the first and last line)