generated from deadlydog/Template.NewGitRepo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add CSharp tests with Using module statement
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...sInSeparateFileIncludedWithUsing/Classes/MyCSharpClassInSeparateFileIncludedWithUsing.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Add-Type -Language CSharp -TypeDefinition @" | ||
namespace MyNamespace { | ||
public enum MyCSharpEnumInSeparateFileIncludedWithUsing | ||
{ | ||
One, | ||
Two | ||
} | ||
public class MyCSharpClassInSeparateFileIncludedWithUsing | ||
{ | ||
public MyCSharpEnumInSeparateFileIncludedWithUsing EnumValue { get; set; } | ||
} | ||
} | ||
"@ |
47 changes: 47 additions & 0 deletions
47
...udedWithUsing/ModuleWithCSharpClassInSeparateFileIncludedWithUsing.ImportModule.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
BeforeAll { | ||
Import-Module "$PSScriptRoot\ModuleWithCSharpClassInSeparateFileIncludedWithUsing.psm1" | ||
} | ||
|
||
Describe 'Module' { | ||
It 'Should return a new class instance without error' { | ||
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsing | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should allow using the class type explicitly' { | ||
$instance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new() | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should allow using the class type implicitly as a function parameter' { | ||
$implicitInstance = Get-MyCSharpClassInSeparateFileIncludedWithUsing | ||
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $implicitInstance | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should allow using the class type explicitly as a function parameter' { | ||
$explicitInstance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new() | ||
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $explicitInstance | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should return a new enum instance without error' { | ||
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsing | ||
$enumValue | Should -Be 'One' | ||
} | ||
|
||
It 'Should allow using the enum type explicitly' { | ||
$enumValue = [MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One | ||
$enumValue | Should -Be 'One' | ||
} | ||
|
||
It 'Should allow using the full enum type as a function parameter' { | ||
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue ([MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One) | ||
$enumValue | Should -Be 'One' | ||
} | ||
|
||
It 'Should allow using the enum string value as a function parameter' { | ||
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue One | ||
$enumValue | Should -Be 'One' | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ludedWithUsing/ModuleWithCSharpClassInSeparateFileIncludedWithUsing.UsingModule.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using module .\ModuleWithCSharpClassInSeparateFileIncludedWithUsing.psm1 | ||
|
||
Describe 'Module' { | ||
It 'Should return a new class instance without error' { | ||
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsing | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should allow using the class type explicitly' { | ||
$instance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new() | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should allow using the class type implicitly as a function parameter' { | ||
$implicitInstance = Get-MyCSharpClassInSeparateFileIncludedWithUsing | ||
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $implicitInstance | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should allow using the class type explicitly as a function parameter' { | ||
$explicitInstance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new() | ||
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $explicitInstance | ||
$instance | Should -Not -Be $null | ||
} | ||
|
||
It 'Should return a new enum instance without error' { | ||
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsing | ||
$enumValue | Should -Be 'One' | ||
} | ||
|
||
It 'Should allow using the enum type explicitly' { | ||
$enumValue = [MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One | ||
$enumValue | Should -Be 'One' | ||
} | ||
|
||
It 'Should allow using the full enum type as a function parameter' { | ||
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue ([MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One) | ||
$enumValue | Should -Be 'One' | ||
} | ||
|
||
It 'Should allow using the enum string value as a function parameter' { | ||
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue One | ||
$enumValue | Should -Be 'One' | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...InSeparateFileIncludedWithUsing/ModuleWithCSharpClassInSeparateFileIncludedWithUsing.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using module .\Classes\MyCSharpClassInSeparateFileIncludedWithUsing.ps1 | ||
|
||
function Get-MyCSharpClassInSeparateFileIncludedWithUsing | ||
{ | ||
return [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new() | ||
} | ||
|
||
function Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter([MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing] $instance) | ||
{ | ||
return $instance | ||
} | ||
|
||
function Get-MyCSharpEnumInSeparateFileIncludedWithUsing | ||
{ | ||
return [MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One | ||
} | ||
|
||
function Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter([MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing] $enumValue) | ||
{ | ||
return $enumValue | ||
} | ||
|
||
Export-ModuleMember -Function Get-MyCSharpClassInSeparateFileIncludedWithUsing | ||
Export-ModuleMember -Function Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter | ||
Export-ModuleMember -Function Get-MyCSharpEnumInSeparateFileIncludedWithUsing | ||
Export-ModuleMember -Function Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter |