forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add New-MockObject function and export it from Pester
- Loading branch information
Showing
4 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe 'New-MockObject' { | ||
|
||
it 'instantiates an object from a class with no public constructors' { | ||
$type = 'Microsoft.PowerShell.Commands.Language' | ||
New-MockObject -Type $type | should beoftype $type | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function New-MockObject { | ||
<# | ||
.SYNOPSIS | ||
This function instantiates a .NET object from a type. The assembly for the particular type must be | ||
loaded. | ||
.PARAMETER Type | ||
The .NET type to create an object from. | ||
.EXAMPLE | ||
PS> $obj = New-MockObject -Type 'System.Diagnostics.Process' | ||
PS> $obj.GetType().FullName | ||
System.Diagnostics.Process | ||
#> | ||
|
||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[type]$Type | ||
) | ||
|
||
[System.Runtime.Serialization.Formatterservices]::GetUninitializedObject($Type) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters