<commit_before>﻿
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module -Verbose PSScriptAnalyzer
$testRootDirectory = Split-Path -Parent $directory
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
$sa = Get-Command Get-ScriptAnalyzerRule

$singularNouns = "PSUseSingularNouns" # this rule does not exist for coreclr version
$approvedVerbs = "PSUseApprovedVerbs"
$cmdletAliases = "PSAvoidUsingCmdletAliases"
$dscIdentical = "PSDSCUseIdenticalParametersForDSC"

Describe "Test available parameters" {
    $params = $sa.Parameters
    Context "Name parameter" {
        It "has a RuleName parameter" {
            $params.ContainsKey("Name") | Should Be $true
        }

        It "accepts string" {
            $params["Name"].ParameterType.FullName | Should Be "System.String[]"
        }
    }

    Context "RuleExtension parameters" {
        It "has a RuleExtension parameter" {
            $params.ContainsKey("CustomRulePath") | Should Be $true
        }

        It "accepts string array" {
            $params["CustomRulePath"].ParameterType.FullName | Should Be "System.String[]"
        }

		It "takes CustomizedRulePath parameter as an alias of CustomRulePath parameter" {
			$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should be $true
		}
    }

}

Describe "Test Name parameters" {
    Context "When used correctly" {
        It "works with 1 name" {
            $rule = Get-ScriptAnalyzerRule -Name $cmdletAliases
            $rule.Count | Should Be 1
            $rule[0].RuleName | Should Be $cmdletAliases
        }

        It "works for DSC Rule" {
            $rule = Get-ScriptAnalyzerRule -Name $dscIdentical
            $rule.Count | Should Be 1
            $rule[0].RuleName | Should Be $dscIdentical
        }

        It "works with 2 names" {
            $rules = Get-ScriptAnalyzerRule -Name $approvedVerbs, $cmdletAliases
            $rules.Count | Should Be 2
            ($rules | Where-Object {$_.RuleName -eq $cmdletAliases}).Count | Should Be 1
            ($rules | Where-Object {$_.RuleName -eq $approvedVerbs}).Count | Should Be 1
        }

        It "get Rules with no parameters supplied" {
			$defaultRules = Get-ScriptAnalyzerRule
            $expectedNumRules = 48
            if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3) -or (Test-PSVersionV4))
            {
                # for PSv3 PSAvoidGlobalAliases is not shipped because
                # it uses StaticParameterBinder.BindCommand which is
                # available only on PSv4 and above
                # for PowerShell Core, PSUseSingularNouns is not
                # shipped because it uses APIs that are not present
                # in dotnet core.
                $expectedNumRules = 47
            }
			$defaultRules.Count | Should be $expectedNumRules
		}

        It "is a positional parameter" {
            $rules = Get-ScriptAnalyzerRule "PSAvoidUsingCmdletAliases"
            $rules.Count | Should Be 1
        }
    }

    Context "When used incorrectly" {
        It "1 incorrect name" {
            $rule = Get-ScriptAnalyzerRule -Name "This is a wrong name"
            $rule.Count | Should Be 0
        }

        It "1 incorrect and 1 correct" {
            $rule = Get-ScriptAnalyzerRule -Name $cmdletAliases, "This is a wrong name"
            $rule.Count | Should Be 1
            $rule[0].RuleName | Should Be $cmdletAliases<commit_msg>Update rule count in GetScriptAnalyzerRule test case<commit_after>﻿
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module -Verbose PSScriptAnalyzer
$testRootDirectory = Split-Path -Parent $directory
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
$sa = Get-Command Get-ScriptAnalyzerRule

$singularNouns = "PSUseSingularNouns" # this rule does not exist for coreclr version
$approvedVerbs = "PSUseApprovedVerbs"
$cmdletAliases = "PSAvoidUsingCmdletAliases"
$dscIdentical = "PSDSCUseIdenticalParametersForDSC"

Describe "Test available parameters" {
    $params = $sa.Parameters
    Context "Name parameter" {
        It "has a RuleName parameter" {
            $params.ContainsKey("Name") | Should Be $true
        }

        It "accepts string" {
            $params["Name"].ParameterType.FullName | Should Be "System.String[]"
        }
    }

    Context "RuleExtension parameters" {
        It "has a RuleExtension parameter" {
            $params.ContainsKey("CustomRulePath") | Should Be $true
        }

        It "accepts string array" {
            $params["CustomRulePath"].ParameterType.FullName | Should Be "System.String[]"
        }

		It "takes CustomizedRulePath parameter as an alias of CustomRulePath parameter" {
			$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should be $true
		}
    }

}

Describe "Test Name parameters" {
    Context "When used correctly" {
        It "works with 1 name" {
            $rule = Get-ScriptAnalyzerRule -Name $cmdletAliases
            $rule.Count | Should Be 1
            $rule[0].RuleName | Should Be $cmdletAliases
        }

        It "works for DSC Rule" {
            $rule = Get-ScriptAnalyzerRule -Name $dscIdentical
            $rule.Count | Should Be 1
            $rule[0].RuleName | Should Be $dscIdentical
        }

        It "works with 2 names" {
            $rules = Get-ScriptAnalyzerRule -Name $approvedVerbs, $cmdletAliases
            $rules.Count | Should Be 2
            ($rules | Where-Object {$_.RuleName -eq $cmdletAliases}).Count | Should Be 1
            ($rules | Where-Object {$_.RuleName -eq $approvedVerbs}).Count | Should Be 1
        }

        It "get Rules with no parameters supplied" {
			$defaultRules = Get-ScriptAnalyzerRule
            $expectedNumRules = 49
            if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3) -or (Test-PSVersionV4))
            {
                # for PSv3 PSAvoidGlobalAliases is not shipped because
                # it uses StaticParameterBinder.BindCommand which is
                # available only on PSv4 and above
                # for PowerShell Core, PSUseSingularNouns is not
                # shipped because it uses APIs that are not present
                # in dotnet core.
                $expectedNumRules = 48
            }
			$defaultRules.Count | Should be $expectedNumRules
		}

        It "is a positional parameter" {
            $rules = Get-ScriptAnalyzerRule "PSAvoidUsingCmdletAliases"
            $rules.Count | Should Be 1
        }
    }

    Context "When used incorrectly" {
        It "1 incorrect name" {
            $rule = Get-ScriptAnalyzerRule -Name "This is a wrong name"
            $rule.Count | Should Be 0
        }

        It "1 incorrect and 1 correct" {
            $rule = Get-ScriptAnalyzerRule -Name $cmdletAliases, "This is a wrong name"
            $rule.Count | Should Be 1
            $rule[0].RuleName | Should Be $cmdletAliases
{'fraction_non_alphanumeric': 0.08806120975891439, 'fraction_numerical': 0.007218131947452, 'mean_word_length': 2.281856939838939, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4729630', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1926, 'n_words': 565}