Tests/Initialize-Psm.Tests.ps1

$moduleRoot = Resolve-Path "$PSScriptRoot\.."
$moduleName = Split-Path $moduleRoot -Leaf
Import-Module "$moduleRoot\PSModuleBuilder.psm1"

Describe "Initialize-Psm" -Tag "Unit" {
    
    Context 'When in an initialized module folder' {   
        BeforeAll { 
            Write-Host -for DarkGreen "In Describe BeforeAll" 
            
            Write-Verbose "Creating new directory Initialize"
            
            try {
                Remove-ItemIfExists "$PSScriptRoot\TestPester\Initialize" | Out-Null
            } catch {
                Write-Verbose "Deleting stuff..."
            }
            
            New-Item "$PSScriptRoot\TestPester\Initialize" -ItemType Directory -Force
            
            Write-Verbose "Changing location to Initialize"
            Set-Location "$PSScriptRoot\TestPester\Initialize"
        }

        Context "Initializing Psm..." {
            InModuleScope PSModuleBuilder {
                
                $parentFolder = (Get-Location).path.split("\")[-1]
                $prefix = $parentFolder.Substring(0,3)
                $version = "0.0.0"
                $user = $env:UserName
                $copyright = "(c) $((Get-Date).Year)..."
                $description = "Really good module..."
                $tags = "hello goodbye"
                $projectUri = "https://somesite.com" 
                
                $moduleFolders = @(
                    "Public",
                    "Internal",
                    "Tests",
                    "Data",
                    "Module-Start",
                    "Module-Stop",
                    "Module-Test"
                )

                $moduleFolders | Foreach-Object {
                    "$PsScriptRoot\TestPester\Initialize\$_" | Should -Not -Exist
                }

                Initialize-Psm -y

                $moduleFolders | Foreach-Object {
                    "$PsScriptRoot\TestPester\Initialize\$_" | Should -Exist
                }

                it "should have a package xml file" {
                    "$PSScriptRoot\TestPester\Initialize\module-psd1.xml" | Should -Exist
                }
                
                $packageXml = Import-Clixml "$PSScriptRoot\TestPester\Initialize\module-psd1.xml"
                
                it "should have props --- ModuleName == $parentFolder" {
                    $packageXml.ModuleName | Should -Be "$parentFolder"
                }
                it "should have props --- RootModule == $parentFolder.psm1" {
                    $packageXml.RootModule | Should -Be "$parentFolder.psm1"
                }
                it "should have props --- DefaultCommandPrefix == $prefix" {
                    $packageXml.DefaultCommandPrefix | Should -Be "$prefix"
                }
                it "should have props --- ModuleVersion == $version" {
                    $packageXml.ModuleVersion | Should -Be "$version"
                }
                it "should have props --- Author == $user" {
                    $packageXml.Author | Should -Be "$user"
                }
                it "should have props --- Copyright == $copyright" {
                    $packageXml.Copyright | Should -Be "$copyright"
                }
                it "should have props --- CompanyName == $company" {
                    $packageXml.CompanyName | Should -BeNullOrEmpty
                }
                it "should have props --- Tags == $tags" {
                    $packageXml.Tags | Should -BeNullOrEmpty
                }
                it "should have props --- ProjectUri == $projectUri" {
                    $packageXml.ProjectUri | Should -BeNullOrEmpty
                }
            }
        }
    }

    AfterAll {
        Write-Host "Changing back to moduleRoot: $PSScriptRoot"
        Set-Location $PSScriptRoot
    }
}