Tests/Test-TablePermissionsExist.Tests.ps1

Describe "Test-TablePermissionsExist" {
    $result = Test-TablePermissionsExist -SourcePath (Create-SampleALProject -PermissionsFile Complete)
    It "should return true" {
        $result | should be $true
    }

    $result = Test-TablePermissionsExist -SourcePath (Create-SampleALProject -PermissionsFile None) -SuppressError
    It "Should return false" {
        $result | should be $false
    }
    $result = Test-TablePermissionsExist -SourcePath (Create-SampleALProject -PermissionsFile Incomplete) -SuppressError
    It "Should return false" {
        $result | should be $false
    }

    function Create-SampleALProject {
        param (
            # Determine whether to create a permissions file or not
            [Parameter(Mandatory=$true)]
            [string]
            [ValidateSet('None','Incomplete','Complete')]
            $PermissionsFile
        )
    
        $ProjectRoot = Create-TempDirectory
        Set-Content -Value 'table 5000 "Permissions Test
        {
        }"'
 -Path (Join-Path $ProjectRoot 'Tab50000.PermissionsTest.al')
    
        switch ($PermissionsFile) {
            'None' {<#do nothing#>}
            'Incomplete' {Set-Content -Value '<PermissionSets><PermissionSet RoleID="TEST" RoleName="Test"></PermissionSet></PermissionSets>' -Path (Join-Path $ProjectRoot 'extensionPermissionSet.xml')}
            'Complete' {Set-Content -Value '<PermissionSets><PermissionSet RoleID="TEST" RoleName="Test"><Permission><ObjectType>0</ObjectType><ObjectID>50000</ObjectID></Permission></PermissionSet></PermissionSets>' -Path (Join-Path $ProjectRoot 'extensionPermissionSet.xml')}
        }
    
        $ProjectRoot
    }
}