46 lines
1.4 KiB
PowerShell
46 lines
1.4 KiB
PowerShell
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
|
Write-Host "Overriding SUT: $functionPath"
|
|
Import-Module $functionPath -Force
|
|
$moduleForMock = ""
|
|
|
|
#region Set-XmlNodeValue
|
|
|
|
Describe Set-XmlNodeValue {
|
|
|
|
[xml]$fakeXml = @"
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<configuration>
|
|
<appSettings>
|
|
<add key="TestNode1" value="TestValue1" />
|
|
<add key="TestNode2" value="TestValue2" />
|
|
</appSettings>
|
|
</configuration>
|
|
"@
|
|
|
|
It "Updates a Node When Valid XPath is Provided" {
|
|
|
|
Set-XmlNodeValue $fakeXml "//appSettings/add[@key='TestNode1']" -AttributeName "value" -AttributeValue "Updated"
|
|
$fakeXml.SelectSingleNode("//appSettings/add[@key='TestNode1']").Value -eq "Updated" | Should Be $true
|
|
}
|
|
|
|
It "Writes a Warning When the Node Doesn't Exist" {
|
|
|
|
{
|
|
( Set-XmlNodeValue $fakeXml "//appSettings/add[@key='IDontExist']" -AttributeName "value" -AttributeValue "Updated" 3>&1 ) -match
|
|
"Could not find node"
|
|
} | Should Be $true
|
|
}
|
|
|
|
It "Makes No Update Unless Needed" {
|
|
|
|
{
|
|
( Set-XmlNodeValue $fakeXml "//appSettings/add[@key='TestNode2']" -AttributeName "value" -AttributeValue "TestValue2" ) -match
|
|
"Node already has correct value 'TestValue2'"
|
|
} | Should Be $true
|
|
}
|
|
}
|
|
|
|
#endregion Set-XmlNodeValue |