Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function CompareCounterSets
$setB
)

$setA.Length | Should Be $setB.Length
$setA.Length | Should -Be $setB.Length

# Depending on the kinds of counters used, the first record in
# exported counters are likely to have embty items, so we'll
Expand All @@ -272,17 +272,17 @@ function CompareCounterSets
# PDH functions that perform the actual exporting of counter data.
for ($i = 1; $i -lt $setA.Length; $i++)
{
$setA[$i].CounterSamples.Length | Should Be $setB[$i].CounterSamples.Length
$setA[$i].CounterSamples.Length | Should -Be $setB[$i].CounterSamples.Length
$samplesA = ($setA[$i].CounterSamples | sort -Property Path)
$samplesB = ($setB[$i].CounterSamples | sort -Property Path)
(DateTimesAreEqualish $setA[$i].TimeStamp $setB[$i].TimeStamp) | Should Be $true
(DateTimesAreEqualish $setA[$i].TimeStamp $setB[$i].TimeStamp) | Should -BeTrue
for ($j = 0; $j -lt $samplesA.Length; $j++)
{
$sampleA = $samplesA[$j]
$sampleB = $samplesB[$j]
(DateTimesAreEqualish $sampleA.TimeStamp $sampleB.TimeStamp) | Should Be $true
$sampleA.Path | Should Be $sampleB.Path
$sampleA.CookedValue | Should Be $sampleB.CookedValue
(DateTimesAreEqualish $sampleA.TimeStamp $sampleB.TimeStamp) | Should -BeTrue
$sampleA.Path | Should -BeExactly $sampleB.Path
$sampleA.CookedValue | Should -Be $sampleB.CookedValue
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $counterValues = $null
# counters and comparing the two sets
function CheckExportResults
{
Test-Path $filePath | Should Be $true
Test-Path $filePath | Should -BeTrue
$importedCounterValues = Import-Counter $filePath

CompareCounterSets $counterValues $importedCounterValues
Expand Down Expand Up @@ -98,16 +98,8 @@ function RunTest($testCase)
else
{
# Here we expect and want the command to fail
try
{
$sb = [ScriptBlock]::Create($cmd)
&$sb
throw "Did not throw expected exception"
}
catch
{
$_.FullyQualifiedErrorId | Should Be $testCase.ExpectedErrorId
}
$sb = [ScriptBlock]::Create($cmd)
{ &$sb } | Should -Throw -ErrorId $testCase.ExpectedErrorId
}
}
finally
Expand Down Expand Up @@ -202,7 +194,7 @@ Describe "Feature tests for Export-Counter cmdlet" -Tags "Feature" {
@{
Name = "Can force overwriting existing file"
Parameters = "-Force"
Script = { Test-Path $filePath | Should Be $true }
Script = { Test-Path $filePath | Should -BeTrue }
}
@{
Name = "Can export BLG format"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@ function ValidateParameters($testCase)
# Use $cmd to debug a test failure
# Write-Host "Command to run: $cmd"

try
{
$sb = [scriptblock]::Create($cmd)
&$sb
throw "Did not throw expected exception"
}
catch
{
$_.FullyQualifiedErrorId | Should Be $testCase.ExpectedErrorId
}
$sb = [scriptblock]::Create($cmd)
{ &$sb } | Should -Throw -ErrorId $testCase.ExpectedErrorId
}
}

Expand All @@ -55,15 +47,15 @@ Describe "CI Tests for Get-Counter cmdlet" -Tags "CI" {
It "Get-Counter with no parameters returns data for a default set of counters" -Skip:$(SkipCounterTests) {
$counterData = Get-Counter
# At the very least we should get processor and memory
$counterData.CounterSamples.Length | should BeGreaterThan 1
$counterData.CounterSamples.Length | Should -BeGreaterThan 1
}

It "Can retrieve the specified counter" -Skip:$(SkipCounterTests) {
$counterPath = $counterPaths.MemoryBytes
$counterData = Get-Counter -Counter $counterPath
$counterData.Length | Should Be 1
$counterData.Length | Should -Be 1
$retrievedPath = RemoveMachineName $counterData[0].CounterSamples[0].Path
[string]::Compare($retrievedPath, $counterPath, $true) | Should Be 0
[string]::Compare($retrievedPath, $counterPath, $true) | Should -Be 0
}
}

Expand Down Expand Up @@ -178,7 +170,7 @@ Describe "Feature tests for Get-Counter cmdlet" -Tags "Feature" {
$counterPath = $counterPaths.MemoryBytes
$counterCount = 5
$counterData = Get-Counter -Counter $counterPath -MaxSamples $counterCount
$counterData.Length | Should Be $counterCount
$counterData.Length | Should -Be $counterCount
}

It "Can specify the sample interval" -Skip:$(SkipCounterTests) {
Expand All @@ -188,32 +180,32 @@ Describe "Feature tests for Get-Counter cmdlet" -Tags "Feature" {
$startTime = Get-Date
$counterData = Get-Counter -Counter $counterPath -SampleInterval $sampleInterval -MaxSamples $counterCount
$endTime = Get-Date
$counterData.Length | Should Be $counterCount
($endTime - $startTime).TotalSeconds | Should Not BeLessThan ($counterCount * $sampleInterval)
$counterData.Length | Should -Be $counterCount
($endTime - $startTime).TotalSeconds | Should -Not -BeLessThan ($counterCount * $sampleInterval)
}

It "Can process array of counter names" -Skip:$(SkipCounterTests) {
$counterPaths = @((TranslateCounterPath "\PhysicalDisk(_Total)\Disk Read Bytes/sec"),
(TranslateCounterPath "\Memory\Available bytes"))
$counterData = Get-Counter -Counter $counterPaths
$counterData.CounterSamples.Length | Should Be $counterPaths.Length
$counterData.CounterSamples.Length | Should -Be $counterPaths.Length
}
}

Context "Get-Counter ListSet tests" {
It "Can retrieve specified counter set" -Skip:$(SkipCounterTests) {
$counterSetName = "Memory"
$counterSet = Get-Counter -ListSet $counterSetName
$counterSet.Length | Should Be 1
$counterSet.CounterSetName | Should Be $counterSetName
$counterSet.Length | Should -Be 1
$counterSet.CounterSetName | Should -BeExactly $counterSetName
}

It "Can process an array of counter set names" -Skip:$(SkipCounterTests) {
$counterSetNames = @("Memory", "Processor")
$counterSets = Get-Counter -ListSet $counterSetNames
$counterSets.Length | Should Be 2
$counterSets[0].CounterSetName | Should Be $counterSetNames[0]
$counterSets[1].CounterSetName | Should Be $counterSetNames[1]
$counterSets.Length | Should -Be 2
$counterSets[0].CounterSetName | Should -BeExactly $counterSetNames[0]
$counterSets[1].CounterSetName | Should -BeExactly $counterSetNames[1]
}

# This test will be skipped for non-English languages, since
Expand All @@ -224,10 +216,10 @@ Describe "Feature tests for Get-Counter cmdlet" -Tags "Feature" {
$wildcardBase = "roc"
$counterSetName = "*$wildcardBase*"
$counterSets = Get-Counter -ListSet $counterSetName
$counterSets.Length | Should BeGreaterThan 1 # should get at least "Processor" and "Process"
$counterSets.Length | Should -BeGreaterThan 1 # should get at least "Processor" and "Process"
foreach ($counterSet in $counterSets)
{
$counterSet.CounterSetName.ToLower().Contains($wildcardBase.ToLower()) | Should Be $true
$counterSet.CounterSetName.ToLower().Contains($wildcardBase.ToLower()) | Should -BeTrue
}
}

Expand All @@ -239,28 +231,19 @@ Describe "Feature tests for Get-Counter cmdlet" -Tags "Feature" {
$wildcardBases = @("Memory", "roc")
$counterSetNames = @($wildcardBases[0], ("*" + $wildcardBases[1] + "*"))
$counterSets = Get-Counter -ListSet $counterSetNames
$counterSets.Length | Should BeGreaterThan 2 # should get at least "Memory", "Processor" and "Process"
$counterSets.Length | Should -BeGreaterThan 2 # should get at least "Memory", "Processor" and "Process"
foreach ($counterSet in $counterSets)
{
($counterSet.CounterSetName.ToLower().Contains($wildcardBases[0].ToLower()) -Or
$counterSet.CounterSetName.ToLower().Contains($wildcardBases[1].ToLower())) | Should Be $true
$counterSet.CounterSetName.ToLower().Contains($wildcardBases[1].ToLower())) | Should -BeTrue
}
}
}
}

