Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
716dca2
[Feature] Use new Pester syntax: -Parameter for Pester tests in Langu…
kalgiz Mar 2, 2018
2552206
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 3, 2018
99333b7
[Feature] Tests in Language correction.
kalgiz Mar 3, 2018
120a358
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 5, 2018
2629006
Replace -Be by -BeTrue
kalgiz Mar 5, 2018
107cb7f
Change -BE to -Be
kalgiz Mar 5, 2018
21e840d
Tests correction in Language/Classes.
kalgiz Mar 5, 2018
b5b2912
Tests correction
kalgiz Mar 5, 2018
0485741
Tests syntax correction for Language/Operators and Language/Parser
kalgiz Mar 6, 2018
64407e5
Tests syntax correction for Language/Scripting
kalgiz Mar 6, 2018
5443e87
Tests correction for Language/Scripting/Debugging
kalgiz Mar 6, 2018
4b55598
Tests correction in Language/Scripting/NativeExecution
kalgiz Mar 6, 2018
dcff47c
Tests correction in Language/CompletionTestSupport.psm1
kalgiz Mar 6, 2018
d9de2a1
Removing extra whitespace from tests
kalgiz Mar 6, 2018
bc0212c
-Be -> -BeNullOrEmpty
kalgiz Mar 6, 2018
83c98ce
Use -BeOfType instead of -BeExactly
kalgiz Mar 6, 2018
e495ed1
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 6, 2018
18c5130
[Feature]
kalgiz Mar 6, 2018
396e0c9
-Be instead of -BeExactly for numbers
kalgiz Mar 6, 2018
06f96e8
[Feature] Put text in Pester tests into quotes
kalgiz Mar 6, 2018
4aad734
Use -Be when case sensitivity not necessary for consistency in tests.
kalgiz Mar 6, 2018
5f43f0b
[Feature] Remove blank line.
kalgiz Mar 6, 2018
6cc1465
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 7, 2018
212e29d
Error Id syntax instead of try catch
kalgiz Mar 7, 2018
4957d58
[Feature] Tests corrections.
kalgiz Mar 7, 2018
752eca7
[Feature] Language/Parser/Ast.Tests correction
kalgiz Mar 7, 2018
6df01ad
[Feature]
kalgiz Mar 8, 2018
5e8cf94
[Feature] Merge branch 'master' of https://github.com/kalgiz/PowerShe…
kalgiz Mar 8, 2018
4f03541
[Feature] Merge branch 'master' of https://github.com/PowerShell/Powe…
kalgiz Mar 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions test/powershell/Language/Classes/ProtectedAccess.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,50 +141,50 @@ class Derived2 : Base {}
'@

Describe "Protected Member Access - w/ default ctor" -Tags "CI" {
It "Method Access" { $derived1.TestMethodAccess() | Should Be 42 }
It "Dynamic Method Access" { $derived1.TestDynamicMethodAccess() | Should Be 42 }
It "Field Access" { $derived1.TestFieldAccess() | Should Be 11 }
It "Dynamic Field Access" { $derived1.TestDynamicFieldAccess() | Should Be 12 }
It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should Be 1111 }
It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should Be 2111 }
It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should Be 3111 }
It "Dynamic Property Access" { $derived1.TestDynamicPropertyAccess() | Should Be 1112 }

It "Method Access - overloaded 1a" { $derived1.TestOverloadedMethodAccess1a() | Should Be 84 }
It "Method Access - overloaded 1b" { $derived1.TestOverloadedMethodAccess1b() | Should Be 11 }
It "Method Access - overloaded 2a" { $derived1.TestOverloadedMethodAccess2a() | Should Be 84 }
It "Method Access - overloaded 2b" { $derived1.TestOverloadedMethodAccess2b() | Should Be 11 }
It "Method Access - overloaded 3a" { $derived1.TestOverloadedMethodAccess3a() | Should Be 84 }
It "Method Access - overloaded 3b" { $derived1.TestOverloadedMethodAccess3b() | Should Be 11 }
It "Implicit ctor calls protected ctor" { $derived3.OverloadedMethod2(42) | Should Be 84 }
It "Method Access" { $derived1.TestMethodAccess() | Should -Be 42 }
It "Dynamic Method Access" { $derived1.TestDynamicMethodAccess() | Should -Be 42 }
It "Field Access" { $derived1.TestFieldAccess() | Should -Be 11 }
It "Dynamic Field Access" { $derived1.TestDynamicFieldAccess() | Should -Be 12 }
It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should -Be 1111 }
It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should -Be 2111 }
It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should -Be 3111 }
It "Dynamic Property Access" { $derived1.TestDynamicPropertyAccess() | Should -Be 1112 }

