Skip to content

Commit 946e02d

Browse files
committed
Move Test-Command and Remove unrequired Test Helper functions
1 parent 1c0140d commit 946e02d

6 files changed

Lines changed: 36 additions & 91 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- TimeZone:
66
- Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone)
77
and renamed to TimeZone - fixes [Issue #157](https://github.com/PowerShell/ComputerManagementDsc/issues/157).
8+
- Moved Test-Command from ComputerManagementDsc.ResourceHelper to
9+
ComputerManagementDsc.Common module to match what TimeZone requires.
10+
It was not exported in ComputerManagementDsc.ResourceHelper and not
11+
used.
812

913
## 5.0.0.0
1014

Modules/ComputerManagementDsc/Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,34 @@ function Test-DscObjectHasProperty
310310
return $false
311311
}
312312

313+
<#
314+
.SYNOPSIS
315+
This function tests if a cmdlet exists.
316+
317+
.PARAMETER Name
318+
The name of the cmdlet to check for.
319+
320+
.PARAMETER Module
321+
The module containing the command.
322+
#>
323+
function Test-Command
324+
{
325+
[CmdletBinding()]
326+
[OutputType([System.Boolean])]
327+
param
328+
(
329+
[Parameter(Mandatory = $true)]
330+
[System.String]
331+
$Name,
332+
333+
[Parameter(Mandatory = $true)]
334+
[System.String]
335+
$Module
336+
)
337+
338+
return ($null -ne (Get-Command @PSBoundParameters -ErrorAction SilentlyContinue))
339+
} # function Test-Command
340+
313341
<#
314342
.SYNOPSIS
315343
Get the of the current time zone Id.
@@ -458,6 +486,7 @@ function Set-TimeZoneUsingDotNet
458486
Export-ModuleMember -Function `
459487
Test-DscParameterState, `
460488
Test-DscObjectHasProperty, `
489+
Test-Command, `
461490
Get-TimeZoneId, `
462491
Test-TimeZoneId, `
463492
Set-TimeZoneId, `

Modules/ComputerManagementDsc/Modules/ComputerManagementDsc.ResourceHelper/ComputerManagementDsc.ResourceHelper.psm1

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
<#
2-
.SYNOPSIS
3-
Tests if the specified command can be found.
4-
5-
.PARAMETER name
6-
The name of the command to test.
7-
#>
8-
function Test-Command
9-
{
10-
param
11-
(
12-
[String] $Name
13-
)
14-
15-
return ($null -ne (Get-Command -Name $Name -ErrorAction Continue 2> $null))
16-
}
17-
181
<#
192
.SYNOPSIS
203
Tests if the current machine is a Nano server.
@@ -167,7 +150,6 @@ function Get-LocalizedData
167150
}
168151

169152
Export-ModuleMember -Function `
170-
Test-Command, `
171153
Test-IsNanoServer, `
172154
New-InvalidArgumentException, `
173155
New-InvalidOperationException, `

Tests/Integration/MSFT_ScheduledTask.Integration.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ try
149149
It 'Should compile the MOF without throwing in W. Australia Standard Time Timezone' {
150150
{
151151

152-
Set-TimeZoneId -Id 'W. Australia Standard Time'
152+
Set-TimeZoneId -TimeZoneId 'W. Australia Standard Time'
153153
. $currentConfig `
154154
-OutputPath $configDir
155155
} | Should -Not -Throw
156156
}
157157

158158
It 'Should apply the MOF correctly in New Zealand Standard Time Timezone' {
159159
{
160-
Set-TimeZoneId -Id 'New Zealand Standard Time'
160+
Set-TimeZoneId -TimeZoneId 'New Zealand Standard Time'
161161
Start-DscConfiguration `
162162
-Path $configDir `
163163
-Wait `
@@ -190,7 +190,7 @@ try
190190
}
191191

192192
AfterAll {
193-
Set-TimeZoneId -Id $currentTimeZoneId
193+
Set-TimeZoneId -TimeZoneId $currentTimeZoneId
194194
}
195195
}
196196

Tests/TestHelpers/CommonTestHelper.psm1

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -81,58 +81,6 @@ function Get-InvalidOperationRecord
8181
return New-Object @newObjectParams
8282
}
8383

84-
<#
85-
.SYNOPSIS
86-
Returns the current Time Zone. This method is used because the
87-
Get-TimeZone cmdlet is not available on OS versions prior to
88-
Windows 10/Windows Server 2016.
89-
#>
90-
function Get-TimeZoneId
91-
{
92-
[CmdletBinding()]
93-
param()
94-
95-
$TimeZone = (Get-CimInstance `
96-
-ClassName WIN32_TimeZone `
97-
-Namespace root\cimv2).StandardName
98-
99-
$timeZoneInfo = [System.TimeZoneInfo]::GetSystemTimeZones() |
100-
Where-Object StandardName -eq $TimeZone
101-
102-
return $timeZoneInfo.Id
103-
} # function Get-TimeZoneId
104-
105-
<#
106-
.SYNOPSIS
107-
Set the current Time Zone. This method is used because the
108-
Set-TimeZone cmdlet is not available on OS versions prior to
109-
Windows 10/Windows Server 2016.
110-
111-
.PARAMETER Id
112-
The Id of the TimeZone to set the system to.
113-
#>
114-
function Set-TimeZoneId
115-
{
116-
[CmdletBinding()]
117-
param(
118-
[Parameter(Mandatory = $true)]
119-
[System.String]
120-
$Id
121-
)
122-
123-
try
124-
{
125-
& tzutil.exe @('/s',$Id)
126-
}
127-
catch
128-
{
129-
$ErrorMsg = $_.Exception.Message
130-
Write-Verbose -Message $ErrorMsg
131-
} # try
132-
} # function Set-TimeZoneId
133-
13484
Export-ModuleMember -Function `
135-
Get-TimeZoneId, `
136-
Set-TimeZoneId, `
13785
Get-InvalidArgumentRecord, `
13886
Get-InvalidOperationRecord

