Skip to content

Commit 66552a4

Browse files
SteveL-MSFTdaxian-dbw
authored andcommitted
Add CDXML CIM DateTime test (PowerShell#4796)
1 parent af798fb commit 66552a4

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

test/powershell/engine/Cdxml/Cdxml.Tests.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Describe "Cdxml cmdlets are supported" -Tag CI,RequireAdminOnWindows {
4343
if ( Test-CimTestInstance ) {
4444
Get-CimInstance @CimCmdletArgs | Remove-CimInstance
4545
}
46-
# if there's a failure with mofcomp then we will have trouble
46+
# if there's a failure with mofcomp then we will have trouble
4747
# executing the tests. Keep track of the exit code
4848
$result = MofComp.exe $deleteMof
4949
$script:MofCompReturnCode = $LASTEXITCODE
@@ -55,7 +55,14 @@ Describe "Cdxml cmdlets are supported" -Tag CI,RequireAdminOnWindows {
5555
# create the class and instances
5656
# and track the exitcode for the compilation of the mof file
5757
# if there's a problem, there's no reason to keep going
58-
$result = MofComp.exe ${script:createMof}
58+
$testMof = Get-Content -Path ${script:createmof} -Raw
59+
$currentTimeZone = [System.TimeZoneInfo]::Local
60+
61+
# this date is simply the same one used in the test mof
62+
$UTCOffset = ($currentTimeZone.GetUtcOffset([datetime]::new(2008, 01, 01, 0, 0, 0))).TotalMinutes.ToString()
63+
$testMof = $testMof.Replace("<UTCOffSet>", $UTCOffset)
64+
Set-Content -Path $testDrive\testmof.mof -Value $testMof
65+
$result = MofComp.exe $testDrive\testmof.mof
5966
$script:MofCompReturnCode = $LASTEXITCODE
6067
if ( $script:MofCompReturnCode -ne 0 ) {
6168
return
@@ -119,6 +126,12 @@ Describe "Cdxml cmdlets are supported" -Tag CI,RequireAdminOnWindows {
119126
( $result.id | sort-object ) -join "," | Should be "1,2,4"
120127
}
121128

129+
It "The Get-CimTest cmdlet should retrieve an object by datetime" @ItSkipOrPending {
130+
$result = Get-CimTest -DateTime ([datetime]::new(2008,01,01,0,0,0))
131+
@($result).Count | Should Be 1
132+
$result.field1 | Should Be "instance 1"
133+
}
134+
122135
It "The Get-CimTest cmdlet should return the proper error if the instance does not exist" @ItSkipOrPending {
123136
{ Get-CimTest -ea stop -id "ThisIdDoesNotExist" } | ShouldBeErrorId "CmdletizationQuery_NotFound_Id,Get-CimTest"
124137
}

test/powershell/engine/Cdxml/assets/CimTest/CimTest.cdxml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
<CmdletParameterMetadata ValueFromPipelineByPropertyName="true" CmdletParameterSets="Id" />
1919
</RegularQuery>
2020
</Property>
21+
<Property PropertyName="DateTime">
22+
<Type PSType="System.DateTime" />
23+
<RegularQuery>
24+
<CmdletParameterMetadata PSName="DateTime" ValueFromPipelineByPropertyName="false" CmdletParameterSets="DateTime" />
25+
</RegularQuery>
26+
</Property>
2127
</QueryableProperties>
2228
</GetCmdletParameters>
2329

test/powershell/engine/Cdxml/assets/CimTest/CreateCimTest.mof

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class PSCore_Test1
3232
[key] string id;
3333
string field1;
3434
sint32 field2;
35+
datetime datetime;
3536
PSCore_subclass subclass;
3637
};
3738

@@ -40,6 +41,7 @@ instance of PSCore_Test1
4041
id = "1";
4142
field1 = "instance 1";
4243
field2 = -1;
44+
datetime = "20080101000000.000000<UTCOffSet>";
4345
subclass = instance of PSCore_subclass{Id="10";subfield1="yup";subfield2=200;};
4446
};
4547

0 commit comments

Comments
 (0)