New pester test for Import-LocalizedData

This commit is contained in:
George Fleming
2016-02-11 10:13:56 -08:00
committed by Andrew Schwartzmeyer
parent 4fe69773d4
commit 43d284f6b3
4 changed files with 87 additions and 0 deletions
@@ -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
}
}
@@ -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)
'@
@@ -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
'@
+29
View File
@@ -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