test/module/Get-MKModuleInfo.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using module ..\.\TestRunnerSupportModule.psm1

Describe "Test Get-MKModuleInfo" {
    BeforeAll {
        $TestSupportModule = [TestRunnerSupportModule]::new('MockModuleB')
    }
    
    AfterAll {
        $TestSupportModule.Teardown()
    }

    Context "Calling by 'ByPath' parameter set with path to directory" {
        $Results = Get-MKModuleInfo -Path $TestSupportModule.MockDirectoryPath

        It "Should return MKModuleInfo" {
            $Results.GetType().Name | Should -Be 'MKModuleInfo'
        }

        It "Should have MKModuleInfo instance set with expected values" {
            $Results.Path | Should -Be $TestSupportModule.MockDirectoryPath
            $Results.ManifestFilePath | Should -Be $TestSupportModule.MockManifestPath
            $Results.RootModuleFilePath | Should -Be $TestSupportModule.MockRootModulePath
            $Results.Version | Should -Be '0.0.1'
        }
    }

    Context "Calling by 'ByPath' parameter set with path to manifest file" {
        $Results = Get-MKModuleInfo -Path $TestSupportModule.MockManifestPath

        It "Should return MKModuleInfo" {
            $Results.GetType().Name | Should -Be 'MKModuleInfo'
        }

        It "Should have MKModuleInfo instance set with expected values" {
            $Results.Path | Should -Be $TestSupportModule.MockDirectoryPath
            $Results.ManifestFilePath | Should -Be $TestSupportModule.MockManifestPath
            $Results.RootModuleFilePath | Should -Be $TestSupportModule.MockRootModulePath
            $Results.Version | Should -Be '0.0.1'
        }
    }

    Context "Calling by 'ByPath' parameter set with path to module file" {
        $Results = Get-MKModuleInfo -Path $TestSupportModule.MockRootModulePath

        It "Should return MKModuleInfo" {
            $Results.GetType().Name | Should -Be 'MKModuleInfo'
        }

        It "Should have MKModuleInfo instance set with expected values" {
            $Results.Path | Should -Be $TestSupportModule.MockDirectoryPath
            $Results.ManifestFilePath | Should -Be $TestSupportModule.MockManifestPath
            $Results.RootModuleFilePath | Should -Be $TestSupportModule.MockRootModulePath
            $Results.Version | Should -Be '0.0.1'
        }
    }

    Context "Calling by 'ByPath' with no value for any parameters" {
        Push-Location
        Set-Location $TestSupportModule.MockDirectoryPath

        $Results = Get-MKModuleInfo
        
        Pop-Location

        It "Should return MKModuleInfo" {
            $Results.GetType().Name | Should -Be 'MKModuleInfo'
        }

        It "Should have MKModuleInfo instance set with expected values" {
            $Results.Path | Should -Be $TestSupportModule.MockDirectoryPath
            $Results.ManifestFilePath | Should -Be $TestSupportModule.MockManifestPath
            $Results.RootModuleFilePath | Should -Be $TestSupportModule.MockRootModulePath
            $Results.Version | Should -Be '0.0.1'
        }
    }

    Context "Calling by 'ByName' parameter set with given name value 'MockModuleB'" {
        $Results = Get-MKModuleInfo -Name 'MockModuleB'

        It "Should return MKModuleInfo" {
            $Results.GetType().Name | Should -Be 'MKModuleInfo'
        }

        It "Should have MKModuleInfo instance set with expected values" {
            $Results.Path | Should -Be $TestSupportModule.MockDirectoryPath
            $Results.ManifestFilePath | Should -Be $TestSupportModule.MockManifestPath
            $Results.RootModuleFilePath | Should -Be $TestSupportModule.MockRootModulePath
            $Results.Version | Should -Be '0.0.1'
        }
    }
}