It "Method Access - overloaded 1a" { $derived1.TestOverloadedMethodAccess1a() | Should -Be 84 }
It "Method Access - overloaded 1b" { $derived1.TestOverloadedMethodAccess1b() | Should -Be 11 }
It "Method Access - overloaded 2a" { $derived1.TestOverloadedMethodAccess2a() | Should -Be 84 }
It "Method Access - overloaded 2b" { $derived1.TestOverloadedMethodAccess2b() | Should -Be 11 }
It "Method Access - overloaded 3a" { $derived1.TestOverloadedMethodAccess3a() | Should -Be 84 }
It "Method Access - overloaded 3b" { $derived1.TestOverloadedMethodAccess3b() | Should -Be 11 }
It "Implicit ctor calls protected ctor" { $derived3.OverloadedMethod2(42) | Should -Be 84 }
}

Describe "Protected Member Access - w/ non-default ctor" -Tags "CI" {
It "Method Access" { $derived2.TestMethodAccess() | Should Be 52 }
It "Dynamic Method Access" { $derived2.TestDynamicMethodAccess() | Should Be 52 }
It "Field Access" { $derived2.TestFieldAccess() | Should Be 11 }
It "Dynamic Field Access" { $derived2.TestDynamicFieldAccess() | Should Be 12 }
It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should Be 1111 }
It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should Be 2111 }
It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should Be 3111 }
It "Dynamic Property Access" { $derived2.TestDynamicPropertyAccess() | Should Be 1112 }

It "Method Access - overloaded 1a" { $derived2.TestOverloadedMethodAccess1a() | Should Be 94 }
It "Method Access - overloaded 1b" { $derived2.TestOverloadedMethodAccess1b() | Should Be 21 }
It "Method Access - overloaded 2a" { $derived2.TestOverloadedMethodAccess2a() | Should Be 94 }
It "Method Access - overloaded 2b" { $derived2.TestOverloadedMethodAccess2b() | Should Be 21 }
It "Method Access - overloaded 3a" { $derived2.TestOverloadedMethodAccess3a() | Should Be 94 }
It "Method Access - overloaded 3b" { $derived2.TestOverloadedMethodAccess3b() | Should Be 21 }
It "Method Access" { $derived2.TestMethodAccess() | Should -Be 52 }
It "Dynamic Method Access" { $derived2.TestDynamicMethodAccess() | Should -Be 52 }
It "Field Access" { $derived2.TestFieldAccess() | Should -Be 11 }
It "Dynamic Field Access" { $derived2.TestDynamicFieldAccess() | Should -Be 12 }
It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should -Be 1111 }
It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should -Be 2111 }
It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should -Be 3111 }
It "Dynamic Property Access" { $derived2.TestDynamicPropertyAccess() | Should -Be 1112 }

It "Method Access - overloaded 1a" { $derived2.TestOverloadedMethodAccess1a() | Should -Be 94 }
It "Method Access - overloaded 1b" { $derived2.TestOverloadedMethodAccess1b() | Should -Be 21 }
It "Method Access - overloaded 2a" { $derived2.TestOverloadedMethodAccess2a() | Should -Be 94 }
It "Method Access - overloaded 2b" { $derived2.TestOverloadedMethodAccess2b() | Should -Be 21 }
It "Method Access - overloaded 3a" { $derived2.TestOverloadedMethodAccess3a() | Should -Be 94 }
It "Method Access - overloaded 3b" { $derived2.TestOverloadedMethodAccess3b() | Should -Be 21 }
}

