195 lines
6.6 KiB
PowerShell
195 lines
6.6 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-StaticConfigValues
|
||
|
|
||
|
Describe "Set-StaticConfigValues" {
|
||
|
|
||
|
# Temp file to write content to
|
||
|
$tempFile = [System.IO.Path]::GetTempFileName()
|
||
|
$tempPath = $tempFile.Split(".") | Select-Object -First 1
|
||
|
|
||
|
New-Item -ItemType Directory $tempPath -ErrorAction SilentlyContinue | Out-Null
|
||
|
|
||
|
$orbPath = ($tempPath + "\ORB")
|
||
|
$stagePath = ($tempPath + "\Stage")
|
||
|
|
||
|
if (!(Test-Path $orbPath))
|
||
|
{
|
||
|
New-Item -ItemType Directory $orbPath | Out-Null
|
||
|
}
|
||
|
|
||
|
if (!(Test-Path $stagePath))
|
||
|
{
|
||
|
New-Item -ItemType Directory $stagePath | Out-Null
|
||
|
}
|
||
|
|
||
|
Write-Warning ("Using temp path: $tempPath for tests")
|
||
|
|
||
|
# Make Directories and Files for Tests
|
||
|
$bankServiceDirectoryORB = New-Item -ItemType Directory ($orbPath + "\BankService")
|
||
|
$bankServiceDirectoryTemp = New-Item -ItemType Directory ($stagePath + "\BankService")
|
||
|
|
||
|
$bankFileNameORB = (Join-Path $bankServiceDirectoryORB "web.config")
|
||
|
$bankFileNameTemp = (Join-Path $bankServiceDirectoryTemp "new.web.config")
|
||
|
|
||
|
# This is a bogus config file that covers everything we want to modify
|
||
|
# Intentionally set with all the wrong values
|
||
|
$utfNoBOM = New-Object System.Text.UTF8Encoding($false)
|
||
|
$sampleBankContent = @"
|
||
|
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<configuration>
|
||
|
<!--
|
||
|
For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.
|
||
|
-->
|
||
|
<system.web>
|
||
|
<customErrors mode="Detailed" />
|
||
|
<compilation debug="true" targetFramework="4.5.2" />
|
||
|
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
|
||
|
<authentication mode="Forms">
|
||
|
<forms loginUrl="~/Authentication/Index" defaultUrl="~/Authentication/Authenticated" timeout="30" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" protection="Encryption" requireSSL="true" />
|
||
|
</authentication>
|
||
|
</system.web>
|
||
|
<system.net>
|
||
|
<connectionManagement>
|
||
|
<add address="*" maxconnection="2048" />
|
||
|
</connectionManagement>
|
||
|
</system.net>
|
||
|
<system.webServer>
|
||
|
<httpErrors existingResponse="PassThrough" errorMode="Detailed" />
|
||
|
<modules />
|
||
|
<defaultDocument>
|
||
|
<files>
|
||
|
<clear />
|
||
|
<add value="BankService.svc" />
|
||
|
<add value="BankManagementService.svc" />
|
||
|
<add value="ValidationService.svc" />
|
||
|
</files>
|
||
|
</defaultDocument>
|
||
|
</system.webServer>
|
||
|
<system.diagnostics>
|
||
|
<trace autoflush="true" />
|
||
|
<sources>
|
||
|
<source name="System.ServiceModel" propagateActivity="true" switchValue="Error">
|
||
|
<!-- Error,ActivityTracing -->
|
||
|
<listeners>
|
||
|
<add name="logListener" />
|
||
|
</listeners>
|
||
|
</source>
|
||
|
</sources>
|
||
|
</system.diagnostics>
|
||
|
<appSettings>
|
||
|
<add key="ShouldDisplayUncaughtExceptions" value="true" />
|
||
|
<add key="ForceUseOfProductionAssetsInDebug" value="false" />
|
||
|
<add key="FakeSetting" value="FakeValue" />
|
||
|
<add key="Broadcasters" value="fakeserver.fh.local,fakeserver2.corp.alkamitech.com" />
|
||
|
<add key="IsTransactionCachingEnabled" value="false" />
|
||
|
</appSettings>
|
||
|
<quartz>
|
||
|
<add key="quartz.scheduler.instanceName" value="FakeValue" />
|
||
|
</quartz>
|
||
|
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
|
||
|
<runtimePolicies/>
|
||
|
</glimpse>
|
||
|
</configuration>
|
||
|
"@
|
||
|
|
||
|
# Save our Bank File
|
||
|
Save-XMLFile $bankFileNameORB $sampleBankContent $utfNoBOM
|
||
|
|
||
|
# Save out Temp File and Modify App Settings for Testing Purposes
|
||
|
$sampleBankContent | Out-File $bankFileNameTemp -Force
|
||
|
[xml]$xml = GC $bankFileNameTemp
|
||
|
|
||
|
# Change some App Settings for Validation
|
||
|
Set-XmlNodeValue $xml "//appSettings/add[@key='FakeSetting']" "value" "WrongValue"
|
||
|
Set-XmlNodeValue $xml "//quartz/add[@key='quartz.scheduler.instanceName']" "value" "WrongValue"
|
||
|
|
||
|
# Remove the Broadcasters Node for Validation
|
||
|
$asNode = $xml.SelectSingleNode("//appSettings")
|
||
|
$bcNode = $xml.SelectSingleNode("//appSettings/add[@key='Broadcasters']")
|
||
|
$asNode.RemoveChild($bcNode)
|
||
|
|
||
|
$tcNode = $xml.SelectSingleNode("//appSettings/add[@key='IsTransactionCachingEnabled']")
|
||
|
$asNode.RemoveChild($tcNode)
|
||
|
|
||
|
# Save the File
|
||
|
Save-XMLFile $bankFileNameTemp $xml.OuterXml $utfNoBOM
|
||
|
$tempXml = GC $bankFileNameTemp
|
||
|
|
||
|
# Execute the Function and Read the Results as XML
|
||
|
Set-StaticConfigValues @( $bankFileNameORB, $bankFileNameTemp ) $bankServiceDirectoryTemp $bankServiceDirectoryORB -Verbose
|
||
|
[xml]$validation = GC $bankFileNameTemp
|
||
|
|
||
|
Context "Setting Static Configuration Values" {
|
||
|
|
||
|
It "Sets ShouldDisplayUncaughtExceptions to 'false'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//appSettings/add[@key='ShouldDisplayUncaughtExceptions']").Value | Should Be "false"
|
||
|
}
|
||
|
|
||
|
It "Sets ForceUseOfProductionAssetsInDebug to 'true'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//appSettings/add[@key='ForceUseOfProductionAssetsInDebug']").Value | Should Be "true"
|
||
|
}
|
||
|
|
||
|
It "Sets compilation.debug to 'false'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//system.web/compilation[@debug]").Debug | Should Be "false"
|
||
|
}
|
||
|
|
||
|
It "Sets httpErrors.errorMode to 'DetailedLocalOnly'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//httpErrors").Debug
|
||
|
}
|
||
|
|
||
|
It "Sets forms.cookieless to 'UseCookies'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//authentication/forms[@cookieless]").cookieless | Should Be "UseCookies"
|
||
|
}
|
||
|
|
||
|
It "Sets glimpse.defaultRuntimePolicy to 'Off'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//glimpse[@defaultRuntimePolicy]").defaultRuntimePolicy | Should Be "Off"
|
||
|
}
|
||
|
|
||
|
It "Sets customErrors.mode to 'RemoteOnly'" {
|
||
|
|
||
|
$validation.SelectSingleNode("//customErrors").mode | Should Be "RemoteOnly"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Copying Child Nodes of Config Sections" {
|
||
|
|
||
|
It "Copies appSettings Values from the deployed config to the new config" {
|
||
|
|
||
|
$validation.SelectSingleNode("//appSettings/add[@key='FakeSetting']").Value | Should Be "FakeValue"
|
||
|
}
|
||
|
|
||
|
It "Copies quartz Values from from the deployed config to the new config" {
|
||
|
|
||
|
$validation.SelectSingleNode("//quartz/add[@key='quartz.scheduler.instanceName']").Value | Should Be "FakeValue"
|
||
|
}
|
||
|
|
||
|
It "Removes All Child Nodes from system.diagnostics to Disable WCF Tracing" {
|
||
|
|
||
|
$validation.SelectSingleNode("//system.diagnostics").ChildNodes.Count | Should Be 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Creating Config Values Which Do Not Exist" {
|
||
|
|
||
|
It "Creates the IsTransactionCachingEnabled Node with the Previous Value If it Doesn't Exist" {
|
||
|
|
||
|
$validation.SelectSingleNode("//appSettings/add[@key='IsTransactionCachingEnabled']").Value | Should Be "false"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion Set-StaticConfigValues
|