MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "New-TimeSpan DRT Unit Tests" -Tags "CI" {4 5 It "Should works proper with new-timespan"{6 $results = New-TimeSpan -Days 10 -Hours 10 -Minutes 10 -Seconds 10 -Milliseconds 107 $results | Should -BeOfType System.Timespan8 $results.Days | Should -Be 109 $results.Hours | Should -Be 1010 $results.Minutes | Should -Be 1011 $results.Seconds | Should -Be 1012 $results.Milliseconds | Should -Be 1013 }14}15 16Describe "New-TimeSpan" -Tags "CI" {17 18 It "Should be able to create a new timespan object" {19 New-Variable -Name testObject -Value $(New-TimeSpan)20 $testObject | Should -BeOfType System.Timespan21 }22 23 Context "Core Functionality Tests" {24 New-Variable -Name testObject -Value $(New-TimeSpan -Days 2 -Hours 23 -Minutes 4 -Seconds 3 -Milliseconds 2) -Force25 26 $expectedOutput = @{ "Days" = "2";27 "Hours" = "23";28 "Minutes" = "4";29 "Seconds" = "3";30 "Milliseconds" = "2";31 "Ticks" = "2558430020000";32 "TotalDays" = "2.96114585648148";33 "TotalHours" = "71.0675005555556";34 "TotalMinutes" = "4264.05003333333";35 "TotalSeconds" = "255843.002";36 "TotalMilliseconds" = "255843002"37 }38 39 $TEN_MILLION = 1000000040 41 It "Should have expected values for time properties set during creation" {42 $testObject.Days | Should -Be $expectedOutput["Days"]43 $testObject.Hours | Should -Be $expectedOutput["Hours"]44 $testObject.Minutes | Should -Be $expectedOutput["Minutes"]45 $testObject.Seconds | Should -Be $expectedOutput["Seconds"]46 $testObject.Milliseconds | Should -Be $expectedOutput["Milliseconds"]47 $testObject.Ticks | Should -Be $expectedOutput["Ticks"]48 }49 50 }51 52 It "Should have matching output when using the Start switch vs piping from another cmdlet" {53 # this file is guaranteed to exist54 $inputObject = (Get-ChildItem $PSScriptRoot/New-TimeSpan.Tests.ps1)55 $inputParameter = New-TimeSpan -Start $inputObject.lastwritetime56 $pipedInput = $inputObject | New-TimeSpan57 58 $difference = [math]::Abs($inputParameter.Milliseconds - $pipedInput.Milliseconds)59 # The difference between commands should be minimal60 $difference | Should -BeLessThan 10061 }62}63 