Tests/Get-BranchNameForDependencies.Tests.ps1
Describe 'Get-BranchNameForDependencies' { InModuleScope Tecman.Tfs.Tools { Context 'Branch dependency specified in environment.json' { Mock Get-EnvironmentKeyValue {return 'ThisBranch'} It 'should return the name of the branch in environment.json' { Get-BranchNameForDependencies -Path $TestDrive | should be 'ThisBranch' } } Context 'Branch dependencies specified in config file, platform within a specified range' { Mock Get-TFSConfigKeyValue {return ConvertFrom-Json ('[{"from": "13.0.0.0", "to": "13.999.0.0", "branch": "BC13"},{"from": "14.0.0.0", "to": "14.999.0.0", "branch": "BC14"}]')} Mock Get-AppKeyValue {return "14.3.0.0"} It 'should return the branch from the corresponding range' { Mock Get-EnvironmentKeyValue {return $null} Get-EnvironmentKeyValue -KeyName 'dependencyBranch' | should be $null Get-BranchNameForDependencies -Path $TestDrive | should be 'BC14' } } Context 'Branch dependencies specified in config file, platform not within a specified range' { Mock Get-TFSConfigKeyValue {return ConvertFrom-Json ('[{"from": "13.0.0.0", "to": "13.999.0.0", "branch": "BC13"},{"from": "14.0.0.0", "to": "14.999.0.0", "branch": "BC14"}]')} Mock Get-AppKeyValue {return "15.0.0.0"} It 'should return the branch from the corresponding range' { Get-BranchNameForDependencies -Path $TestDrive | should be '' } } Context 'Branch dependencies specified in config file, platform within a specified range, environment file takes precedence' { Mock Get-TFSConfigKeyValue {return ConvertFrom-Json ('[{"from": "13.0.0.0", "to": "13.999.0.0", "branch": "BC13"},{"from": "14.0.0.0", "to": "14.999.0.0", "branch": "BC14"}]')} Mock Get-EnvironmentKeyValue {return 'ThisBranch'} Mock Get-AppKeyValue {return "14.0.0.0"} It 'should return the branch from the corresponding range' { Get-BranchNameForDependencies -Path $TestDrive | should be 'ThisBranch' } } } } |