<commit_before>[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
param(
    [Parameter()]
    [string]
    $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot `
                                         -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" `
                                         -Resolve)
)

Import-Module -Name (Join-Path -Path $PSScriptRoot `
                                -ChildPath "..\UnitTestHelper.psm1" `
                                -Resolve)

$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule `
                                              -DscResource "SPUserProfileServiceApp"

Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture {
    InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock {
        Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope

        # Initialize tests
        $getTypeFullName = "Microsoft.Office.Server.Administration.UserProfileApplication"
        $mockPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
        $mockCredential = New-Object -TypeName System.Management.Automation.PSCredential `
                                     -ArgumentList @("$($Env:USERDOMAIN)\$($Env:USERNAME)", $mockPassword)
        $mockFarmCredential = New-Object -TypeName System.Management.Automation.PSCredential `
                                         -ArgumentList @("DOMAIN\sp_farm", $mockPassword)

        try { [Microsoft.Office.Server.UserProfiles.UserProfileManager] }
        catch {
            try {
                Add-Type -TypeDefinition @"
                    namespace Microsoft.Office.Server.UserProfiles {
                        public class UserProfileManager {
                            public UserProfileManager(System.Object a)
                            {
                            }
                        }
                    }
"@ -ErrorAction SilentlyContinue
            }
            catch {
                Write-Verbose -Message "The Type Microsoft.Office.Server.UserProfiles.DirectoryServiceNamingContext was already added."
            }
        }
        # Mocks for all contexts
        Mock -CommandName Get-SPDSCFarmAccount -MockWith {
            return $mockFarmCredential
        }
        Mock -CommandName New-SPProfileServiceApplication -MockWith {
            return (@{
                NetBIOSDomainNamesEnabled =  $false
                NoILMUsed = $false
            }
            )
        }
        Mock -CommandName New-SPProfileServiceApplicationProxy -MockWith { }
        Mock -CommandName Add-SPDSCUserToLocalAdmin -MockWith { }
        Mock -CommandName Test-SPDSCUserIsLocalAdmin -MockWith { return $false }
        Mock -CommandName Remove-SPDSCUserToLocalAdmin -MockWith { }
        Mock -CommandName Remove-SPServiceApplication -MockWith { }

        Mock -CommandName Get-SPWebApplication -MockWith {
            return @{
                IsAdministrationWebApplication = $true
                Url = "http://fake.contoso.com"
                Sites = @("FakeSite1")
            }
        }
        Mock -CommandName Get-SPServiceContext -MockWith {
            return (@{
                Fake1 = $true
            })
        }

        # Test contexts
        Context -Name "When PSDSCRunAsCredential matches the Farm Account" -Fixture {
            $testParams = @{
                Name = "User Profile Service App"
                ApplicationPool = "SharePoint Service Applications"
                Ensure = "Present"
            }

            Mock -CommandName Get-SPDSCFarmAccount -MockWith {
                return $mockCredential
            }

            Mock -CommandName Get-SPServiceApplication -MockWith {
                return $null
            }

            Mock -CommandName Restart-Service {}

            It "Should throw exception in the Get method" {
                { Get-TargetResource @testParams } | Should throw "Specified PSDSCRunAsCredential "
            }

            It "Should throw exception in the Test method" {
                { Test-TargetResource @testParams } | Should throw "Specified PSDSCRunAsCredential "
            }<commit_msg>Fix tests<commit_after>[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
param(
    [Parameter()]
    [string]
    $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot `
                                         -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" `
                                         -Resolve)
)

Import-Module -Name (Join-Path -Path $PSScriptRoot `
                                -ChildPath "..\UnitTestHelper.psm1" `
                                -Resolve)

$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule `
                                              -DscResource "SPUserProfileServiceApp"

Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture {
    InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock {
        Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope

        # Initialize tests
        $getTypeFullName = "Microsoft.Office.Server.Administration.UserProfileApplication"
        $mockPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
        $mockCredential = New-Object -TypeName System.Management.Automation.PSCredential `
                                     -ArgumentList @("$($Env:USERDOMAIN)\$($Env:USERNAME)", $mockPassword)
        $mockFarmCredential = New-Object -TypeName System.Management.Automation.PSCredential `
                                         -ArgumentList @("DOMAIN\sp_farm", $mockPassword)

        try { [Microsoft.Office.Server.UserProfiles.UserProfileManager] }
        catch {
            try {
                Add-Type -TypeDefinition @"
                    namespace Microsoft.Office.Server.UserProfiles {
                        public class UserProfileManager {
                            public UserProfileManager(System.Object a)
                            {
                            }
                        }
                    }
"@ -ErrorAction SilentlyContinue
            }
            catch {
                Write-Verbose -Message "The Type Microsoft.Office.Server.UserProfiles.DirectoryServiceNamingContext was already added."
            }
        }
        # Mocks for all contexts
        Mock -CommandName Get-SPDSCFarmAccount -MockWith {
            return $mockFarmCredential
        }
        Mock -CommandName New-SPProfileServiceApplication -MockWith {
            return (@{
                NetBIOSDomainNamesEnabled =  $false
                NoILMUsed = $false
            }
            )
        }
        Mock -CommandName New-SPProfileServiceApplicationProxy -MockWith { }
        Mock -CommandName Add-SPDSCUserToLocalAdmin -MockWith { }
        Mock -CommandName Test-SPDSCUserIsLocalAdmin -MockWith { return $false }
        Mock -CommandName Remove-SPDSCUserToLocalAdmin -MockWith { }
        Mock -CommandName Remove-SPServiceApplication -MockWith { }

        Mock -CommandName Get-SPWebApplication -MockWith {
            return @{
                IsAdministrationWebApplication = $true
                Url = "http://fake.contoso.com"
                Sites = @("FakeSite1")
            }
        }
        Mock -CommandName Get-SPServiceContext -MockWith {
            return (@{
                Fake1 = $true
            })
        }

        # Test contexts
        Context -Name "When PSDSCRunAsCredential matches the Farm Account" -Fixture {
            $testParams = @{
                Name = "<NAME>"
                ApplicationPool = "SharePoint Service Applications"
                Ensure = "Present"
            }

            Mock -CommandName Get-SPDSCFarmAccount -MockWith {
                return $mockCredential
            }

            Mock -CommandName Get-SPServiceApplication -MockWith {
                return $null
            }

            Mock -CommandName Restart-Service {}

            It "Should NOT throw exception in the Get method" {
                { Get-TargetResource @testParams } | (Get-TargetResource @testParams).Ensure | Should Be "Present"
            }

            It "Should throw exception in the Test method" {
                { Test-TargetResource @testParams } | Should throw "Specified PSDSCRunAsCredential "
            }
{'fraction_non_alphanumeric': 0.07971266365426949, 'fraction_numerical': 0.003475842891901286, 'mean_word_length': 1.6732734592753173, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4825420', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2099, 'n_words': 424}