163 lines
6.3 KiB
PowerShell
163 lines
6.3 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 = ""
|
|||
|
|
|||
|
Describe "New-AlkamiManifest" {
|
|||
|
|
|||
|
function New-FakeCsProj {
|
|||
|
$sampleCsproj = @"
|
|||
|
<?xml version="1.0"?>
|
|||
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|||
|
<PropertyGroup>
|
|||
|
<Platform>AnyCPU</Platform>
|
|||
|
<ProjectGuid>{deadbeef-dead-beef-dead-beef00000075}</ProjectGuid>
|
|||
|
<OutputType>Library</OutputType>
|
|||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|||
|
<RootNamespace>Alkami.MicroServices.Testing.FakeService</RootNamespace>
|
|||
|
<AssemblyName>Alkami.MicroServices.Testing.FakeService</AssemblyName>
|
|||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
|||
|
<FileAlignment>512</FileAlignment>
|
|||
|
<RestorePackages>true</RestorePackages>
|
|||
|
<TargetFrameworkProfile />
|
|||
|
</PropertyGroup>
|
|||
|
</Project>
|
|||
|
"@
|
|||
|
|
|||
|
$testFile = "TestDrive:\Alkami.Microservices.Testing.FakeService.csproj"
|
|||
|
Set-Content -Path $testFile -Value $sampleCsproj
|
|||
|
}
|
|||
|
|
|||
|
function New-FakeManifest{
|
|||
|
$sampleManifest = @"
|
|||
|
<?xml version="1.0"?>
|
|||
|
<packageManifest>
|
|||
|
<version>1.0</version>
|
|||
|
<general>
|
|||
|
<creatorCode>Alkami</creatorCode>
|
|||
|
<element>Alkami.MicroServices.Testing.FakeService</element>
|
|||
|
<componentType>Service</componentType>
|
|||
|
<bankIdentifiers>
|
|||
|
<bankIdentifier name="MyFIName">DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF</bankIdentifier>
|
|||
|
</bankIdentifiers>
|
|||
|
</general>
|
|||
|
<serviceManifest>
|
|||
|
<runtime>framework</runtime>
|
|||
|
<entryPoint>Alkami.MicroServices.Testing.FakeService</entryPoint>
|
|||
|
<migrations>
|
|||
|
<package id="Alkami.MicroServices.Testing.FakeService" version="1.0" />
|
|||
|
</migrations>
|
|||
|
<db_role>my_service_role</db_role>
|
|||
|
</serviceManifest>
|
|||
|
</packageManifest>
|
|||
|
"@
|
|||
|
|
|||
|
$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
|
|||
|
}
|
|||
|
}
|