. $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-NewRelicAppName Describe "Set-NewRelicAppName" { # 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 $tempOrb = ($tempPath + "\ORB") if (!(Test-Path $tempOrb)) { New-Item -ItemType Directory $tempOrb | Out-Null } Write-Warning ("Using temp path: $tempOrb for tests") # Make Directories and Files for Tests $bankServiceDirectory = New-Item -ItemType Directory ($tempOrb + "\BankService") $radiumServiceDirectory = New-Item -ItemType Directory ($tempOrb + "\Radium") $bankFileRandomName = (Join-Path $bankServiceDirectory "foo.bar") $radiumFileRandomName = (Join-Path $radiumServiceDirectory "foo.bar") $bankFileNew = (Join-Path $bankServiceDirectory "new.web.config") $radiumFileNew = (Join-Path $radiumServiceDirectory "new.Alkami.App.Radium.WindowsService.exe.config") $bankFile = (Join-Path $bankServiceDirectory "web.config") $radiumFile = (Join-Path $radiumServiceDirectory "Alkami.App.Radium.WindowsService.exe.config") $testXml = @" "@ $testXml | Out-File $bankFile -Force $testXml | Out-File $bankFileNew -Force $testXml | Out-File $bankFileRandomName -Force $testXml | Out-File $radiumFile -Force $testXml | Out-File $radiumFileNew -Force $testXml | Out-File $radiumFileRandomName -Force $testfiles = @($bankFileRandomName, $radiumFileRandomName) It "Updates the Application Name Using the File List Specified" { Set-NewRelicAppName "File List" -configFiles $testfiles (GC $bankFileRandomName | Select-String "File List Bank").Count | Should Be 1 (GC $radiumFileRandomName | Select-String "File List Radium").Count | Should Be 1 } It "Updates the Application Name Using the File Path Specified" { Set-NewRelicAppName "File Path" -filePath $tempOrb (GC $bankFile | Select-String "File Path Bank").Count | Should Be 1 (GC $radiumFile | Select-String "File Path Radium").Count | Should Be 1 (GC $bankFileNew | Select-String "File Path Bank").Count | Should Be 1 (GC $radiumFileNew | Select-String "File Path Radium").Count | Should Be 1 } It "Writes a Warning if an Invalid File is Specified" { $fakeFile = Join-Path $tempFile "someNonExistantFile.txt" if (Test-Path $fakeFile) { Remove-Item $fakeFile -Force } { ( Set-NewRelicAppName "Foo Bar" -configFiles @( $fakeFile ) 3>&1) -match "Could Not Find Config File $fakeFile" } | Should Be $true } It "Writes a Warning if No Files and No Path is Specified" { { ( Set-NewRelicAppName "Foo Bar" 3>&1 ) -match "Execution cannot continue" } | Should Be $true } } #endregion Set-NewRelicAppName