Describe "Protected Member Access - members not visible outside class" -Tags "CI" {
Set-StrictMode -v 3
It "Invalid protected field Get Access" { { $derived1.Field } | Should Throw }
It "Invalid protected property Get Access" { { $derived1.Property } | Should Throw }
It "Invalid protected field Set Access" { { $derived1.Field = 1 } | Should Throw }
It "Invalid protected property Set Access" { { $derived1.Property = 1 } | Should Throw }
It "Invalid protected field Get Access" { { $derived1.Field } | Should -Throw -ErrorId "PropertyNotFoundStrict" }
It "Invalid protected property Get Access" { { $derived1.Property } | Should -Throw -ErrorId "PropertyNotFoundStrict" }
It "Invalid protected field Set Access" { { $derived1.Field = 1 } | Should -Throw -ErrorId "PropertyAssignmentException"}
It "Invalid protected property Set Access" { { $derived1.Property = 1 } | Should -Throw -ErrorId "PropertyAssignmentException" }

It "Invalid protected constructor Access" { { [Base]::new() } | Should Throw }
It "Invalid protected method Access" { { $derived1.Method() } | Should Throw }
It "Invalid protected constructor Access" { { [Base]::new() } | Should -Throw -ErrorId "MethodCountCouldNotFindBest" }
It "Invalid protected method Access" { { $derived1.Method() } | Should -Throw -ErrorId "MethodNotFound" }
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,7 @@ namespace Dummy
[C1]::new().Ensure = "Present"

It 'Error when ValidateSet should be ExceptionWhenSetting' {
try
{
[C1]::new().Ensure = "foo"
throw "Exception expected"
}
catch
{
$_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting'
}
{ [C1]::new().Ensure = "foo" } | Should -Throw -ErrorId 'ExceptionWhenSetting'
}
}

Expand All @@ -73,13 +65,7 @@ namespace Dummy
# This call should not throw exception
[C1]::Ensure = "Present"
It 'Error when ValidateSet should be ExceptionWhenSetting'{
try {
[C1]::Ensure = "foo"
throw "Exception expected"
}
catch {
$_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting'
}
{ [C1]::Ensure = "foo" } | Should -Throw -ErrorId 'ExceptionWhenSetting'
}
}

Expand All @@ -89,13 +75,7 @@ namespace Dummy
[C1]::new().f = 10
[C1]::new().f = 1
It 'Error when ValidateSet should be ExceptionWhenSetting'{
try {
[C1]::new().f = 20
throw "Exception expected"
}
catch {
$_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting'
}
{ [C1]::new().f = 20 } | Should -Throw -ErrorId 'ExceptionWhenSetting'
}
}

Expand All @@ -104,13 +84,7 @@ namespace Dummy
# This call should not throw exception
[C1]::f = 5
It 'Error when ValidateSet should be ExceptionWhenSetting'{
try {
[C1]::f = 20
throw "Exception expected"
}
catch {
$_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting'
}
{ [C1]::f = 20 } | Should -Throw -ErrorId 'ExceptionWhenSetting'
}
}

Expand All @@ -120,13 +94,7 @@ namespace Dummy
[C1]::o = "abc"
[C1]::o = 5
It 'Error when ValidateSet should be ExceptionWhenSetting'{
try {
[C1]::o = 1
throw "Exception expected"
}
catch {
$_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting'
}
{ [C1]::o = 1 } | Should -Throw -ErrorId 'ExceptionWhenSetting'
}
}

Expand All @@ -142,57 +110,51 @@ namespace Dummy

It 'Implicitly Transform to 100' {
$c.arg = 100
$c.arg | should be 100
$c.arg | Should -Be 100
}
It 'Implicitly Transform to foo' {
$c.arg = "foo"
$c.arg | should be "foofoo"
$c.arg | Should -BeExactly "foofoo"
}
}

Context 'Property.Instance.Transformation.String' {
$c = [scriptblock]::Create('class C1 { [Dummy.DoubleStringTransformation()][string]$arg }; [C1]::new()').Invoke()[0]
It 'set to foo' {
$c.arg = "foo"
$c.arg | should be "foofoo"
$c.arg | Should -BeExactly "foofoo"
}
}

