February 2019
Intermediate to advanced
626 pages
15h 51m
English
The New-MockObject command provides a way to create an uninitialized version of a type. An instance of an uninitialized type has all of the properties and methods of the initialized instance, but without any of the code behind and potentially without some default values.
It is possible to use New-MockObject to generate an instance of the sqlConnection object used in the previous example. As the object is uninitialized, errors are likely when attempting to use the methods that the type provides:
PS> $sqlConnection = New-MockObject System.Data.SqlClient.SqlConnectionPS> $sqlConnection.Open()Exception calling "Open" with "0" argument(s): "Object reference not set to an instance of an object."At line:1 char:1+ $sqlConnection.Open() ...
Read now
Unlock full access