Internal/Get-PsmTestContent.ps1

function Get-PsmTestContent {
  <#
    .Synopsis
      Get-PsmTestContent creates the test content
    .DESCRIPTION
      Get-PsmTestContent creates the test content
    .EXAMPLE
      Get-PsmTestContent Get-Something
      Get-PsmTestContent Get-Something -WhatIf
  #>
      
  [CmdletBinding(SupportsShouldProcess=$true)]  
  param (
    [Parameter(
      Mandatory=$true, 
      ValueFromPipeline=$true,  
      ValueFromPipelineByPropertyName=$true)]
    [string]$functionName,
    
    [Parameter(
      Mandatory=$true, 
      ValueFromPipeline=$true,  
      ValueFromPipelineByPropertyName=$true)]
    [string]$module

  )  

  BEGIN{
    Write-Verbose "Starting Get-PsmTestContent..."
  }#begin

  PROCESS{
    if ($psCmdlet.ShouldProcess(<# on target --> #>"$functionName", <# What if: Performing operation --> #>"Creating valid pester test syntax.")) { 
"`$moduleRoot = Resolve-Path `"`$PSScriptRoot\..`"
`$moduleName = Split-Path `$moduleRoot -Leaf
Import-Module `"`$moduleRoot\$module`"
 
Describe `"$functionName`" {
     
    Context 'When it is good...' {
        BeforeAll {
            Write-Host -for DarkGreen `"Setting up in Good-Context--BeforeAll`"
        }
 
        $functionName `"param-this`" `"param-that`"
        it `"should pass`" {
            $false | Should -be `$true
        }
 
        `$testCases = @(
            @{ file = `"jsonfile.json`"; data = (@{test = `"data`"; some = `"stuff`"} | ConvertTo-Json) }
            @{ file = `"csvfile.csv`"; data = `"top,row,2,1`" }
            @{ file = `"something.js`"; data = `"console.log('looky here');`" }
        )
 
        It `"$functionName <file> should create file`" -TestCases `$testCases {
            param (`$file, `$data)
            $functionName `$file `$data
            $false | Should -Be `$true
        }
    }
 
    Context 'When it is bad...' {
        BeforeAll {
          Write-Host -for DarkGreen `"Setting up in Bad-Context--BeforeAll`"
        }
        InModuleScope PSModuleBuilder {
            it `"should throw #1`" {
                { $functionName `"some-file.txt`" `"some text data...`" } | Should -Throw
            }
            it `"should throw #2`" {
                Mock Get-Something { }
                { $functionName `"some-file.txt`" `"some text data...`" } | Should -Throw
            }
            it `"should throw #3`" {
                Mock Confirm-IsInitializedModulePath { }
                Mock Import-CliXml -MockWith { @{ RootModule = `"SomeModule`" } }
                { $functionName `"some-file.txt`" `"some text data...`" } | Should -Throw
            }
        }
    }
 
    AfterAll {
        Write-Host `"Changing back to moduleRoot location: `$PSScriptRoot`"
        Set-Location `$PSScriptRoot
    }
}
"

    }
  }#process
  END{
    Write-Verbose "Finished Get-PsmTestContent..."
  }#end
}