. $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 = "" Describe "New-AlkamiManifest" { function New-FakeCsProj { $sampleCsproj = @" AnyCPU {deadbeef-dead-beef-dead-beef00000075} Library Properties Alkami.MicroServices.Testing.FakeService Alkami.MicroServices.Testing.FakeService v4.7.2 512 true "@ $testFile = "TestDrive:\Alkami.Microservices.Testing.FakeService.csproj" Set-Content -Path $testFile -Value $sampleCsproj } function New-FakeManifest{ $sampleManifest = @" 1.0 Alkami Alkami.MicroServices.Testing.FakeService Service DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF framework Alkami.MicroServices.Testing.FakeService my_service_role "@ $testFile = "TestDrive:\AlkamiManifest.xml" Set-Content -Path $testFile -value $sampleManifest } Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith { return "SUT"} Mock -ModuleName $moduleForMock -CommandName Write-Verbose -MockWith { } Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith { } Context "When no csproj file is found" { It "Creates a file" { Mock -modulename $moduleForMock -CommandName Set-Content {} Mock -modulename $moduleForMock -CommandName Write-Warning New-AlkamiManifest -Type "service" -Destination "testdrive:\" -ProjectLocation "testdrive:\" Assert-MockCalled -CommandName Write-Warning -Times 1 -Scope It -ParameterFilter {$Message -like "*there is no csproj file*" } Assert-MockCalled -CommandName Set-Content -Times 1 -Exactly -Scope It } } Context "When Attempting to create a manifest when one already exists" { New-FakeCsProj New-FakeManifest It "Returns if no force flag is supplied" { Mock -ModuleName $moduleForMock -CommandName Set-Content {} Mock -ModuleName $moduleForMock -CommandName Write-Warning -ParameterFilter {$Message -like "*there's already a file*" } # testing on warning text isn't ideal, but we also check below that no files are created. New-AlkamiManifest -Type "service" -Destination "testdrive:\" -ProjectLocation "testdrive:\" Assert-MockCalled -CommandName Write-Warning -Times 1 -Scope It -ParameterFilter {$Message -like "*there's already a file*" } Assert-MockCalled -CommandName Set-Content -Times 0 -Exactly -Scope It } It "Generates a file if a force flag is supplied" { Mock -ModuleName $moduleForMock -CommandName set-content {} # testing on warning text isn't ideal, but we also check below that no files are created. New-AlkamiManifest -Type "service" -Destination "TestDrive:\" -ProjectLocation "testdrive:\" -Force Assert-MockCalled -CommandName Set-Content -Times 1 -Exactly -Scope It } } Context "When attempting to create a new manifest"{ It "Generates a File" { New-FakeCsProj New-AlkamiManifest -Type "service" -Destination "TestDrive:\" -ProjectLocation "testdrive:\" -force $file = Get-Content -Path "TestDrive:\AlkamiManifest.xml" $file | Should -Not -BeNullOrEmpty } } Context "When Creating Widget Manifests" { #TBD } Context "When Creating Service Manifests" { It "Generates a file with a ServiceManifest section"{ New-FakeCsProj New-AlkamiManifest -Type "service" -Destination "TestDrive:\" -ProjectLocation "testdrive:\" -force $file = (Get-Content -Path "TestDrive:\AlkamiManifest.xml") $file | Should -Not -BeNullOrEmpty $fileXml = [xml]$file $filexml.packageManifest.ServiceManifest | Should -Not -BeNullOrEmpty } } Context "When Creating Hotfix Manifests" { It "Generates a file with an Hotfix section"{ New-FakeCsProj New-AlkamiManifest -Type "Hotfix" -Destination "TestDrive:\" -ProjectLocation "testdrive:\" -force $file = (Get-Content -Path "TestDrive:\AlkamiManifest.xml") $file | Should -Not -BeNullOrEmpty $fileXml = [xml]$file $filexml.packageManifest.HotfixManifest | Should -Not -BeNullOrEmpty } } Context "When Creating Api Component Manifests" { It "Generates a file with an ApiComponent section"{ New-FakeCsProj New-AlkamiManifest -Type "ApiComponent" -Destination "TestDrive:\" -ProjectLocation "testdrive:\" -force $file = (Get-Content -Path "TestDrive:\AlkamiManifest.xml") $file | Should -Not -BeNullOrEmpty $fileXml = [xml]$file $filexml.packageManifest.ApiComponentsManifest | Should -Not -BeNullOrEmpty } } Context "When Creating Migration Manifests" { #TBD } Context "When Creating Theme Manifests" { #TBD } Context "When Creating Template Manifests" { #TBD } }