Skip to content

Commit 2792bae

Browse files
committed
test: Add CSharp tests with Using module statement
1 parent 7804afc commit 2792bae

4 files changed

+132
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Add-Type -Language CSharp -TypeDefinition @"
2+
namespace MyNamespace {
3+
public enum MyCSharpEnumInSeparateFileIncludedWithUsing
4+
{
5+
One,
6+
Two
7+
}
8+
9+
public class MyCSharpClassInSeparateFileIncludedWithUsing
10+
{
11+
public MyCSharpEnumInSeparateFileIncludedWithUsing EnumValue { get; set; }
12+
}
13+
}
14+
"@
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
BeforeAll {
2+
Import-Module "$PSScriptRoot\ModuleWithCSharpClassInSeparateFileIncludedWithUsing.psm1"
3+
}
4+
5+
Describe 'Module' {
6+
It 'Should return a new class instance without error' {
7+
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsing
8+
$instance | Should -Not -Be $null
9+
}
10+
11+
It 'Should allow using the class type explicitly' {
12+
$instance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new()
13+
$instance | Should -Not -Be $null
14+
}
15+
16+
It 'Should allow using the class type implicitly as a function parameter' {
17+
$implicitInstance = Get-MyCSharpClassInSeparateFileIncludedWithUsing
18+
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $implicitInstance
19+
$instance | Should -Not -Be $null
20+
}
21+
22+
It 'Should allow using the class type explicitly as a function parameter' {
23+
$explicitInstance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new()
24+
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $explicitInstance
25+
$instance | Should -Not -Be $null
26+
}
27+
28+
It 'Should return a new enum instance without error' {
29+
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsing
30+
$enumValue | Should -Be 'One'
31+
}
32+
33+
It 'Should allow using the enum type explicitly' {
34+
$enumValue = [MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One
35+
$enumValue | Should -Be 'One'
36+
}
37+
38+
It 'Should allow using the full enum type as a function parameter' {
39+
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue ([MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One)
40+
$enumValue | Should -Be 'One'
41+
}
42+
43+
It 'Should allow using the enum string value as a function parameter' {
44+
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue One
45+
$enumValue | Should -Be 'One'
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using module .\ModuleWithCSharpClassInSeparateFileIncludedWithUsing.psm1
2+
3+
Describe 'Module' {
4+
It 'Should return a new class instance without error' {
5+
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsing
6+
$instance | Should -Not -Be $null
7+
}
8+
9+
It 'Should allow using the class type explicitly' {
10+
$instance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new()
11+
$instance | Should -Not -Be $null
12+
}
13+
14+
It 'Should allow using the class type implicitly as a function parameter' {
15+
$implicitInstance = Get-MyCSharpClassInSeparateFileIncludedWithUsing
16+
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $implicitInstance
17+
$instance | Should -Not -Be $null
18+
}
19+
20+
It 'Should allow using the class type explicitly as a function parameter' {
21+
$explicitInstance = [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new()
22+
$instance = Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter -instance $explicitInstance
23+
$instance | Should -Not -Be $null
24+
}
25+
26+
It 'Should return a new enum instance without error' {
27+
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsing
28+
$enumValue | Should -Be 'One'
29+
}
30+
31+
It 'Should allow using the enum type explicitly' {
32+
$enumValue = [MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One
33+
$enumValue | Should -Be 'One'
34+
}
35+
36+
It 'Should allow using the full enum type as a function parameter' {
37+
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue ([MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One)
38+
$enumValue | Should -Be 'One'
39+
}
40+
41+
It 'Should allow using the enum string value as a function parameter' {
42+
$enumValue = Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter -enumValue One
43+
$enumValue | Should -Be 'One'
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using module .\Classes\MyCSharpClassInSeparateFileIncludedWithUsing.ps1
2+
3+
function Get-MyCSharpClassInSeparateFileIncludedWithUsing
4+
{
5+
return [MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing]::new()
6+
}
7+
8+
function Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter([MyNamespace.MyCSharpClassInSeparateFileIncludedWithUsing] $instance)
9+
{
10+
return $instance
11+
}
12+
13+
function Get-MyCSharpEnumInSeparateFileIncludedWithUsing
14+
{
15+
return [MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing]::One
16+
}
17+
18+
function Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter([MyNamespace.MyCSharpEnumInSeparateFileIncludedWithUsing] $enumValue)
19+
{
20+
return $enumValue
21+
}
22+
23+
Export-ModuleMember -Function Get-MyCSharpClassInSeparateFileIncludedWithUsing
24+
Export-ModuleMember -Function Get-MyCSharpClassInSeparateFileIncludedWithUsingWithParameter
25+
Export-ModuleMember -Function Get-MyCSharpEnumInSeparateFileIncludedWithUsing
26+
Export-ModuleMember -Function Get-MyCSharpEnumInSeparateFileIncludedWithUsingWithParameter

0 commit comments

Comments
 (0)