MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Get-Culture" -Tags "CI" {5 6 It "Should return a type of CultureInfo for Get-Culture cmdlet" {7 8 $culture = Get-Culture9 $culture | Should -BeOfType CultureInfo10 ($culture).EnglishName | Should -BeExactly $Host.CurrentCulture.EnglishName11 12 Get-Culture -NoUserOverrides | Should -BeOfType CultureInfo13 }14 15 It "Should have (Get-Culture).Name variable be equivalent to `$PSCulture" {16 17 (Get-Culture).Name | Should -BeExactly $PSCulture18 }19 20 It "Should return the specified culture with '-Name' parameter" {21 22 $ci = Get-Culture -Name ru-RU23 $ci | Should -BeOfType CultureInfo24 $ci.Name | Should -BeExactly "ru-RU"25 26 $ci = Get-Culture -Name ru-RU -NoUserOverrides27 $ci | Should -BeOfType CultureInfo28 $ci.Name | Should -BeExactly "ru-RU"29 }30 31 It "Should return specified cultures with '-Name' parameter" {32 33 $ciArray = Get-Culture "", "ru-RU"34 $ciArray | Should -HaveCount 235 $ciArray[0] | Should -BeOfType CultureInfo36 $ciArray[0].EnglishName | Should -BeExactly "Invariant Language (Invariant Country)"37 38 $ciArray[1] | Should -BeOfType CultureInfo39 $ciArray[1].Name | Should -BeExactly "ru-RU"40 $ciArray[1].EnglishName | Should -BeExactly "Russian (Russia)"41 }42 43 It "Should accept values from a pipeline for '-Name' parameter" {44 45 $ciArray = "", "ru-RU" | Get-Culture46 $ciArray | Should -HaveCount 247 $ciArray[0] | Should -BeOfType CultureInfo48 $ciArray[0].EnglishName | Should -BeExactly "Invariant Language (Invariant Country)"49 $ciArray[1] | Should -BeOfType CultureInfo50 $ciArray[1].Name | Should -BeExactly "ru-RU"51 $ciArray[1].EnglishName | Should -BeExactly "Russian (Russia)"52 }53 54 It "Should return the culture array with '-ListAvailable' parameter" {55 56 $ciArray = Get-Culture -ListAvailable57 $ciArray.Count | Should -BeGreaterThan 058 $ciArray[0] | Should -BeOfType CultureInfo59 }60 61 It "Should write an error on unsupported culture name" {62 63 { Get-Culture -Name "abcdefghijkl" -ErrorAction Stop } | Should -PassThru -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetCultureCommand"64 }65}66 67Describe "`$PSCulture" -Tags "CI" {68 69 It "`$PSCulture is the current thread culture" {70 $PSCulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentCulture.Name)71 }72 73 It "`$PSUICulture is the current thread culture" {74 $PSUICulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentUICulture.Name)75 }76 77 It "`$PSCulture follows the current thread culture" {78 $oldCulture = [CultureInfo]::CurrentCulture79 $newCulture = "ru-RU"80 81 # Workaround to pass tests locally82 if ($oldCulture -eq "ru-RU") {83 $newCulture = "fr-FR"84 }85 86 try {87 [CultureInfo]::currentculture = $newCulture88 $PSCulture | Should -BeExactly $newCulture89 $PSCulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentCulture.Name)90 } finally {91 [CultureInfo]::CurrentCulture = $oldCulture92 }93 }94 95 It "`$PSUICulture follows the current thread culture" {96 $oldUICulture = [CultureInfo]::CurrentUICulture97 $newUICulture = "ru-RU"98 99 if ($oldUICulture -eq "ru-RU") {100 $newUICulture = "fr-FR"101 }102 103 try {104 [CultureInfo]::CurrentUICulture = $newUICulture105 $PSUICulture | Should -BeExactly $newUICulture106 $PSUICulture | Should -BeExactly $([System.Threading.Thread]::CurrentThread.CurrentUICulture.Name)107 } finally {108 [CultureInfo]::CurrentUICulture = $oldUICulture109 }110 }111}112 