Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1
T
2016-08-02 12:05:24 -07:00

62 lines
3.0 KiB
PowerShell

Describe "XML cmdlets" -Tags 'P1', 'RI' {
Context "Select-XML" {
BeforeAll {
$fileName = New-Item -Path 'TestDrive:\testSelectXml.xml'
Push-Location "$fileName\.."
"<Root>" | out-file -LiteralPath $fileName
" <Node Attribute='blah' />" | out-file -LiteralPath $fileName -Append
"</Root>" | out-file -LiteralPath $fileName -Append
$fileNameWithDots = $fileName.FullName.Replace("\", "\.\")
$driveLetter = [string]($fileName.FullName)[0]
$fileNameAsNetworkPath = "\\localhost\$driveLetter`$" + $fileName.FullName.SubString(2)
class TestData
{
[string] $testName
[hashtable] $parameters
TestData($name, $parameters)
{
$this.testName = $name
$this.parameters = $parameters
}
}
$testcases = @()
$testcases += [TestData]::new('literalpath with relative paths', @{LiteralPath = $fileName.Name; XPath = 'Root'})
$testcases += [TestData]::new('literalpath with absolute paths', @{LiteralPath = $fileName.FullName; XPath = 'Root'})
$testcases += [TestData]::new('literalpath with path with dots', @{LiteralPath = $fileNameWithDots; XPath = 'Root'})
$testcases += [TestData]::new('literalpath with network path', @{LiteralPath = $fileNameAsNetworkPath; XPath = 'Root'})
$testcases += [TestData]::new('path with relative paths', @{Path = $fileName.Name; XPath = 'Root'})
$testcases += [TestData]::new('path with absolute paths', @{Path = $fileName.FullName; XPath = 'Root'})
$testcases += [TestData]::new('path with path with dots', @{Path = $fileNameWithDots; XPath = 'Root'})
$testcases += [TestData]::new('path with network path', @{Path = $fileNameAsNetworkPath; XPath = 'Root'})
}
AfterAll {
Remove-Item -LiteralPath $fileName -Force -ErrorAction SilentlyContinue
Pop-Location
}
$testcases | % {
$params = $_.parameters
It $_.testName {
@(Select-XML @params).Count | Should Be 1
}
}
It "literalpath with non filesystem path" {
Select-XML -literalPath cert:\currentuser\my "Root" -ErrorVariable selectXmlError -ErrorAction SilentlyContinue
$selectXmlError.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand'
}
It "path with non filesystem path" {
Select-XML -Path cert:\currentuser\my "Root" -ErrorVariable selectXmlError -ErrorAction SilentlyContinue
$selectXmlError.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand'
}
}
}