1+ Describe " Verifying templating component" {
2+ BeforeAll {
3+ $outPath = (Get-Item - Path ' TestDrive:\' ).FullName
4+ $resourcePath = Resolve-PSFPath - Path " $PSScriptRoot \..\resources"
5+ $templateName = ' TestTemplate-{0}' -f (Get-Random )
6+ }
7+
8+ It " Should Record the template correctly" {
9+ { New-PSMDTemplate - TemplateName $templateName - FilePath " $resourcePath \þnameþ.txt" - OutPath $outPath - EnableException - ErrorAction Stop } | Should -Not - Throw
10+ $templateInfo = Get-PSMDTemplate - TemplateName $templateName - Path $outPath
11+ $templateRaw = Import-PSFClixml - Path $templateInfo.Path
12+ try { $template = [PSModuleDevelopment.Template.Template ]$templateRaw }
13+ catch {
14+ Write-Warning " Conversion to template Failed!"
15+ Write-Warning " ======================================================================="
16+ $_ | Format-List - Force | Out-Host
17+ Write-Warning " ======================================================================="
18+ $_.Exception | Format-List - Force | Out-Host
19+ Write-Warning " ======================================================================="
20+ throw
21+ }
22+ $template.Name | Should - Be $templateName
23+ $template.Parameters.Count | Should - Be 1
24+ $template.Scripts.Count | Should - Be 1
25+ $template.Scripts.Values.ScriptBlock | Should - BeOfType ([scriptblock ])
26+ }
27+
28+ It " Should Invoke the template correctly" {
29+ { Invoke-PSMDTemplate - TemplateName $templateName - Path $outPath - OutPath $outPath - Name Test - EnableException } | Should -Not - Throw
30+ $content = Get-Content - Path " TestDrive:\Test.txt" - ErrorAction Stop
31+ $values = $content | ConvertFrom-StringData - ErrorAction Stop
32+ $values.Name | Should - Be Test
33+ $values.Value | Should - Be ' 123'
34+ }
35+
36+ It " Should Remove the template correctly" {
37+ { Remove-PSMDTemplate - TemplateName $templateName - EnableException - Confirm:$false } | Should -Not - Throw
38+ Get-PSMDTemplate - TemplateName $templateName | Should - BeNullOrEmpty
39+ }
40+ }
0 commit comments