2016-03-04 14:48:30 -08:00
|
|
|
Describe "New-Object" {
|
2015-07-15 10:15:39 -07:00
|
|
|
It "should create an object with 4 fields" {
|
2016-03-24 20:20:06 -07:00
|
|
|
$o = New-Object psobject
|
|
|
|
|
$val = $o.GetType()
|
2015-07-15 10:15:39 -07:00
|
|
|
|
2016-03-24 20:20:06 -07:00
|
|
|
$val.IsPublic | Should Not BeNullOrEmpty
|
|
|
|
|
$val.Name | Should Not BeNullOrEmpty
|
|
|
|
|
$val.IsSerializable | Should Not BeNullOrEmpty
|
|
|
|
|
$val.BaseType | Should Not BeNullOrEmpty
|
2015-07-15 10:15:39 -07:00
|
|
|
|
2016-03-24 20:20:06 -07:00
|
|
|
$val.IsPublic | Should Be $true
|
|
|
|
|
$val.IsSerializable | Should Be $false
|
|
|
|
|
$val.Name | Should Be 'PSCustomObject'
|
|
|
|
|
$val.BaseType | Should Be 'System.Object'
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
2016-03-22 19:58:34 -07:00
|
|
|
|
|
|
|
|
It "should create an object with using Property switch" {
|
2016-03-24 20:20:06 -07:00
|
|
|
$hash = @{
|
|
|
|
|
FirstVal = 'test1'
|
|
|
|
|
SecondVal = 'test2'
|
|
|
|
|
}
|
|
|
|
|
$o = New-Object psobject -Property $hash
|
2016-03-22 19:58:34 -07:00
|
|
|
|
2016-03-24 20:20:06 -07:00
|
|
|
$o.FirstVal | Should Be 'test1'
|
|
|
|
|
$o.SecondVal | Should Be 'test2'
|
2016-03-22 19:58:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "should create a .Net object with using ArgumentList switch" {
|
2016-03-24 20:20:06 -07:00
|
|
|
$o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4"
|
|
|
|
|
$o.GetType() | Should Be ([System.Version])
|
2016-03-22 19:58:34 -07:00
|
|
|
|
2016-03-24 20:20:06 -07:00
|
|
|
$o | Should Be "1.2.3.4"
|
2016-03-22 19:58:34 -07:00
|
|
|
}
|
2015-07-24 10:38:51 -07:00
|
|
|
}
|