From 43d284f6b3ce7f82135c5bc73a6ab79e550dc8d1 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Wed, 10 Feb 2016 16:02:28 -0800 Subject: [PATCH] New pester test for Import-LocalizedData --- .../powershell/Import-LocalizedData.Tests.ps1 | 36 +++++++++++++++++++ test/powershell/assets/de-DE/localized.psd1 | 11 ++++++ test/powershell/assets/en-US/localized.psd1 | 11 ++++++ test/powershell/assets/localized.ps1 | 29 +++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 test/powershell/Import-LocalizedData.Tests.ps1 create mode 100644 test/powershell/assets/de-DE/localized.psd1 create mode 100644 test/powershell/assets/en-US/localized.psd1 create mode 100644 test/powershell/assets/localized.ps1 diff --git a/test/powershell/Import-LocalizedData.Tests.ps1 b/test/powershell/Import-LocalizedData.Tests.ps1 new file mode 100644 index 0000000000..640c88e466 --- /dev/null +++ b/test/powershell/Import-LocalizedData.Tests.ps1 @@ -0,0 +1,36 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +$assetsDir = Join-Path -Path $here -ChildPath assets + +Describe "Import-LocalizedData" { + + BeforeAll { + $script = "localized.ps1" + $sunday = "Sunday" + $sundayInGerman = $sunday + " (in German)" + } + + It "Should be able to import string using default culture" { + # Set-Culture is broken, but let's verify that default culture is en-US + $culture = Get-Culture + $culture.Name | Should Be "en-US" + + $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir + $d.d0 | Should be $sunday + } + + It "Should be able to import string using en-US culture" { + $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture en-US + $d.d0 | Should be $sunday + } + + It "Should be able to import string using de-DE culture" { + $d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE + $d.d0 | Should be $sundayInGerman + } + + It "Should be able to import string and store in binding variable" { + Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE -BindingVariable d + $d.d0 | Should be $sundayInGerman + } + +} diff --git a/test/powershell/assets/de-DE/localized.psd1 b/test/powershell/assets/de-DE/localized.psd1 new file mode 100644 index 0000000000..10da27ee59 --- /dev/null +++ b/test/powershell/assets/de-DE/localized.psd1 @@ -0,0 +1,11 @@ +# culture="de-DE" +ConvertFrom-StringData @' + messageDate = Today is + d0 = Sunday (in German) + d1 = Monday (in German) + d2 = Tuesday (in German) + d3 = Wednesday (in German) + d4 = Thursday (in German) + d5 = Friday (in German) + d6 = Saturday (in German) +'@ diff --git a/test/powershell/assets/en-US/localized.psd1 b/test/powershell/assets/en-US/localized.psd1 new file mode 100644 index 0000000000..83814f14b0 --- /dev/null +++ b/test/powershell/assets/en-US/localized.psd1 @@ -0,0 +1,11 @@ +# culture="en-US" +ConvertFrom-StringData @' + messageDate = Today is + d0 = Sunday + d1 = Monday + d2 = Tuesday + d3 = Wednesday + d4 = Thursday + d5 = Friday + d6 = Saturday +'@ diff --git a/test/powershell/assets/localized.ps1 b/test/powershell/assets/localized.ps1 new file mode 100644 index 0000000000..5f1bf4e5f3 --- /dev/null +++ b/test/powershell/assets/localized.ps1 @@ -0,0 +1,29 @@ +# Sample code from https://technet.microsoft.com/en-us/library/hh847854.aspx + + $Day = DATA { +# culture="en-US" +ConvertFrom-StringData @' + messageDate = Today is + d0 = Sunday + d1 = Monday + d2 = Tuesday + d3 = Wednesday + d4 = Thursday + d5 = Friday + d6 = Saturday +'@ +} + + +Import-LocalizedData -BindingVariable Day + +# Build an array of weekdays. +$a = $Day.d0, $Day.d1, $Day.d2, $Day.d3, $Day.d4, $Day.d5, $Day.d6 + + + # Get the day of the week as a number (Monday = 1). + # Index into $a to get the name of the day. + # Use string formatting to build a sentence. + + "{0} {1}" -f $Day.messageDate, $a[(get-date -uformat %u)] | Out-Host +