Context Property.Instance.Transformation.Int {
$c = [scriptblock]::Create('class C1 { [Dummy.DoubleInt()][int]$arg }; [C1]::new()').Invoke()[0]
It 'arg should be 200' {
$c.arg = 100
$c.arg | should be 200
$c.arg | Should -Be 200
}
It 'Set to string should fail with ExceptionWhenSetting' {
try {
$c.arg = "abc"
throw "Exception expected"
}
catch {
$_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting'
}
{ $c.arg = "abc" } | Should -Throw -ErrorId 'ExceptionWhenSetting'
}
}

Context Property.Instance.Transformation.Nullable {
$c = [scriptblock]::Create('class C1 { [Nullable[int]][Dummy.DoubleStringTransformation()]$arg }; [C1]::new()').Invoke()[0]
It 'arg should be 100' {
$c.arg = 100
$c.arg | should be 100
$c.arg | Should -Be 100
}
}

Context Property.Instance.Transformation.Order {
$c = [scriptblock]::Create('class C1 { [Dummy.DoubleStringTransformation()][Dummy.AppendStringTransformation()]$arg }; [C1]::new()').Invoke()[0]
It 'arg should be 100' {
$c.arg = 100
$c.arg | should be 100
$c.arg | Should -Be 100
}

It 'arg should be foo___foo___g' {
$c.arg = "foo"
$c.arg | should be "foo___foo___"
$c.arg | Should -BeExactly "foo___foo___"
}
}
}
Expand All @@ -211,7 +173,7 @@ Describe 'Type resolution with attributes' -Tag "CI" {
[void] OnEvent([string]$Message) {}
}

[MyEventSource]::new() | Should Not Be $null
[MyEventSource]::new() | Should -Not -BeNullOrEmpty

}
}
Expand Down Expand Up @@ -302,14 +264,14 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
}

It 'Dynamically generated set works in C# with default (immediate) cache expire' {
Get-TestValidateSet4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1"
Get-TestValidateSet4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1"
}

It 'Empty dynamically generated set throws in C#' {
$exc = {
Get-TestValidateSet5 -Param1 "TestString1" -ErrorAction Stop
} | ShouldBeErrorId "ParameterArgumentValidationError,Test.Language.TestValidateSetCommand5"
$exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should BeExactly "ValidateSetGeneratedValidValuesListIsNull"
$exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should -BeExactly "ValidateSetGeneratedValidValuesListIsNull"
}
}

Expand Down Expand Up @@ -390,7 +352,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
}

It 'Dynamically generated set works in PowerShell script with default (immediate) cache expire' {
Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1"
Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1"
}

It 'Get the appropriate error message' {
Expand All @@ -401,7 +363,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
$exc = {
Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction Stop
} | ShouldBeErrorId "ParameterArgumentValidationError,Get-TestValidateSetPS5"
$exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should BeExactly "ValidateSetGeneratedValidValuesListIsNull"
$exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should -BeExactly "ValidateSetGeneratedValidValuesListIsNull"
}

It 'Unimplemented valid values generator type throws in PowerShell script' {
Expand Down Expand Up @@ -437,7 +399,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {

try {
Import-Module -Name $moduleFile -Force
Test-ValidateSet 'Hello' | Should Be 'Hello'
Test-ValidateSet 'Hello' | Should -BeExactly 'Hello'
} finally {
Remove-Module -Name $moduleFile -Force
}
Expand Down Expand Up @@ -502,14 +464,14 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
}

It 'Can implement CachedValidValuesGeneratorBase in PowerShell' {
Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1"
Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1"
}

It 'Can implement CachedValidValuesGeneratorBase with cache expiration in PowerShell' {
Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1"
Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1"
Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1"
Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1"
Start-Sleep 3
Get-TestValidateSetPS5 -Param1 "TestString2" -ErrorAction SilentlyContinue | Should BeExactly "TestString2"
Get-TestValidateSetPS5 -Param1 "TestString2" -ErrorAction SilentlyContinue | Should -BeExactly "TestString2"
}
}
}
Loading