As powershell keeps gaining popularity in the Microsoft world, it’s became a common task to define the build process in a PS scripts.
One example for such use is in the new vNext scriptable build. In each vNext task the build parameters are delegated from the UI (task.json) to the powershell script where they are validated, processed and eventually are passed to the appropriate executable.
While TFS, Nant, MSBuild… have custom Typemock actions that are provided, powershell users can benefit powershell’s ability to use .Net assemblies to call Typemock code directly.
In order to incorporate Typemock into any type of build, 3 actions need to be performed:
- Register – In case Typemock is not Installed on the build machine (AutoDeploy).
- Start – Typemock is to be turned on before tests execution.
- Stop – Typemock is to be shut down after tests execution.
To run these 3 we’ll need to load Typemock.CLI.Common.dll and use the classes RegisterInfo, StartInfo and StopInfo, respectively. Each of these classes has an execute method that should be called to start the action.
That’s how the script should look like:
# Load Typemock Assemblies
$CLICommon = "$ScriptRoot\AutoDeploy\TypeMock.CLI.Common.dll"
$Configuration = "$ScriptRoot\AutoDeploy\Configuration.dll"
$Integration = "$ScriptRoot\AutoDeploy\TypeMock.Integration.dll"
$RegisterInfo = new-object TypeMock.CLI.Common.TypeMockRegisterInfo
$RegisterInfo.AutoDeploy = $autoDeployEnabled -eq 'True'
$RegisterInfo.IsolatorRootDirectory = ".\AutoDeploy"
$RegisterInfo.Company = $licenseName
$RegisterInfo.License = $licenseKey
$StartInfo = new-object TypeMock.CLI.Common.TypeMockStartInfo
$StopInfo = new-object TypeMock.CLI.Common.TypeMockStopInfo
The full script will be available as part of the installation in the upcoming release.