Tests/Unit/ComputerManagementDsc.Common.Tests.ps1

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ try
445445
Context '"Get-TimeZone" not available and current timezone is set to "Pacific Standard Time"' {
446446
Mock `
447447
-CommandName Get-Command `
448-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
449448
-ParameterFilter {
450449
$Name -eq 'Get-TimeZone'
451450
}
@@ -463,7 +462,6 @@ try
463462
It 'Should call expected mocks' {
464463
Assert-MockCalled `
465464
-CommandName Get-Command `
466-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
467465
-ParameterFilter {
468466
$Name -eq 'Get-TimeZone'
469467
} -Exactly -Times 1
@@ -475,7 +473,6 @@ try
475473
Context '"Get-TimeZone" not available and current timezone is set to "Russia TZ 11 Standard Time"' {
476474
Mock `
477475
-CommandName Get-Command `
478-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
479476
-ParameterFilter {
480477
$Name -eq 'Get-TimeZone'
481478
}
@@ -493,7 +490,6 @@ try
493490
It 'Should call expected mocks' {
494491
Assert-MockCalled `
495492
-CommandName Get-Command `
496-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
497493
-ParameterFilter {
498494
$Name -eq 'Get-TimeZone'
499495
} -Exactly -Times 1
@@ -509,7 +505,6 @@ try
509505

510506
Mock `
511507
-CommandName Get-Command `
512-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
513508
-ParameterFilter {
514509
$Name -eq 'Get-TimeZone'
515510
} -MockWith {
@@ -531,7 +526,6 @@ try
531526
It 'Should call expected mocks' {
532527
Assert-MockCalled `
533528
-CommandName Get-Command `
534-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
535529
-ParameterFilter {
536530
$Name -eq 'Get-TimeZone'
537531
} -Exactly -Times 1
@@ -563,14 +557,12 @@ try
563557
Context '"Set-TimeZone" and "Add-Type" is not available, Tzutil Returns 0' {
564558
Mock `
565559
-CommandName Get-Command `
566-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
567560
-ParameterFilter {
568561
$Name -eq 'Add-Type'
569562
}
570563

571564
Mock `
572565
-CommandName Get-Command `
573-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
574566
-ParameterFilter {
575567
$Name -eq 'Set-TimeZone'
576568
}
@@ -589,14 +581,12 @@ try
589581
It 'Should call expected mocks' {
590582
Assert-MockCalled `
591583
-CommandName Get-Command `
592-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
593584
-ParameterFilter {
594585
$Name -eq 'Add-Type'
595586
} -Exactly -Times 1
596587

597588
Assert-MockCalled `
598589
-CommandName Get-Command `
599-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
600590
-ParameterFilter {
601591
$Name -eq 'Set-TimeZone'
602592
} -Exactly -Times 1
@@ -609,7 +599,6 @@ try
609599
Context '"Set-TimeZone" is not available but "Add-Type" is available' {
610600
Mock `
611601
-CommandName Get-Command `
612-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
613602
-ParameterFilter {
614603
$Name -eq 'Add-Type'
615604
} -MockWith {
@@ -618,7 +607,6 @@ try
618607

619608
Mock `
620609
-CommandName Get-Command `
621-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
622610
-ParameterFilter {
623611
$Name -eq 'Set-TimeZone'
624612
}
@@ -638,14 +626,12 @@ try
638626
It 'Should call expected mocks' {
639627
Assert-MockCalled `
640628
-CommandName Get-Command `
641-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
642629
-ParameterFilter {
643630
$Name -eq 'Add-Type'
644631
} -Exactly -Times 1
645632

646633
Assert-MockCalled `
647634
-CommandName Get-Command `
648-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
649635
-ParameterFilter {
650636
$Name -eq 'Set-TimeZone'
651637
} -Exactly -Times 1
@@ -668,14 +654,12 @@ try
668654

669655
Mock `
670656
-CommandName Get-Command `
671-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
672657
-ParameterFilter {
673658
$Name -eq 'Add-Type'
674659
}
675660

676661
Mock `
677662
-CommandName Get-Command `
678-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
679663
-ParameterFilter {
680664
$Name -eq 'Set-TimeZone'
681665
} -MockWith {
@@ -691,14 +675,12 @@ try
691675
It 'Should call expected mocks' {
692676
Assert-MockCalled `
693677
-CommandName Get-Command `
694-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
695678
-ParameterFilter {
696679
$Name -eq 'Add-Type'
697680
} -Exactly -Times 0
698681

699682
Assert-MockCalled `
700683
-CommandName Get-Command `
701-
-ModuleName 'ComputerManagementDsc.ResourceHelper' `
702684
-ParameterFilter {
703685
$Name -eq 'Set-TimeZone'
704686
} -Exactly -Times 1

0 commit comments

Comments
 (0)