Skip to content

Commit

Permalink
test: Add CSharp tests with Using module statement
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlydog committed Aug 17, 2023
1 parent 7804afc commit 2792bae
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
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; }
}
}
"@
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'
}
}
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'
}
}
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

0 comments on commit 2792bae

Please sign in to comment.