Describe "Get-Counter cmdlet does not run on IoT" -Tags "CI" {

It "Get-Counter throws PlatformNotSupportedException" -Skip:$(-not [System.Management.Automation.Platform]::IsIoT) {

try
{
Get-Counter
throw "'Get-Counter' on IoT is expected to throw a PlatformNotSupportedException, and it did not."
}
catch
{
$_.FullyQualifiedErrorId | should be "System.PlatformNotSupportedException,Microsoft.PowerShell.Commands.GetCounterCommand"
}
It "Get-Counter throws PlatformNotSupportedException" -Skip:$(-Not [System.Management.Automation.Platform]::IsIoT) {
{ Get-Counter } | Should -Throw -ErrorId "System.PlatformNotSupportedException,Microsoft.PowerShell.Commands.GetCounterCommand"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Describe 'Get-WinEvent' -Tags "CI" {
Context "Get-WinEvent ListProvider parameter" {
It 'Get-WinEvent can list the providers' {
$result = Get-WinEvent -listprovider * -erroraction ignore
$result | should not BeNullOrEmpty
$result | Should -Not -BeNullOrEmpty
}
It 'Get-WinEvent can get a provider by name' {
$providers = Get-WinEvent -listprovider * -erroraction ignore
$result = Get-WinEvent -listprovider ($providers[0].name)
$result | should not BeNullOrEmpty
$result | Should -Not -BeNullOrEmpty
}

}
Expand All @@ -44,36 +44,36 @@ Describe 'Get-WinEvent' -Tags "CI" {
# we sample the first 20 results, as this could be very large
$results = Get-WinEvent -provider $providerForTests.Name -max 20
foreach($event in $results ) {
$event.providername | should be $providerForTests.name
$event.providername | Should -BeExactly $providerForTests.name
}
}
It 'Get-WinEvent can get events via logname' {
$results = get-winevent -logname $providerForTests.LogLinks.LogName -MaxEvents 10
$results | should not BeNullOrEmpty
$results | Should -Not -BeNullOrEmpty
}
It 'Get-WinEvent can use the simplest of filters' {
$filter = @{ ProviderName = $providerForTests.Name }
$testEvents = Get-WinEvent -filterhashtable $filter
$testEvents.Count | should be $events.Count
$testEvents.Count | Should -Be $events.Count
}
It 'Get-WinEvent can use a filter which includes two items' {
$filter = @{ ProviderName = $providerForTests.Name; Id = $events[0].Id}
$results = Get-WinEvent -filterHashtable $filter
$results | Should not BeNullOrEmpty
$results | Should -Not -BeNullOrEmpty
}
It 'Get-WinEvent can retrieve event via XmlQuery' {
$level = $events[0].Level
$logname = $providerForTests.loglinks.logname
$filter = "<QueryList><Query><Select Path='${logname}'>*[System[Level=${level}]]</Select></Query></QueryList>"
$results = Get-WinEvent -filterXml $filter -max 3
$results | should Not BeNullOrEmpty
$results | Should -Not -BeNullOrEmpty
}
It 'Get-WinEvent can retrieve event via XPath' {
$level = $events[0].Level
$logname = $providerForTests.loglinks.logname
$xpathFilter = "*[System[Level=$level]]"
$results = Get-WinEvent -logname $logname -filterXPath $xpathFilter -max 3
$results | should Not BeNullOrEmpty
$results | Should -Not -BeNullOrEmpty
}

}
Expand All @@ -84,46 +84,46 @@ Describe 'Get-WinEvent' -Tags "CI" {
$eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx")
$filter = "<QueryList><Query><Select Path='file://$eventLogFile'>*[UserData/*/Param2='Windows x64']</Select></Query></QueryList>"
$results = Get-WinEvent -FilterXml $filter -ea silentlycontinue
@($results).Count | Should be 1
$results.RecordId | should be 10
@($results).Count | Should -Be 1
$results.RecordId | Should -Be 10
}
It 'Get-WinEvent can retrieve events with UserData queries using FilterHashtable (one value)' {
# this relies on apriori knowledge about the log file
# the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue
$eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx")
$filter = @{ path = "$eventLogFile"; Param2 = "Windows x64"}
$results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue
@($results).Count | Should be 1
$results.RecordId | should be 10
@($results).Count | Should -Be 1
$results.RecordId | Should -Be 10
}
It 'Get-WinEvent can retrieve events with UserData queries using FilterHashtable (array of values)' {
# this relies on apriori knowledge about the log file
# the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue
$eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx")
$filter = @{ path = "$eventLogFile"; DriverName = "Remote Desktop Easy Print", "Microsoft enhanced Point and Print compatibility driver" }
$results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue
@($results).Count | Should be 2
($results.RecordId -contains 9) | should be $true
($results.RecordId -contains 11) | should be $true
@($results).Count | Should -Be 2
($results.RecordId -contains 9) | Should -BeTrue
($results.RecordId -contains 11) | Should -BeTrue
}
It 'Get-WinEvent can retrieve events with UserData queries using FilterHashtable (multiple named params)' {
# this relies on apriori knowledge about the log file
# the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue
$eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx")
$filter = @{ path = "$eventLogFile"; PackageAware="Not package aware"; DriverName = "Remote Desktop Easy Print", "Microsoft enhanced Point and Print compatibility driver" }
$results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue
@($results).Count | Should be 2
($results.RecordId -contains 9) | should be $true
($results.RecordId -contains 11) | should be $true
@($results).Count | Should -Be 2
($results.RecordId -contains 9) | Should -BeTrue
($results.RecordId -contains 11) | Should -BeTrue
}
It 'Get-WinEvent can retrieve events with UserData queries using FilterXPath' {
# this relies on apriori knowledge about the log file
# the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue
$eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx")
$filter = "*/UserData/*/Param2='Windows x64'"
$results = Get-WinEvent -path $eventLogFile -filterXPath $filter -ea silentlycontinue
@($results).Count | Should be 1
$results.RecordId | should be 10
@($results).Count | Should -Be 1
$results.RecordId | Should -Be 10
}
}
Context "Get-WinEvent Queries with SuppressHashFilter" {
Expand All @@ -135,8 +135,8 @@ Describe 'Get-WinEvent' -Tags "CI" {
$results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue
$filterSuppress = @{ path = "$eventLogFile"; SuppressHashFilter=@{Id=370}}
$resultsSuppress = Get-WinEvent -filterHashtable $filterSuppress -ea silentlycontinue
@($results).Count | Should be 3
@($resultsSuppress).Count | Should be 2
@($results).Count | Should -Be 3
@($resultsSuppress).Count | Should -Be 2
}
It 'Get-WinEvent can suppress events by UserData' {
# this relies on apriori knowledge about the log file
Expand All @@ -146,11 +146,11 @@ Describe 'Get-WinEvent' -Tags "CI" {
$results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue
$filterSuppress = @{ path = "$eventLogFile"; SuppressHashFilter=@{Param2 = "Windows x64"}}
$resultsSuppress = Get-WinEvent -filterHashtable $filterSuppress -ea silentlycontinue
@($results).Count | Should be 3
@($resultsSuppress).Count | Should be 2
@($results).Count | Should -Be 3
@($resultsSuppress).Count | Should -Be 2
}
}
It 'can query a System log' {
Get-WinEvent -LogName System -MaxEvents 1 | Should Not BeNullOrEmpty
Get-WinEvent -LogName System -MaxEvents 1 | Should -Not -BeNullOrEmpty
}
}
Loading