Change some context to it

This commit is contained in:
Yanbing Wang 2016-08-26 19:37:51 -07:00
parent 312ec5ffd0
commit bbbd6a9dfc
2 changed files with 81 additions and 89 deletions

View file

@ -9,8 +9,9 @@ Describe 'Testing of script internationalization' -Tags "CI" {
BeforeAll {
$dir=$PSScriptRoot
}
It 'converFromString-Data.' {
Context 'converFromString-Data.' {
data mydata
{
@ -20,29 +21,29 @@ Describe 'Testing of script internationalization' -Tags "CI" {
'@
}
$mydata.string1 | Should Be 'string1'
$mydata.string2 | Should Be 'string2'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2' }
}
It 'Import default culture' {
Context 'Import default culture' {
import-localizedData mydata;
$mydata.string1 | Should Be 'string1 for en-US'
$mydata.string2 | Should be 'string2 for en-US'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for en-US' }
It '$mydata.string2' { $mydata.string2 | Should be 'string2 for en-US' }
}
It 'Import specific culture' {
Context 'Import specific culture' {
import-localizedData mydata -uiculture en-US
$mydata.string1 | Should Be 'string1 for en-US'
$mydata.string2 | Should Be 'string2 for en-US'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for en-US' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for en-US' }
import-localizedData mydata -uiculture fr-FR
$mydata.string1 | Should Be 'string1 for fr-FR'
$mydata.string2 | Should Be 'string2 for fr-FR'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for fr-FR' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for fr-FR' }
}
It 'Import non existing culture' {
@ -52,51 +53,51 @@ Describe 'Testing of script internationalization' -Tags "CI" {
$ev[0].Exception.GetType() | Should Be System.Management.Automation.PSInvalidOperationException
}
It 'Import different file name' {
Context 'Import different file name' {
import-localizedData mydata -filename foo
$mydata.string1 | Should Be 'string1 from foo in en-US'
$mydata.string2 | Should Be 'string2 from foo in en-US'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 from foo in en-US' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 from foo in en-US' }
import-localizedData mydata -filename foo -uiculture fr-FR
$mydata.string1 | Should Be 'string1 from foo in fr-FR'
$mydata.string2 | Should Be 'string2 from foo in fr-FR'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 from foo in fr-FR' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 from foo in fr-FR' }
}
It 'Import different file base' {
Context 'Import different file base' {
import-localizedData mydata -basedirectory "${dir}\newbase"
$mydata.string1 | Should Be 'string1 for en-US under newbase'
$mydata.string2 | Should Be 'string2 for en-US under newbase'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for en-US under newbase' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for en-US under newbase' }
import-localizedData mydata -basedirectory "${dir}\newbase" -uiculture fr-FR
$mydata.string1 | Should Be 'string1 for fr-FR under newbase'
$mydata.string2 | Should Be 'string2 for fr-FR under newbase'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for fr-FR under newbase' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for fr-FR under newbase' }
}
It 'Import different file base and file name' {
Context 'Import different file base and file name' {
import-localizedData mydata -basedirectory "${dir}\newbase" -filename foo
$mydata.string1 | Should Be 'string1 for en-US from foo under newbase'
$mydata.string2 | Should Be 'string2 for en-US from foo under newbase'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for en-US from foo under newbase' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for en-US from foo under newbase' }
import-localizedData mydata -basedirectory "${dir}\newbase" -filename foo -uiculture fr-FR
$mydata.string1 | Should Be 'string1 for fr-FR from foo under newbase'
$mydata.string2 | Should Be 'string2 for fr-FR from foo under newbase'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for fr-FR from foo under newbase' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for fr-FR from foo under newbase' }
}
It "Import variable that doesn't exist" {
Context "Import variable that doesn't exist" {
import-localizedData mydata2
$mydata2.string1 | Should Be 'string1 for en-US'
$mydata2.string2 | Should Be 'string2 for en-US'
It '$mydata.string1' { $mydata2.string1 | Should Be 'string1 for en-US' }
It '$mydata.string2' { $mydata2.string2 | Should Be 'string2 for en-US' }
}
It 'Import bad psd1 file - tests the use of disallowed variables' {
@ -110,76 +111,68 @@ Describe 'Testing of script internationalization' -Tags "CI" {
$script:exception.exception.gettype() | Should Be System.management.automation.psinvalidoperationexception
}
It 'Import if psd1 file' {
Context 'Import if psd1 file' {
import-localizedData mydata -filename if
if ($psculture -eq 'en-US')
{
$mydata.string1 | Should Be 'string1 for en-US in if'
$mydata.string2 | Should Be 'string2 for en-US in if'
It '$mydata.string1' { $mydata.string1 | Should Be 'string1 for en-US in if' }
It '$mydata.string2' { $mydata.string2 | Should Be 'string2 for en-US in if' }
}
else
{
$mydata | Should Be $null
It '$mydata should not be null' { $mydata | Should Be $null }
}
}
It 'Allowed cmdlets checked properly' {
$testData = @(
@{cmd = 'data d { @{ x=$(get-command)} }';Expected='*get-command*'},
@{cmd = 'data d { if ($(get-command)) {} }';Expected='*get-command*'},
@{cmd = 'data d { @(get-command) }';Expected='*get-command*'}
)
It 'Allowed cmdlets checked properly' -TestCase:$testData {
param ($cmd, $Expected)
$script:exception = $null
& {
trap {$script:exception = $_.Exception ; continue }
iex 'data d { @{ x=$(get-command)} }'
trap {$script:exception = $_.Exception ; continue }
iex $cmd
}
$exception -like '*get-command*' | Should Be $true
$script:exception = $null
& {
trap {$script:exception = $_.Exception ; continue }
iex 'data d { if ($(get-command)) {} }'
}
$exception -like '*get-command*' | Should Be $true
$script:exception = $null
& {
trap {$script:exception = $_.Exception ; continue }
iex 'data d { @(get-command) }'
}
$exception -like '*get-command*' | Should Be $true
#$exception -like '*get-command*' | Should Be $true
$exception -like $Expected | Should Be $true
}
It 'Check alternate syntax that also supports complex variable names' {
Context 'Check alternate syntax that also supports complex variable names' {
& {
$script:mydata = data { 123 }
}
$mydata | Should Be 123
It '$mydata' { $mydata | Should Be 123 }
$mydata = data { 456 }
& {
# This import should not clobber the one at script scope
import-localizedData mydata -uiculture en-US
}
$mydata | Should Be 456
It '$mydata' { $mydata | Should Be 456 }
& {
# This import should clobber the one at script scope
import-localizedData script:mydata -uiculture en-US
}
$script:mydata.string1 | Should Be 'string1 for en-US'
It '$script:mydata.string1' { $script:mydata.string1 | Should Be 'string1 for en-US'}
}
It 'Check fallback to current directory plus -SupportedCommand parameter' {
Context 'Check fallback to current directory plus -SupportedCommand parameter' {
new-alias MyConvertFrom-StringData ConvertFrom-StringData
import-localizeddata local:mydata -uiculture fr-ca -filename I18n.Tests_fallback.psd1 -SupportedCommand MyConvertFrom-StringData
$mydata[0].string1 | Should Be 'fallback string1 for en-US'
$mydata[1] | Should Be 42
It '$mydata[0].string1' { $mydata[0].string1 | Should Be 'fallback string1 for en-US' }
It '$mydata[1]' { $mydata[1] | Should Be 42 }
}
}

View file

@ -302,44 +302,43 @@ Describe 'get-help other tests' -Tags "CI" {
It 'Common parameters should also not appear in parameters maml' { $x.parameters.parameter.Count | Should Be 2}
}
Context 'helpFunc3 -?' {
It 'helpFunc3 -?' {
##############################################
##############################################
function helpFunc3()
{
#
#
#.Synopsis
#
# A synopsis of helpFunc3.
#
#
}
function helpFunc3()
{
#
#
#.Synopsis
#
# A synopsis of helpFunc3.
#
#
$x = helpFunc3 -?
$x.Synopsis | Should Be "A synopsis of helpFunc3."
}
$x = helpFunc3 -?
It '$x.Synopsis' { $x.Synopsis | Should Be "A synopsis of helpFunc3." }
}
It 'get-help helpFunc4' {
Context 'get-help helpFunc4' {
<#
.Description
description
<#
.Description
description
.Synopsis
.Synopsis
.Component
component
#>
function helpFunc4()
{
}
.Component
component
#>
function helpFunc4()
{
}
$x = get-help helpFunc4
It '$x.Synopsis should be empty' { $x.Synopsis | Should Be "" }
$x.Synopsis | Should Be ""
}
Context 'get-help helpFunc5' {
@ -439,7 +438,7 @@ Describe 'get-help other tests' -Tags "CI" {
It '$x should not be $null' { $x | Should Not Be $null }
}
Context 'get-help helpFunc10' {
It 'get-help helpFunc10' {
#######################################################
# .SYNOPSIS
# Help on helpFunc10
@ -449,7 +448,7 @@ Describe 'get-help other tests' -Tags "CI" {
}
$x = get-help helpFunc10
It '$x.Synopsis' { $x.Synopsis | Should Be 'Help on helpFunc10' }
$x.Synopsis | Should Be 'Help on helpFunc10'
}
Context 'get-help helpFunc11' {