Tests/Add-TestAppsToAppJson.Tests.ps1
Describe Add-TestAppsToAppJson { InModuleScope Tecman.Tfs.Tools { function New-SampleAppJson { param( # path to create the new json file in [Parameter(Mandatory=$false)] [string] $Path, # the type of dependencies to create [Parameter(Mandatory=$false)] [ValidateSet('None','CleverDynamics','Microsoft','Both')] [string] $DependenciesToInclude ) switch ($DependenciesToInclude) { 'None' {} 'CleverDynamics' {$Dependencies = '{"appId": "71e01521-10a7-4ce5-b172-59100577b37b", name: "CleverDynamics App", "publisher": "Clever Dynamics", "version": "1.0.0.0"}'} 'Microsoft' {$Dependencies = '{"appId": "556630ef-27cc-404e-9380-8495676ad0bf", name: "Microsoft App", "publisher": "Microsoft", "version": "1.0.0.0"}'} 'Both' {$Dependencies = '{"appId": "71e01521-10a7-4ce5-b172-59100577b37b", name: "CleverDynamics App", "publisher": "Clever Dynamics", "version": "1.0.0.0"},{"appId": "556630ef-27cc-404e-9380-8495676ad0bf", name: "Microsoft App", "publisher": "Microsoft", "version": "1.0.0.0"}'} } $AppJsonContent = "{`"appId`": `"c31c6a51-053e-40d2-a70e-c837b4c4af3a`", `"name`": `"test app`", `"publisher`": `"test publisher`", `"platform`": `"15.0.0.0`", `"dependencies`": [$Dependencies]}" Set-Content -Path (Join-Path $Path 'app.json') -Value $AppJsonContent } function New-SampleEnvironmentJson{ param( # path to create the new json file in [Parameter(Mandatory=$false)] [string] $Path ) $TestDependency = '{"appId": "dg1be5ea-f753-4d25-bb44-a28f4624fb14", "name": "Test", "publisher": "Test", "version": "15.0.0.0"}' Set-Content -Path (Join-Path $Path 'environment.json') -Value "{`"testapps`": [$TestDependency]}" } context 'App json has no dependencies'{ It 'Adds the test dependencies to app json'{ New-SampleAppJson -Path $TestDrive -DependenciesToInclude 'None' New-SampleEnvironmentJson -Path $TestDrive Add-TestAppsToAppJson -SourcePath $TestDrive [System.Array]$Dependencies = Get-AppKeyValue -SourcePath $TestDrive -KeyName 'dependencies' $Dependencies.GetValue(0).Name | should be 'Test' } } context 'App json has CleverDynamics dependencies'{ It 'Adds the test dependencies to app json'{ New-SampleAppJson -Path $TestDrive -DependenciesToInclude 'CleverDynamics' New-SampleEnvironmentJson -Path $TestDrive Add-TestAppsToAppJson -SourcePath $TestDrive [System.Array]$Dependencies = Get-AppKeyValue -SourcePath $TestDrive -KeyName 'dependencies' $Dependencies.GetValue(1).Name | should be 'Test' } } context 'App json has Microsoft dependencies'{ It 'Adds the test dependencies to app json'{ New-SampleAppJson -Path $TestDrive -DependenciesToInclude 'Microsoft' New-SampleEnvironmentJson -Path $TestDrive Add-TestAppsToAppJson -SourcePath $TestDrive [System.Array]$Dependencies = Get-AppKeyValue -SourcePath $TestDrive -KeyName 'dependencies' $Dependencies.GetValue(1).Name | should be 'Test' } } context 'App json has Both dependencies'{ It 'Adds the test dependencies to app json'{ New-SampleAppJson -Path $TestDrive -DependenciesToInclude 'Both' New-SampleEnvironmentJson -Path $TestDrive Add-TestAppsToAppJson -SourcePath $TestDrive [System.Array]$Dependencies = Get-AppKeyValue -SourcePath $TestDrive -KeyName 'dependencies' $Dependencies.GetValue(2).Name | should be 'Test' } } } } |