1- $CommandName = $MyInvocation.MyCommand.Name.Replace (" .Tests.ps1" , " " )
2- Write-Host - Object " Running $PSCommandPath " - ForegroundColor Cyan
3- $global :TestConfig = Get-TestConfig
4- . " $PSScriptRoot \..\private\functions\Get-DirectoryRestoreFile.ps1"
1+ # Requires -Module @ { ModuleName = " Pester" ; ModuleVersion = " 5.0" }
2+ param (
3+ $ModuleName = " dbatools" ,
4+ $CommandName = " Get-ObjectNameParts" ,
5+ $PSDefaultParameterValues = $TestConfig.Defaults
6+ )
57
6- Describe " $CommandName Unit Tests" - Tag ' UnitTests' {
7- Context " Validate parameters" {
8- [object []]$params = (Get-Command $CommandName ).Parameters.Keys | Where-Object { $_ -notin (' whatif' , ' confirm' ) }
9- [object []]$knownParameters = ' ObjectName'
10- It " Should only contain our specific parameters" {
11- (@ (Compare-Object - ReferenceObject ($knownParameters | Where-Object { $_ }) - DifferenceObject $params ).Count ) | Should Be 0
8+ . " $PSScriptRoot \..\private\functions\Get-ObjectNameParts.ps1"
9+
10+ Describe $CommandName - Tag UnitTests {
11+ Context ' Parameter validation' {
12+ BeforeAll {
13+ $command = Get-Command $CommandName
14+ $hasParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin (' whatif' , ' confirm' ) }
15+ $expectedParameters = @ (
16+ ' ObjectName'
17+ )
18+ }
19+
20+ It ' Should have the expected parameters' {
21+ Compare-Object - ReferenceObject $expectedParameters - DifferenceObject $hasParameters | Should - BeNullOrEmpty
1222 }
1323 }
1424}
1525
16- Describe " $CommandName Integration Tests " - Tag ' IntegrationTests' {
17- Context " Test one part names" {
18- It " Should return correct parts" {
26+ Describe $CommandName - Tag IntegrationTests {
27+ Context ' Test one part names' {
28+ It ' Should return correct parts' {
1929 $objectName = ' table1' , ' [table2]' , ' [tab..le3]' , ' [table]]x4]' , ' [table5]]]'
20- $table = ' table1' , ' table2' , ' tab..le3' , ' table]] x4' , ' table5] ]'
21- for ($i = 0 ; $i -lt $input .Count ; $i ++ ) {
30+ $table = ' table1' , ' table2' , ' tab..le3' , ' table]x4' , ' table5]'
31+ for ($i = 0 ; $i -lt $objectName .Count ; $i ++ ) {
2232 $result = Get-ObjectNameParts - ObjectName $objectName [$i ]
23- $result.Parsed | Should Be $true
24- $result.Database | Should Be $null
25- $result.Schema | Should Be $null
26- $result.Name | Should Be $table [$i ]
33+ $result.Parsed | Should - Be $true
34+ $result.Database | Should - BeNull
35+ $result.Schema | Should - BeNull
36+ $result.Name | Should - Be $table [$i ]
2737 }
2838 }
2939 }
30- Context " Test two part names" {
31- It " Should return correct parts" {
32- $objectName = ' schema1.table1' , ' [sche..ma2].[table2]' , ' schema3 .[tab..le3]' , ' [schema4].[table]]x4]' , ' schema5.[table5]]]'
33- $table = ' table1' , ' table2' , ' tab..le3' , ' table]] x4' , ' table5] ]'
40+ Context ' Test two part names' {
41+ It ' Should return correct parts' {
42+ $objectName = ' schema1.table1' , ' [sche..ma2].[table2]' , ' [sche ma3] .[tab..le3]' , ' [schema4].[table]]x4]' , ' schema5.[table5]]]'
43+ $table = ' table1' , ' table2' , ' tab..le3' , ' table]x4' , ' table5]'
3444 $schema = ' schema1' , ' sche..ma2' , ' sche ma3' , ' schema4' , ' schema5'
35- for ($i = 0 ; $i -lt $input .Count ; $i ++ ) {
45+ for ($i = 0 ; $i -lt $objectName .Count ; $i ++ ) {
3646 $result = Get-ObjectNameParts - ObjectName $objectName [$i ]
37- $result.Parsed | Should Be $true
38- $result.Database | Should Be $null
39- $result.Schema | Should Be $schema [$i ]
40- $result.Name | Should Be $table [$i ]
47+ $result.Parsed | Should - Be $true
48+ $result.Database | Should - BeNull
49+ $result.Schema | Should - Be $schema [$i ]
50+ $result.Name | Should - Be $table [$i ]
4151 }
4252 }
4353 }
44- Context " Test three part names" {
45- It " Should return correct parts" {
54+ Context ' Test three part names' {
55+ It ' Should return correct parts' {
4656 $objectName = ' database1.schema1.table1' , ' database2..table2' , ' database3..[tab..le3]' , ' db4.[sche..ma4].table4'
4757 $table = ' table1' , ' table2' , ' tab..le3' , ' table4'
4858 $schema = ' schema1' , $null , $null , ' sche..ma4'
4959 $database = ' database1' , ' database2' , ' database3' , ' db4'
50- for ($i = 0 ; $i -lt $input .Count ; $i ++ ) {
60+ for ($i = 0 ; $i -lt $objectName .Count ; $i ++ ) {
5161 $result = Get-ObjectNameParts - ObjectName $objectName [$i ]
52- $result.Parsed | Should Be $true
53- $result.Database | Should Be $database [$i ]
54- $result.Schema | Should Be $schema [$i ]
55- $result.Name | Should Be $table [$i ]
62+ $result.Parsed | Should - Be $true
63+ $result.Database | Should - Be $database [$i ]
64+ $result.Schema | Should - Be $schema [$i ]
65+ $result.Name | Should - Be $table [$i ]
5666 }
5767 }
5868 }
59- Context " Test wrong names" {
60- It " Should not return parts for 'part1.part2.part3.part4'" {
61- (Get-ObjectNameParts - ObjectName ' part1.part2.part3.part4' ).Parsed | Should Be $false
69+ Context ' Test wrong names' {
70+ It ' Should not return parts for '' part1.part2.part3.part4'' ' {
71+ (Get-ObjectNameParts - ObjectName ' part1.part2.part3.part4' ).Parsed | Should - Be $false
6272 }
6373 }
6474}
0 commit comments