diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a62f23b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,14 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +#*.c text +#*.h text + +# Declare files that will always have CRLF line endings on checkout. +#*.sln text eol=crlf + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..da288fd --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [master] + pull_request: + branches: [master] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. diff --git a/.vscode/settings.json b/.vscode/settings.json index e706ec6..d699d89 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "igel", "igelos", "psigel" - ] + ], + "favorites.sortDirection": "ASC" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6ff8741 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# PSIGEL Changelog + +## v0.10.0 - 20200429 + +### Added + +* cross platform support (Windows, Linux, MacOS) +* support for Powershell 7 +* Remove-UMSAPICookie +* Site, Department, CostCenter, AssetID, InServiceDate and SerialNumber to Get-UMSDevice -Filter details +* support for Datatype Version in Get-UMSFirmware, Get-UMSStatus +* Get-UMSDirectoryRecursive + +### Changed + +* set minimum Powershell Requirement for the module to 5.1 +* SerialNumber Length to 18 + +### Fixed + +* reset / update empty values of devices + +### Removed + +* remove \*-OS\* functions diff --git a/Docs/Get-OSFirmware.md b/Docs/Get-OSFirmware.md deleted file mode 100644 index d3c9db0..0000000 --- a/Docs/Get-OSFirmware.md +++ /dev/null @@ -1,73 +0,0 @@ ---- -external help file: PSIGEL-help.xml -Module Name: PSIGEL -online version: -schema: 2.0.0 ---- - -# Get-OSFirmware - -## SYNOPSIS -Gets firmware from a device. - -## SYNTAX - -``` -Get-OSFirmware [-SSHSession] [] -``` - -## DESCRIPTION -Gets firmware from a device via Posh-SSH. - -## EXAMPLES - -### Example 1 - -Get firmware from device with name V10-01: - -```powershell -$Params = @{ - ComputerName = 'V10-01' - Credential = Get-Credential - AcceptKey = $true -} -$SSHSession = New-SSHSession @Params - -Get-OSFirmware -SSHSession $SSHSession - -Version -------- -10.05.500.01 -``` - -## PARAMETERS - -### -SSHSession -Posh-SSH SSHSession - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.Object - -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS diff --git a/Docs/Get-OSUpdateConfiguration.md b/Docs/Get-OSUpdateConfiguration.md deleted file mode 100644 index ed6287c..0000000 --- a/Docs/Get-OSUpdateConfiguration.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -external help file: PSIGEL-help.xml -Module Name: PSIGEL -online version: -schema: 2.0.0 ---- - -# Get-OSUpdateConfiguration - -## SYNOPSIS -Gets firmware from a device. - -## SYNTAX - -``` -Get-OSUpdateConfiguration [-SSHSession] [] -``` - -## DESCRIPTION -Gets update configuration from a device via Posh-SSH. - -## EXAMPLES - -### Example 1 - -Get update configuration from device with name V10-01: - -```powershell -$Params = @{ - ComputerName = 'V10-01' - Credential = Get-Credential - AcceptKey = $true -} -$SSHSession = New-SSHSession @Params - -Get-OSUpdateConfiguration -SSHSession $SSHSession - -Host : V10-01 -Protocol : http -Hostname : igelrmserver -Port : 9080 -Username : igelums -Password : 0009330f34121a177eb62d -Path : ums_filetransfer/IGEL_Universal_Desktop_LX-10.05.500 -``` - -## PARAMETERS - -### -SSHSession -Posh-SSH SSHSession - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.Object - -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS diff --git a/Docs/Get-OSWifiConnection.md b/Docs/Get-OSWifiConnection.md deleted file mode 100644 index edaab99..0000000 --- a/Docs/Get-OSWifiConnection.md +++ /dev/null @@ -1,98 +0,0 @@ ---- -external help file: PSIGEL-help.xml -Module Name: PSIGEL -online version: -schema: 2.0.0 ---- - -# Get-OSWifiConnection - -## SYNOPSIS -Gets wifi connection from a device. - -## SYNTAX - -``` -Get-OSWifiConnection [-SSHSession] [[-Interface] ] [] -``` - -## DESCRIPTION -Gets wifi connection from a device via Posh-SSH. - -## EXAMPLES - -### Example 1 - -Get WiFi connection from device with name V10-01: - -```powershell -$Params = @{ - ComputerName = 'V10-01' - Credential = Get-Credential - AcceptKey = $true -} -$SSHSession = New-SSHSession @Params - -Get-OSUpdateConfiguration -SSHSession $SSHSession - -Host : V10-01 -Interface : wlan0 -ESSID : WLAN-0123456 -Mode : Managed -Frequency : 5,18 -AccessPoint : 00:42:6D:36:F8:E8 -BitRate : 18 -TxPower : 20 -LinkQualityActual : 68 -LinkQualityMax : 70 -SignalLevel : -42 -``` - -## PARAMETERS - -### -Interface -Wifi interface of the device - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 1 -Default value: wlan0 -Accept pipeline input: True (ByPropertyName) -Accept wildcard characters: False -``` - -### -SSHSession -Posh-SSH SSHSession - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.Object - -### System.String - -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS diff --git a/Docs/Guides/Scripting-with-PSIGEL.md b/Docs/Guides/Scripting-with-PSIGEL.md new file mode 100644 index 0000000..0c98f92 --- /dev/null +++ b/Docs/Guides/Scripting-with-PSIGEL.md @@ -0,0 +1,273 @@ +# Scripting with PSIGEL + +## Table of contents + +- [Installation](#installation) +- [Setup](#setup) +- [Configuration](#configuration) +- [Authentication](#authentication) +- [Creating a script](#creating-a-script) + +## Installation + +There are several ways to install PSIGEL: + +### Powershell Gallery + +```powershell +C:\> Install-Module -Name PSIGEL -Repository PSGallery +``` + +### Github Repository + +#### Clone + +Use your favorite Git client (e.g. git, Github Desktop etc.) to clone the PSIGEL repository via HTTPS `https://github.com/IGEL-Community/PSIGEL.git` + +#### Release + +Download and extract the latest [release](https://github.com/IGEL-Community/PSIGEL/releases). + +## Setup + +### Import the module + +Powershell needs to import the PSIGEL module. This is done automatically if it resides within one of the Powershell Module Paths: + +```powershell +C:\> [Environment]::GetEnvironmentVariable('PSModulePath') -split ';' +``` + +If you installed it by using the [PSGallery](#powershell-gallery) it will be located in one of the above paths. If it is not, you have to import the Module: + +```powershell +C:\> Import-Module -FullyQualifiedName C:\Path\to\PSIGEL.psd1 +``` + +## Configuration + +If you want to script with PSIGEL, you will use parameters like `Computername` multiple times. To avoid unnecessary repetitions you can set Default Parameter Values (example): + +```powershell +C:\> $PSDefaultParameterValues = @{ + '*-UMS*:Computername' = 'igelrmserver' # Name or IP address of the UMS server + '*-UMS*:TCPPort' = 9443 # set, if the TCP Port differs from the default port 8443 +} +``` + +## Authentication + +A cookie is needed for authentication with the REST API of the IMI. In PSIGEL this is done by creating a WebSession with the function `New-UMSAPICookie`. It then is provided to the functions with the parameter `WebSession`. + +A simple way for an interactive, single time used script would be: + +```powershell +C:\> $WebSession = New-UMSAPICookie -Credential (Get-Credential) +``` + +For the use in an unattended or repeated script you want to automatically add your credentials. + +Within Windows you can store your credential in a secure way by using: + +```powershell +C:\> Get-Credential | Export-Clixml -Path ('C:\Path\To\Your.cred') +``` + +**Warning:** This method does not create an encrypted file within Linux / MacOS. + +You can now import the saved credential and create the WebSession: + +```powershell +C:\> $WebSession = New-UMSAPICookie -Credential (Import-Clixml -Path 'C:\Path\To\Your.cred') +``` + +Finally we add the WebSession to the Default Parameter Values as well: + +```powershell +C:\> $PSDefaultParameterValues.Add('*-UMS*:WebSession', $WebSession) +``` + +## Creating a script + +First, lets get information on all used firmwares: + +```powershell +C:\> $FirmwareColl = Get-UMSFirmware + +C:\> $FirmwareColl + +Id Product Version FirmwareType +-- ------- ------- ------------ + 1 IGEL OS 11 11.3.100.1 LX + 2 IGEL OS 11 11.3.110.1 LX +``` + +Now lets find out which is the Id of the latest firmware: + +```powershell +C:\> $LatestFirmwareId = ($FirmwareColl | Sort-Object -Property Version -Descending | + Select-Object -First 1 ).Id + +C:\> $LatestFirmwareId + +2 +``` + +Lets find out all online devices that are not on the latest firmware: + +```powershell +C:\> $UpdateDeviceColl = Get-UMSDevice -Filter online | + Where-Object { $_.Online -eq $false -and $_.FirmwareId -ne $LatestFirmwareId } +C:\> $UpdateDeviceColl + +Id : 505 +ObjectType : tc +UnitId : 0A0000000001 +Mac : 0A0000000001 +Name : BR-HR-001 +ParentId : 504 +FirmwareId : 1 +LastIp : +MovedToBin : False +Online : False + +... + +Id : 572 +ObjectType : tc +UnitId : 0A0000000011 +Mac : 0A0000000011 +Name : L-DIS-011 +ParentId : 520 +FirmwareId : 1 +LastIp : +MovedToBin : False +Online : False +``` + +Using the pipeline we set the description "update" to those devices: + +```powershell +C:\> $UpdateDeviceColl | Update-UMSDevice -Comment 'update' + +Message : Update successful. +Id : 505 + +... + +Message : Update successful. +Id : 572 +``` + +Check for the comment on one of the devices: + +```powershell +C:\> $UpdateDeviceColl | Get-UMSDevice -Filter details | + Select-Object -Property Id, Name, Comment -First 1 + +Id : 505 +Name : BR-HR-001 +Comment : update +``` + +Since the **API does not support views and jobs** we get back to the UMS. We create a view for all devices that have the comment "update". then we create a new scheduled job "Update on Shutdown" for that view and execute it. + +As last step we restart the selected devices to initiate the update and avoid being asked to confirm each restart: + +```powershell +C:\> $UpdateDeviceColl | Restart-UMSDevice -Confirm:$False + +Message : Ok. +Id : 505 +ExecId : ID-igelrmserver-40687-1583585133100-2-0 +Mac : 0A0000000001 +ExecTime : 1583588208593 +State : SUCCESS + +... + +Message : Ok. +Id : 572 +ExecId : ID-igelrmserver-40687-1583585133100-8-0 +Mac : 0A0000000011 +ExecTime : 1583588208904 +State : SUCCESS +``` + +After the reboot we remove the comment "update" from all devices that now have the latest firmware: + +```powershell +C:\> Get-UMSDevice -Filter details | Where-Object { + $_.Comment -eq 'update' -and $_.FirmwareId -eq $LatestFirmwareId + } | Update-UMSDevice -Comment '' + +Message : Update successful. +Id : 505 + +... + +Message : Update successful. +Id : 572 +``` + +At last we remove the WebSession Cookie: + +```powershell +Remove-UMSAPICookie + +D7588A4A667B3B76650245A8BF335036 +``` + +If we create the view to begin with and schedule the execution of the job just after the execution of the script, then we have created a simple update workflow for our devices. Notice: we don't bother with a reboot here, but rather let the update process start, when the devices a shutdown by the user or per policy. + +- The complete script (with removed unnecessary output) as follows: + +```powershell +# set parameters +$CredPath = 'C:\Path\To\Your.cred' +$PSDefaultParameterValues = @{ + '*-UMS*:Computername' = 'igelrmserver' +} + +#create a websession +$WebSession = New-UMSAPICookie -Credential (Import-Clixml -Path $CredPath) +$PSDefaultParameterValues.Add('*-UMS*:WebSession', $WebSession) + +# get all firmwares +$FirmwareColl = Get-UMSFirmware + +# get latest firmware +$LatestFirmwareId = ($FirmwareColl | Sort-Object -Property Version -Descending | + Select-Object -First 1 ).Id + +# remove a comment "update" from all devices with the latest firmware +$null = Get-UMSDevice -Filter details | Where-Object { + $_.Comment -eq 'update' -and $_.FirmwareId -eq $LatestFirmwareId +} | Update-UMSDevice -Comment '' + +# get all online devices that do not have the latest firmware +$UpdateDeviceColl = Get-UMSDevice -Filter online | Where-Object { + $_.Online -eq $false -and $_.FirmwareId -ne $LatestFirmwareId +} + +# set a comment "update" to all devices with not the latest firmware +$UpdateDeviceColl | Update-UMSDevice -Comment 'update' + +# remove the used websession +$null = Remove-UMSAPICookie + +<# +promptly after the execution of this script, a scheduled job "update on Shutdown" +on a view for all devices with the comment "update" should start in the UMS. +#> +``` + +Output: + +```powershell +Message Id +------- -- +Update successful. 505 +.. +Update successful. 572 +``` diff --git a/Docs/Media/PSIGEL_1280_320.png b/Docs/Media/PSIGEL_1280_320.png new file mode 100644 index 0000000..0f20d23 Binary files /dev/null and b/Docs/Media/PSIGEL_1280_320.png differ diff --git a/Docs/Get-UMSDevice.md b/Docs/Reference/Get-UMSDevice.md similarity index 90% rename from Docs/Get-UMSDevice.md rename to Docs/Reference/Get-UMSDevice.md index 3d709d1..2d4a2ac 100644 --- a/Docs/Get-UMSDevice.md +++ b/Docs/Reference/Get-UMSDevice.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDevice.md schema: 2.0.0 --- @@ -60,7 +60,7 @@ MovedToBin : False ### Example 2 -Get 'online' information on device with ID 195.: +Get 'online' information on device with ID 195: ```powershell Get-UMSDevice -ComputerName 'igelrmserver' -WebSession $WebSession -Id 58 -Filter online @@ -94,7 +94,13 @@ FirmwareId : 2 LastIp : 192.168.56.101 MovedToBin : False NetworkName : V11-01 +Site : Comment : [SingleLicensed] +Department : +CostCenter : +AssetID : +InServiceDate : +SerialNumber : ProductId : UC1-LX CpuSpeed : 1608 CpuType : Intel(R) Core(TM) i7-7Y75 CPU @ 1.30GHz @@ -132,7 +138,7 @@ BiosDate : 01.12.2006 00:00:00 ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -142,7 +148,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -173,7 +179,7 @@ Accepted values: short, details, online, shadow Required: False Position: Benannt -Default value: None +Default value: short Accept pipeline input: False Accept wildcard characters: False ``` @@ -204,7 +210,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -219,7 +225,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -240,8 +246,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSDeviceAssignment.md b/Docs/Reference/Get-UMSDeviceAssignment.md similarity index 89% rename from Docs/Get-UMSDeviceAssignment.md rename to Docs/Reference/Get-UMSDeviceAssignment.md index d38c84c..1b2e10e 100644 --- a/Docs/Get-UMSDeviceAssignment.md +++ b/Docs/Reference/Get-UMSDeviceAssignment.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDeviceAssignment.md schema: 2.0.0 --- @@ -46,11 +46,10 @@ AssigneeType : profile AssignmentPosition : 1 ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -60,7 +59,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -106,7 +105,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -121,7 +120,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -142,8 +141,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSDeviceDirectory.md b/Docs/Reference/Get-UMSDeviceDirectory.md similarity index 91% rename from Docs/Get-UMSDeviceDirectory.md rename to Docs/Reference/Get-UMSDeviceDirectory.md index 892ce4e..9e4ded4 100644 --- a/Docs/Get-UMSDeviceDirectory.md +++ b/Docs/Reference/Get-UMSDeviceDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDeviceDirectory.md schema: 2.0.0 --- @@ -74,7 +74,7 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -84,7 +84,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -146,7 +146,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -161,7 +161,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -182,8 +182,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSDeviceDirectoryAssignment.md b/Docs/Reference/Get-UMSDeviceDirectoryAssignment.md similarity index 89% rename from Docs/Get-UMSDeviceDirectoryAssignment.md rename to Docs/Reference/Get-UMSDeviceDirectoryAssignment.md index 8c8b58d..3224347 100644 --- a/Docs/Get-UMSDeviceDirectoryAssignment.md +++ b/Docs/Reference/Get-UMSDeviceDirectoryAssignment.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDeviceDirectoryAssignment.md schema: 2.0.0 --- @@ -45,11 +45,10 @@ AssigneeType : profile AssignmentPosition : 1 ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -59,7 +58,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -105,7 +104,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -120,7 +119,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -141,8 +140,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Reference/Get-UMSDirectoryRecursive.md b/Docs/Reference/Get-UMSDirectoryRecursive.md new file mode 100644 index 0000000..49bd95e --- /dev/null +++ b/Docs/Reference/Get-UMSDirectoryRecursive.md @@ -0,0 +1,240 @@ +--- +external help file: PSIGEL-help.xml +Module Name: PSIGEL +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDirectoryRecursive.md +schema: 2.0.0 +--- + +# Get-UMSDirectoryRecursive + +## SYNOPSIS +Gets either all directory or element ids from below given directory id. + +## SYNTAX + +### Directory (Default) +``` +Get-UMSDirectoryRecursive [-Id] [-DirectoryColl] [] +``` + +### Element +``` +Get-UMSDirectoryRecursive [-Id] [-DirectoryColl] [-ElementColl] [] +``` + +## DESCRIPTION +Gets either all directory or element ids from below given directory id. + +## EXAMPLES + +### Example 1 +Get information on all directories below device directory with the ID 197: + +```powershell +$DeviceDirectoryColl = Get-UMSDeviceDirectory -ComputerName 'igelrmserver' -WebSession $WebSession +Get-UMSDirectoryRecursive -Id 197 -DirectoryColl $DeviceDirectoryColl + +Id : 197 +Name : Computers +ParentId : 48 +MovedToBin : False +ObjectType : tcdirectory + +Id : 198 +Name : Computers01 +ParentId : 197 +MovedToBin : False +ObjectType : tcdirectory + +Id : 199 +Name : Room1013 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 200 +Name : Room1014 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 201 +Name : Room1015 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 202 +Name : Room1108 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 203 +Name : Room1U07 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 208 +Name : Computers2 +ParentId : 197 +MovedToBin : False +ObjectType : tcdirectory + +Id : 209 +Name : Room2204 +ParentId : 208 +MovedToBin : False +ObjectType : tcdirectory +``` + +### Example 2 +Get 'short' information on all devices below device directory with the ID 197: + +```powershell +$DeviceColl = Get-UMSDevice -ComputerName 'igelrmserver' -WebSession $WebSession +$DeviceDirectoryColl = Get-UMSDeviceDirectory -ComputerName 'igelrmserver' -WebSession $WebSession +Get-UMSDirectoryRecursive -Id 197 -DirectoryColl $DeviceDirectoryColl -ElementColl $DeviceColl + +Id : 112567 +ObjectType : tc +UnitId : 00E0C5347154 +Mac : 00E0C5347154 +Name : DEV1417 +ParentId : 201 +FirmwareId : 6 +LastIp : 192.168.11.123 +MovedToBin : False + +Id : 3404 +ObjectType : tc +UnitId : 00E0C537A54E +Mac : 00E0C537A54E +Name : DEV0577 +ParentId : 203 +FirmwareId : 6 +LastIp : 192.168.73.1 +MovedToBin : False + +Id : 3430 +ObjectType : tc +UnitId : 00E0C5417B66 +Mac : 00E0C5417B66 +Name : DEV0006 +ParentId : 203 +FirmwareId : 6 +LastIp : 192.168.85.11 +MovedToBin : False + +... + +Id : 4308 +ObjectType : tc +UnitId : 00E0C53FF551 +Mac : 00E0C53FF551 +Name : DEV7479 +ParentId : 216 +FirmwareId : 20 +LastIp : +MovedToBin : False +``` + +### Example 3 +Get information on all profiles below profile directory with the ID 908: + +```powershell +$ProfileDirectoryColl = Get-UMSProfileDirectory -ComputerName 'igelrmserver' -WebSession $WebSession +$ProfileColl = Get-UMSProfile -ComputerName 'igelrmserver' -WebSession $WebSession +908 | Get-UMSDirectoryRecursive -DirectoryColl $ProfileDirectoryColl -ElementColl $ProfileColl + +FirmwareId : 39 +IsMasterProfile : False +OverridesSessions : False +Id : 18902 +Name : 05|USBStorageHotplug:Disable +ParentId : 11722 +MovedToBin : False +ObjectType : profile + +FirmwareId : 39 +IsMasterProfile : False +OverridesSessions : False +Id : 12047 +Name : 06|Password_DomainAutomaticLogin:Off|UDW +ParentId : 11724 +MovedToBin : False +ObjectType : profile + +... + +FirmwareId : 39 +IsMasterProfile : False +OverridesSessions : False +Id : 94461 +Name : 07|Update_Snapshots_Download_W10|UDW +ParentId : 11726 +MovedToBin : False +ObjectType : profile +``` + +## PARAMETERS + +### -DirectoryColl +Collection of all Directories. Can be determined from Get-UMSDeviceDirectory or Get-UMSProfileDirectory. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: Benannt +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ElementColl +Collection of all Elements. Can be determined from Get-UMSDevice or Get-UMSProfile. + +```yaml +Type: Object +Parameter Sets: Element +Aliases: + +Required: True +Position: Benannt +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Id +ID of the starting device directory + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: Benannt +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Int32 + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Docs/Get-UMSFirmware.md b/Docs/Reference/Get-UMSFirmware.md similarity index 90% rename from Docs/Get-UMSFirmware.md rename to Docs/Reference/Get-UMSFirmware.md index 2837cc6..4fbb19f 100644 --- a/Docs/Get-UMSFirmware.md +++ b/Docs/Reference/Get-UMSFirmware.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSFirmware.md schema: 2.0.0 --- @@ -54,11 +54,10 @@ Id Product Version FirmwareType 2 IGEL OS 11 11.01.100.01 LX ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -68,7 +67,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -114,7 +113,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -129,7 +128,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -150,8 +149,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSProfile.md b/Docs/Reference/Get-UMSProfile.md similarity index 91% rename from Docs/Get-UMSProfile.md rename to Docs/Reference/Get-UMSProfile.md index 4eb5fd3..cf015c6 100644 --- a/Docs/Get-UMSProfile.md +++ b/Docs/Reference/Get-UMSProfile.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSProfile.md schema: 2.0.0 --- @@ -84,7 +84,7 @@ ObjectType : profile ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -94,7 +94,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -140,7 +140,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -155,7 +155,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -176,8 +176,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSProfileAssignment.md b/Docs/Reference/Get-UMSProfileAssignment.md similarity index 91% rename from Docs/Get-UMSProfileAssignment.md rename to Docs/Reference/Get-UMSProfileAssignment.md index e9a5ec3..1f60b6b 100644 --- a/Docs/Get-UMSProfileAssignment.md +++ b/Docs/Reference/Get-UMSProfileAssignment.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSProfileAssignment.md schema: 2.0.0 --- @@ -57,11 +57,10 @@ ReceiverType : tcdirectory AssignmentPosition : 0 ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -71,7 +70,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -132,7 +131,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -147,7 +146,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -168,8 +167,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSProfileDirectory.md b/Docs/Reference/Get-UMSProfileDirectory.md similarity index 91% rename from Docs/Get-UMSProfileDirectory.md rename to Docs/Reference/Get-UMSProfileDirectory.md index 42095ff..3d20284 100644 --- a/Docs/Get-UMSProfileDirectory.md +++ b/Docs/Reference/Get-UMSProfileDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSProfileDirectory.md schema: 2.0.0 --- @@ -80,7 +80,7 @@ DirectoryChildren : @{ObjectType=profile; Id=669} ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -90,7 +90,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -152,7 +152,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -167,7 +167,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -188,8 +188,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Get-UMSStatus.md b/Docs/Reference/Get-UMSStatus.md similarity index 87% rename from Docs/Get-UMSStatus.md rename to Docs/Reference/Get-UMSStatus.md index 571be8f..8dacceb 100644 --- a/Docs/Get-UMSStatus.md +++ b/Docs/Reference/Get-UMSStatus.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSStatus.md schema: 2.0.0 --- @@ -37,11 +37,10 @@ ServerUuid : 8be5a3db-ee78-48a9-9caf-52054ec6bf14 Server : igelrmserver:8443 ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -51,7 +50,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -82,7 +81,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -97,7 +96,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -118,8 +117,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Move-UMSDevice.md b/Docs/Reference/Move-UMSDevice.md similarity index 92% rename from Docs/Move-UMSDevice.md rename to Docs/Reference/Move-UMSDevice.md index 45758a2..d0be0ec 100644 --- a/Docs/Move-UMSDevice.md +++ b/Docs/Reference/Move-UMSDevice.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSDevice.md schema: 2.0.0 --- @@ -59,7 +59,7 @@ $PSDefaultParameterValues += @{ ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -69,7 +69,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -145,7 +145,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -160,7 +160,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -197,8 +197,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Move-UMSDeviceDirectory.md b/Docs/Reference/Move-UMSDeviceDirectory.md similarity index 92% rename from Docs/Move-UMSDeviceDirectory.md rename to Docs/Reference/Move-UMSDeviceDirectory.md index ad5b4d0..d084492 100644 --- a/Docs/Move-UMSDeviceDirectory.md +++ b/Docs/Reference/Move-UMSDeviceDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSDeviceDirectory.md schema: 2.0.0 --- @@ -59,7 +59,7 @@ $PSDefaultParameterValues += @{ ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -69,7 +69,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -145,7 +145,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -160,7 +160,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -197,8 +197,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Move-UMSProfile.md b/Docs/Reference/Move-UMSProfile.md similarity index 92% rename from Docs/Move-UMSProfile.md rename to Docs/Reference/Move-UMSProfile.md index f1ed74e..a833363 100644 --- a/Docs/Move-UMSProfile.md +++ b/Docs/Reference/Move-UMSProfile.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSProfile.md schema: 2.0.0 --- @@ -59,7 +59,7 @@ $PSDefaultParameterValues += @{ ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -69,7 +69,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -145,7 +145,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -160,7 +160,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -197,8 +197,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Move-UMSProfileDirectory.md b/Docs/Reference/Move-UMSProfileDirectory.md similarity index 92% rename from Docs/Move-UMSProfileDirectory.md rename to Docs/Reference/Move-UMSProfileDirectory.md index a43397a..0d3b706 100644 --- a/Docs/Move-UMSProfileDirectory.md +++ b/Docs/Reference/Move-UMSProfileDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSProfileDirectory.md schema: 2.0.0 --- @@ -59,7 +59,7 @@ $PSDefaultParameterValues += @{ ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -69,7 +69,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -145,7 +145,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -160,7 +160,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -197,8 +197,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/New-UMSAPICookie.md b/Docs/Reference/New-UMSAPICookie.md similarity index 90% rename from Docs/New-UMSAPICookie.md rename to Docs/Reference/New-UMSAPICookie.md index 9e51b4e..269349c 100644 --- a/Docs/New-UMSAPICookie.md +++ b/Docs/Reference/New-UMSAPICookie.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSAPICookie.md schema: 2.0.0 --- @@ -29,13 +29,14 @@ Create websession cookie and assign it to variable $WebSession: ```powershell $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential (Get-Credential) ``` + ### Example 2 Create / use process to store and read credential to and from file and use it to create a websession cookie for use in $WebSession variable: ```powershell #Save credential securely to file (one time only): -Get-Credential | Export-Clixml -Path ('{0}\igelums@igelrmserver.cred' -f ${env:\userprofile}) -Credential (Get-Credential) +Get-Credential | Export-Clixml -Path ('{0}\igelums@igelrmserver.cred' -f ${env:\userprofile}) #Load credential from file $Credential = Import-Clixml -Path ('{0}\igelums@igelrmserver.cred' -f ${env:\userprofile}) @@ -47,7 +48,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -57,7 +58,7 @@ Accepted values: 3 Required: False Position: 3 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -118,7 +119,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 4 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -133,7 +134,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -155,8 +156,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/New-UMSDevice.md b/Docs/Reference/New-UMSDevice.md similarity index 95% rename from Docs/New-UMSDevice.md rename to Docs/Reference/New-UMSDevice.md index cf8b99f..b94dac0 100644 --- a/Docs/New-UMSDevice.md +++ b/Docs/Reference/New-UMSDevice.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSDevice.md schema: 2.0.0 --- @@ -98,7 +98,7 @@ ParentId : 665 ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -108,7 +108,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -304,7 +304,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -349,7 +349,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -386,8 +386,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/New-UMSDeviceDirectory.md b/Docs/Reference/New-UMSDeviceDirectory.md similarity index 91% rename from Docs/New-UMSDeviceDirectory.md rename to Docs/Reference/New-UMSDeviceDirectory.md index 73b85b8..2382278 100644 --- a/Docs/New-UMSDeviceDirectory.md +++ b/Docs/Reference/New-UMSDeviceDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSDeviceDirectory.md schema: 2.0.0 --- @@ -51,7 +51,7 @@ Directory successfully inserted. 739 Leipzig ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -61,7 +61,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -122,7 +122,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -137,7 +137,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -174,8 +174,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/New-UMSProfileAssignment.md b/Docs/Reference/New-UMSProfileAssignment.md similarity index 93% rename from Docs/New-UMSProfileAssignment.md rename to Docs/Reference/New-UMSProfileAssignment.md index 49eea6f..4653cf7 100644 --- a/Docs/New-UMSProfileAssignment.md +++ b/Docs/Reference/New-UMSProfileAssignment.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: https://github.com/IGEL-Community/PSIGEL/blob/master/Docs/New-UMSAPICookie.md +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSProfileAssignment.md schema: 2.0.0 --- @@ -60,7 +60,7 @@ Message Id ReceiverId ReceiverType ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -70,7 +70,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -162,7 +162,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -177,7 +177,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -214,8 +214,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/New-UMSProfileDirectory.md b/Docs/Reference/New-UMSProfileDirectory.md similarity index 91% rename from Docs/New-UMSProfileDirectory.md rename to Docs/Reference/New-UMSProfileDirectory.md index 91fb95a..02df15a 100644 --- a/Docs/New-UMSProfileDirectory.md +++ b/Docs/Reference/New-UMSProfileDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSProfileDirectory.md schema: 2.0.0 --- @@ -51,7 +51,7 @@ Directory successfully inserted. 745 06 ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -61,7 +61,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -122,7 +122,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -137,7 +137,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -174,8 +174,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Reference/Remove-UMSAPICookie.md b/Docs/Reference/Remove-UMSAPICookie.md new file mode 100644 index 0000000..4f7798e --- /dev/null +++ b/Docs/Reference/Remove-UMSAPICookie.md @@ -0,0 +1,165 @@ +--- +external help file: PSIGEL-help.xml +Module Name: PSIGEL +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSAPICookie.md +schema: 2.0.0 +--- + +# Remove-UMSAPICookie + +## SYNOPSIS +Removes a websession cookie. + +## SYNTAX + +``` +Remove-UMSAPICookie [-Computername] [[-TCPPort] ] [[-ApiVersion] ] + [[-SecurityProtocol] ] [-WebSession] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Removes a websession cookie for the UMS API. + +## EXAMPLES + +### Example 1 + +Removes a websession cookie, gets the cookie value back as output. + +```powershell +Remove-UMSAPICookie -ComputerName 'igelrmserver' -WebSession $WebSession + +D7588A4A667B3B76650245A8BF335036 +``` + +### Example 1 + +Removes a websession cookie, omits output. + +```powershell +$null = Remove-UMSAPICookie -ComputerName 'igelrmserver' -WebSession $WebSession +``` + +## PARAMETERS + +### -ApiVersion +API Version to use + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: 3 + +Required: False +Position: 2 +Default value: 3 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Computername +Computername of the UMS Server + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Benannt +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SecurityProtocol +Set SSL/TLS protocol + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: +Accepted values: Tls12, Tls11, Tls, Ssl3 + +Required: False +Position: 3 +Default value: Tls12 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TCPPort +TCP Port API + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: 8443 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WebSession +Websession Cookie + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Benannt +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### Keine + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Docs/Remove-UMSDevice.md b/Docs/Reference/Remove-UMSDevice.md similarity index 94% rename from Docs/Remove-UMSDevice.md rename to Docs/Reference/Remove-UMSDevice.md index 7c55c7a..6d57092 100644 --- a/Docs/Remove-UMSDevice.md +++ b/Docs/Reference/Remove-UMSDevice.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSDevice.md schema: 2.0.0 --- @@ -94,11 +94,10 @@ Offline deletion successful. 751 Offline deletion successful. 752 ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -108,7 +107,7 @@ Accepted values: 3 Required: False Position: Benannt -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -184,7 +183,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: Benannt -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -199,7 +198,7 @@ Aliases: Required: False Position: Benannt -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -236,8 +235,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Remove-UMSDeviceDirectory.md b/Docs/Reference/Remove-UMSDeviceDirectory.md similarity index 92% rename from Docs/Remove-UMSDeviceDirectory.md rename to Docs/Reference/Remove-UMSDeviceDirectory.md index 1de0836..fd93693 100644 --- a/Docs/Remove-UMSDeviceDirectory.md +++ b/Docs/Reference/Remove-UMSDeviceDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSDeviceDirectory.md schema: 2.0.0 --- @@ -68,7 +68,7 @@ Deletion successful. 687 ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -78,7 +78,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -139,7 +139,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -154,7 +154,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -191,8 +191,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Remove-UMSProfile.md b/Docs/Reference/Remove-UMSProfile.md similarity index 92% rename from Docs/Remove-UMSProfile.md rename to Docs/Reference/Remove-UMSProfile.md index fd94213..5591aa2 100644 --- a/Docs/Remove-UMSProfile.md +++ b/Docs/Reference/Remove-UMSProfile.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSProfile.md schema: 2.0.0 --- @@ -63,11 +63,10 @@ Deleted profile. 69 Deleted profile. 390 ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -77,7 +76,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -138,7 +137,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -153,7 +152,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -190,8 +189,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Remove-UMSProfileAssignment.md b/Docs/Reference/Remove-UMSProfileAssignment.md similarity index 92% rename from Docs/Remove-UMSProfileAssignment.md rename to Docs/Reference/Remove-UMSProfileAssignment.md index e38d808..2990173 100644 --- a/Docs/Remove-UMSProfileAssignment.md +++ b/Docs/Reference/Remove-UMSProfileAssignment.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSProfileAssignment.md schema: 2.0.0 --- @@ -62,11 +62,10 @@ deleted profile assignment. 390 71 tcdirectory deleted profile assignment. 69 71 tcdirectory ``` - ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -76,7 +75,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -122,7 +121,7 @@ Aliases: Required: True Position: 5 Default value: None -Accept pipeline input: True (ByPropertyName) +Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ``` @@ -168,7 +167,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -183,7 +182,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -220,8 +219,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Remove-UMSProfileDirectory.md b/Docs/Reference/Remove-UMSProfileDirectory.md similarity index 92% rename from Docs/Remove-UMSProfileDirectory.md rename to Docs/Reference/Remove-UMSProfileDirectory.md index a14266d..62a8c5a 100644 --- a/Docs/Remove-UMSProfileDirectory.md +++ b/Docs/Reference/Remove-UMSProfileDirectory.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSProfileDirectory.md schema: 2.0.0 --- @@ -66,7 +66,7 @@ Deletion successful. 230 ## PARAMETERS ### -ApiVersion -API Version to use (Default: 3) +API Version to use ```yaml Type: Int32 @@ -76,7 +76,7 @@ Accepted values: 3 Required: False Position: 2 -Default value: None +Default value: 3 Accept pipeline input: False Accept wildcard characters: False ``` @@ -137,7 +137,7 @@ Accepted values: Tls12, Tls11, Tls, Ssl3 Required: False Position: 3 -Default value: None +Default value: Tls12 Accept pipeline input: False Accept wildcard characters: False ``` @@ -152,7 +152,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: 8443 Accept pipeline input: False Accept wildcard characters: False ``` @@ -189,8 +189,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Reset-UMSDevice.md b/Docs/Reference/Reset-UMSDevice.md similarity index 91% rename from Docs/Reset-UMSDevice.md rename to Docs/Reference/Reset-UMSDevice.md index afb2867..263253c 100644 --- a/Docs/Reset-UMSDevice.md +++ b/Docs/Reference/Reset-UMSDevice.md @@ -1,7 +1,7 @@ --- external help file: PSIGEL-help.xml Module Name: PSIGEL -online version: +online version: https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Reset-UMSDevice.md schema: 2.0.0 --- @@ -19,7 +19,7 @@ Reset-UMSDevice [-Computername] [[-TCPPort] ] [[-ApiVersion] + + [CmdletBinding(DefaultParameterSetName = 'Login')] + param ( + [Parameter(Mandatory, ParameterSetName = 'Function')] + $WebSession, + + [Parameter(Mandatory, ParameterSetName = 'Function')] + [Parameter(Mandatory, ParameterSetName = 'Login')] + [ValidateSet('Tls12', 'Tls11', 'Tls', 'Ssl3')] + [String[]] + $SecurityProtocol, + + [Parameter(Mandatory, ParameterSetName = 'Function')] + [Parameter(Mandatory, ParameterSetName = 'Login')] + [String] + $Uri, + + [Parameter(ParameterSetName = 'Function')] + [Parameter(ParameterSetName = 'Login')] + [String] + $Body, + + [Parameter(ParameterSetName = 'Function')] + [Parameter(ParameterSetName = 'Login')] + [String] + $ContentType, + + [Parameter(ParameterSetName = 'Function')] + [Parameter(Mandatory, ParameterSetName = 'Login')] + $Headers, + + [Parameter(Mandatory, ParameterSetName = 'Function')] + [Parameter(Mandatory, ParameterSetName = 'Login')] + [ValidateSet('Get', 'Post', 'Put', 'Delete')] + [String] + $Method + ) + + begin + { + } + process + { + $null = $PSBoundParameters.Remove('SecurityProtocol') + $null = $PSBoundParameters.Add('ErrorAction', 'Stop') + Switch (Get-Variable -Name PSEdition -ValueOnly) + { + 'Desktop' + { + try + { + Invoke-RestMethod @PSBoundParameters + } + catch [System.Net.WebException] + { + switch ($($PSItem.Exception.Response.StatusCode.value__)) + { + 400 + { + Write-Warning -Message ('Bad Request: The request does not match the API, e.g. it uses the wrong HTTP method. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 401 + { + Write-Warning -Message ('Unauthorized: The client has not logged in or has sent the wrong credentials. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 404 + { + Write-Warning -Message ('Not Found: The endpoint does not exist, it may be misspelled. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 415 + { + Write-Warning -Message ('Unsupported Media Type: The body content, e.g. JSON, does not match the Content-Type header or is not well-formed. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 500 + { + Write-Warning -Message ('Internal Server Error: The server has encountered an error, check the server logfiles catalina.log and stderr. Uri: {0} Method: {1}' -f $Uri, $Method) + } + default + { + Write-Warning -Message ('Some error occured see HTTP status code {0} for further details. Uri: {1} Method: {2}' -f $PSItem.Exception.Response.StatusCode, $Uri, $Method) + } + } + } + } + 'Core' + { + try + { + $null = $PSBoundParameters.Add('SslProtocol', $SecurityProtocol) + $null = $PSBoundParameters.Add('SkipCertificateCheck', $true) + Invoke-RestMethod @PSBoundParameters + } + catch [Microsoft.PowerShell.Commands.HttpResponseException] + { + switch ($($PSItem.Exception.Response.StatusCode.value__)) + { + 400 + { + Write-Warning -Message ('Bad Request: The request does not match the API, e.g. it uses the wrong HTTP method. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 401 + { + Write-Warning -Message ('Unauthorized: The client has not logged in or has sent the wrong credentials. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 404 + { + Write-Warning -Message ('Not Found: The endpoint does not exist, it may be misspelled. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 415 + { + Write-Warning -Message ('Unsupported Media Type: The body content, e.g. JSON, does not match the Content-Type header or is not well-formed. Uri: {0} Method: {1}' -f $Uri, $Method) + } + 500 + { + Write-Warning -Message ('Internal Server Error: The server has encountered an error, check the server logfiles catalina.log and stderr. Uri: {0} Method: {1}' -f $Uri, $Method) + } + default + { + Write-Warning -Message ('Some error occured see HTTP status code {0} for further details. Uri: {1} Method: {2}' -f $PSItem.Exception.Response.StatusCode, $Uri, $Method) + } + } + } + } + } + } + end + { + } +} \ No newline at end of file diff --git a/PSIGEL/Private/Invoke-UMSRestMethodWebSession.ps1 b/PSIGEL/Private/Invoke-UMSRestMethodWebSession.ps1 deleted file mode 100644 index f4fdae5..0000000 --- a/PSIGEL/Private/Invoke-UMSRestMethodWebSession.ps1 +++ /dev/null @@ -1,117 +0,0 @@ -function Invoke-UMSRestMethodWebSession -{ - <# - .SYNOPSIS - Invoke-RestMethod Wrapper for UMS API - - .DESCRIPTION - Invoke-RestMethod Wrapper for UMS API - - .EXAMPLE - $Params = @{ - WebSession = $WebSession - Uri = $Uri - Method = 'Put' - ContentType = 'application/json' - Headers = @{} - SecurityProtocol = ($SecurityProtocol -join ',') - } - Invoke-UMSRestMethodWebSession @Params - - .EXAMPLE - $Params = @{ - WebSession = $WebSession - Uri = $Uri - Body = $Body - Method = 'Put' - ContentType = 'application/json' - Headers = @{} - SecurityProtocol = ($SecurityProtocol -join ',') - } - Invoke-UMSRestMethodWebSession @Params - - #> - - [CmdletBinding()] - param ( - [Parameter(Mandatory)] - $WebSession, - - [Parameter(Mandatory)] - [ValidateSet('Tls12', 'Tls11', 'Tls', 'Ssl3')] - [String[]] - $SecurityProtocol, - - [Parameter(Mandatory)] - [String] - $Uri, - - [String] - $Body, - - [String] - $ContentType, - - $Headers, - - [Parameter(Mandatory)] - [ValidateSet('Get', 'Post', 'Put', 'Delete')] - [String] - $Method - ) - - begin - { - Add-Type -AssemblyName Microsoft.PowerShell.Commands.Utility - Add-Type -TypeDefinition @' - using System.Net; - using System.Security.Cryptography.X509Certificates; - public class TrustAllCertsPolicy : ICertificatePolicy { - public bool CheckValidationResult( - ServicePoint srvPoint, X509Certificate certificate, - WebRequest request, int certificateProblem) { - return true; - } - } -'@ - [Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy - [Net.ServicePointManager]::SecurityProtocol = $SecurityProtocol -join ',' - $null = $PSBoundParameters.Remove('SecurityProtocol') - } - process - { - try - { - Invoke-RestMethod @PSBoundParameters -ErrorAction Stop - } - catch [System.Net.WebException] - { - switch ($($PSItem.Exception.Response.StatusCode.value__)) - { - 400 - { - Write-Warning -Message ('Error executing IMI RestAPI request. Uri: {0} Method: {1}' -f $Uri, $Method) - } - 401 - { - Write-Warning -Message ('Error logging in, it seems as you have entered invalid credentials. Uri: {0} Method: {1}' -f $Uri, $Method) - } - 403 - { - Write-Warning -Message ('Error logging in, it seems as you have not subscripted this version of IMI. Uri: {0} Method: {1}' -f $Uri, $Method) - } - 415 - { - Write-Warning -Message ('Unsupported Media Type. Uri: {0} Method: {1}' -f $Uri, $Method) - } - default - { - Write-Warning -Message ('Some error occured see HTTP status code for further details. Uri: {0} Method: {1}' -f $Uri, $Method) - } - } - } - } - end - { - } -} \ No newline at end of file diff --git a/PSIGEL/Public/Get-OSFirmware.ps1 b/PSIGEL/Public/Get-OSFirmware.ps1 deleted file mode 100644 index f532d87..0000000 --- a/PSIGEL/Public/Get-OSFirmware.ps1 +++ /dev/null @@ -1,33 +0,0 @@ -#Requires -Modules Posh-SSH -function Get-OSFirmware -{ - [CmdletBinding()] - param ( - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] - $SSHSession - ) - - begin - { - $Command = "cat /etc/firmware" - } - process - { - try - { - $CommandResultColl = (Invoke-SSHCommandStream -SSHSession $SSHSession -Command $Command) -replace ('\s', '') - $Properties = [ordered]@{ - 'Version' = [string]$CommandResultColl - } - $Result = New-Object psobject -Property $Properties - $Result - } - catch - { - Write-Output -InputObject $PSItem.Exception.Message - } - } - end - { - } -} \ No newline at end of file diff --git a/PSIGEL/Public/Get-OSUpdateConfiguration.ps1 b/PSIGEL/Public/Get-OSUpdateConfiguration.ps1 deleted file mode 100644 index dda2b8d..0000000 --- a/PSIGEL/Public/Get-OSUpdateConfiguration.ps1 +++ /dev/null @@ -1,66 +0,0 @@ -#Requires -Modules Posh-SSH -function Get-OSUpdateConfiguration -{ - [CmdletBinding()] - param ( - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] - $SSHSession - ) - - begin - { - $Command = 'cat /wfs/updateconf.ini' - $PatternProtocol = 'protocol=\"(?.*)\"' - $PatternHostname = 'hostname=\"(?.*)\"' - $PatternPort = 'port=\"(?.*)\"' - $PatternUsername = 'username=\"(?.*)\"' - $PatternPassword = 'password=\"(?.*)\"' - $PatternPath = 'path=\"(?.*)\"' - } - process - { - try - { - $CommandResultColl = Invoke-SSHCommandStream -SSHSession $SSHSession -Command $Command - $Properties = [ordered]@{ - Host = [String]$SSHSession.Host - } - foreach ($CommandResult in $CommandResultColl) - { - if ($CommandResult -match $PatternProtocol) - { - $Properties.Protocol = [String]$matches.Protocol - } - if ($CommandResult -match $PatternHostname) - { - $Properties.Hostname = [String]$matches.Hostname - } - if ($CommandResult -match $PatternPort) - { - $Properties.Port = [Int]$matches.Port - } - if ($CommandResult -match $PatternUsername) - { - $Properties.Username = [String]$matches.Username - } - if ($CommandResult -match $PatternPassword) - { - $Properties.Password = [String]$matches.Password - } - if ($CommandResult -match $PatternPath) - { - $Properties.Path = [String]$matches.Path - } - } - $Result = New-Object psobject -Property $Properties - $Result - } - catch - { - Write-Output -InputObject $PSItem.Exception.Message - } - } - end - { - } -} \ No newline at end of file diff --git a/PSIGEL/Public/Get-OSWifiConnection.ps1 b/PSIGEL/Public/Get-OSWifiConnection.ps1 deleted file mode 100644 index 6e24caf..0000000 --- a/PSIGEL/Public/Get-OSWifiConnection.ps1 +++ /dev/null @@ -1,87 +0,0 @@ -#Requires -Modules Posh-SSH -function Get-OSWifiConnection -{ - [CmdletBinding()] - param ( - [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] - $SSHSession, - - [Parameter(ValueFromPipelineByPropertyName)] - [String] - $Interface = 'wlan0' - ) - - begin - { - $Command = "iwconfig $Interface" - $PatternESSID = 'ESSID(:|=)\"(?.*)\"' - $PatternMode = 'Mode(:|=)(?[^\s]*)' - $PatternFrequency = 'Frequency(:|=)(?[^\s]*)\s(?[^\s]*)' - $PatternAccessPoint = 'Access Point:\s(?[^\s]*)' - $PatternBitRate = 'Bit Rate(:|=)(?[^\s]*)\s(?[^\s]*)' - $PatternTxPower = 'Tx-Power(:|=)(?[^\s]*)\s(?[^\s]*)' - #$PatternLinkQuality = 'Link Quality(:|=)(?[^\s]*)' - $PatternLinkQualityActual = 'Link Quality(:|=)(?\d+)' - $PatternLinkQualityMax = 'Link Quality(:|=)\d*\/(?\d+)' - $PatternSignalLevel = 'Signal level(:|=)(?[^\s]*)\s(?[^\s]*)' - } - process - { - try - { - $CommandResultColl = Invoke-SSHCommandStream -SSHSession $SSHSession -Command $Command - $Properties = [ordered]@{ - Host = [String]$SSHSession.Host - Interface = [String]$Interface - } - foreach ($CommandResult in $CommandResultColl) - { - if ($CommandResult -match $PatternESSID) - { - $Properties.ESSID = [String]$matches.ESSID - } - if ($CommandResult -match $PatternMode) - { - $Properties.Mode = [String]$matches.Mode - } - if ($CommandResult -match $PatternFrequency) - { - $Properties.Frequency = [Single]$matches.Frequency - } - if ($CommandResult -match $PatternAccessPoint) - { - $Properties.AccessPoint = [String]$matches.AccessPoint - } - if ($CommandResult -match $PatternBitRate) - { - $Properties.BitRate = [Int]$matches.BitRate - } - if ($CommandResult -match $PatternTxPower) - { - $Properties.TxPower = [Int]$matches.TxPower - } - if ($CommandResult -match $PatternLinkQualityActual) - { - $Properties.LinkQualityActual = [Int]$matches.LinkQualityActual - } - if ($CommandResult -match $PatternLinkQualityMax) - { - $Properties.LinkQualityMax = [Int]$matches.LinkQualityMax - } - if ($CommandResult -match $PatternSignalLevel) - { - $Properties.SignalLevel = [Int]$matches.SignalLevel - } - } - $Result = New-Object psobject -Property $Properties - $Result - } - catch - { - Write-Output -InputObject $PSItem.Exception.Message - } - } - end - { - } -} \ No newline at end of file diff --git a/PSIGEL/Public/Get-UMSDevice.ps1 b/PSIGEL/Public/Get-UMSDevice.ps1 index 936ba4e..193b2cc 100644 --- a/PSIGEL/Public/Get-UMSDevice.ps1 +++ b/PSIGEL/Public/Get-UMSDevice.ps1 @@ -42,7 +42,7 @@ WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } Switch ($PsCmdlet.ParameterSetName) @@ -50,12 +50,12 @@ 'All' { $Params.Add('Uri', ('{0}{1}' -f $BaseURL, $FilterString)) - $APIObjectColl = (Invoke-UMSRestMethodWebSession @Params).SyncRoot + $APIObjectColl = (Invoke-UMSRestMethod @Params).SyncRoot } 'Id' { $Params.Add('Uri', ('{0}/{1}{2}' -f $BaseURL, $Id, $FilterString)) - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } } @@ -90,7 +90,13 @@ { $Properties += [ordered]@{ 'NetworkName' = [String]$APIObject.networkName + 'Site' = [String]$APIObject.site 'Comment' = [String]$APIObject.comment + 'Department' = [String]$APIObject.department + 'CostCenter' = [String]$APIObject.costCenter + 'AssetID' = [String]$APIObject.assetID + 'InServiceDate' = [String]$APIObject.inServiceDate + 'SerialNumber' = [String]$APIObject.serialNumber 'ProductId' = [String]$APIObject.productId 'CpuSpeed' = [Int]$APIObject.cpuSpeed 'CpuType' = [String]$APIObject.cpuType diff --git a/PSIGEL/Public/Get-UMSDeviceAssignment.ps1 b/PSIGEL/Public/Get-UMSDeviceAssignment.ps1 index df55525..3272d98 100644 --- a/PSIGEL/Public/Get-UMSDeviceAssignment.ps1 +++ b/PSIGEL/Public/Get-UMSDeviceAssignment.ps1 @@ -39,10 +39,10 @@ Uri = '{0}/{1}/assignments/profiles' -f $BaseURL, $Id Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params $Result = foreach ($APIObject in $APIObjectColl) { $ProfileColl = foreach ($child in $APIObject) diff --git a/PSIGEL/Public/Get-UMSDeviceDirectory.ps1 b/PSIGEL/Public/Get-UMSDeviceDirectory.ps1 index 2ca08c9..1cb576b 100644 --- a/PSIGEL/Public/Get-UMSDeviceDirectory.ps1 +++ b/PSIGEL/Public/Get-UMSDeviceDirectory.ps1 @@ -46,7 +46,7 @@ WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } Switch ($PSCmdlet.ParameterSetName) @@ -54,12 +54,12 @@ 'All' { $Params.Add('Uri', ('{0}{1}' -f $BaseURL, $FilterString)) - $APIObjectColl = (Invoke-UMSRestMethodWebSession @Params).SyncRoot + $APIObjectColl = (Invoke-UMSRestMethod @Params).SyncRoot } 'Id' { $Params.Add('Uri', ('{0}/{1}{2}' -f $BaseURL, $Id, $FilterString)) - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } } $Result = foreach ($APIObject in $APIObjectColl) diff --git a/PSIGEL/Public/Get-UMSDeviceDirectoryAssignment.ps1 b/PSIGEL/Public/Get-UMSDeviceDirectoryAssignment.ps1 index 942cf2f..56e534b 100644 --- a/PSIGEL/Public/Get-UMSDeviceDirectoryAssignment.ps1 +++ b/PSIGEL/Public/Get-UMSDeviceDirectoryAssignment.ps1 @@ -39,10 +39,10 @@ function Get-UMSDeviceDirectoryAssignment Uri = ('{0}/{1}/assignments/profiles' -f $BaseURL, $Id) Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params $Result = foreach ($APIObject in $APIObjectColl) { $ProfileColl = foreach ($child in $APIObject) diff --git a/PSIGEL/Public/Get-UMSDirectoryRecursive.ps1 b/PSIGEL/Public/Get-UMSDirectoryRecursive.ps1 new file mode 100644 index 0000000..f96f621 --- /dev/null +++ b/PSIGEL/Public/Get-UMSDirectoryRecursive.ps1 @@ -0,0 +1,53 @@ +function Get-UMSDirectoryRecursive +{ + [CmdletBinding(DefaultParameterSetName = 'Directory')] + param ( + [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [Int] + $Id, + + [Parameter(Mandatory)] + $DirectoryColl, + + [Parameter(Mandatory, ParameterSetName = 'Element')] + $ElementColl + ) + Begin + { + } + Process + { + $ResultDirectoryColl = { + ($DirectoryColl).where{ $_.Id -eq $Id } + $ChildDirColl = ($DirectoryColl).where{ $_.ParentId -eq $Id } + foreach ($ChildDir in $ChildDirColl) + { + Get-UMSDirectoryRecursive -Id $ChildDir.Id -DirectoryColl $DirectoryColl + } + } + Switch ($PsCmdlet.ParameterSetName) + { + 'Directory' + { + $Result = (& $ResultDirectoryColl) + } + 'Element' + { + $Result = foreach ($Directory in (& $ResultDirectoryColl)) + { + foreach ($Element in $ElementColl) + { + if ($Element.ParentId -eq $Directory.Id) + { + $Element + } + } + } + } + } + $Result + } + End + { + } +} \ No newline at end of file diff --git a/PSIGEL/Public/Get-UMSFirmware.ps1 b/PSIGEL/Public/Get-UMSFirmware.ps1 index 561d4b8..c339434 100644 --- a/PSIGEL/Public/Get-UMSFirmware.ps1 +++ b/PSIGEL/Public/Get-UMSFirmware.ps1 @@ -38,7 +38,7 @@ WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } Switch ($PsCmdlet.ParameterSetName) @@ -46,12 +46,12 @@ 'All' { $Params.Add('Uri', ('{0}' -f $BaseURL)) - $APIObjectColl = (Invoke-UMSRestMethodWebSession @Params).FwResource + $APIObjectColl = (Invoke-UMSRestMethod @Params).FwResource } 'Id' { $Params.Add('Uri', ('{0}/{1}' -f $BaseURL, $Id)) - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } } $Result = foreach ($APIObject in $APIObjectColl) @@ -59,7 +59,7 @@ $Properties = [ordered]@{ 'Id' = [Int]$APIObject.id 'Product' = [String]$APIObject.product - 'Version' = [String]$APIObject.version + 'Version' = [Version]::new($APIObject.version) 'FirmwareType' = [String]$APIObject.firmwareType } New-Object psobject -Property $Properties diff --git a/PSIGEL/Public/Get-UMSProfile.ps1 b/PSIGEL/Public/Get-UMSProfile.ps1 index d98e661..1141040 100644 --- a/PSIGEL/Public/Get-UMSProfile.ps1 +++ b/PSIGEL/Public/Get-UMSProfile.ps1 @@ -38,7 +38,7 @@ WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } Switch ($PsCmdlet.ParameterSetName) @@ -46,12 +46,12 @@ 'All' { $Params.Add('Uri', ('{0}' -f $BaseURL)) - $APIObjectColl = (Invoke-UMSRestMethodWebSession @Params).SyncRoot + $APIObjectColl = (Invoke-UMSRestMethod @Params).SyncRoot } 'Id' { $Params.Add('Uri', ('{0}/{1}' -f $BaseURL, $Id)) - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } } $Result = foreach ($APIObject in $APIObjectColl) diff --git a/PSIGEL/Public/Get-UMSProfileAssignment.ps1 b/PSIGEL/Public/Get-UMSProfileAssignment.ps1 index 51507ff..25ef2df 100644 --- a/PSIGEL/Public/Get-UMSProfileAssignment.ps1 +++ b/PSIGEL/Public/Get-UMSProfileAssignment.ps1 @@ -41,7 +41,7 @@ WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } @@ -56,7 +56,7 @@ $Params.Add('Uri', ('{0}/{1}/assignments/tcdirectories' -f $BaseURL, $Id)) } } - $APIObjectColl = (Invoke-UMSRestMethodWebSession @Params).SyncRoot + $APIObjectColl = (Invoke-UMSRestMethod @Params).SyncRoot $Result = foreach ($APIObject in $APIObjectColl) { $ProfileColl = foreach ($child in $APIObject) diff --git a/PSIGEL/Public/Get-UMSProfileDirectory.ps1 b/PSIGEL/Public/Get-UMSProfileDirectory.ps1 index 4629822..e2d5730 100644 --- a/PSIGEL/Public/Get-UMSProfileDirectory.ps1 +++ b/PSIGEL/Public/Get-UMSProfileDirectory.ps1 @@ -46,7 +46,7 @@ function Get-UMSProfileDirectory WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } Switch ($PSCmdlet.ParameterSetName) @@ -54,12 +54,12 @@ function Get-UMSProfileDirectory 'All' { $Params.Add('Uri', ('{0}{1}' -f $BaseURL, $FilterString)) - $APIObjectColl = (Invoke-UMSRestMethodWebSession @Params).SyncRoot + $APIObjectColl = (Invoke-UMSRestMethod @Params).SyncRoot } 'Id' { $Params.Add('Uri', ('{0}/{1}{2}' -f $BaseURL, $Id, $FilterString)) - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } } $Result = foreach ($APIObject in $APIObjectColl) diff --git a/PSIGEL/Public/Get-UMSStatus.ps1 b/PSIGEL/Public/Get-UMSStatus.ps1 index 28e042b..1e84f3a 100644 --- a/PSIGEL/Public/Get-UMSStatus.ps1 +++ b/PSIGEL/Public/Get-UMSStatus.ps1 @@ -34,19 +34,19 @@ WebSession = $WebSession Method = 'Get' ContentType = 'application/json' - Headers = @{} + Headers = @{ } Uri = $BaseURL SecurityProtocol = ($SecurityProtocol -join ',') } - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params $Result = foreach ($APIObject in $APIObjectColl) { $Properties = [ordered]@{ - 'RmGuiServerVersion' = [String]$APIObject.rmGuiServerVersion + 'RmGuiServerVersion' = [Version]::new($APIObject.rmGuiServerVersion) 'BuildNumber' = [Int]$APIObject.buildNumber - 'ActiveMqVersion' = [String]$APIObject.activeMQVersion - 'DerbyVersion' = [String]$APIObject.derbyVersion + 'ActiveMqVersion' = [Version]::new($APIObject.activeMQVersion) + 'DerbyVersion' = [Version]::new($APIObject.derbyVersion) 'ServerUuid' = [String]$APIObject.serverUUID 'Server' = [String]$APIObject.server } diff --git a/PSIGEL/Public/Move-UMSDevice.ps1 b/PSIGEL/Public/Move-UMSDevice.ps1 index bdee8e7..ec14d26 100644 --- a/PSIGEL/Public/Move-UMSDevice.ps1 +++ b/PSIGEL/Public/Move-UMSDevice.ps1 @@ -50,12 +50,12 @@ function Move-UMSDevice Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0} to DestId: {1}' -f $Id, $DestId))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Move-UMSDeviceDirectory.ps1 b/PSIGEL/Public/Move-UMSDeviceDirectory.ps1 index eef592d..b3d7747 100644 --- a/PSIGEL/Public/Move-UMSDeviceDirectory.ps1 +++ b/PSIGEL/Public/Move-UMSDeviceDirectory.ps1 @@ -50,12 +50,12 @@ function Move-UMSDeviceDirectory Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0} to DestID: {1}' -f $Id, $DestId))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Move-UMSProfile.ps1 b/PSIGEL/Public/Move-UMSProfile.ps1 index 6797e43..644a226 100644 --- a/PSIGEL/Public/Move-UMSProfile.ps1 +++ b/PSIGEL/Public/Move-UMSProfile.ps1 @@ -50,12 +50,12 @@ function Move-UMSProfile Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0} to DestID: {1}' -f $Id, $DestId))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Move-UMSProfileDirectory.ps1 b/PSIGEL/Public/Move-UMSProfileDirectory.ps1 index 449a0d4..510cee2 100644 --- a/PSIGEL/Public/Move-UMSProfileDirectory.ps1 +++ b/PSIGEL/Public/Move-UMSProfileDirectory.ps1 @@ -50,12 +50,12 @@ function Move-UMSProfileDirectory Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0} to DestId: {1}' -f $Id, $DestId))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/New-UMSAPICookie.ps1 b/PSIGEL/Public/New-UMSAPICookie.ps1 index 529f735..f241baa 100644 --- a/PSIGEL/Public/New-UMSAPICookie.ps1 +++ b/PSIGEL/Public/New-UMSAPICookie.ps1 @@ -27,61 +27,60 @@ Begin { - Add-Type -AssemblyName Microsoft.PowerShell.Commands.Utility - Add-Type -TypeDefinition @' - using System.Net; - using System.Security.Cryptography.X509Certificates; - public class TrustAllCertsPolicy : ICertificatePolicy { - public bool CheckValidationResult( - ServicePoint srvPoint, X509Certificate certificate, - WebRequest request, int certificateProblem) { - return true; - } - } -'@ - [Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy - [Net.ServicePointManager]::SecurityProtocol = $SecurityProtocol -join ',' } Process { $Username = $Credential.Username $Password = $Credential.GetNetworkCredential().password - - $BUArray = @($Computername, $TCPPort, $ApiVersion) $BaseURL = 'https://{0}:{1}/umsapi/v{2}/' -f $BUArray $Header = @{ 'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($Username + ':' + $Password)) } - $Params = @{ - Uri = '{0}login' -f $BaseURL - Headers = $Header - Method = 'Post' - ContentType = 'application/json' - ErrorAction = 'Stop' + Uri = '{0}login' -f $BaseURL + Headers = $Header + Method = 'Post' + ContentType = 'application/json' + SecurityProtocol = $SecurityProtocol } + switch (Get-Variable -Name PSEdition -ValueOnly) + { + 'Desktop' + { + Add-Type -AssemblyName Microsoft.PowerShell.Commands.Utility + Add-Type -TypeDefinition @' + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +'@ + [Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + [Net.ServicePointManager]::SecurityProtocol = $SecurityProtocol -join ',' + } + } + $SessionResponse = Invoke-UMSRestMethod @Params - Try + if ($SessionResponse) { - $SessionResponse = Invoke-RestMethod @Params $Cookie = New-Object -TypeName System.Net.Cookie $Cookie.Name = ($SessionResponse.Message).Split('=')[0] $Cookie.Path = '/' $Cookie.Value = ($SessionResponse.Message).Split('=')[1] $Cookie.Domain = $Computername - } - Catch - { - $_.Exception.Message - } - if ($PSCmdlet.ShouldProcess($Computername)) - { - $WebSession = New-Object -TypeName Microsoft.Powershell.Commands.Webrequestsession - $WebSession.Cookies.Add($Cookie) - $Result = $WebSession - $Result + if ($PSCmdlet.ShouldProcess($Computername)) + { + $WebSession = New-Object -TypeName Microsoft.Powershell.Commands.Webrequestsession + $WebSession.Cookies.Add($Cookie) + $Result = $WebSession + $Result + } } } End diff --git a/PSIGEL/Public/New-UMSDevice.ps1 b/PSIGEL/Public/New-UMSDevice.ps1 index 1204355..617d15d 100644 --- a/PSIGEL/Public/New-UMSDevice.ps1 +++ b/PSIGEL/Public/New-UMSDevice.ps1 @@ -53,7 +53,7 @@ $CostCenter, [Parameter(ValueFromPipelineByPropertyName)] - [ValidateScript( {$_ -match [IPAddress]$_})] + [ValidateScript( { $_ -match [IPAddress]$_ })] [String] $LastIP, @@ -70,7 +70,7 @@ $InserviceDate, [Parameter(ValueFromPipelineByPropertyName)] - [ValidateLength(19, 19)] + [ValidateLength(18, 18)] [String] $SerialNumber ) @@ -102,12 +102,12 @@ Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('MAC: {0}' -f $Mac)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/New-UMSDeviceDirectory.ps1 b/PSIGEL/Public/New-UMSDeviceDirectory.ps1 index d0409e5..7ed907a 100644 --- a/PSIGEL/Public/New-UMSDeviceDirectory.ps1 +++ b/PSIGEL/Public/New-UMSDeviceDirectory.ps1 @@ -43,12 +43,12 @@ function New-UMSDeviceDirectory Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Name: {0}' -f $Name)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/New-UMSProfileAssignment.ps1 b/PSIGEL/Public/New-UMSProfileAssignment.ps1 index eaeab15..aa7da27 100644 --- a/PSIGEL/Public/New-UMSProfileAssignment.ps1 +++ b/PSIGEL/Public/New-UMSProfileAssignment.ps1 @@ -72,14 +72,14 @@ Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } $SPArray = @($Id, $ReceiverId, $ReceiverType) if ($PSCmdlet.ShouldProcess(('Id: {0}, ReceiverId: {1}, ReceiverType: {2}' -f $SPArray))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/New-UMSProfileDirectory.ps1 b/PSIGEL/Public/New-UMSProfileDirectory.ps1 index 37bc795..04d789f 100644 --- a/PSIGEL/Public/New-UMSProfileDirectory.ps1 +++ b/PSIGEL/Public/New-UMSProfileDirectory.ps1 @@ -43,12 +43,12 @@ function New-UMSProfileDirectory Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Name: {0}' -f $Name)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Remove-UMSAPICookie.ps1 b/PSIGEL/Public/Remove-UMSAPICookie.ps1 new file mode 100644 index 0000000..0954eff --- /dev/null +++ b/PSIGEL/Public/Remove-UMSAPICookie.ps1 @@ -0,0 +1,66 @@ +function Remove-UMSAPICookie +{ + [cmdletbinding(SupportsShouldProcess, ConfirmImpact = 'Low')] + param + ( + [Parameter(Mandatory)] + [String] + $Computername, + + [ValidateRange(0, 65535)] + [Int] + $TCPPort = 8443, + + [ValidateSet(3)] + [Int] + $ApiVersion = 3, + + [ValidateSet('Tls12', 'Tls11', 'Tls', 'Ssl3')] + [String[]] + $SecurityProtocol = 'Tls12', + + [Parameter(Mandatory)] + $WebSession + ) + + Begin + { + } + Process + { + $BUArray = @($Computername, $TCPPort, $ApiVersion) + $BaseURL = 'https://{0}:{1}/umsapi/v{2}/' -f $BUArray + $Cookie = $WebSession.Cookies.GetCookies('https://{0}' -f $Computername) + $Header = @{ + 'Cookie' = ('{0}={1}' -f $Cookie.Name, $Cookie.Value) + } + $Params = @{ + Uri = '{0}logout' -f $BaseURL + WebSession = $WebSession + Headers = $Header + Method = 'Post' + ContentType = 'application/json' + SecurityProtocol = $SecurityProtocol + } + if ($PSCmdlet.ShouldProcess($Cookie.Value)) + { + $Result = (Invoke-UMSRestMethod @Params) + } + switch ($Result) + { + { 'null' -or $null } + { + $Cookie.Value + } + Default + { + Write-Warning ('Could not remove Cookie {0}={1}!' -f $Cookie.Name, $Cookie.Value) + } + } + #> + + } + End + { + } +} \ No newline at end of file diff --git a/PSIGEL/Public/Remove-UMSDevice.ps1 b/PSIGEL/Public/Remove-UMSDevice.ps1 index 438c9fe..e605ea4 100644 --- a/PSIGEL/Public/Remove-UMSDevice.ps1 +++ b/PSIGEL/Public/Remove-UMSDevice.ps1 @@ -42,7 +42,7 @@ WebSession = $WebSession Method = 'Delete' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } Switch ($PsCmdlet.ParameterSetName) @@ -58,7 +58,7 @@ } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $ID)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Remove-UMSDeviceDirectory.ps1 b/PSIGEL/Public/Remove-UMSDeviceDirectory.ps1 index 63931fb..1bf2bae 100644 --- a/PSIGEL/Public/Remove-UMSDeviceDirectory.ps1 +++ b/PSIGEL/Public/Remove-UMSDeviceDirectory.ps1 @@ -39,12 +39,12 @@ function Remove-UMSDeviceDirectory Uri = ('{0}/{1}' -f $BaseURL, $Id) Method = 'Delete' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Remove-UMSProfile.ps1 b/PSIGEL/Public/Remove-UMSProfile.ps1 index 75d0c14..23446bc 100644 --- a/PSIGEL/Public/Remove-UMSProfile.ps1 +++ b/PSIGEL/Public/Remove-UMSProfile.ps1 @@ -39,12 +39,12 @@ Uri = ('{0}/{1}' -f $BaseURL, $Id) Method = 'Delete' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Remove-UMSProfileAssignment.ps1 b/PSIGEL/Public/Remove-UMSProfileAssignment.ps1 index 2b5574f..c3fe505 100644 --- a/PSIGEL/Public/Remove-UMSProfileAssignment.ps1 +++ b/PSIGEL/Public/Remove-UMSProfileAssignment.ps1 @@ -22,7 +22,7 @@ [Parameter(Mandatory)] $WebSession, - [Parameter(Mandatory, ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)] [Int] $Id, @@ -59,13 +59,13 @@ Uri = $Uri Method = 'Delete' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } $SPArray = @($Id, $ReceiverId, $ReceiverType) if ($PSCmdlet.ShouldProcess(('Id: {0}, ReceiverID {1}, ReceiverType: {2}' -f $SPArray))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Remove-UMSProfileDirectory.ps1 b/PSIGEL/Public/Remove-UMSProfileDirectory.ps1 index 711a549..4ef92ee 100644 --- a/PSIGEL/Public/Remove-UMSProfileDirectory.ps1 +++ b/PSIGEL/Public/Remove-UMSProfileDirectory.ps1 @@ -39,12 +39,12 @@ function Remove-UMSProfileDirectory Uri = ('{0}/{1}' -f $BaseURL, $Id) Method = 'Delete' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Reset-UMSDevice.ps1 b/PSIGEL/Public/Reset-UMSDevice.ps1 index 9cd546b..53c3457 100644 --- a/PSIGEL/Public/Reset-UMSDevice.ps1 +++ b/PSIGEL/Public/Reset-UMSDevice.ps1 @@ -46,12 +46,12 @@ Body = $Body Method = 'Post' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Restart-UMSDevice.ps1 b/PSIGEL/Public/Restart-UMSDevice.ps1 index 154e87a..1f84618 100644 --- a/PSIGEL/Public/Restart-UMSDevice.ps1 +++ b/PSIGEL/Public/Restart-UMSDevice.ps1 @@ -46,12 +46,12 @@ Body = $Body Method = 'Post' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Send-UMSDeviceSetting.ps1 b/PSIGEL/Public/Send-UMSDeviceSetting.ps1 index 5cb485d..675f0de 100644 --- a/PSIGEL/Public/Send-UMSDeviceSetting.ps1 +++ b/PSIGEL/Public/Send-UMSDeviceSetting.ps1 @@ -46,12 +46,12 @@ Body = $Body Method = 'Post' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Start-UMSDevice.ps1 b/PSIGEL/Public/Start-UMSDevice.ps1 index e3860e9..4bb631c 100644 --- a/PSIGEL/Public/Start-UMSDevice.ps1 +++ b/PSIGEL/Public/Start-UMSDevice.ps1 @@ -46,12 +46,12 @@ Body = $Body Method = 'Post' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Stop-UMSDevice.ps1 b/PSIGEL/Public/Stop-UMSDevice.ps1 index 9a9d761..4706b6d 100644 --- a/PSIGEL/Public/Stop-UMSDevice.ps1 +++ b/PSIGEL/Public/Stop-UMSDevice.ps1 @@ -46,12 +46,12 @@ Body = $Body Method = 'Post' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess('Id: {0}' -f $Id)) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Update-UMSDevice.ps1 b/PSIGEL/Public/Update-UMSDevice.ps1 index 9b3f47b..149f1fc 100644 --- a/PSIGEL/Public/Update-UMSDevice.ps1 +++ b/PSIGEL/Public/Update-UMSDevice.ps1 @@ -44,7 +44,7 @@ $CostCenter, [Parameter(ParameterSetName = 'Set')] - [ValidateScript( {$_ -match [IPAddress]$_})] + [ValidateScript( { $_ -match [IPAddress]$_ })] [String] $LastIP, @@ -61,7 +61,7 @@ $InserviceDate, [Parameter(ParameterSetName = 'Set')] - [ValidateLength(19, 19)] + [ValidateLength(18, 18)] [String] $SerialNumber ) @@ -77,40 +77,40 @@ { 'Set' { - $BodyHashTable = @{} - if ($Name) + $BodyHashTable = @{ } + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'Name' }) { $BodyHashTable.Add('name', $Name) } - if ($Site) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'Site' }) { $BodyHashTable.Add('site', $Site) } - if ($Department) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'Department' }) { $BodyHashTable.Add('department', $Department) } - if ($CostCenter) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'CostCenter' }) { $BodyHashTable.Add('costCenter', $CostCenter) } - if ($LastIP) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'LastIP' }) { $BodyHashTable.Add('lastIP', $LastIP) } - if ($Comment) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'Comment' }) { $BodyHashTable.Add('comment', $Comment) } - if ($AssetId) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'AssetId' }) { $BodyHashTable.Add('assetID', $AssetId) } - if ($InserviceDate) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'InserviceDate' }) { $BodyHashTable.Add('inserviceDate', $InserviceDate) } - if ($SerialNumber) + if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'SerialNumber' }) { $BodyHashTable.Add('serialNumber', $SerialNumber) } @@ -121,12 +121,12 @@ Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0}' -f $Id))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Update-UMSDeviceDirectory.ps1 b/PSIGEL/Public/Update-UMSDeviceDirectory.ps1 index a239003..97f0bcc 100644 --- a/PSIGEL/Public/Update-UMSDeviceDirectory.ps1 +++ b/PSIGEL/Public/Update-UMSDeviceDirectory.ps1 @@ -47,12 +47,12 @@ function Update-UMSDeviceDirectory Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0}' -f $Id))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Update-UMSProfile.ps1 b/PSIGEL/Public/Update-UMSProfile.ps1 index 6645102..1678444 100644 --- a/PSIGEL/Public/Update-UMSProfile.ps1 +++ b/PSIGEL/Public/Update-UMSProfile.ps1 @@ -47,12 +47,12 @@ Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0}' -f $Id))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/Public/Update-UMSProfileDirectory.ps1 b/PSIGEL/Public/Update-UMSProfileDirectory.ps1 index 76d8a5d..a9b74a7 100644 --- a/PSIGEL/Public/Update-UMSProfileDirectory.ps1 +++ b/PSIGEL/Public/Update-UMSProfileDirectory.ps1 @@ -47,12 +47,12 @@ function Update-UMSProfileDirectory Body = $Body Method = 'Put' ContentType = 'application/json' - Headers = @{} + Headers = @{ } SecurityProtocol = ($SecurityProtocol -join ',') } if ($PSCmdlet.ShouldProcess(('Id: {0}' -f $Id))) { - $APIObjectColl = Invoke-UMSRestMethodWebSession @Params + $APIObjectColl = Invoke-UMSRestMethod @Params } $Result = foreach ($APIObject in $APIObjectColl) { diff --git a/PSIGEL/en-US/PSIGEL-help.xml b/PSIGEL/en-US/PSIGEL-help.xml index 52c416a..a86470e 100644 --- a/PSIGEL/en-US/PSIGEL-help.xml +++ b/PSIGEL/en-US/PSIGEL-help.xml @@ -1,319 +1,5 @@  - - - Get-OSFirmware - Get - OSFirmware - - Gets firmware from a device. - - - - Gets firmware from a device via Posh-SSH. - - - - Get-OSFirmware - - SSHSession - - Posh-SSH SSHSession - - Object - - Object - - - None - - - - - - SSHSession - - Posh-SSH SSHSession - - Object - - Object - - - None - - - - - - System.Object - - - - - - - - - - System.Object - - - - - - - - - - - - - - -------------------------- Example 1 -------------------------- - $Params = @{ - ComputerName = 'V10-01' - Credential = Get-Credential - AcceptKey = $true -} -$SSHSession = New-SSHSession @Params - -Get-OSFirmware -SSHSession $SSHSession - -Version -------- -10.05.500.01 - - - - - - - - - - Get-OSUpdateConfiguration - Get - OSUpdateConfiguration - - Gets firmware from a device. - - - - Gets update configuration from a device via Posh-SSH. - - - - Get-OSUpdateConfiguration - - SSHSession - - Posh-SSH SSHSession - - Object - - Object - - - None - - - - - - SSHSession - - Posh-SSH SSHSession - - Object - - Object - - - None - - - - - - System.Object - - - - - - - - - - System.Object - - - - - - - - - - - - - - -------------------------- Example 1 -------------------------- - $Params = @{ - ComputerName = 'V10-01' - Credential = Get-Credential - AcceptKey = $true -} -$SSHSession = New-SSHSession @Params - -Get-OSUpdateConfiguration -SSHSession $SSHSession - -Host : V10-01 -Protocol : http -Hostname : igelrmserver -Port : 9080 -Username : igelums -Password : 0009330f34121a177eb62d -Path : ums_filetransfer/IGEL_Universal_Desktop_LX-10.05.500 - - - - - - - - - - Get-OSWifiConnection - Get - OSWifiConnection - - Gets wifi connection from a device. - - - - Gets wifi connection from a device via Posh-SSH. - - - - Get-OSWifiConnection - - SSHSession - - Posh-SSH SSHSession - - Object - - Object - - - None - - - Interface - - Wifi interface of the device - - String - - String - - - wlan0 - - - - - - Interface - - Wifi interface of the device - - String - - String - - - wlan0 - - - SSHSession - - Posh-SSH SSHSession - - Object - - Object - - - None - - - - - - System.Object - - - - - - - - System.String - - - - - - - - - - System.Object - - - - - - - - - - - - - - -------------------------- Example 1 -------------------------- - $Params = @{ - ComputerName = 'V10-01' - Credential = Get-Credential - AcceptKey = $true -} -$SSHSession = New-SSHSession @Params - -Get-OSUpdateConfiguration -SSHSession $SSHSession - -Host : V10-01 -Interface : wlan0 -ESSID : WLAN-0123456 -Mode : Managed -Frequency : 5,18 -AccessPoint : 00:42:6D:36:F8:E8 -BitRate : 18 -TxPower : 20 -LinkQualityActual : 68 -LinkQualityMax : 70 -SignalLevel : -42 - - - - - - - Get-UMSDevice @@ -332,7 +18,7 @@ SignalLevel : -42 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -342,7 +28,7 @@ SignalLevel : -42 Int32 - None + 3 Computername @@ -372,7 +58,7 @@ SignalLevel : -42 String - None + short Id @@ -402,7 +88,7 @@ SignalLevel : -42 String[] - None + Tls12 TCPPort @@ -414,7 +100,7 @@ SignalLevel : -42 Int32 - None + 8443 WebSession @@ -434,14 +120,14 @@ SignalLevel : -42 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -465,7 +151,7 @@ SignalLevel : -42 String - None + short Id @@ -489,7 +175,7 @@ SignalLevel : -42 String[] - None + Tls12 TCPPort @@ -501,7 +187,7 @@ SignalLevel : -42 Int32 - None + 8443 WebSession @@ -603,7 +289,13 @@ FirmwareId : 2 LastIp : 192.168.56.101 MovedToBin : False NetworkName : V11-01 +Site : Comment : [SingleLicensed] +Department : +CostCenter : +AssetID : +InServiceDate : +SerialNumber : ProductId : UC1-LX CpuSpeed : 1608 CpuType : Intel(R) Core(TM) i7-7Y75 CPU @ 1.30GHz @@ -641,7 +333,12 @@ BiosDate : 01.12.2006 00:00:00 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDevice.md + + @@ -680,12 +377,12 @@ BiosDate : 01.12.2006 00:00:00 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -695,7 +392,7 @@ BiosDate : 01.12.2006 00:00:00 Int32 - None + 3 SecurityProtocol @@ -713,7 +410,7 @@ BiosDate : 01.12.2006 00:00:00 String[] - None + Tls12 WebSession @@ -745,14 +442,14 @@ BiosDate : 01.12.2006 00:00:00 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -788,7 +485,7 @@ BiosDate : 01.12.2006 00:00:00 String[] - None + Tls12 TCPPort @@ -800,7 +497,7 @@ BiosDate : 01.12.2006 00:00:00 Int32 - None + 8443 WebSession @@ -865,7 +562,12 @@ AssignmentPosition : 1 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDeviceAssignment.md + + @@ -885,7 +587,7 @@ AssignmentPosition : 1 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -895,7 +597,7 @@ AssignmentPosition : 1 Int32 - None + 3 Computername @@ -952,7 +654,7 @@ AssignmentPosition : 1 String[] - None + Tls12 TCPPort @@ -964,7 +666,7 @@ AssignmentPosition : 1 Int32 - None + 8443 WebSession @@ -984,14 +686,14 @@ AssignmentPosition : 1 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -1039,7 +741,7 @@ AssignmentPosition : 1 String[] - None + Tls12 TCPPort @@ -1051,7 +753,7 @@ AssignmentPosition : 1 Int32 - None + 8443 WebSession @@ -1132,7 +834,12 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDeviceDirectory.md + + @@ -1171,12 +878,12 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -1186,7 +893,7 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory Int32 - None + 3 SecurityProtocol @@ -1204,7 +911,7 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory String[] - None + Tls12 WebSession @@ -1236,14 +943,14 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -1279,7 +986,7 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory String[] - None + Tls12 TCPPort @@ -1291,7 +998,7 @@ DirectoryChildren : {@{ObjectType=tcdirectory; Id=664}, @{ObjectType=tcdirectory Int32 - None + 8443 WebSession @@ -1355,7 +1062,288 @@ AssignmentPosition : 1 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDeviceDirectoryAssignment.md + + + + + + Get-UMSDirectoryRecursive + Get + UMSDirectoryRecursive + + Gets either all directory or element ids from below given directory id. + + + + Gets either all directory or element ids from below given directory id. + + + + Get-UMSDirectoryRecursive + + DirectoryColl + + Collection of all Directories. Can be determined from Get-UMSDeviceDirectory or Get-UMSProfileDirectory. + + Object + + Object + + + None + + + ElementColl + + Collection of all Elements. Can be determined from Get-UMSDevice or Get-UMSProfile. + + Object + + Object + + + None + + + Id + + ID of the starting device directory + + Int32 + + Int32 + + + None + + + + + + DirectoryColl + + Collection of all Directories. Can be determined from Get-UMSDeviceDirectory or Get-UMSProfileDirectory. + + Object + + Object + + + None + + + ElementColl + + Collection of all Elements. Can be determined from Get-UMSDevice or Get-UMSProfile. + + Object + + Object + + + None + + + Id + + ID of the starting device directory + + Int32 + + Int32 + + + None + + + + + + System.Int32 + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + $DeviceDirectoryColl = Get-UMSDeviceDirectory -ComputerName 'igelrmserver' -WebSession $WebSession +Get-UMSDirectoryRecursive -Id 197 -DirectoryColl $DeviceDirectoryColl + +Id : 197 +Name : Computers +ParentId : 48 +MovedToBin : False +ObjectType : tcdirectory + +Id : 198 +Name : Computers01 +ParentId : 197 +MovedToBin : False +ObjectType : tcdirectory + +Id : 199 +Name : Room1013 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 200 +Name : Room1014 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 201 +Name : Room1015 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 202 +Name : Room1108 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 203 +Name : Room1U07 +ParentId : 198 +MovedToBin : False +ObjectType : tcdirectory + +Id : 208 +Name : Computers2 +ParentId : 197 +MovedToBin : False +ObjectType : tcdirectory + +Id : 209 +Name : Room2204 +ParentId : 208 +MovedToBin : False +ObjectType : tcdirectory + + + + + + -------------------------- Example 2 -------------------------- + $DeviceColl = Get-UMSDevice -ComputerName 'igelrmserver' -WebSession $WebSession +$DeviceDirectoryColl = Get-UMSDeviceDirectory -ComputerName 'igelrmserver' -WebSession $WebSession +Get-UMSDirectoryRecursive -Id 197 -DirectoryColl $DeviceDirectoryColl -ElementColl $DeviceColl + +Id : 112567 +ObjectType : tc +UnitId : 00E0C5347154 +Mac : 00E0C5347154 +Name : DEV1417 +ParentId : 201 +FirmwareId : 6 +LastIp : 192.168.11.123 +MovedToBin : False + +Id : 3404 +ObjectType : tc +UnitId : 00E0C537A54E +Mac : 00E0C537A54E +Name : DEV0577 +ParentId : 203 +FirmwareId : 6 +LastIp : 192.168.73.1 +MovedToBin : False + +Id : 3430 +ObjectType : tc +UnitId : 00E0C5417B66 +Mac : 00E0C5417B66 +Name : DEV0006 +ParentId : 203 +FirmwareId : 6 +LastIp : 192.168.85.11 +MovedToBin : False + +... + +Id : 4308 +ObjectType : tc +UnitId : 00E0C53FF551 +Mac : 00E0C53FF551 +Name : DEV7479 +ParentId : 216 +FirmwareId : 20 +LastIp : +MovedToBin : False + + + + + + -------------------------- Example 3 -------------------------- + $ProfileDirectoryColl = Get-UMSProfileDirectory -ComputerName 'igelrmserver' -WebSession $WebSession +$ProfileColl = Get-UMSProfile -ComputerName 'igelrmserver' -WebSession $WebSession +908 | Get-UMSDirectoryRecursive -DirectoryColl $ProfileDirectoryColl -ElementColl $ProfileColl + +FirmwareId : 39 +IsMasterProfile : False +OverridesSessions : False +Id : 18902 +Name : 05|USBStorageHotplug:Disable +ParentId : 11722 +MovedToBin : False +ObjectType : profile + +FirmwareId : 39 +IsMasterProfile : False +OverridesSessions : False +Id : 12047 +Name : 06|Password_DomainAutomaticLogin:Off|UDW +ParentId : 11724 +MovedToBin : False +ObjectType : profile + +... + +FirmwareId : 39 +IsMasterProfile : False +OverridesSessions : False +Id : 94461 +Name : 07|Update_Snapshots_Download_W10|UDW +ParentId : 11726 +MovedToBin : False +ObjectType : profile + + + + + + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSDirectoryRecursive.md + + @@ -1375,7 +1363,7 @@ AssignmentPosition : 1 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -1385,7 +1373,7 @@ AssignmentPosition : 1 Int32 - None + 3 Computername @@ -1427,7 +1415,7 @@ AssignmentPosition : 1 String[] - None + Tls12 TCPPort @@ -1439,7 +1427,7 @@ AssignmentPosition : 1 Int32 - None + 8443 WebSession @@ -1459,14 +1447,14 @@ AssignmentPosition : 1 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -1502,7 +1490,7 @@ AssignmentPosition : 1 String[] - None + Tls12 TCPPort @@ -1514,7 +1502,7 @@ AssignmentPosition : 1 Int32 - None + 8443 WebSession @@ -1579,7 +1567,12 @@ Id Product Version FirmwareType - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSFirmware.md + + @@ -1599,7 +1592,7 @@ Id Product Version FirmwareType ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -1609,7 +1602,7 @@ Id Product Version FirmwareType Int32 - None + 3 Computername @@ -1651,7 +1644,7 @@ Id Product Version FirmwareType String[] - None + Tls12 TCPPort @@ -1663,7 +1656,7 @@ Id Product Version FirmwareType Int32 - None + 8443 WebSession @@ -1683,14 +1676,14 @@ Id Product Version FirmwareType ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -1726,7 +1719,7 @@ Id Product Version FirmwareType String[] - None + Tls12 TCPPort @@ -1738,7 +1731,7 @@ Id Product Version FirmwareType Int32 - None + 8443 WebSession @@ -1830,7 +1823,12 @@ ObjectType : profile - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSProfile.md + + @@ -1850,7 +1848,7 @@ ObjectType : profile ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -1860,7 +1858,7 @@ ObjectType : profile Int32 - None + 3 Computername @@ -1913,7 +1911,7 @@ ObjectType : profile String[] - None + Tls12 TCPPort @@ -1925,7 +1923,7 @@ ObjectType : profile Int32 - None + 8443 WebSession @@ -1945,14 +1943,14 @@ ObjectType : profile ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -2000,7 +1998,7 @@ ObjectType : profile String[] - None + Tls12 TCPPort @@ -2012,7 +2010,7 @@ ObjectType : profile Int32 - None + 8443 WebSession @@ -2088,7 +2086,12 @@ AssignmentPosition : 0 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSProfileAssignment.md + + @@ -2108,7 +2111,7 @@ AssignmentPosition : 0 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -2118,7 +2121,7 @@ AssignmentPosition : 0 Int32 - None + 3 Computername @@ -2175,7 +2178,7 @@ AssignmentPosition : 0 String[] - None + Tls12 TCPPort @@ -2187,7 +2190,7 @@ AssignmentPosition : 0 Int32 - None + 8443 WebSession @@ -2207,14 +2210,14 @@ AssignmentPosition : 0 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -2262,7 +2265,7 @@ AssignmentPosition : 0 String[] - None + Tls12 TCPPort @@ -2274,7 +2277,7 @@ AssignmentPosition : 0 Int32 - None + 8443 WebSession @@ -2361,7 +2364,12 @@ DirectoryChildren : @{ObjectType=profile; Id=669} - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSProfileDirectory.md + + @@ -2400,12 +2408,12 @@ DirectoryChildren : @{ObjectType=profile; Id=669} Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -2415,7 +2423,7 @@ DirectoryChildren : @{ObjectType=profile; Id=669} Int32 - None + 3 SecurityProtocol @@ -2433,7 +2441,7 @@ DirectoryChildren : @{ObjectType=profile; Id=669} String[] - None + Tls12 WebSession @@ -2453,14 +2461,14 @@ DirectoryChildren : @{ObjectType=profile; Id=669} ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -2484,7 +2492,7 @@ DirectoryChildren : @{ObjectType=profile; Id=669} String[] - None + Tls12 TCPPort @@ -2496,7 +2504,7 @@ DirectoryChildren : @{ObjectType=profile; Id=669} Int32 - None + 8443 WebSession @@ -2552,8 +2560,13 @@ Server : igelrmserver:8443 - - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Get-UMSStatus.md + + + Move-UMSDevice @@ -2591,12 +2604,12 @@ Server : igelrmserver:8443 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -2606,7 +2619,7 @@ Server : igelrmserver:8443 Int32 - None + 3 SecurityProtocol @@ -2624,7 +2637,7 @@ Server : igelrmserver:8443 String[] - None + Tls12 WebSession @@ -2690,14 +2703,14 @@ Server : igelrmserver:8443 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -2757,7 +2770,7 @@ Server : igelrmserver:8443 String[] - None + Tls12 TCPPort @@ -2769,7 +2782,7 @@ Server : igelrmserver:8443 Int32 - None + 8443 WebSession @@ -2854,7 +2867,12 @@ $PSDefaultParameterValues += @{ - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSDevice.md + + @@ -2893,12 +2911,12 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -2908,7 +2926,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 3 SecurityProtocol @@ -2926,7 +2944,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 WebSession @@ -2992,14 +3010,14 @@ $PSDefaultParameterValues += @{ ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -3059,7 +3077,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 TCPPort @@ -3071,7 +3089,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 WebSession @@ -3156,7 +3174,12 @@ $PSDefaultParameterValues += @{ - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSDeviceDirectory.md + + @@ -3195,12 +3218,12 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -3210,7 +3233,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 3 SecurityProtocol @@ -3228,7 +3251,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 WebSession @@ -3294,14 +3317,14 @@ $PSDefaultParameterValues += @{ ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -3361,7 +3384,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 TCPPort @@ -3373,7 +3396,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 WebSession @@ -3458,7 +3481,12 @@ $PSDefaultParameterValues += @{ - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSProfile.md + + @@ -3497,12 +3525,12 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -3512,7 +3540,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 3 SecurityProtocol @@ -3530,7 +3558,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 WebSession @@ -3596,14 +3624,14 @@ $PSDefaultParameterValues += @{ ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -3663,7 +3691,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 TCPPort @@ -3675,7 +3703,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 WebSession @@ -3760,7 +3788,12 @@ $PSDefaultParameterValues += @{ - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Move-UMSProfileDirectory.md + + @@ -3799,7 +3832,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 Credential @@ -3816,7 +3849,7 @@ $PSDefaultParameterValues += @{ ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -3826,7 +3859,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 3 SecurityProtocol @@ -3844,7 +3877,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 Confirm @@ -3874,14 +3907,14 @@ $PSDefaultParameterValues += @{ ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -3929,7 +3962,7 @@ $PSDefaultParameterValues += @{ String[] - None + Tls12 TCPPort @@ -3941,7 +3974,7 @@ $PSDefaultParameterValues += @{ Int32 - None + 8443 WhatIf @@ -3992,7 +4025,7 @@ $PSDefaultParameterValues += @{ -------------------------- Example 2 -------------------------- #Save credential securely to file (one time only): -Get-Credential | Export-Clixml -Path ('{0}\igelums@igelrmserver.cred' -f ${env:\userprofile}) -Credential (Get-Credential) +Get-Credential | Export-Clixml -Path ('{0}\igelums@igelrmserver.cred' -f ${env:\userprofile}) #Load credential from file $Credential = Import-Clixml -Path ('{0}\igelums@igelrmserver.cred' -f ${env:\userprofile}) @@ -4004,7 +4037,12 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSAPICookie.md + + @@ -4043,7 +4081,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent Int32 - None + 8443 Department @@ -4132,7 +4170,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -4142,7 +4180,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent Int32 - None + 3 SecurityProtocol @@ -4160,7 +4198,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent String[] - None + Tls12 WebSession @@ -4262,14 +4300,14 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 AssetId @@ -4425,7 +4463,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent String[] - None + Tls12 SerialNumber @@ -4461,7 +4499,7 @@ $WebSession = New-UMSAPICookie -Computername 'igelrmserver' -Credential $Credent Int32 - None + 8443 WebSession @@ -4590,7 +4628,12 @@ ParentId : 665 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSDevice.md + + @@ -4629,12 +4672,12 @@ ParentId : 665 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -4644,7 +4687,7 @@ ParentId : 665 Int32 - None + 3 SecurityProtocol @@ -4662,7 +4705,7 @@ ParentId : 665 String[] - None + Tls12 WebSession @@ -4716,14 +4759,14 @@ ParentId : 665 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -4771,7 +4814,7 @@ ParentId : 665 String[] - None + Tls12 TCPPort @@ -4783,7 +4826,7 @@ ParentId : 665 Int32 - None + 8443 WebSession @@ -4860,7 +4903,12 @@ Directory successfully inserted. 739 Leipzig - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSDeviceDirectory.md + + @@ -4899,12 +4947,12 @@ Directory successfully inserted. 739 Leipzig Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -4914,7 +4962,7 @@ Directory successfully inserted. 739 Leipzig Int32 - None + 3 SecurityProtocol @@ -4932,7 +4980,7 @@ Directory successfully inserted. 739 Leipzig String[] - None + Tls12 WebSession @@ -5014,14 +5062,14 @@ Directory successfully inserted. 739 Leipzig ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -5062,19 +5110,311 @@ Directory successfully inserted. 739 Leipzig ReceiverId - Id of the device or device directory + Id of the device or device directory + + Int32 + + Int32 + + + None + + + ReceiverType + + Type of the device or device directory + + String + + String + + + None + + + SecurityProtocol + + Set SSL/TLS protocol + + String[] + + String[] + + + Tls12 + + + TCPPort + + TCP Port API + + Int32 + + Int32 + + + 8443 + + + WebSession + + Websession Cookie + + Object + + Object + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Int32 + + + + + + + + System.String + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + New-UMSProfileAssignment -Computername 'igelrmserver' -WebSession $WebSession -Id 390 -ReceiverId 58 -ReceiverType tc + +Message Id ReceiverId ReceiverType +------- -- ---------- ------------ +1 asssignments successfully assigned. 390 58 tc + + + + + + -------------------------- Example 2 -------------------------- + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = (Get-Credential) + '*-UMS*:Computername' = 'igelrmserver' +} +$PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = New-UMSAPICookie +} + +(Get-UMSProfile).where{$_.Name -match '^(01|07)'} | + New-UMSProfileAssignment -ReceiverId 664 -ReceiverType tcdirectory + +Message Id ReceiverId ReceiverType +------- -- ---------- ------------ +1 asssignments successfully assigned. 390 664 tcdirectory +1 asssignments successfully assigned. 669 664 tcdirectory + + + + + + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSProfileAssignment.md + + + + + + New-UMSProfileDirectory + New + UMSProfileDirectory + + Creates a profile directory. + + + + Creates a profile directory via API. + + + + New-UMSProfileDirectory + + Computername + + Computername of the UMS Server + + String + + String + + + None + + + TCPPort + + TCP Port API + + Int32 + + Int32 + + + 8443 + + + ApiVersion + + API Version to use + + + 3 + + Int32 + + Int32 + + + 3 + + + SecurityProtocol + + Set SSL/TLS protocol + + + Tls12 + Tls11 + Tls + Ssl3 + + String[] + + String[] + + + Tls12 + + + WebSession + + Websession Cookie + + Object + + Object + + + None + + + Name + + Name of the profile directory + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + ApiVersion + + API Version to use + + Int32 + + Int32 + + + 3 + + + Computername + + Computername of the UMS Server + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. - Int32 + SwitchParameter - Int32 + SwitchParameter - None + False - - ReceiverType + + Name - Type of the device or device directory + Name of the profile directory String @@ -5093,7 +5433,7 @@ Directory successfully inserted. 739 Leipzig String[] - None + Tls12 TCPPort @@ -5105,7 +5445,7 @@ Directory successfully inserted. 739 Leipzig Int32 - None + 8443 WebSession @@ -5133,14 +5473,6 @@ Directory successfully inserted. 739 Leipzig - - - System.Int32 - - - - - System.String @@ -5168,32 +5500,23 @@ Directory successfully inserted. 739 Leipzig -------------------------- Example 1 -------------------------- - New-UMSProfileAssignment -Computername 'igelrmserver' -WebSession $WebSession -Id 390 -ReceiverId 58 -ReceiverType tc + New-UMSProfileDirectory -Computername 'igelrmserver' -WebSession $WebSession -Name '06' -Message Id ReceiverId ReceiverType -------- -- ---------- ------------ -1 asssignments successfully assigned. 390 58 tc +Message Id Name +------- -- ---- +Directory successfully inserted. 743 06 -------------------------- Example 2 -------------------------- - $PSDefaultParameterValues = @{ - '*-UMS*:Credential' = (Get-Credential) - '*-UMS*:Computername' = 'igelrmserver' -} -$PSDefaultParameterValues += @{ - '*-UMS*:WebSession' = New-UMSAPICookie -} - -(Get-UMSProfile).where{$_.Name -match '^(01|07)'} | - New-UMSProfileAssignment -ReceiverId 664 -ReceiverType tcdirectory + '05', '06' | New-UMSProfileDirectory -Computername 'igelrmserver' -WebSession $WebSession -Message Id ReceiverId ReceiverType -------- -- ---------- ------------ -1 asssignments successfully assigned. 390 664 tcdirectory -1 asssignments successfully assigned. 669 664 tcdirectory +Message Id Name +------- -- ---- +Directory successfully inserted. 744 05 +Directory successfully inserted. 745 06 @@ -5202,25 +5525,25 @@ Message Id ReceiverId ReceiverType Online Version: - https://github.com/IGEL-Community/PSIGEL/blob/master/Docs/New-UMSAPICookie.md + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/New-UMSProfileDirectory.md - New-UMSProfileDirectory - New - UMSProfileDirectory + Remove-UMSAPICookie + Remove + UMSAPICookie - Creates a profile directory. + Removes a websession cookie. - Creates a profile directory via API. + Removes a websession cookie for the UMS API. - New-UMSProfileDirectory + Remove-UMSAPICookie Computername @@ -5243,12 +5566,12 @@ Message Id ReceiverId ReceiverType Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -5258,7 +5581,7 @@ Message Id ReceiverId ReceiverType Int32 - None + 3 SecurityProtocol @@ -5276,7 +5599,7 @@ Message Id ReceiverId ReceiverType String[] - None + Tls12 WebSession @@ -5290,18 +5613,6 @@ Message Id ReceiverId ReceiverType None - - Name - - Name of the profile directory - - String - - String - - - None - Confirm @@ -5330,14 +5641,14 @@ Message Id ReceiverId ReceiverType ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -5363,18 +5674,6 @@ Message Id ReceiverId ReceiverType False - - Name - - Name of the profile directory - - String - - String - - - None - SecurityProtocol @@ -5385,7 +5684,7 @@ Message Id ReceiverId ReceiverType String[] - None + Tls12 TCPPort @@ -5397,7 +5696,7 @@ Message Id ReceiverId ReceiverType Int32 - None + 8443 WebSession @@ -5427,7 +5726,7 @@ Message Id ReceiverId ReceiverType - System.String + Keine @@ -5452,29 +5751,27 @@ Message Id ReceiverId ReceiverType -------------------------- Example 1 -------------------------- - New-UMSProfileDirectory -Computername 'igelrmserver' -WebSession $WebSession -Name '06' + Remove-UMSAPICookie -ComputerName 'igelrmserver' -WebSession $WebSession -Message Id Name -------- -- ---- -Directory successfully inserted. 743 06 +D7588A4A667B3B76650245A8BF335036 - -------------------------- Example 2 -------------------------- - '05', '06' | New-UMSProfileDirectory -Computername 'igelrmserver' -WebSession $WebSession - -Message Id Name -------- -- ---- -Directory successfully inserted. 744 05 -Directory successfully inserted. 745 06 + -------------------------- Example 1 -------------------------- + $null = Remove-UMSAPICookie -ComputerName 'igelrmserver' -WebSession $WebSession - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSAPICookie.md + + @@ -5494,7 +5791,7 @@ Directory successfully inserted. 745 06 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -5504,7 +5801,7 @@ Directory successfully inserted. 745 06 Int32 - None + 3 Computername @@ -5568,7 +5865,7 @@ Directory successfully inserted. 745 06 String[] - None + Tls12 TCPPort @@ -5580,7 +5877,7 @@ Directory successfully inserted. 745 06 Int32 - None + 8443 WebSession @@ -5611,14 +5908,14 @@ Directory successfully inserted. 745 06 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -5678,7 +5975,7 @@ Directory successfully inserted. 745 06 String[] - None + Tls12 TCPPort @@ -5690,7 +5987,7 @@ Directory successfully inserted. 745 06 Int32 - None + 8443 WebSession @@ -5804,7 +6101,12 @@ Offline deletion successful. 752 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSDevice.md + + @@ -5843,12 +6145,12 @@ Offline deletion successful. 752 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -5858,7 +6160,7 @@ Offline deletion successful. 752 Int32 - None + 3 SecurityProtocol @@ -5876,7 +6178,7 @@ Offline deletion successful. 752 String[] - None + Tls12 WebSession @@ -5930,14 +6232,14 @@ Offline deletion successful. 752 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -5985,7 +6287,7 @@ Offline deletion successful. 752 String[] - None + Tls12 TCPPort @@ -5997,7 +6299,7 @@ Offline deletion successful. 752 Int32 - None + 8443 WebSession @@ -6091,7 +6393,12 @@ Deletion successful. 687 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSDeviceDirectory.md + + @@ -6130,12 +6437,12 @@ Deletion successful. 687 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -6145,7 +6452,7 @@ Deletion successful. 687 Int32 - None + 3 SecurityProtocol @@ -6163,7 +6470,7 @@ Deletion successful. 687 String[] - None + Tls12 WebSession @@ -6217,14 +6524,14 @@ Deletion successful. 687 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -6272,7 +6579,7 @@ Deletion successful. 687 String[] - None + Tls12 TCPPort @@ -6284,7 +6591,7 @@ Deletion successful. 687 Int32 - None + 8443 WebSession @@ -6376,7 +6683,12 @@ Deleted profile. 390 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSProfile.md + + @@ -6415,12 +6727,12 @@ Deleted profile. 390 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -6430,7 +6742,7 @@ Deleted profile. 390 Int32 - None + 3 SecurityProtocol @@ -6448,7 +6760,7 @@ Deleted profile. 390 String[] - None + Tls12 WebSession @@ -6462,7 +6774,7 @@ Deleted profile. 390 None - + Id ID of the profile @@ -6530,14 +6842,14 @@ Deleted profile. 390 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -6563,7 +6875,7 @@ Deleted profile. 390 False - + Id ID of the profile @@ -6609,7 +6921,7 @@ Deleted profile. 390 String[] - None + Tls12 TCPPort @@ -6621,7 +6933,7 @@ Deleted profile. 390 Int32 - None + 8443 WebSession @@ -6720,7 +7032,12 @@ deleted profile assignment. 69 71 tcdirectory - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSProfileAssignment.md + + @@ -6759,12 +7076,12 @@ deleted profile assignment. 69 71 tcdirectory Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -6774,7 +7091,7 @@ deleted profile assignment. 69 71 tcdirectory Int32 - None + 3 SecurityProtocol @@ -6792,7 +7109,7 @@ deleted profile assignment. 69 71 tcdirectory String[] - None + Tls12 WebSession @@ -6846,14 +7163,14 @@ deleted profile assignment. 69 71 tcdirectory ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -6901,7 +7218,7 @@ deleted profile assignment. 69 71 tcdirectory String[] - None + Tls12 TCPPort @@ -6913,7 +7230,7 @@ deleted profile assignment. 69 71 tcdirectory Int32 - None + 8443 WebSession @@ -7005,7 +7322,12 @@ Deletion successful. 230 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Remove-UMSProfileDirectory.md + + @@ -7017,7 +7339,7 @@ Deletion successful. 230 - Resets a device to factory defaults and removes it completely (without recycle bin) via API. The device has to be online to be reset, otherwise the device is only removed. + Resets a device to factory defaults and removes it completely (without recycle bin) via API. @@ -7044,12 +7366,12 @@ Deletion successful. 230 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -7059,7 +7381,7 @@ Deletion successful. 230 Int32 - None + 3 SecurityProtocol @@ -7077,7 +7399,7 @@ Deletion successful. 230 String[] - None + Tls12 WebSession @@ -7131,14 +7453,14 @@ Deletion successful. 230 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -7186,7 +7508,7 @@ Deletion successful. 230 String[] - None + Tls12 TCPPort @@ -7198,7 +7520,7 @@ Deletion successful. 230 Int32 - None + 8443 WebSession @@ -7304,7 +7626,12 @@ State : SUCCESS - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Reset-UMSDevice.md + + @@ -7343,12 +7670,12 @@ State : SUCCESS Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -7358,7 +7685,7 @@ State : SUCCESS Int32 - None + 3 SecurityProtocol @@ -7376,7 +7703,7 @@ State : SUCCESS String[] - None + Tls12 WebSession @@ -7430,14 +7757,14 @@ State : SUCCESS ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -7485,7 +7812,7 @@ State : SUCCESS String[] - None + Tls12 TCPPort @@ -7497,7 +7824,7 @@ State : SUCCESS Int32 - None + 8443 WebSession @@ -7596,7 +7923,12 @@ State : SUCCESS - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Restart-UMSDevice.md + + @@ -7635,12 +7967,12 @@ State : SUCCESS Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -7650,7 +7982,7 @@ State : SUCCESS Int32 - None + 3 SecurityProtocol @@ -7668,7 +8000,7 @@ State : SUCCESS String[] - None + Tls12 WebSession @@ -7722,14 +8054,14 @@ State : SUCCESS ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -7777,7 +8109,7 @@ State : SUCCESS String[] - None + Tls12 TCPPort @@ -7789,7 +8121,7 @@ State : SUCCESS Int32 - None + 8443 WebSession @@ -7888,7 +8220,12 @@ State : SUCCESS - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Send-UMSDeviceSetting.md + + @@ -7927,12 +8264,12 @@ State : SUCCESS Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -7942,7 +8279,7 @@ State : SUCCESS Int32 - None + 3 SecurityProtocol @@ -7960,7 +8297,7 @@ State : SUCCESS String[] - None + Tls12 WebSession @@ -8014,14 +8351,14 @@ State : SUCCESS ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -8069,7 +8406,7 @@ State : SUCCESS String[] - None + Tls12 TCPPort @@ -8081,7 +8418,7 @@ State : SUCCESS Int32 - None + 8443 WebSession @@ -8180,7 +8517,12 @@ State : SUCCESS SUCCESS - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Start-UMSDevice.md + + @@ -8219,12 +8561,12 @@ State : SUCCESS SUCCESS Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -8234,7 +8576,7 @@ State : SUCCESS SUCCESS Int32 - None + 3 SecurityProtocol @@ -8252,7 +8594,7 @@ State : SUCCESS SUCCESS String[] - None + Tls12 WebSession @@ -8306,14 +8648,14 @@ State : SUCCESS SUCCESS ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -8361,7 +8703,7 @@ State : SUCCESS SUCCESS String[] - None + Tls12 TCPPort @@ -8373,7 +8715,7 @@ State : SUCCESS SUCCESS Int32 - None + 8443 WebSession @@ -8472,7 +8814,12 @@ State : SUCCESS - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Stop-UMSDevice.md + + @@ -8492,7 +8839,7 @@ State : SUCCESS ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -8502,7 +8849,7 @@ State : SUCCESS Int32 - None + 3 AssetId @@ -8639,7 +8986,7 @@ State : SUCCESS String[] - None + Tls12 SerialNumber @@ -8675,7 +9022,7 @@ State : SUCCESS Int32 - None + 8443 WebSession @@ -8706,14 +9053,14 @@ State : SUCCESS ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 AssetId @@ -8845,7 +9192,7 @@ State : SUCCESS String[] - None + Tls12 SerialNumber @@ -8881,7 +9228,7 @@ State : SUCCESS Int32 - None + 8443 WebSession @@ -8970,7 +9317,12 @@ Update successful. 195 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Update-UMSDevice.md + + @@ -9009,12 +9361,12 @@ Update successful. 195 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -9024,7 +9376,7 @@ Update successful. 195 Int32 - None + 3 SecurityProtocol @@ -9042,7 +9394,7 @@ Update successful. 195 String[] - None + Tls12 WebSession @@ -9108,14 +9460,14 @@ Update successful. 195 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -9175,7 +9527,7 @@ Update successful. 195 String[] - None + Tls12 TCPPort @@ -9187,7 +9539,7 @@ Update successful. 195 Int32 - None + 8443 WebSession @@ -9287,7 +9639,7 @@ Updated directory successfully. 665 Online Version: - https://github.com/IGEL-Community/PSIGEL/blob/master/Docs/Update-UMSDevice.md + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Update-UMSDeviceDirectory.md @@ -9328,12 +9680,12 @@ Updated directory successfully. 665 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -9343,7 +9695,7 @@ Updated directory successfully. 665 Int32 - None + 3 SecurityProtocol @@ -9361,7 +9713,7 @@ Updated directory successfully. 665 String[] - None + Tls12 WebSession @@ -9427,14 +9779,14 @@ Updated directory successfully. 665 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -9494,7 +9846,7 @@ Updated directory successfully. 665 String[] - None + Tls12 TCPPort @@ -9506,7 +9858,7 @@ Updated directory successfully. 665 Int32 - None + 8443 WebSession @@ -9604,7 +9956,12 @@ Update successful. 669 - + + + Online Version: + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Update-UMSProfile.md + + @@ -9643,12 +10000,12 @@ Update successful. 669 Int32 - None + 8443 ApiVersion - API Version to use (Default: 3) + API Version to use 3 @@ -9658,7 +10015,7 @@ Update successful. 669 Int32 - None + 3 SecurityProtocol @@ -9676,7 +10033,7 @@ Update successful. 669 String[] - None + Tls12 WebSession @@ -9742,14 +10099,14 @@ Update successful. 669 ApiVersion - API Version to use (Default: 3) + API Version to use Int32 Int32 - None + 3 Computername @@ -9809,7 +10166,7 @@ Update successful. 669 String[] - None + Tls12 TCPPort @@ -9821,7 +10178,7 @@ Update successful. 669 Int32 - None + 8443 WebSession @@ -9922,7 +10279,7 @@ Updated directory successfully. 668 Online Version: - https://github.com/IGEL-Community/PSIGEL/blob/master/Docs/Stop-UMSDevice.md + https://github.com/IGEL-Community/PSIGEL/Docs/Reference/Update-UMSProfileDirectory.md diff --git a/README.MD b/README.MD index 749a88d..6c11e41 100644 --- a/README.MD +++ b/README.MD @@ -1,133 +1,158 @@ # PSIGEL -This is a module to interact with the IGEL UMS via API and IGEL OS Devices via SSH. +[![GitHub last commit][github-commit-badge]][github-psigel] +[![GitHub release (latest by date)][github-release-badge]][github-psigel] +[![PowerShell Gallery Version][psgallery-v-badge]][powershell-gallery] +[![PS Gallery][psgallery-dl-badge]][powershell-gallery] +[![GitHub stars][github-start-badge]][github-psigel] +[![IGEL-Community Slack][slack-badge]][slack-igelcommunity] -**API** functions got the noun-prefix **UMS** (for Universal Management Server), e.g. Get-**UMS**Something +![Logo](/Docs/Media/PSIGEL_1280_320.png) -**SSH** functions got the noun-prefix **OS** (for Device), e.g. Get-**OS**Something +## Table of contents -To connect to the Devices via **SSH**, the Module [Posh-SSH](https://github.com/darkoperator/Posh-SSH) by Carlos Perez aka darkoperator is required. +- [Overview](#overview) +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Getting Started](#getting-started) +- [Documentation](#documentation) +- [Maintainer](#maintainer) +- [License](#license) -The **API** uses a cookie as authentication. You can create it with [New-UMSAPICookie](/#new-umsapicookie): +## Overview -```powershell -$Websession = New-UMSAPICookie -Computername igelrmserver -``` - -My goal is to support all [API-functionalities](https://kb.igel.com/igelimi-v3/en/imi-api-v3-reference-2723425.html) IGEL provides. Use at own risk! Suggestions are welcome. - -## Installation - -If you have the [PowerShellGet](https://github.com/powershell/powershellget) module installed you can enter the following command: - -```powershell -Install-Module -Name PSIGEL -``` - -Alternatively you can download a ZIP file of the latest version from our [Releases](https://github.com/IGEL-Community/PSIGEL/releases) page. - -## PSIGEL Cmdlets -### [Get-OSFirmware](/Docs/Get-OSFirmware.md) -Gets firmware from a device. - -### [Get-OSUpdateConfiguration](/Docs/Get-OSUpdateConfiguration.md) -Gets firmware from a device. - -### [Get-OSWifiConnection](/Docs/Get-OSWifiConnection.md) -Gets wifi connection from a device. - -### [Get-UMSDevice](/Docs/Get-UMSDevice.md) -Gets information on a device. - -### [Get-UMSDeviceAssignment](/Docs/Get-UMSDeviceAssignment.md) -Gets information on a profile or master profile assignment of a device. - -### [Get-UMSDeviceDirectory](/Docs/Get-UMSDeviceDirectory.md) -Gets information on a device directory. - -### [Get-UMSDeviceDirectoryAssignment](/Docs/Get-UMSDeviceDirectoryAssignment.md) -Gets information on a profile or master profile assignment of a device directory. - -### [Get-UMSFirmware](/Docs/Get-UMSFirmware.md) -Gets information on a firmware. - -### [Get-UMSProfile](/Docs/Get-UMSProfile.md) -Gets information on a profile. +**PSIGEL** is a powershell module that makes use of the REST API provided by the [**IGEL**](https://www.igel.com) Management Interface (IMI). -### [Get-UMSProfileAssignment](/Docs/Get-UMSProfileAssignment.md) -Gets information on a device or device directory assignment of a profile. +via [IGEL Knowledgebase](https://kb.igel.com/igelimi-v3/en/imi-manual-2723216.html) : +> IGEL Management Interface (IMI) enables you to connect UMS to systems management tools. It is a programming interface that can create and delete thin clients, move them between directories, reboot them and much more. Its implementation as a REST API makes IMI agnostic of hardware platforms, operating systems and programming languages, thus ensuring maximum interoperability. -### [Get-UMSProfileDirectory](/Docs/Get-UMSProfileDirectory.md) -Gets information on a profile directory. +## Prerequisites -### [Get-UMSStatus](/Docs/Get-UMSStatus.md) -Gets information on the UMS. +|OS|min. PS Version (Edition)| +|-|-| +|Windows|5.1 (Desktop)\*| +|Windows|7 (Core)\*| +|Linux|7 (Core)\*| +|MacOS|7 (Core)| -### [Move-UMSDevice](/Docs/Move-UMSDevice.md) -Moves a device to a device directory. +\* tested -### [Move-UMSDeviceDirectory](/Docs/Move-UMSDeviceDirectory.md) -Moves a device directory to a device directory. +## Quickstart -### [Move-UMSProfile](/Docs/Move-UMSProfile.md) -Moves a profile to a profile directory. +### Installation -### [Move-UMSProfileDirectory](/Docs/Move-UMSProfileDirectory.md) -Moves a profile directory to profile directory. - -### [New-UMSAPICookie](/Docs/New-UMSAPICookie.md) -Creates a websession cookie. - -### [New-UMSDevice](/Docs/New-UMSDevice.md) -Creates a new device. - -### [New-UMSDeviceDirectory](/Docs/New-UMSDeviceDirectory.md) -Creates a device directory. - -### [New-UMSProfileAssignment](/Docs/New-UMSProfileAssignment.md) -Creates a profile assignment on a device or device directory. - -### [New-UMSProfileDirectory](/Docs/New-UMSProfileDirectory.md) -Creates a profile directory. - -### [Remove-UMSDevice](/Docs/Remove-UMSDevice.md) -Removes a device. - -### [Remove-UMSDeviceDirectory](/Docs/Remove-UMSDeviceDirectory.md) -Removes a device directory. +If you have the [PowerShellGet](https://github.com/powershell/powershellget) module installed you can enter the following command: -### [Remove-UMSProfile](/Docs/Remove-UMSProfile.md) -Removes a profile. +```powershell +C:\> Install-Module -Name PSIGEL +``` -### [Remove-UMSProfileAssignment](/Docs/Remove-UMSProfileAssignment.md) -Removes a profile assignment from a device or device directory. +Alternatively you can download a ZIP file of the latest version from our [Releases](https://github.com/IGEL-Community/PSIGEL/releases) page. -### [Remove-UMSProfileDirectory](/Docs/Remove-UMSProfileDirectory.md) -Removes a profile directory. +### Basic usage -### [Reset-UMSDevice](/Docs/Reset-UMSDevice.md) -Resets a device to factory defaults. +Import Module: -### [Restart-UMSDevice](/Docs/Restart-UMSDevice.md) -Restarts a device. +```powershell +C:\> Import-Module -Name PSIGEL +``` -### [Send-UMSDeviceSetting](/Docs/Send-UMSDeviceSetting.md) -Sends settings to a device. +Create a WebSession -### [Start-UMSDevice](/Docs/Start-UMSDevice.md) -Wakes up a device. +```powershell +C:\> $WebSession = New-UMSAPICookie -Computername igelrmserver -Credential (Get-Credential) +``` -### [Stop-UMSDevice](/Docs/Stop-UMSDevice.md) -Shuts down a device. +Call a Function - e.g. get status information from the UMS server: -### [Update-UMSDevice](/Docs/Update-UMSDevice.md) -Updates properties of a device. +```powershell +C:\> Get-UMSStatus -Computername igelrmserver -WebSession $WebSession + +RmGuiServerVersion : 6.3.130 +BuildNumber : 44584 +ActiveMqVersion : 5.7.0 +DerbyVersion : 10.12.1.1 +ServerUuid : f30fb3a2-37d4-4cbb-b884-4f5061d3260e +Server : igelrmserver:8443 +``` -### [Update-UMSDeviceDirectory](/Docs/Update-UMSDeviceDirectory.md) -Updates the name of a device directory. +Remove WebSession: -### [Update-UMSProfile](/Docs/Update-UMSProfile.md) -Updates the name of a profile. +```powershell +C:\> $null = Remove-UMSAPICookie -Computername igelrmserver -WebSession $WebSession +``` -### [Update-UMSProfileDirectory](/Docs/Update-UMSProfileDirectory.md) -Updates the name of a profile directory. \ No newline at end of file +## Documentation + +- [Scripting with PSIGEL](/Docs/Guides/Scripting-with-PSIGEL.md) + - [Installation](/Docs/Guides/Scripting-with-PSIGEL.md#installation) + - [Setup](/Docs/Guides/Scripting-with-PSIGEL.md#setup) + - [Configuration](/Docs/Guides/Scripting-with-PSIGEL.md#configuration) + - [Authentication](/Docs/Guides/Scripting-with-PSIGEL.md#authentication) + - [Creating a script](/Docs/Guides/Scripting-with-PSIGEL.md#creating-a-script) +- Functions + - [Get-UMSDevice](/Docs/Reference/Get-UMSDevice.md) + - [Get-UMSDeviceAssignment](/Docs/Reference/Get-UMSDeviceAssignment.md) + - [Get-UMSDeviceDirectory](/Docs/Reference/Get-UMSDeviceDirectory.md) + - [Get-UMSDeviceDirectoryAssignment](/Docs/Reference/Get-UMSDeviceDirectoryAssignment.md) + - [Get-UMSDirectoryRecursive](/Docs/Reference/Get-UMSDirectoryRecursive.md) + - [Get-UMSFirmware](/Docs/Reference/Get-UMSFirmware.md) + - [Get-UMSProfile](/Docs/Reference/Get-UMSProfile.md) + - [Get-UMSProfileAssignment](/Docs/Reference/Get-UMSProfileAssignment.md) + - [Get-UMSProfileDirectory](/Docs/Reference/Get-UMSProfileDirectory.md) + - [Get-UMSStatus](/Docs/Reference/Get-UMSStatus.md) + - [Move-UMSDevice](/Docs/Reference/Move-UMSDevice.md) + - [Move-UMSDeviceDirectory](/Docs/Reference/Move-UMSDeviceDirectory.md) + - [Move-UMSProfile](/Docs/Reference/Move-UMSProfile.md) + - [Move-UMSProfileDirectory](/Docs/Reference/Move-UMSProfileDirectory.md) + - [New-UMSAPICookie](/Docs/Reference/New-UMSAPICookie.md) + - [New-UMSDevice](/Docs/Reference/New-UMSDevice.md) + - [New-UMSDeviceDirectory](/Docs/Reference/New-UMSDeviceDirectory.md) + - [New-UMSProfileAssignment](/Docs/Reference/New-UMSProfileAssignment.md) + - [New-UMSProfileDirectory](/Docs/Reference/New-UMSProfileDirectory.md) + - [Remove-UMSAPICookie](/Docs/Reference/Remove-UMSAPICookie.md) + - [Remove-UMSDevice](/Docs/Reference/Remove-UMSDevice.md) + - [Remove-UMSDeviceDirectory](/Docs/Reference/Remove-UMSDeviceDirectory.md) + - [Remove-UMSProfile](/Docs/Reference/Remove-UMSProfile.md) + - [Remove-UMSProfileAssignment](/Docs/Reference/Remove-UMSProfileAssignment.md) + - [Remove-UMSProfileDirectory](/Docs/Reference/Remove-UMSProfileDirectory.md) + - [Reset-UMSDevice](/Docs/Reference/Reset-UMSDevice.md) + - [Restart-UMSDevice](/Docs/Reference/Restart-UMSDevice.md) + - [Send-UMSDeviceSetting](/Docs/Reference/Send-UMSDeviceSetting.md) + - [Start-UMSDevice](/Docs/Reference/Start-UMSDevice.md) + - [Stop-UMSDevice](/Docs/Reference/Stop-UMSDevice.md) + - [Update-UMSDevice](/Docs/Reference/Update-UMSDevice.md) + - [Update-UMSDeviceDirectory](/Docs/Reference/Update-UMSDeviceDirectory.md) + - [Update-UMSProfile](/Docs/Reference/Update-UMSProfile.md) + - [Update-UMSProfileDirectory](/Docs/Reference/Update-UMSProfileDirectory.md) +- Other sources + - [igelexperts.com](https://www.igelexperts.com/category/igel/psigel/) +- [Changelog](CHANGELOG.md) + +## Maintainer + +- Falk Heiland +[![https://github.com/falkheiland][github-fh-badge]][github-fh] +[![http://twitter.com/falkheiland][twitter-fh-badge]][twitter-fh] + +## License + +This project is [licensed under the MIT License](LICENSE). + +[![MIT licensed][mit-badge]][mit-license] + +[psgallery-dl-badge]: https://img.shields.io/powershellgallery/dt/PSIGEL.svg?logo=powershell +[powershell-gallery]: https://www.powershellgallery.com/packages/PSIGEL/ +[mit-badge]: https://img.shields.io/github/license/IGEL-Community/PSIGEL?logo=github +[mit-license]: LICENSE +[github-commit-badge]: https://img.shields.io/github/last-commit/IGEL-Community/PSIGEL?logo=github +[github-psigel]: https://github.com/IGEL-Community/PSIGEL +[github-release-badge]: https://img.shields.io/github/release/IGEL-Community/PSIGEL/all.svg?logo=github +[psgallery-v-badge]: https://img.shields.io/powershellgallery/v/PSIGEL?include_prereleases&logo=powershell +[github-start-badge]: https://img.shields.io/github/stars/IGEL-Community/PSIGEL?logo=github +[slack-badge]: https://img.shields.io/badge/chat-IGEL%20Community-brightgreen?logo=slack +[slack-igelcommunity]: https://igelcommunity.slack.com/ +[github-fh-badge]: https://img.shields.io/badge/Github-falkheiland-green?logo=github +[github-fh]: https://github.com/falkheiland +[twitter-fh-badge]: https://img.shields.io/badge/Twitter-falkheiland-blue?logo=twitter +[twitter-fh]: https://twitter.com/falkheiland diff --git a/Scripts/GetDirectories.ps1 b/Scripts/GetDirectories.ps1 new file mode 100644 index 0000000..dac65bb --- /dev/null +++ b/Scripts/GetDirectories.ps1 @@ -0,0 +1,41 @@ +$UMSCredPath = 'C:\Credentials\UmsRmdb.cred' + +$PSDefaultParameterValues = @{ + 'New-UMSAPICookie:Credential' = Import-Clixml -Path $UMSCredPath + '*-UMS*:Computername' = 'igelrmserver' + '*-UMS*:SecurityProtocol' = 'Tls' +} +$PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = (New-UMSAPICookie) +} + +#$DeviceColl = Get-UMSDevice +$DeviceDirectoryColl = Get-UMSDeviceDirectory +$StartDirectoryColl = ($DeviceDirectoryColl).where{ @(197) -contains $_.Id } + +function Get-Coll +{ + param ( + $id + ) + + $Coll = @() + + $Coll += ($DeviceDirectoryColl).where{ $_.Id -eq $id } + + $ChildDirColl = ($DeviceDirectoryColl).where{ $_.ParentId -eq $id } + + foreach ($ChildDir in $ChildDirColl) + { + $childColl = Get-Coll -id $ChildDir.Id + $Coll += $childColl + } + $Coll +} + +$Result = foreach ($StartDirectory in $StartDirectoryColl) +{ + Get-Coll -id $StartDirectory.Id +} + +$Result diff --git a/Scripts/GetOSDeviceWifiInformation.ps1 b/Scripts/GetOSDeviceWifiInformation.ps1 index 981703b..da644ce 100644 --- a/Scripts/GetOSDeviceWifiInformation.ps1 +++ b/Scripts/GetOSDeviceWifiInformation.ps1 @@ -1,35 +1,57 @@ -$UMSCredPath = 'C:\Credentials\UmsRmdb.cred' -$UMSUser = 'rmdb' -$UMSPassword = Get-Content $UMSCredPath | ConvertTo-SecureString -$RootCredPath = 'C:\Credentials\TCRoot.cred' -$RootCredential = (Import-Clixml -Path $RootCredPath) -#Id of the devicedirectory -[Int]$TcDirId = 999 +<# + requires function Invoke-Parallel: + https://raw.githubusercontent.com/RamblingCookieMonster/Invoke-Parallel/master/Invoke-Parallel/Invoke-Parallel.ps1 +#> + +[Int]$DeviceDirId = 75 +[String]$Computername = 'igelrmserver' +[String[]]$SecurityProtocol = 'Tls12' +[String]$UMSCPath = 'C:\Credentials\UmsRmdb.cred' +[String]$DeviceCPath = 'C:\Credentials\DeviceRoot.cred' +[Switch]$Online = $false +[String]$PathToInvokeParallel = '{0}\Invoke-Parallel.ps1' -f $PSScriptRoot +$SSHCredential = (Import-Clixml -Path $DeviceCPath) $PSDefaultParameterValues = @{ - '*-UMS*:Credential' = (New-Object System.Management.Automation.PsCredential($UMSUser, $UMSPassword)) - '*-UMS*:Computername' = 'igelrmserver.acme.org' - '*-UMS*:SecurityProtocol' = 'Tls12' + '*-UMS*:Credential' = (Import-Clixml -Path $UMSCPath) + '*-UMS*:Computername' = $Computername + '*-UMS*:SecurityProtocol' = $SecurityProtocol } -$WebSession = New-UMSAPICookie - $PSDefaultParameterValues += @{ - '*-UMS*:WebSession' = $WebSession + '*-UMS*:WebSession' = (New-UMSAPICookie) +} + +if (!(Get-Command Invoke-Parallel -ErrorAction SilentlyContinue)) +{ + . $PathToInvokeParallel } -$DirColl = (Get-UMSDeviceDirectory -Id $TcDirId -Filter children).DirectoryChildren -$DeviceColl = $DirColl.where{$_.ObjectType -eq 'tc'} | Get-UMSDevice -Filter online -$OnlineDeviceColl = $DeviceColl.Where{$_.Online -eq $true} +$DirColl = (Get-UMSDeviceDirectory -Id $DeviceDirId -Filter children).DirectoryChildren + +switch ($Online) +{ + $true + { + $DeviceColl = ($DirColl.where{$_.ObjectType -eq 'tc'} | Get-UMSDevice -Filter online).where{$_.Online -eq $true} + } + Default + { + $DeviceColl = $DirColl.where{$_.ObjectType -eq 'tc'} | Get-UMSDevice + } +} -$UpdateConfigurationColl = $OnlineDeviceColl | - Invoke-Parallel -RunspaceTimeout 10 -ScriptBlock { - $SshSession = New-SSHSession -Computername $_.Name -Credential $Using:RootCredential -AcceptKey - Get-OSWifiConnection -SSHSession $SshSession - $null = Remove-SSHSession -SSHSession $SshSession +$DeviceWifiColl = $DeviceColl | + Invoke-Parallel -RunspaceTimeout 20 -ScriptBlock { + $SshSession = New-SSHSession -Computername $_.Name -Credential $Using:SSHCredential -AcceptKey -ErrorAction SilentlyContinue + if ($SshSession) + { + Get-OSWifiConnection -SSHSession $SshSession + $null = Remove-SSHSession -SSHSession $SshSession + } } -$UpdateConfigurationColl | Select-Object Host, Interface, ESSID, Mode, Frequency, AccessPoint, BitRate, @{ +$DeviceWifiColl | Select-Object Host, Interface, ESSID, Mode, Frequency, AccessPoint, BitRate, @{ name = 'LinkQuality' expression = { [math]::Round(($_.LinkQualityActual / $_.LinkQualityMax * 100), 0) } }, SignalLevel | diff --git a/Scripts/GetUMSDeviceUpgradeToOs11.ps1 b/Scripts/GetUMSDeviceUpgradeToOs11.ps1 new file mode 100644 index 0000000..111a222 --- /dev/null +++ b/Scripts/GetUMSDeviceUpgradeToOs11.ps1 @@ -0,0 +1,98 @@ +<# + +Join-Object function is required +https://github.com/RamblingCookieMonster/PowerShell/blob/master/Join-Object.ps1 + +- Gets all devices and all firmwares from UMS +- throws out all 'legacy' devices (non-IGEL devices) +- looks for devices with product ids from $SupportedDeviceCollJson +- categorizes devices with OS11 and higher as non upgradeble + +IGEL Devices That Can Be Upgraded to IGEL OS 11 +CPU with 64-bit support +≥ 2 GB RAM +≥ 2 GB Flash +No VIA graphics adapter +https://kb.igel.com/igelos-10.05.800/en/igel-devices-that-can-be-upgraded-to-igel-os-11-14686133.html + +#> +#$Path = '{0}\IGELDevicesAbleToUpgradeToOS11-{1}.xlsx' -f $Env:TEMP, ((Get-Date).ToString('s') -replace '(-|:)', '') + +$SupportedDeviceCollJson = @' +{ + "ProductId": + [ + "UD2-LX 40", + "UD3-LX 51", + "UD3-LX 50", + "UD5-LX 50", + "UD6-LX 51", + "UD7-LX 10", + "UD9-LX 41", + "UD9-LX 40", + "IZ2 40", + "IZ3 51", + "IZ3 50" + ] +} +'@ +$SupportedDeviceColl = $SupportedDeviceCollJson | ConvertFrom-Json + +$PSDefaultParameterValues = @{ + '*-UMS*:Credential' = (Get-Credential) + '*-UMS*:Computername' = 'igelrmserver' + '*-UMS*:SecurityProtocol' = 'Tls12' +} + +$PSDefaultParameterValues += @{ + '*UMS*:WebSession' = (New-UMSAPICookie) +} + +$FirmwareColl = Get-UMSFirmware + +$DeviceColl = Get-UMSDevice -Filter details | +Where-Object { ($_.ProductId) -and ($_.DeviceType -notmatch '^Legacy') } +Select-Object -Property Name, Id, FirmwareId, MemorySize, FlashSize, OsType, DeviceType, ProductId, @{ + name = 'ProductIdParsed' + expression = + { + ([regex]::match($_.ProductId, "^(UD(2|3|5|6|7|9)-LX\s\d{2,2})")).value + } +}, @{ + name = 'Codec' + expression = + { + ([regex]::match($_.ProductId, "(a|c|ac)$")).value + } +} + +$JoinObjectParams = @{ + Left = $DeviceColl + LeftJoinProperty = 'FirmwareId' + Right = $FirmwareColl + RightJoinProperty = 'Id' + RightProperties = 'Product', 'Version', 'FirmwareTyp' + Type = 'AllInLeft' +} +$DeviceFirmwareColl = Join-Object @JoinObjectParams + +$AddMemberParams = @{ + MemberType = 'NoteProperty' + Name = 'Upgrade to OS11' + PassThru = $True + Force = $True +} + +$Result = foreach ($Device in $DeviceFirmwareColl) +{ + if (($SupportedDeviceColl.ProductId -contains $Device.ProductIdParsed) -and ($Device.Version -lt '11.0.0')) + { + $Device | Add-Member @AddMemberParams -Value $True + } + else + { + $Device | Add-Member @AddMemberParams -Value $False + } +} + +$Result | Out-GridView diff --git a/Scripts/ImportDevices.ps1 b/Scripts/ImportDevices.ps1 new file mode 100644 index 0000000..e0779be --- /dev/null +++ b/Scripts/ImportDevices.ps1 @@ -0,0 +1,44 @@ +$PSDefaultParameterValues = @{ + '*-UMS*:Computername' = 'igelrmserver' + 'New-UMSAPICookie:Credential' = (Get-Credential) +} +$PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = New-UMSAPICookie +} + +$Path = 'C:\Temp\' + +$IGELImportFile = '{0}2260123456-000010.csv' -f $Path +$AssetExportFile = '{0}Assets.csv' -f $Path + +$IGELImportColl = Import-Csv -Delimiter ';' -Path $IGELImportFile -Header '0', 'SerialNumber', 'MacAddress', '3', '4' +$AssetExportColl = Import-Csv -Delimiter ';' -Path $AssetExportFile + +$DevicePrefix = 'DEV-' +$MajorVersion = 10 + +$FirmwareId = (((Get-UMSFirmware).where{ $_.Version.Major -eq $MajorVersion } | + Sort-Object -Property Version -Descending)[0]).Id + +$NewDeviceCollParams = @{ + Left = $IGELImportColl + LeftJoinProperty = 'SerialNumber' + LeftProperties = 'SerialNumber', 'MacAddress' + Right = $AssetExportColl + RightJoinProperty = 'SerialNumber' + RightProperties = 'InventoryNumber' + Type = 'AllInLeft' +} +$NewDeviceColl = Join-Object @NewDeviceCollParams + +foreach ($NewDevice in $NewDeviceColl) +{ + $NewDeviceParams = @{ + Mac = $NewDevice.MacAddress + FirmwareId = $FirmwareId + Name = '{0}{1}' -f $DevicePrefix, $NewDevice.InventoryNumber + SerialNumber = $NewDevice.SerialNumber + AssetId = $NewDevice.InventoryNumber + } + New-UMSDevice @NewDeviceParams +} diff --git a/Scripts/Invoke-Parallel.ps1 b/Scripts/Invoke-Parallel.ps1 new file mode 100644 index 0000000..6888c83 --- /dev/null +++ b/Scripts/Invoke-Parallel.ps1 @@ -0,0 +1,558 @@ +function Invoke-Parallel { + <# + .SYNOPSIS + Function to control parallel processing using runspaces + + .DESCRIPTION + Function to control parallel processing using runspaces + + Note that each runspace will not have access to variables and commands loaded in your session or in other runspaces by default. + This behaviour can be changed with parameters. + + .PARAMETER ScriptFile + File to run against all input objects. Must include parameter to take in the input object, or use $args. Optionally, include parameter to take in parameter. Example: C:\script.ps1 + + .PARAMETER ScriptBlock + Scriptblock to run against all computers. + + You may use $Using: language in PowerShell 3 and later. + + The parameter block is added for you, allowing behaviour similar to foreach-object: + Refer to the input object as $_. + Refer to the parameter parameter as $parameter + + .PARAMETER InputObject + Run script against these specified objects. + + .PARAMETER Parameter + This object is passed to every script block. You can use it to pass information to the script block; for example, the path to a logging folder + + Reference this object as $parameter if using the scriptblock parameterset. + + .PARAMETER ImportVariables + If specified, get user session variables and add them to the initial session state + + .PARAMETER ImportModules + If specified, get loaded modules and pssnapins, add them to the initial session state + + .PARAMETER Throttle + Maximum number of threads to run at a single time. + + .PARAMETER SleepTimer + Milliseconds to sleep after checking for completed runspaces and in a few other spots. I would not recommend dropping below 200 or increasing above 500 + + .PARAMETER RunspaceTimeout + Maximum time in seconds a single thread can run. If execution of your code takes longer than this, it is disposed. Default: 0 (seconds) + + WARNING: Using this parameter requires that maxQueue be set to throttle (it will be by default) for accurate timing. Details here: + http://gallery.technet.microsoft.com/Run-Parallel-Parallel-377fd430 + + .PARAMETER NoCloseOnTimeout + Do not dispose of timed out tasks or attempt to close the runspace if threads have timed out. This will prevent the script from hanging in certain situations where threads become non-responsive, at the expense of leaking memory within the PowerShell host. + + .PARAMETER MaxQueue + Maximum number of powershell instances to add to runspace pool. If this is higher than $throttle, $timeout will be inaccurate + + If this is equal or less than throttle, there will be a performance impact + + The default value is $throttle times 3, if $runspaceTimeout is not specified + The default value is $throttle, if $runspaceTimeout is specified + + .PARAMETER LogFile + Path to a file where we can log results, including run time for each thread, whether it completes, completes with errors, or times out. + + .PARAMETER AppendLog + Append to existing log + + .PARAMETER Quiet + Disable progress bar + + .EXAMPLE + Each example uses Test-ForPacs.ps1 which includes the following code: + param($computer) + + if(test-connection $computer -count 1 -quiet -BufferSize 16){ + $object = [pscustomobject] @{ + Computer=$computer; + Available=1; + Kodak=$( + if((test-path "\\$computer\c$\users\public\desktop\Kodak Direct View Pacs.url") -or (test-path "\\$computer\c$\documents and settings\all users\desktop\Kodak Direct View Pacs.url") ){"1"}else{"0"} + ) + } + } + else{ + $object = [pscustomobject] @{ + Computer=$computer; + Available=0; + Kodak="NA" + } + } + + $object + + .EXAMPLE + Invoke-Parallel -scriptfile C:\public\Test-ForPacs.ps1 -inputobject $(get-content C:\pcs.txt) -runspaceTimeout 10 -throttle 10 + + Pulls list of PCs from C:\pcs.txt, + Runs Test-ForPacs against each + If any query takes longer than 10 seconds, it is disposed + Only run 10 threads at a time + + .EXAMPLE + Invoke-Parallel -scriptfile C:\public\Test-ForPacs.ps1 -inputobject c-is-ts-91, c-is-ts-95 + + Runs against c-is-ts-91, c-is-ts-95 (-computername) + Runs Test-ForPacs against each + + .EXAMPLE + $stuff = [pscustomobject] @{ + ContentFile = "windows\system32\drivers\etc\hosts" + Logfile = "C:\temp\log.txt" + } + + $computers | Invoke-Parallel -parameter $stuff { + $contentFile = join-path "\\$_\c$" $parameter.contentfile + Get-Content $contentFile | + set-content $parameter.logfile + } + + This example uses the parameter argument. This parameter is a single object. To pass multiple items into the script block, we create a custom object (using a PowerShell v3 language) with properties we want to pass in. + + Inside the script block, $parameter is used to reference this parameter object. This example sets a content file, gets content from that file, and sets it to a predefined log file. + + .EXAMPLE + $test = 5 + 1..2 | Invoke-Parallel -ImportVariables {$_ * $test} + + Add variables from the current session to the session state. Without -ImportVariables $Test would not be accessible + + .EXAMPLE + $test = 5 + 1..2 | Invoke-Parallel {$_ * $Using:test} + + Reference a variable from the current session with the $Using: syntax. Requires PowerShell 3 or later. Note that -ImportVariables parameter is no longer necessary. + + .FUNCTIONALITY + PowerShell Language + + .NOTES + Credit to Boe Prox for the base runspace code and $Using implementation + http://learn-powershell.net/2012/05/10/speedy-network-information-query-using-powershell/ + http://gallery.technet.microsoft.com/scriptcenter/Speedy-Network-Information-5b1406fb#content + https://github.com/proxb/PoshRSJob/ + + Credit to T Bryce Yehl for the Quiet and NoCloseOnTimeout implementations + + Credit to Sergei Vorobev for the many ideas and contributions that have improved functionality, reliability, and ease of use + + .LINK + https://github.com/RamblingCookieMonster/Invoke-Parallel + #> + [cmdletbinding(DefaultParameterSetName='ScriptBlock')] + Param ( + [Parameter(Mandatory=$false,position=0,ParameterSetName='ScriptBlock')] + [System.Management.Automation.ScriptBlock]$ScriptBlock, + + [Parameter(Mandatory=$false,ParameterSetName='ScriptFile')] + [ValidateScript({Test-Path $_ -pathtype leaf})] + $ScriptFile, + + [Parameter(Mandatory=$true,ValueFromPipeline=$true)] + [Alias('CN','__Server','IPAddress','Server','ComputerName')] + [PSObject]$InputObject, + + [PSObject]$Parameter, + + [switch]$ImportVariables, + [switch]$ImportModules, + [switch]$ImportFunctions, + + [int]$Throttle = 20, + [int]$SleepTimer = 200, + [int]$RunspaceTimeout = 0, + [switch]$NoCloseOnTimeout = $false, + [int]$MaxQueue, + + [validatescript({Test-Path (Split-Path $_ -parent)})] + [switch] $AppendLog = $false, + [string]$LogFile, + + [switch] $Quiet = $false + ) + begin { + #No max queue specified? Estimate one. + #We use the script scope to resolve an odd PowerShell 2 issue where MaxQueue isn't seen later in the function + if( -not $PSBoundParameters.ContainsKey('MaxQueue') ) { + if($RunspaceTimeout -ne 0){ $script:MaxQueue = $Throttle } + else{ $script:MaxQueue = $Throttle * 3 } + } + else { + $script:MaxQueue = $MaxQueue + } + $ProgressId = Get-Random + Write-Verbose "Throttle: '$throttle' SleepTimer '$sleepTimer' runSpaceTimeout '$runspaceTimeout' maxQueue '$maxQueue' logFile '$logFile'" + + #If they want to import variables or modules, create a clean runspace, get loaded items, use those to exclude items + if ($ImportVariables -or $ImportModules -or $ImportFunctions) { + $StandardUserEnv = [powershell]::Create().addscript({ + + #Get modules, snapins, functions in this clean runspace + $Modules = Get-Module | Select-Object -ExpandProperty Name + $Snapins = Get-PSSnapin | Select-Object -ExpandProperty Name + $Functions = Get-ChildItem function:\ | Select-Object -ExpandProperty Name + + #Get variables in this clean runspace + #Called last to get vars like $? into session + $Variables = Get-Variable | Select-Object -ExpandProperty Name + + #Return a hashtable where we can access each. + @{ + Variables = $Variables + Modules = $Modules + Snapins = $Snapins + Functions = $Functions + } + }).invoke()[0] + + if ($ImportVariables) { + #Exclude common parameters, bound parameters, and automatic variables + Function _temp {[cmdletbinding(SupportsShouldProcess=$True)] param() } + $VariablesToExclude = @( (Get-Command _temp | Select-Object -ExpandProperty parameters).Keys + $PSBoundParameters.Keys + $StandardUserEnv.Variables ) + Write-Verbose "Excluding variables $( ($VariablesToExclude | Sort-Object ) -join ", ")" + + # we don't use 'Get-Variable -Exclude', because it uses regexps. + # One of the veriables that we pass is '$?'. + # There could be other variables with such problems. + # Scope 2 required if we move to a real module + $UserVariables = @( Get-Variable | Where-Object { -not ($VariablesToExclude -contains $_.Name) } ) + Write-Verbose "Found variables to import: $( ($UserVariables | Select-Object -expandproperty Name | Sort-Object ) -join ", " | Out-String).`n" + } + if ($ImportModules) { + $UserModules = @( Get-Module | Where-Object {$StandardUserEnv.Modules -notcontains $_.Name -and (Test-Path $_.Path -ErrorAction SilentlyContinue)} | Select-Object -ExpandProperty Path ) + $UserSnapins = @( Get-PSSnapin | Select-Object -ExpandProperty Name | Where-Object {$StandardUserEnv.Snapins -notcontains $_ } ) + } + if($ImportFunctions) { + $UserFunctions = @( Get-ChildItem function:\ | Where-Object { $StandardUserEnv.Functions -notcontains $_.Name } ) + } + } + + #region functions + Function Get-RunspaceData { + [cmdletbinding()] + param( [switch]$Wait ) + #loop through runspaces + #if $wait is specified, keep looping until all complete + Do { + #set more to false for tracking completion + $more = $false + + #Progress bar if we have inputobject count (bound parameter) + if (-not $Quiet) { + Write-Progress -Id $ProgressId -Activity "Running Query" -Status "Starting threads"` + -CurrentOperation "$startedCount threads defined - $totalCount input objects - $script:completedCount input objects processed"` + -PercentComplete $( Try { $script:completedCount / $totalCount * 100 } Catch {0} ) + } + + #run through each runspace. + Foreach($runspace in $runspaces) { + + #get the duration - inaccurate + $currentdate = Get-Date + $runtime = $currentdate - $runspace.startTime + $runMin = [math]::Round( $runtime.totalminutes ,2 ) + + #set up log object + $log = "" | Select-Object Date, Action, Runtime, Status, Details + $log.Action = "Removing:'$($runspace.object)'" + $log.Date = $currentdate + $log.Runtime = "$runMin minutes" + + #If runspace completed, end invoke, dispose, recycle, counter++ + If ($runspace.Runspace.isCompleted) { + + $script:completedCount++ + + #check if there were errors + if($runspace.powershell.Streams.Error.Count -gt 0) { + #set the logging info and move the file to completed + $log.status = "CompletedWithErrors" + Write-Verbose ($log | ConvertTo-Csv -Delimiter ";" -NoTypeInformation)[1] + foreach($ErrorRecord in $runspace.powershell.Streams.Error) { + Write-Error -ErrorRecord $ErrorRecord + } + } + else { + #add logging details and cleanup + $log.status = "Completed" + Write-Verbose ($log | ConvertTo-Csv -Delimiter ";" -NoTypeInformation)[1] + } + + #everything is logged, clean up the runspace + $runspace.powershell.EndInvoke($runspace.Runspace) + $runspace.powershell.dispose() + $runspace.Runspace = $null + $runspace.powershell = $null + } + #If runtime exceeds max, dispose the runspace + ElseIf ( $runspaceTimeout -ne 0 -and $runtime.totalseconds -gt $runspaceTimeout) { + $script:completedCount++ + $timedOutTasks = $true + + #add logging details and cleanup + $log.status = "TimedOut" + Write-Verbose ($log | ConvertTo-Csv -Delimiter ";" -NoTypeInformation)[1] + Write-Error "Runspace timed out at $($runtime.totalseconds) seconds for the object:`n$($runspace.object | out-string)" + + #Depending on how it hangs, we could still get stuck here as dispose calls a synchronous method on the powershell instance + if (!$noCloseOnTimeout) { $runspace.powershell.dispose() } + $runspace.Runspace = $null + $runspace.powershell = $null + $completedCount++ + } + + #If runspace isn't null set more to true + ElseIf ($runspace.Runspace -ne $null ) { + $log = $null + $more = $true + } + + #log the results if a log file was indicated + if($logFile -and $log) { + ($log | ConvertTo-Csv -Delimiter ";" -NoTypeInformation)[1] | out-file $LogFile -append + } + } + + #Clean out unused runspace jobs + $temphash = $runspaces.clone() + $temphash | Where-Object { $_.runspace -eq $Null } | ForEach-Object { + $Runspaces.remove($_) + } + + #sleep for a bit if we will loop again + if($PSBoundParameters['Wait']){ Start-Sleep -milliseconds $SleepTimer } + + #Loop again only if -wait parameter and there are more runspaces to process + } while ($more -and $PSBoundParameters['Wait']) + + #End of runspace function + } + #endregion functions + + #region Init + + if($PSCmdlet.ParameterSetName -eq 'ScriptFile') { + $ScriptBlock = [scriptblock]::Create( $(Get-Content $ScriptFile | out-string) ) + } + elseif($PSCmdlet.ParameterSetName -eq 'ScriptBlock') { + #Start building parameter names for the param block + [string[]]$ParamsToAdd = '$_' + if( $PSBoundParameters.ContainsKey('Parameter') ) { + $ParamsToAdd += '$Parameter' + } + + $UsingVariableData = $Null + + # This code enables $Using support through the AST. + # This is entirely from Boe Prox, and his https://github.com/proxb/PoshRSJob module; all credit to Boe! + + if($PSVersionTable.PSVersion.Major -gt 2) { + #Extract using references + $UsingVariables = $ScriptBlock.ast.FindAll({$args[0] -is [System.Management.Automation.Language.UsingExpressionAst]},$True) + + If ($UsingVariables) { + $List = New-Object 'System.Collections.Generic.List`1[System.Management.Automation.Language.VariableExpressionAst]' + ForEach ($Ast in $UsingVariables) { + [void]$list.Add($Ast.SubExpression) + } + + $UsingVar = $UsingVariables | Group-Object -Property SubExpression | ForEach-Object {$_.Group | Select-Object -First 1} + + #Extract the name, value, and create replacements for each + $UsingVariableData = ForEach ($Var in $UsingVar) { + try { + $Value = Get-Variable -Name $Var.SubExpression.VariablePath.UserPath -ErrorAction Stop + [pscustomobject]@{ + Name = $Var.SubExpression.Extent.Text + Value = $Value.Value + NewName = ('$__using_{0}' -f $Var.SubExpression.VariablePath.UserPath) + NewVarName = ('__using_{0}' -f $Var.SubExpression.VariablePath.UserPath) + } + } + catch { + Write-Error "$($Var.SubExpression.Extent.Text) is not a valid Using: variable!" + } + } + $ParamsToAdd += $UsingVariableData | Select-Object -ExpandProperty NewName -Unique + + $NewParams = $UsingVariableData.NewName -join ', ' + $Tuple = [Tuple]::Create($list, $NewParams) + $bindingFlags = [Reflection.BindingFlags]"Default,NonPublic,Instance" + $GetWithInputHandlingForInvokeCommandImpl = ($ScriptBlock.ast.gettype().GetMethod('GetWithInputHandlingForInvokeCommandImpl',$bindingFlags)) + + $StringScriptBlock = $GetWithInputHandlingForInvokeCommandImpl.Invoke($ScriptBlock.ast,@($Tuple)) + + $ScriptBlock = [scriptblock]::Create($StringScriptBlock) + + Write-Verbose $StringScriptBlock + } + } + + $ScriptBlock = $ExecutionContext.InvokeCommand.NewScriptBlock("param($($ParamsToAdd -Join ", "))`r`n" + $Scriptblock.ToString()) + } + else { + Throw "Must provide ScriptBlock or ScriptFile"; Break + } + + Write-Debug "`$ScriptBlock: $($ScriptBlock | Out-String)" + Write-Verbose "Creating runspace pool and session states" + + #If specified, add variables and modules/snapins to session state + $sessionstate = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault() + if($ImportVariables -and $UserVariables.count -gt 0) { + foreach($Variable in $UserVariables) { + $sessionstate.Variables.Add((New-Object -TypeName System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList $Variable.Name, $Variable.Value, $null) ) + } + } + if ($ImportModules) { + if($UserModules.count -gt 0) { + foreach($ModulePath in $UserModules) { + $sessionstate.ImportPSModule($ModulePath) + } + } + if($UserSnapins.count -gt 0) { + foreach($PSSnapin in $UserSnapins) { + [void]$sessionstate.ImportPSSnapIn($PSSnapin, [ref]$null) + } + } + } + if($ImportFunctions -and $UserFunctions.count -gt 0) { + foreach ($FunctionDef in $UserFunctions) { + $sessionstate.Commands.Add((New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $FunctionDef.Name,$FunctionDef.ScriptBlock)) + } + } + + #Create runspace pool + $runspacepool = [runspacefactory]::CreateRunspacePool(1, $Throttle, $sessionstate, $Host) + $runspacepool.Open() + + Write-Verbose "Creating empty collection to hold runspace jobs" + $Script:runspaces = New-Object System.Collections.ArrayList + + #If inputObject is bound get a total count and set bound to true + $bound = $PSBoundParameters.keys -contains "InputObject" + if(-not $bound) { + [System.Collections.ArrayList]$allObjects = @() + } + + #Set up log file if specified + if( $LogFile -and (-not (Test-Path $LogFile) -or $AppendLog -eq $false)){ + New-Item -ItemType file -Path $logFile -Force | Out-Null + ("" | Select-Object -Property Date, Action, Runtime, Status, Details | ConvertTo-Csv -NoTypeInformation -Delimiter ";")[0] | Out-File $LogFile + } + + #write initial log entry + $log = "" | Select-Object -Property Date, Action, Runtime, Status, Details + $log.Date = Get-Date + $log.Action = "Batch processing started" + $log.Runtime = $null + $log.Status = "Started" + $log.Details = $null + if($logFile) { + ($log | convertto-csv -Delimiter ";" -NoTypeInformation)[1] | Out-File $LogFile -Append + } + $timedOutTasks = $false + #endregion INIT + } + process { + #add piped objects to all objects or set all objects to bound input object parameter + if($bound) { + $allObjects = $InputObject + } + else { + [void]$allObjects.add( $InputObject ) + } + } + end { + #Use Try/Finally to catch Ctrl+C and clean up. + try { + #counts for progress + $totalCount = $allObjects.count + $script:completedCount = 0 + $startedCount = 0 + foreach($object in $allObjects) { + #region add scripts to runspace pool + #Create the powershell instance, set verbose if needed, supply the scriptblock and parameters + $powershell = [powershell]::Create() + + if ($VerbosePreference -eq 'Continue') { + [void]$PowerShell.AddScript({$VerbosePreference = 'Continue'}) + } + + [void]$PowerShell.AddScript($ScriptBlock).AddArgument($object) + + if ($parameter) { + [void]$PowerShell.AddArgument($parameter) + } + + # $Using support from Boe Prox + if ($UsingVariableData) { + Foreach($UsingVariable in $UsingVariableData) { + Write-Verbose "Adding $($UsingVariable.Name) with value: $($UsingVariable.Value)" + [void]$PowerShell.AddArgument($UsingVariable.Value) + } + } + + #Add the runspace into the powershell instance + $powershell.RunspacePool = $runspacepool + + #Create a temporary collection for each runspace + $temp = "" | Select-Object PowerShell, StartTime, object, Runspace + $temp.PowerShell = $powershell + $temp.StartTime = Get-Date + $temp.object = $object + + #Save the handle output when calling BeginInvoke() that will be used later to end the runspace + $temp.Runspace = $powershell.BeginInvoke() + $startedCount++ + + #Add the temp tracking info to $runspaces collection + Write-Verbose ( "Adding {0} to collection at {1}" -f $temp.object, $temp.starttime.tostring() ) + $runspaces.Add($temp) | Out-Null + + #loop through existing runspaces one time + Get-RunspaceData + + #If we have more running than max queue (used to control timeout accuracy) + #Script scope resolves odd PowerShell 2 issue + $firstRun = $true + while ($runspaces.count -ge $Script:MaxQueue) { + #give verbose output + if($firstRun) { + Write-Verbose "$($runspaces.count) items running - exceeded $Script:MaxQueue limit." + } + $firstRun = $false + + #run get-runspace data and sleep for a short while + Get-RunspaceData + Start-Sleep -Milliseconds $sleepTimer + } + #endregion add scripts to runspace pool + } + Write-Verbose ( "Finish processing the remaining runspace jobs: {0}" -f ( @($runspaces | Where-Object {$_.Runspace -ne $Null}).Count) ) + + Get-RunspaceData -wait + if (-not $quiet) { + Write-Progress -Id $ProgressId -Activity "Running Query" -Status "Starting threads" -Completed + } + } + finally { + #Close the runspace pool, unless we specified no close on timeout and something timed out + if ( ($timedOutTasks -eq $false) -or ( ($timedOutTasks -eq $true) -and ($noCloseOnTimeout -eq $false) ) ) { + Write-Verbose "Closing the runspace pool" + $runspacepool.close() + } + #collect garbage + [gc]::Collect() + } + } +} diff --git a/Scripts/Test.ps1 b/Scripts/Test.ps1 new file mode 100644 index 0000000..2022fc6 --- /dev/null +++ b/Scripts/Test.ps1 @@ -0,0 +1,129 @@ +$DSC = [IO.Path]::DirectorySeparatorChar +$PSIGELPath = 'GitHub{0}PSIGEL{0}PSIGEL{0}PSIGEL.psd1' -f $DSC + +$PSDefaultParameterValues = @{ + '*-UMS*:Computername' = 'igelrmserver' + '*-UMS*:TCPPort' = 9443 + '*-UMS*:Confirm' = $False + #'*-UMS*:SecurityProtocol' = 'Tls' +} + +if (($PSEdition -eq 'Core' -and $IsWindows) -or ($PSEdition -eq 'Desktop' -and ($PSVersionTable.PSVersion.Major -eq 5 -and $PSVersionTable.PSVersion.Minor -eq 1))) +{ + # PS7 on Windows or Windows PowerShell 5.1 + Import-Module -FullyQualifiedName ('C:\{0}' -f $PSIGELPath) -Force + $PSDefaultParameterValues.Add('New-UMSAPICookie:Credential', (Import-Clixml -Path 'C:\Credentials\UmsRmdb.cred')) +} +elseif ($PSEdition -eq 'core' -and (-Not $IsWindows) ) +{ + # PS7 on Linux OR MacOS + Import-Module -FullyQualifiedName ('/mnt/c/{0}' -f $PSIGELPath) -Force + # Dont use the following method in production, since on linux the clixml file is not encrypted + $PSDefaultParameterValues.Add('New-UMSAPICookie:Credential', (Import-Clixml -Path '/mnt/c/Credentials/UmsRmdbWsl.cred')) +} + + +$WebSession = New-UMSAPICookie +$PSDefaultParameterValues.Add('*-UMS*:WebSession', $WebSession) +#<# +#$Result = '' +#$Result = Get-UMSDevice -Id 512 +#$Result = Get-UMSDevice +#$Result = (Get-UMSFirmware | Sort-Object -Property Version -Descending | Select-Object -First 1 ).Id +#$Result + +$FirmwareColl = Get-UMSFirmware +#$FirmwareColl + +$LatestFirmwareId = ($FirmwareColl | Sort-Object -Property Version -Descending | + Select-Object -First 1 ).Id +#$LatestFirmwareId + +$UpdateDeviceColl = Get-UMSDevice -Filter online | Where-Object { + $_.Online -eq $false -and $_.FirmwareId -ne $LatestFirmwareId +} +#$UpdateDeviceColl + +$UpdateDeviceColl | Update-UMSDevice -Comment 'update' + +#$UpdateDeviceColl | Get-UMSDevice -Filter details | +#Select-Object -Property Id, Name, Comment -First 1 + +#$UpdateDeviceColl | Restart-UMSDevice -Confirm:$False + +$null = Get-UMSDevice -Filter details | Where-Object { + $_.Comment -eq 'update' -and $_.FirmwareId -ne $LatestFirmwareId +} | Update-UMSDevice -Comment '' + +$null = Remove-UMSAPICookie +#> + +#> + +### if ($PSBoundParameters.GetEnumerator().Where{ $_.Key -eq 'Comment' }) + +<# +($WebSession.Cookies.GetCookies('https://igelrmserver').Value) + +$NewParams = @{ + Mac = '0A00000000AA' + Name = 'NewDevice01' + FirmwareId = 1 + ParentId = -1 +} +$MoveParams = @{ + DestId = 502 # PSIGEL +} +$UpdateParams = @{ + Name = 'UpdatedDevice01' +} + +$Result = @( + $null = [pscustomobject]$NewParams | + New-UMSDevice | Tee-Object -Variable 'NewUMSDevice' | + Move-UMSDevice @MoveParams | Tee-Object -Variable 'MoveUMSDevice' | + Update-UMSDevice @UpdateParams | Tee-Object -Variable 'UpdateUMSDevice' | + Get-UMSDevice | Tee-Object -Variable 'GetUMSDevice' | + Start-UMSDevice | Tee-Object -Variable 'StartUMSDevice' | + Send-UMSDeviceSetting | Tee-Object -Variable 'SendUMSDeviceSettings' | + Remove-UMSDevice | Tee-Object -Variable 'RemoveUMSDevice' + + $NewUMSDevice + $MoveUMSDevice + $UpdateUMSDevice + $GetUMSDevice + $StartUMSDevice + $SendUMSDeviceSettings + $RemoveUMSDevice +) +$Result +#> + + +#Get-UMSDevice -WebSession $Result + +<# + + $Result = @( + $null = ((($NewParams.Mac | + New-UMSDevice -FirmwareId $NewParams.FirmwareId | Tee-Object -Variable 'NewUMSDevice').Id | + Move-UMSDevice @MoveParams | Tee-Object -Variable 'MoveUMSDevice').Id | + Update-UMSDevice @UpdateParams | Tee-Object -Variable 'UpdateUMSDevice').Id | + Remove-UMSDevice @RemoveParams | Tee-Object -Variable 'RemoveUMSDevice' + + $NewUMSDevice + $MoveUMSDevice + $UpdateUMSDevice + $RemoveUMSDevice + ) + $Result + #> + + + + + +<# +$Result = '' +$Result +#> \ No newline at end of file diff --git a/Tests/Config.psd1 b/Tests/Config.psd1 new file mode 100644 index 0000000..ee8f82e --- /dev/null +++ b/Tests/Config.psd1 @@ -0,0 +1,1923 @@ +<# +Tests Config +#> + +@{ + + Computername = 'igelrmserver' + TCPPort = 9443 + CredPath = 'C:\Credentials\UMSRmdb.cred' + CredPathWsl = '/mnt/c/Credentials/UmsRmdbWsl.cred' + SecurityProtocol = 'Tls12' + ProfileRootDirId = 527 # Profiles/PSIGEL + DeviceRootDirId = 502 # Devices/PSIGEL + OutputPath = @{ + Desktop = 'Desktop' + CoreW10 = 'CoreW10' + CoreWSL = 'CoreWSL' + } + + Tests = @( + # PSIGEL + @{ + Name = 'PSIGEL' + } + # Invoke-UMSRestMethod + @{ + Name = 'Invoke-UMSRestMethod' + Tags = 'UnitTests' + #CodeCoveragePath = 'Private' + } + # New-UMSFilterString + @{ + Name = 'New-UMSFilterString' + Tags = 'UnitTests' + #CodeCoveragePath = 'Private' + } + # New-UMSAPICookie + @{ + Name = 'New-UMSAPICookie' + Tags = 'UnitTests, IntegrationTests' + #CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ } + } + } + # Get-UMSStatus + @{ + Name = 'Get-UMSStatus' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Expected = @{ + RmGuiServerVersion = '6.3.130' + BuildNumber = 44584 + ActiveMqVersion = '5.7.0' + DerbyVersion = '10.12.1.1' + ServerUuid = 'f30fb3a2-37d4-4cbb-b884-4f4060d3160e' + Server = 'igelrmserver:8443' + } + Options = @{ + ExcludedPaths = '' + } + } + } + } + # New-UMSDeviceDirectory + @{ + Name = 'New-UMSDeviceDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Name = 'QA' + } + Expected = @{ + Message = 'Directory successfully inserted.' + Id = 597 + Name = 'QA' + } + Options = @{ + #ExcludedPaths = 'Id' + } + } + } + } + # New-UMSDevice + @{ + Name = 'New-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Mac = '0A0000000007' + Name = '007' + FirmwareId = 1 + ParentId = -1 + } + Params2 = @{ + Mac = '0A0000000008' + Name = '008' + FirmwareId = 1 + ParentId = -1 + } + Expected = @( + @{ + Mac = '0A0000000007' + Message = 'Device successfully inserted.' + Id = 598 + Name = '007' + ParentId = -1 + } + @{ + Mac = '0A0000000008' + Message = 'Device successfully inserted.' + Id = 599 + Name = '008' + ParentId = - 1 + } + ) + Options = @{ + #ExcludedPaths = 'Id' + } + } + } + } + # New-UMSProfileDirectory + @{ + Name = 'New-UMSProfileDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Name = 'Devices' + } + Expected = @{ + Message = 'Directory successfully inserted.' + Id = 600 + Name = 'Devices' + } + Options = @{ + #ExcludedPaths = 'Id' + } + } + } + } + # New-UMSProfileAssignment + @{ + Name = 'New-UMSProfileAssignment' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 538 # NW_WLAN + ReceiverId = 504 # BR_HR + ReceiverType = 'tcdirectory' + } + Params2 = @{ + Id = 538 # NW_WLAN + ReceiverId = 577 # BR-MKT-003 + ReceiverType = 'tc' + } + Expected = @( + @{ + Id = 538 + Message = '1 asssignments successfully assigned to device directory <{1}>.' + ReceiverId = 504 + ReceiverType = 'tcdirectory' + } + @{ + Id = 538 + Message = '1 asssignments successfully assigned to device <{1}>.' + ReceiverId = 577 + ReceiverType = 'tc' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Remove-UMSDevice + @{ + Name = 'Remove-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 572 # L-DIS-011 + } + Params2 = @{ + Id = 522 # L-DIS-012 + } + Expected = @( + @{ + Id = 572 + Message = 'Offline deletion successful.' + } + @{ + Id = 522 + Message = 'Offline deletion successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Remove-UMSDeviceDirectory + @{ + Name = 'Remove-UMSDeviceDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 520 # L_Distribution + } + Expected = @( + @{ + Id = 520 + Message = 'Deletion successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Remove-UMSProfile + @{ + Name = 'Remove-UMSProfile' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 542 # SYS_TZ_CET + } + Expected = @{ + Message = 'Deleted profile.' + Id = 542 + } + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Remove-UMSProfileDirectory + @{ + Name = 'Remove-UMSProfileDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 541 # System + } + Expected = @{ + Message = 'Deletion successful.' + Id = 541 + } + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Remove-UMSProfileAssignment + @{ + Name = 'Remove-UMSProfileAssignment' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 538 # NW_WLAN + ReceiverId = 505 # BR-HR-01 + ReceiverType = 'tc' + } + Params2 = @{ + Id = 540 # SEC_PW_Root + ReceiverId = 502 # PSIGEL + ReceiverType = 'tcdirectory' + } + Expected = @( + @{ + Message = 'deleted profile assignment.' + Id = 538 + ReceiverId = 505 + ReceiverType = 'tc' + } + @{ + Message = 'deleted profile assignment.' + Id = 540 + ReceiverId = 502 + ReceiverType = 'tcdirectory' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Move-UMSDevice + @{ + Name = 'Move-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 518 # L-DEV-009 + DestId = 514 # A_Development + } + Params2 = @{ + Id = 578 # L-DEV-010 + DestId = 514 # A_Development + } + Params3 = @{ + Id = 598 # 007 + DestId = 597 # QA + } + Params4 = @{ + Id = 599 # 008 + DestId = 597 # QA + } + Expected = @( + @{ + Id = 518 + Message = 'successful.' + } + @{ + Id = 578 + Message = 'successful.' + } + @{ + Id = 598 + Message = 'successful.' + } + @{ + Id = 599 + Message = 'successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Move-UMSDeviceDirectory + @{ + Name = 'Move-UMSDeviceDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 597 # QA + DestId = 511 # Augsburg + } + Params2 = @{ + Id = 517 # L_Development + DestId = 503 # Bremen + } + Expected = @( + @{ + Id = 597 + Message = 'successful.' + } + @{ + Id = 517 + Message = 'successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Move-UMSProfileDirectory + @{ + Name = 'Move-UMSProfileDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 534 # Network User Interface + DestId = 527 # PSIGEL + } + Expected = @( + @{ + Id = 534 + Message = 'successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Move-UMSProfile + @{ + Name = 'Move-UMSProfile' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 535 # NW_LNG_DE + DestId = 534 # Interface + } + Expected = @( + @{ + Id = 535 + Message = 'successful' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Update-UMSDeviceDirectory + @{ + Name = 'Update-UMSDeviceDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 517 # L_Develpoment + Name = 'BR_Development' + } + Params2 = @{ + Id = 597 # QA + Name = 'A_QA' + } + Expected = @( + @{ + Id = 517 + Message = 'Updated directory successfully.' + } + @{ + Id = 597 + Message = 'Updated directory successfully.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + #Update-UMSDevice + @{ + Name = 'Update-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 518 # L-DEV-009 + Name = 'A-DEV-009' + } + Params2 = @{ + Id = 578 # L-DEV-010 + Name = 'A-DEV-010' + } + Params3 = @{ + Id = 598 # 007 + Name = 'A-QA-007' + } + Params4 = @{ + Id = 599 # 008 + Name = 'A-QA-008' + } + Expected = @( + @{ + Id = 518 + Message = 'Update successful.' + } + @{ + Id = 578 + Message = 'Update successful.' + } + @{ + Id = 598 + Message = 'Update successful.' + } + @{ + Id = 599 + Message = 'Update successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Update-UMSProfileDirectory + @{ + Name = 'Update-UMSProfileDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 534 # Network user Interface + Name = 'User Interface' + } + Expected = @( + @{ + Id = 534 + Message = 'Updated directory successfully.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Update-UMSProfile + @{ + Name = 'Update-UMSProfile' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 535 # NW_LNG_DE + Name = 'UI_LNG_DE' # + } + Expected = @( + @{ + Id = 535 + Message = 'Update successful.' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Start-UMSDevice + @{ + Name = 'Start-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 576 # BR-MKT-004 + } + Expected = @( + @{ + ExecId = 'ID-igelrmserver-40687-1583585133100-2-0' + ExecTime = '1583588923907' + Id = 576 + Mac = '0A0000000004' + Message = 'OK.' + State = 'SUCCESS' + } + ) + Options = @{ + ExcludedPaths = 'ExecId', 'ExecTime' + } + } + } + } + # Send-UMSDeviceSetting + @{ + Name = 'Send-UMSDeviceSetting' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 576 # BR-MKT-004 + } + Expected = @( + @{ + ExecId = 'ID-igelrmserver-40687-1583585133100-5-0' + ExecTime = '1583589223680' + Id = 576 + Mac = '0A0000000004' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + ) + Options = @{ + ExcludedPaths = 'ExecId', 'ExecTime' + } + } + } + } + # Restart-UMSDevice + @{ + Name = 'Restart-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 576 # BR-MKT-004 + } + Expected = @( + @{ + ExecId = 'ID-igelrmserver-40687-1583585133100-5-0' + ExecTime = '1583589223680' + Id = 576 + Mac = '0A0000000004' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + ) + Options = @{ + ExcludedPaths = 'ExecId', 'ExecTime' + } + } + } + } + # Stop-UMSDevice + @{ + Name = 'Stop-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 576 # BR-MKT-004 + } + Expected = @( + @{ + ExecId = 'ID-igelrmserver-40687-1583585133100-5-0' + ExecTime = '1583589223680' + Id = 576 + Mac = '0A0000000004' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + ) + Options = @{ + ExcludedPaths = 'ExecId', 'ExecTime' + } + } + } + } + # Reset-UMSDevice + @{ + Name = 'Reset-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 576 # BR-MKT-004 + } + Expected = @( + @{ + ExecId = 'ID-igelrmserver-40687-1583585133100-2-0' + ExecTime = '1583586682807' + Id = 576 + Mac = '0A0000000004' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + ) + Options = @{ + ExcludedPaths = 'ExecId', 'ExecTime' + } + } + } + } + # Pipeline.UMSProfileAssignment + @{ + Name = 'Pipeline.UMSProfileAssignment' + Tags = 'IntegrationTests' + ParameterSets = @{ + ValueFromPipeline = @{ + NewAssignmentParams = @{ + Id = 595 # SES_RDP_Session02 + ReceiverId = 512 # A-DEV-005 + ReceiverType = 'tc' + } + RemoveAssignmentParams = @{ + Id = 595 # SES_RDP_Session02 + ReceiverId = 512 # A-DEV-005 + ReceiverType = 'tc' + } + Expected = @( + @{ + Id = 595 + Message = '1 asssignments successfully assigned to device <{1}>.' + ReceiverId = 512 + ReceiverType = 'tc' + } + @{ + Id = 595 + Message = 'deleted profile assignment.' + ReceiverId = 512 + ReceiverType = 'tc' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + ValueFromPipelineByPropertyName = @{ + NewAssignmentParams = @{ + Id = 596 # SES_RDP_Session03 + ReceiverId = 514 # A_Development + ReceiverType = 'tcdirectory' + } + RemoveAssignmentParams = @{ + Id = 596 # SES_RDP_Session03 + ReceiverId = 514 # A_Development + ReceiverType = 'tcdirectory' + } + Expected = @( + @{ + Id = 596 + Message = '1 asssignments successfully assigned to device directory <{1}>.' + ReceiverId = 514 + ReceiverType = 'tcdirectory' + } + @{ + Id = 596 + Message = 'deleted profile assignment.' + ReceiverId = 514 + ReceiverType = 'tcdirectory' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + + } + } + # Pipeline.UMSDevice + @{ + Name = 'Pipeline.UMSDevice' + Tags = 'IntegrationTests' + ParameterSets = @{ + ValueFromPipeline = @{ + NewParams = @{ + Mac = '0A00000000AA' + Name = 'NewDevice01' + FirmwareId = 1 + ParentId = -1 + } + MoveParams = @{ + DestId = 502 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedDevice01' + } + Expected = @( + @{ + Mac = '0A00000000AA' + Message = 'Device successfully inserted.' + Id = 601 + Name = 'NewDevice01' + ParentId = -1 + } + @{ + Id = 601 + Message = 'successful.' + } + @{ + Message = 'Update successful.' + Id = 601 + } + @{ + FirmwareId = 1 + Id = 601 + LastIp = '' + Mac = '0A00000000AA' + MovedToBin = 'False' + Name = 'UpdatedDevice01' + ObjectType = 'tc' + ParentId = 502 + UnitId = '0A00000000AA' + } + @{ + Id = 601 + Mac = '0A00000000AA' + Message = 'OK.' + State = 'SUCCESS' + } + @{ + Id = 601 + Mac = '0A00000000AA' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + @{ + Id = 601 + Mac = '0A00000000AA' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + @{ + Id = 601 + Mac = '0A00000000AA' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + @{ + Message = 'Offline deletion successful.' + Id = 601 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + ValueFromPipelineByPropertyName = @{ + NewParams = @{ + Mac = '0A00000000AB' + Name = 'NewDevice02' + FirmwareId = 1 + ParentId = -1 + } + MoveParams = @{ + DestId = 502 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedDevice02' + } + Expected = @( + @{ + Mac = '0A00000000AB' + Message = 'Device successfully inserted.' + Id = 602 + Name = 'NewDevice02' + ParentId = -1 + } + @{ + Id = 602 + Message = 'successful.' + } + @{ + Message = 'Update successful.' + Id = 602 + } + @{ + FirmwareId = 1 + Id = 602 + LastIp = '' + Mac = '0A00000000AB' + MovedToBin = 'False' + Name = 'UpdatedDevice02' + ObjectType = 'tc' + ParentId = 502 + UnitId = '0A00000000AB' + } + @{ + Id = 602 + Mac = '0A00000000AB' + Message = 'OK.' + State = 'SUCCESS' + } + @{ + Id = 602 + Mac = '0A00000000AB' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + @{ + Id = 602 + Mac = '0A00000000AB' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + @{ + Id = 602 + Mac = '0A00000000AB' + Message = 'Found no IP address for device.' + State = 'FAILED' + } + @{ + Message = 'Offline deletion successful.' + Id = 602 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + + } + } + # Pipeline.UMSDeviceDirectory + @{ + Name = 'Pipeline.UMSDeviceDirectory' + Tags = 'IntegrationTests' + ParameterSets = @{ + ValueFromPipeline = @{ + NewParams = @{ + Name = 'NewDeviceDirectory01' + } + MoveParams = @{ + DestId = 502 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedDeviceDirectory01' + } + Expected = @( + @{ + Message = 'Directory successfully inserted.' + Id = 603 + Name = 'NewDeviceDirectory01' + } + @{ + Id = 603 + Message = 'successful.' + } + @{ + Message = 'Updated directory successfully.' + Id = 603 + } + @{ + Message = 'Deletion successful.' + Id = 603 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + ValueFromPipelineByPropertyName = @{ + NewParams = @{ + Name = 'NewDeviceDirectory02' + } + MoveParams = @{ + DestId = 502 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedDeviceDirectory02' + } + Expected = @( + @{ + Message = 'Directory successfully inserted.' + Id = 604 + Name = 'NewDeviceDirectory02' + } + @{ + Id = 604 + Message = 'successful.' + } + @{ + Message = 'Updated directory successfully.' + Id = 604 + } + @{ + Message = 'Deletion successful.' + Id = 604 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Pipeline.UMSProfile + @{ + Name = 'Pipeline.UMSProfile' + Tags = 'IntegrationTests' + ParameterSets = @{ + ValueFromPipeline = @{ + MoveParams = @{ + Id = 595 # SES_RDP_Session02 + DestId = 527 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedProfile' + } + Expected = @( + @{ + Id = 595 + Message = 'successful' + } + @{ + Message = 'Update successful.' + Id = 595 + } + @{ + Message = 'Deleted profile.' + Id = 595 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + ValueFromPipelineByPropertyName = @{ + MoveParams = @{ + Id = 596 # SES_RDP_Session03 + DestId = 527 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedProfile' + } + Expected = @( + @{ + Id = 596 + Message = 'successful' + } + @{ + Message = 'Update successful.' + Id = 596 + } + @{ + Message = 'Deleted profile.' + Id = 596 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + + } + } + # Pipeline.UMSProfileDirectory + @{ + Name = 'Pipeline.UMSProfileDirectory' + Tags = 'IntegrationTests' + ParameterSets = @{ + ValueFromPipeline = @{ + NewParams = @{ + Name = 'NewProfileDirectory01' + } + MoveParams = @{ + DestId = 527 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedProfileDirectory01' + } + Expected = @( + @{ + Message = 'Directory successfully inserted.' + Id = 605 + Name = 'NewProfileDirectory01' + } + @{ + Id = 605 + Message = 'successful.' + } + @{ + Message = 'Updated directory successfully.' + Id = 605 + } + @{ + Message = 'Deletion successful.' + Id = 605 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + ValueFromPipelineByPropertyName = @{ + NewParams = @{ + Name = 'NewProfileDirectory02' + } + MoveParams = @{ + DestId = 527 # PSIGEL + } + UpdateParams = @{ + Name = 'UpdatedProfileDirectory02' + } + Expected = @( + @{ + Message = 'Directory successfully inserted.' + Id = 606 + Name = 'NewProfileDirectory02' + } + @{ + Id = 606 + Message = 'successful.' + } + @{ + Message = 'Updated directory successfully.' + Id = 606 + } + @{ + Message = 'Deletion successful.' + Id = 606 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Get-UMSFirmware + @{ + Name = 'Get-UMSFirmware' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Expected = @( + @{ + Id = 1 + Product = 'IGEL OS 11' + Version = '11.3.100.1' + FirmwareType = 'LX' + } + @{ + Id = 2 + Product = 'IGEL OS 11' + Version = '11.3.110.1' + FirmwareType = 'LX' + } + ) + Options = @{ + #ExcludedPaths = 'Id' + } + } + } + } + # Get-UMSDevice + @{ + Name = 'Get-UMSDevice' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + } + Expected = @( + @{ + Id = 505 + ObjectType = 'tc' + UnitId = '0A0000000001' + Mac = '0A0000000001' + Name = 'BR-HR-001' + ParentId = 504 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 507 + ObjectType = 'tc' + UnitId = '0A0000000002' + Mac = '0A0000000002' + Name = 'BR-HR-002' + ParentId = 504 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 512 + ObjectType = 'tc' + UnitId = '0A0000000005' + Mac = '0A0000000005' + Name = 'A-DEV-005' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 513 + ObjectType = 'tc' + UnitId = '0A0000000006' + Mac = '0A0000000006' + Name = 'A-DEV-006' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 518 + ObjectType = 'tc' + UnitId = '0A0000000009' + Mac = '0A0000000009' + Name = 'A-DEV-009' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 576 + ObjectType = 'tc' + UnitId = '0A0000000004' + Mac = '0A0000000004' + Name = 'BR-MKT-004' + ParentId = 508 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 577 + ObjectType = 'tc' + UnitId = '0A0000000003' + Mac = '0A0000000003' + Name = 'BR-MKT-003' + ParentId = 508 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 578 + ObjectType = 'tc' + UnitId = '0A0000000010' + Mac = '0A0000000010' + Name = 'A-DEV-010' + ParentId = 514 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 598 + ObjectType = 'tc' + UnitId = '0A0000000007' + Mac = '0A0000000007' + Name = 'A-QA-007' + ParentId = 597 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 599 + ObjectType = 'tc' + UnitId = '0A0000000008' + Mac = '0A0000000008' + Name = 'A-QA-008' + ParentId = 597 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + Details = @{ + Params1 = @{ + Id = 518 # A-DEV-009 + Filter = 'details' + } + Expected = @( + @{ + Id = 518 + ObjectType = 'tc' + UnitId = '0A0000000009' + Mac = '0A0000000009' + Name = 'A-DEV-009' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + NetworkName = '' + Site = '' + Comment = '' + Department = '' + CostCenter = '' + AssetID = '' + InServiceDate = '' + SerialNumber = '' + ProductId = '' + CpuSpeed = 0 + CpuType = '' + DeviceType = '' + DeviceSerialNumber = '' + OsType = '' + FlashSize = 0 + MemorySize = 0 + NetworkSpeed = 0 + GraphicsChipset0 = '' + GraphicsChipset1 = '' + MonitorVendor1 = '' + MonitorModel1 = '' + MonitorSerialnumber1 = '' + MonitorSize1 = 0 + MonitorNativeResolution1 = '' + Monitor1YearOfManufacture = 0 + Monitor1WeekOfManufacture = 0 + MonitorVendor2 = '' + MonitorModel2 = '' + MonitorSerialnumber2 = '' + MonitorSize2 = 0 + MonitorNativeResolution2 = '' + Monitor2YearOfManufacture = 0 + Monitor2WeekOfManufacture = 0 + BiosVendor = '' + BiosVersion = '' + TotalUsagetime = -1 + TotalUptime = -1 + BatteryLevel = -1 + LastBootTime = '' + BiosDate = '' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + Online = @{ + Params1 = @{ + Id = 578 # A-DEV-010 + Filter = 'online' + } + Expected = @( + @{ + Id = 578 + ObjectType = 'tc' + UnitId = '0A0000000010' + Mac = '0A0000000010' + Name = 'A-DEV-010' + ParentId = 514 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + Online = 'False' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Get-UMSDeviceDirectory + @{ + Name = 'Get-UMSDeviceDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + } + Expected = @( + @{ + Id = 514 + Name = 'A_Development' + ParentId = 511 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 597 + Name = 'A_QA' + ParentId = 511 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 516 + Name = 'Leipzig' + ParentId = 502 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 517 + Name = 'BR_Development' + ParentId = 503 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 502 + Name = 'PSIGEL' + ParentId = -1 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 503 + Name = 'Bremen' + ParentId = 502 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 504 + Name = 'BR_HR' + ParentId = 503 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 508 + Name = 'BR_Marketing' + ParentId = 503 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 511 + Name = 'Augsburg' + ParentId = 502 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + Children = @{ + Params1 = @{ + Id = 514 # A-DEV-009 + Filter = 'children' + } + Expected = @( + @{ + Id = 514 + Name = 'A_Development' + ParentId = 511 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + DirectoryChildren = { + @{ + ObjectType = 'tc' + Id = 512 + } + @{ + ObjectType = 'tc' + Id = 578 + } + @{ + ObjectType = 'tc' + Id = 513 + } + @{ + ObjectType = 'tc' + Id = 518 + } + } + } + ) + Options = @{ + ExcludedPaths = 'DirectoryChildren' + } + } + } + } + # Get-UMSProfile + @{ + Name = 'Get-UMSProfile' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + } + Expected = @( + @{ + FirmwareId = 1 + IsMasterProfile = 'False' + OverridesSessions = 'False' + Id = 529 + Name = 'SES_RDP_Session01' + ParentId = 528 + MovedToBin = 'False' + ObjectType = 'profile' + } + @{ + FirmwareId = 1 + IsMasterProfile = 'False' + OverridesSessions = 'False' + Id = 532 + Name = 'ACC_Terminal_LocalTerminal' + ParentId = 531 + MovedToBin = 'False' + ObjectType = 'profile' + } + @{ + FirmwareId = 2 + IsMasterProfile = 'False' + OverridesSessions = 'False' + Id = 535 + Name = 'UI_LNG_DE' + ParentId = 534 + MovedToBin = 'False' + ObjectType = 'profile' + } + @{ + FirmwareId = 2 + IsMasterProfile = 'False' + OverridesSessions = 'False' + Id = 537 + Name = 'NW_LAN' + ParentId = 533 + MovedToBin = 'False' + ObjectType = 'profile' + } + @{ + FirmwareId = 2 + IsMasterProfile = 'False' + OverridesSessions = 'False' + Id = 538 + Name = 'NW_WLAN' + ParentId = 533 + MovedToBin = 'False' + ObjectType = 'profile' + } + @{ + FirmwareId = 1 + IsMasterProfile = 'False' + OverridesSessions = 'False' + Id = 540 + Name = 'SEC_PW_Root' + ParentId = 539 + MovedToBin = 'False' + ObjectType = 'profile' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Get-UMSProfileDirectory + @{ + Name = 'Get-UMSProfileDirectory' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + } + Expected = @( + @{ + Id = 528 + Name = 'Sessions' + ParentId = 527 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + @{ + Id = 531 + Name = 'Accessories' + ParentId = 527 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + @{ + Id = 533 + Name = 'Network' + ParentId = 527 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + @{ + Id = 534 + Name = 'User Interface' + ParentId = 527 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + @{ + Id = 600 + Name = 'Devices' + ParentId = -2 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + @{ + Id = 539 + Name = 'Security' + ParentId = 527 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + @{ + Id = 527 + Name = 'PSIGEL' + ParentId = -2 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + Children = @{ + Params1 = @{ + Id = 533 # Network + Filter = 'children' + } + Expected = @( + @{ + Id = 533 + Name = 'Network' + ParentId = 527 + MovedToBin = 'False' + ObjectType = 'profiledirectory' + DirectoryChildren = { + @{ + ObjectType = 'profile' + Id = 537 + } + @{ + ObjectType = 'profile' + Id = 538 + } + } + } + ) + Options = @{ + ExcludedPaths = 'DirectoryChildren' + } + } + } + } + # Get-UMSProfileAssignment + @{ + Name = 'Get-UMSProfileAssignment' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 538 # NW_LAN + } + Expected = @( + @{ + Id = 538 + Type = 'profile' + ReceiverId = 577 + ReceiverType = 'tc' + AssignmentPosition = 0 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + Directory = @{ + Params1 = @{ + Id = 538 # NW_LAN + Directory = $true + } + Expected = @( + @{ + Id = 538 + Type = 'profile' + ReceiverId = 504 + ReceiverType = 'tcdirectory' + AssignmentPosition = 0 + } + @{ + Id = 538 + Type = 'profile' + ReceiverId = 517 + ReceiverType = 'tcdirectory' + AssignmentPosition = 1 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Get-UMSDeviceAssignment + @{ + Name = 'Get-UMSDeviceAssignment' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 577 # BR-MKT-003 + } + Expected = @( + @{ + Id = 577 + ReceiverId = 577 + ReceiverType = 'tc' + AssigneeId = 538 + AssigneeType = 'profile' + AssignmentPosition = 0 + } + @{ + Id = 577 + ReceiverId = 503 + ReceiverType = 'tcdirectory' + AssigneeId = 537 + AssigneeType = 'profile' + AssignmentPosition = 1 + } + @{ + Id = 577 + ReceiverId = 502 + ReceiverType = 'tcdirectory' + AssigneeId = 529 + AssigneeType = 'profile' + AssignmentPosition = 2 + } + @{ + Id = 577 + ReceiverId = 502 + ReceiverType = 'tcdirectory' + AssigneeId = 535 + AssigneeType = 'profile' + AssignmentPosition = 3 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Get-UMSDeviceDirectoryAssignment + @{ + Name = 'Get-UMSDeviceDirectoryAssignment' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + Id = 504 # BR_HR + } + Expected = @( + @{ + Id = 504 + ReceiverId = 504 + ReceiverType = 'tcdirectory' + AssigneeId = 538 + AssigneeType = 'profile' + AssignmentPosition = 0 + } + @{ + Id = 504 + ReceiverId = 502 + ReceiverType = 'tcdirectory' + AssigneeId = 535 + AssigneeType = 'profile' + AssignmentPosition = 1 + } + @{ + Id = 504 + ReceiverId = 502 + ReceiverType = 'tcdirectory' + AssigneeId = 529 + AssigneeType = 'profile' + AssignmentPosition = 2 + } + @{ + Id = 504 + ReceiverId = 503 + ReceiverType = 'tcdirectory' + AssigneeId = 537 + AssigneeType = 'profile' + AssignmentPosition = 3 + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Get-UMSDirectoryRecursive + @{ + Name = 'Get-UMSDirectoryRecursive' + Tags = 'UnitTests, IntegrationTests' + CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ + Params1 = @{ + #DirectoryColl = 'Get-UMSDeviceDirectory' + Id = 511 # Augsburg + } + Expected = @( + @{ + Id = 511 + Name = 'Augsburg' + ParentId = 502 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 514 + Name = 'A_Development' + ParentId = 511 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + @{ + Id = 597 + Name = 'A_QA' + ParentId = 511 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + Element = @{ + Params1 = @{ + #DirectoryColl = 'Get-UMSDeviceDirectory' + #ElementColl = 'Get-UMSDevice' + Id = 511 # Augsburg + } + Expected = @( + @{ + Id = 512 + ObjectType = 'tc' + UnitId = '0A0000000005' + Mac = '0A0000000005' + Name = 'A-DEV-005' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 513 + ObjectType = 'tc' + UnitId = '0A0000000006' + Mac = '0A0000000006' + Name = 'A-DEV-006' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 518 + ObjectType = 'tc' + UnitId = '0A0000000009' + Mac = '0A0000000009' + Name = 'A-DEV-009' + ParentId = 514 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 578 + ObjectType = 'tc' + UnitId = '0A0000000010' + Mac = '0A0000000010' + Name = 'A-DEV-010' + ParentId = 514 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 598 + ObjectType = 'tc' + UnitId = '0A0000000007' + Mac = '0A0000000007' + Name = 'A-QA-007' + ParentId = 597 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + @{ + Id = 599 + ObjectType = 'tc' + UnitId = '0A0000000008' + Mac = '0A0000000008' + Name = 'A-QA-008' + ParentId = 597 + FirmwareId = 1 + LastIp = '' + MovedToBin = 'False' + } + ) + Options = @{ + ExcludedPaths = '' + } + } + } + } + # Remove-UMSAPICookie + @{ + Name = 'Remove-UMSAPICookie' + Tags = 'UnitTests, IntegrationTests' + #CodeCoveragePath = 'Public' + ParameterSets = @{ + Default = @{ } + } + } + ) +} diff --git a/Tests/Get-OSFirmware.Tests.ps1 b/Tests/Get-OSFirmware.Tests.ps1 deleted file mode 100644 index 710d048..0000000 --- a/Tests/Get-OSFirmware.Tests.ps1 +++ /dev/null @@ -1,88 +0,0 @@ -$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) -$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) -$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf -$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") - -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - BeforeAll { - $Global:ConfirmPreference = 'None' - . ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) - $PSDefaultParameterValues = @{ - '*:SSHSession' = New-MockObject -Type 'SSH.SshSession' - } - } - - Context "Parameter Validation" { - - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys - $KnownParameters = 'SSHSession' - - It "Should contain our specific parameters" { - (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count - } - } - - Context "Code Execution" { - Mock 'Invoke-SSHCommandStream' { - @' -10.05.500.01 -'@ - } - Mock 'Write-Output' {} - - $Result = Get-OSFirmware - - It 'Assert Invoke-SSHCommandStream is called exactly 1 time' { - $AMCParams = @{ - CommandName = 'Invoke-SSHCommandStream' - Times = 1 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - - It 'Result Count should be 1' { - @($Result).Count | Should Be 1 - } - - It 'Result should have type [pscustomobject]' { - $Result | Should -HaveType [pscustomobject] - } - - It 'Result.Version should be exactly 10.05.500.01' { - $Result.Version | Should BeExactly '10.05.500.01' - } - - - It 'Assert Write-Output is called exactly 0 times' { - $AMCParams = @{ - CommandName = 'Write-Output' - Times = 0 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - } - - Context "Error Handling" { - Mock 'Invoke-SSHCommandStream' {throw 'Error'} - Mock 'Write-Output' {} - - $Result = Get-OSFirmware - - It 'Assert Write-Output is called exactly 1 time' { - $AMCParams = @{ - CommandName = 'Write-Output' - Times = 1 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - - It 'Result should be null or empty' { - $Result | Should BeNullOrEmpty - } - } -} \ No newline at end of file diff --git a/Tests/Get-OSUpdateConfiguration.Tests.ps1 b/Tests/Get-OSUpdateConfiguration.Tests.ps1 deleted file mode 100644 index e061b86..0000000 --- a/Tests/Get-OSUpdateConfiguration.Tests.ps1 +++ /dev/null @@ -1,118 +0,0 @@ -$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) -$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) -$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf -$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") - -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - BeforeAll { - $Global:ConfirmPreference = 'None' - . ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) - $PSDefaultParameterValues = @{ - '*:SSHSession' = New-MockObject -Type 'SSH.SshSession' - } - } - - Context "Parameter Validation" { - - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys - $KnownParameters = 'SSHSession' - - It "Should contain our specific parameters" { - (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count - } - } - - Context "Code Execution" { - Mock 'Invoke-SSHCommandStream' { - @' -[UPDATECONF] -protocol="http" -hostname="igelrmserver.acme.org" -port="8443" -username="igelums" -password="00a8430e21213a154e5c2f" -path="ums_filetransfer/IGEL_Universal_Desktop_LX-10.05.500" -'@ - } - Mock 'Write-Output' {} - - $Result = Get-OSUpdateConfiguration - - It 'Assert Invoke-SSHCommandStream is called exactly 1 time' { - $AMCParams = @{ - CommandName = 'Invoke-SSHCommandStream' - Times = 1 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - - It 'Result Count should be 1' { - @($Result).Count | Should Be 1 - } - - It 'Result should have type [pscustomobject]' { - $Result | Should -HaveType [pscustomobject] - } - - It 'Result.Protocol should be exactly http' { - $Result.Protocol | Should BeExactly 'http' - } - - It 'Result.Hostname should be exactly igelrmserver.acme.org' { - $Result.Hostname | Should BeExactly 'igelrmserver.acme.org' - } - - It 'Result.Port should have type [Int]' { - $Result.Port | Should -HaveType [Int] - } - - It 'Result.Port should be exactly 8443' { - $Result.Port | Should BeExactly 8443 - } - - It 'Result.Username should be exactly igelums' { - $Result.Username | Should BeExactly 'igelums' - } - - It 'Result.Password should be exactly 00a8430e21213a154e5c2f' { - $Result.Password | Should BeExactly '00a8430e21213a154e5c2f' - } - - It 'Result.Path should be exactly ums_filetransfer/IGEL_Universal_Desktop_LX-10.05.500' { - $Result.Path | Should BeExactly 'ums_filetransfer/IGEL_Universal_Desktop_LX-10.05.500' - } - - - It 'Assert Write-Output is called exactly 0 times' { - $AMCParams = @{ - CommandName = 'Write-Output' - Times = 0 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - } - - Context "Error Handling" { - Mock 'Invoke-SSHCommandStream' {throw 'Error'} - Mock 'Write-Output' {} - - $Result = Get-OSUpdateConfiguration - - It 'Assert Write-Output is called exactly 1 time' { - $AMCParams = @{ - CommandName = 'Write-Output' - Times = 1 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - - It 'Result should be null or empty' { - $Result | Should BeNullOrEmpty - } - } -} \ No newline at end of file diff --git a/Tests/Get-OSWifiConnection.Tests.ps1 b/Tests/Get-OSWifiConnection.Tests.ps1 deleted file mode 100644 index 42346fd..0000000 --- a/Tests/Get-OSWifiConnection.Tests.ps1 +++ /dev/null @@ -1,152 +0,0 @@ -$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) -$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) -$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf -$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") - -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - BeforeAll { - $Global:ConfirmPreference = 'None' - . ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) - $PSDefaultParameterValues = @{ - '*:SSHSession' = New-MockObject -Type 'SSH.SshSession' - } - } - - Context "Parameter Validation" { - - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys - $KnownParameters = 'SSHSession', 'Interface' - - It "Should contain our specific parameters" { - (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count - } - } - - Context "Code Execution" { - Mock 'Invoke-SSHCommandStream' { - @' -wlan0 IEEE 802.11 ESSID:"WLAN-0123456" - Mode:Managed Frequency:5.18 GHz Access Point: 00:42:4C:24:E8:F9 - Bit Rate=54 Mb/s Tx-Power=20 dBm - Retry short long limit:2 RTS thr:off Fragment thr:off - Encryption key:off - Power Management:off - Link Quality=66/70 Signal level=-44 dBm - Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 - Tx excessive retries:0 Invalid misc:17 Missed beacon:0 -'@ - } - Mock 'Write-Output' {} - - $Result = Get-OSWifiConnection - - It 'Assert Invoke-SSHCommandStream is called exactly 1 time' { - $AMCParams = @{ - CommandName = 'Invoke-SSHCommandStream' - Times = 1 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - - It 'Result Count should be 1' { - @($Result).Count | Should Be 1 - } - - It 'Result should have type [pscustomobject]' { - $Result | Should -HaveType [pscustomobject] - } - - It 'Result.ESSID should be exactly WLAN-0123456' { - $Result.ESSID | Should BeExactly 'WLAN-0123456' - } - - It 'Result.Mode should be exactly Managed' { - $Result.Mode | Should BeExactly 'Managed' - } - - It 'Result.Frequency should have type [Single]' { - $Result.Frequency | Should -HaveType [Single] - } - - It 'Result.Frequency should be exactly 5.18' { - $Result.Frequency | Should BeExactly '5.18' - } - - It 'Result.AccessPoint should be exactly 00:42:4C:24:E8:F9' { - $Result.AccessPoint | Should BeExactly '00:42:4C:24:E8:F9' - } - - It 'Result.BitRate should have type [Int]' { - $Result.BitRate | Should -HaveType [Int] - } - - It 'Result.BitRate should be exactly 54' { - $Result.BitRate | Should BeExactly 54 - } - - It 'Result.TxPower should have type [Int]' { - $Result.TxPower | Should -HaveType [Int] - } - - It 'Result.TxPower should be exactly 20' { - $Result.TxPower | Should BeExactly 20 - } - - It 'Result.LinkQualityActual should have type [Int]' { - $Result.LinkQualityActual | Should -HaveType [Int] - } - - It 'Result.LinkQualityActual should be exactly 66' { - $Result.LinkQualityActual | Should BeExactly 66 - } - - It 'Result.LinkQualityMax should have type [Int]' { - $Result.LinkQualityMax | Should -HaveType [Int] - } - - It 'Result.LinkQualityMax should be exactly 70' { - $Result.LinkQualityMax | Should BeExactly 70 - } - - It 'Result.SignalLevel should have type [Int]' { - $Result.SignalLevel | Should -HaveType [Int] - } - - It 'Result.SignalLevel should be exactly -44' { - $Result.SignalLevel | Should BeExactly -44 - } - - - It 'Assert Write-Output is called exactly 0 times' { - $AMCParams = @{ - CommandName = 'Write-Output' - Times = 0 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - } - - Context "Error Handling" { - Mock 'Invoke-SSHCommandStream' {throw 'Error'} - Mock 'Write-Output' {} - - $Result = Get-OSWifiConnection -Interface 'wlan0' - - It 'Assert Write-Output is called exactly 1 time' { - $AMCParams = @{ - CommandName = 'Write-Output' - Times = 1 - Exactly = $true - } - Assert-MockCalled @AMCParams - } - - It 'Result should be null or empty' { - $Result | Should BeNullOrEmpty - } - } -} \ No newline at end of file diff --git a/Tests/Get-UMSDevice.Tests.ps1 b/Tests/Get-UMSDevice.Tests.ps1 index 029c68a..1110bea 100644 --- a/Tests/Get-UMSDevice.Tests.ps1 +++ b/Tests/Get-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Filter', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSDevice Should not throw' { { Get-UMSDevice } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ SyncRoot = @{ mac = '0123456789AB' @@ -70,7 +63,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDevice @@ -83,9 +76,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -111,7 +104,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName ID" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ mac = '0123456789AB' firmwareID = '1' @@ -124,7 +117,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { links = '{}' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDevice -Id 2 @@ -137,9 +130,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -165,7 +158,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Filter online" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ mac = '0123456789AB' firmwareID = '1' @@ -178,7 +171,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { objectType = 'tc' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDevice -Id 2 -Filter online @@ -191,9 +184,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -219,7 +212,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Filter shadow" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ mac = '0123456789AB' firmwareID = '1' @@ -235,7 +228,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { objectType = 'tc' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDevice -Id 2 -Filter shadow @@ -248,9 +241,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -272,7 +265,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Filter details" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ mac = '0123456789AB' firmwareID = '1' @@ -316,7 +309,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { objectType = 'tc' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDevice -Id 2 -Filter details @@ -329,9 +322,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -357,7 +350,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Filter details no datetime" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ mac = '0123456789AB' firmwareID = '1' @@ -401,7 +394,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { objectType = 'tc' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDevice -Id 2 -Filter details @@ -414,9 +407,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -431,20 +424,20 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { @($Result).Count | Should BeExactly 1 } - It 'Result.BiosDate should be bull or empty' { + It 'Result.BiosDate should be null or empty' { $Result.BiosDate | Should -BeNullOrEmpty } - It 'Result.LastBoottime should be bull or empty' { + It 'Result.LastBoottime should be null or empty' { $Result.LastBoottime | Should -BeNullOrEmpty } } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSDevice } | should throw 'Error' + It 'should throw Error' { + { Get-UMSDevice } | Should throw 'Error' } It 'Result should be null or empty' { @@ -454,58 +447,157 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + if ($IsLinux) { - Clear-Variable -Name $Result + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + } + else + { + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[0].Id - $Mac = $UMS.UMSDevice[0].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default + + It "doesn't throw" { + { $Script:Result = @( + Get-UMSDevice + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ParameterSetName Details" { + + $Script:Result = '' + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Details + + It "doesn't throw" { + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSDevice @Params1 + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ParameterSetName Online" { + + $Script:Result = '' + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Online It "doesn't throw" { - { $Script:Result = Get-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSDevice @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It "Result.Id should be exactly $Id" { - $Result.Id | Should -BeExactly $Id + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] } - It 'Result.Mac should have type [String]' { - $Result.Mac | Should -HaveType [String] + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] } - It "Result.Mac should be exactly $Mac" { - $Result.Mac | Should -BeExactly $Mac + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSDeviceAssignment.Tests.ps1 b/Tests/Get-UMSDeviceAssignment.Tests.ps1 index 606e828..00077f4 100644 --- a/Tests/Get-UMSDeviceAssignment.Tests.ps1 +++ b/Tests/Get-UMSDeviceAssignment.Tests.ps1 @@ -2,47 +2,40 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } InModuleScope $Script:ModuleName { $PSDefaultParameterValues = @{ - '*:WebSession' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' - '*:Computername' = 'igelrmserver.acme.org' + '*:WebSession' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' + '*:Computername' = 'igelrmserver.acme.org' 'Get-UMSDeviceAssignment:Id' = 2 } Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSDeviceAssignment Should not throw' { { Get-UMSDeviceAssignment } | Should -Not -Throw @@ -56,7 +49,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ assignee = @{ @@ -74,9 +67,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSDeviceAssignment -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -106,10 +99,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSDeviceAssignment } | should throw 'Error' + It 'should throw Error' { + { Get-UMSDeviceAssignment } | Should throw 'Error' } It 'Result should be null or empty' { @@ -119,67 +112,62 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDeviceAssignment[0].Id - $ReceiverType = $UMS.UMSDeviceAssignment.ReceiverType - $AssigneeId = $UMS.UMSDeviceAssignment.AssigneeId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Get-UMSDeviceAssignment } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSDeviceAssignment @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] - } - - It "Result.Id should be exactly $UMS.UMSDeviceAssignment.Id" { - $Result.Id | Should -BeExactly $UMS.UMSDeviceAssignment.Id - } - - It 'Result.ReceiverType should have type [String]' { - $Result.ReceiverType | Should -HaveType [String] - } - - It "Result.ReceiverType should be exactly $ReceiverType)" { - $Result.ReceiverType | Should -BeExactly $ReceiverType + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It 'Result.AssigneeID should have type [Int]' { - $Result.AssigneeID | Should -HaveType [Int] + It 'Result[0].ReceiverType should have type [String]' { + $Result[0].ReceiverType | Should -HaveType [String] } - It "Result.AssigneeID should be exactly $AssigneeId)" { - $Result.AssigneeID | Should -BeExactly $AssigneeId + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSDeviceDirectory.Tests.ps1 b/Tests/Get-UMSDeviceDirectory.Tests.ps1 index 0b0b36e..844bbb1 100644 --- a/Tests/Get-UMSDeviceDirectory.Tests.ps1 +++ b/Tests/Get-UMSDeviceDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Filter', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSDeviceDirectory Should not throw' { { Get-UMSDeviceDirectory } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ SyncRoot = @{ id = '2' @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSDeviceDirectory - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -97,7 +90,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName ID" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ id = '2' name = 'ProfileName' @@ -109,9 +102,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSDeviceDirectory -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -137,7 +130,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Filter children" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ DirectoryChildren = @( @{ @@ -156,7 +149,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { objectType = 'tcdirectory' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSDeviceDirectory -Id 2 -Filter children @@ -169,9 +162,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -196,10 +189,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSDeviceDirectory } | should throw 'Error' + It 'should throw Error' { + { Get-UMSDeviceDirectory } | Should throw 'Error' } It 'Result should be null or empty' { @@ -209,58 +202,104 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDeviceDirectory[0].Id - $Name = $UMS.UMSDeviceDirectory[0].Name $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default + + It "doesn't throw" { + { $Script:Result = @( + Get-UMSDeviceDirectory + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ParameterSetName Children" { + + $Script:Result = '' + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Children It "doesn't throw" { - { $Script:Result = Get-UMSDeviceDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSDeviceDirectory @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It "Result.Id should be exactly $Id" { - $Result.Id | Should -BeExactly $Id + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] } - It 'Result.Name should have type [String]' { - $Result.Name | Should -HaveType [String] + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] } - It "Result.Name should be exactly $Name" { - $Result.Name | Should -BeExactly $Name + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSDeviceDirectoryAssignment.Tests.ps1 b/Tests/Get-UMSDeviceDirectoryAssignment.Tests.ps1 index 69cbf5e..c873fa8 100644 --- a/Tests/Get-UMSDeviceDirectoryAssignment.Tests.ps1 +++ b/Tests/Get-UMSDeviceDirectoryAssignment.Tests.ps1 @@ -2,47 +2,40 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } InModuleScope $Script:ModuleName { $PSDefaultParameterValues = @{ - '*:WebSession' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' - '*:Computername' = 'igelrmserver.acme.org' + '*:WebSession' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' + '*:Computername' = 'igelrmserver.acme.org' 'Get-UMSDeviceDirectoryAssignment:Id' = 2 } Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSDeviceDirectoryAssignment Should not throw' { { Get-UMSDeviceDirectoryAssignment } | Should -Not -Throw @@ -56,7 +49,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ assignee = @{ @@ -74,9 +67,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSDeviceDirectoryAssignment -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -106,10 +99,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSDeviceDirectoryAssignment } | should throw 'Error' + It 'should throw Error' { + { Get-UMSDeviceDirectoryAssignment } | Should throw 'Error' } It 'Result should be null or empty' { @@ -119,67 +112,62 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDeviceDirectoryAssignment[0].Id - $ReceiverType = $UMS.UMSDeviceDirectoryAssignment.ReceiverType - $AssigneeId = $UMS.UMSDeviceDirectoryAssignment.AssigneeId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Get-UMSDeviceDirectoryAssignment } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSDeviceDirectoryAssignment @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] - } - - It "Result.Id should be exactly $UMS.UMSDeviceDirectoryAssignment.Id" { - $Result.Id | Should -BeExactly $UMS.UMSDeviceDirectoryAssignment.Id - } - - It 'Result.ReceiverType should have type [String]' { - $Result.ReceiverType | Should -HaveType [String] - } - - It "Result.ReceiverType should be exactly $ReceiverType)" { - $Result.ReceiverType | Should -BeExactly $ReceiverType + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It 'Result.AssigneeID should have type [Int]' { - $Result.AssigneeID | Should -HaveType [Int] + It 'Result[0].ReceiverType should have type [String]' { + $Result[0].ReceiverType | Should -HaveType [String] } - It "Result.AssigneeID should be exactly $AssigneeId)" { - $Result.AssigneeID | Should -BeExactly $AssigneeId + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSDirectoryRecursive.Tests.ps1 b/Tests/Get-UMSDirectoryRecursive.Tests.ps1 new file mode 100644 index 0000000..0e42c84 --- /dev/null +++ b/Tests/Get-UMSDirectoryRecursive.Tests.ps1 @@ -0,0 +1,390 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { + + BeforeAll { + if ($null -ne $Result) + { + Clear-Variable -Name $Result -ErrorAction SilentlyContinue + $Script:Result = '' + } + } + + Context "Basics" { + + It "Is valid Powershell (Has no script errors)" { + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop + $ErrorColl = $Null + $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) + $ErrorColl | Should -HaveCount 0 + } + + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys + $KnownParameters = 'Id', 'DirectoryColl', 'ElementColl' + + It "Should contain our specific parameters" { + (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + } + } + + InModuleScope $Script:ModuleName { + + <# + $PSDefaultParameterValues = @{ + '*:Id' = 999 + '*:DirectoryColl' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' + '*:ElementColl' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' + } + #> + + Context "General Execution" { + + $Script:Result = '' + + Mock 'Get-UMSDirectoryRecursive' { } + + It 'Get-UMSDirectoryRecursive Should not throw' { + { Get-UMSDirectoryRecursive -Id 99 -DirectoryColl @{ } } | Should -Not -Throw + } + + It 'Get-UMSDirectoryRecursive -ApiVersion 10 Stop Should throw' { + { Get-UMSDirectoryRecursive -ApiVersion 10 -ErrorAction Stop } | Should -Throw + } + + } + + Context "Mock Get-UMSDirectoryRecursive" { + + $Script:Result = '' + + $DirectoryColl = @( + [pscustomobject]@{ + Id = 99 + Name = 'Directory1' + ParentId = 9 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 999 + Name = 'Directory11' + ParentId = 99 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 9999 + Name = 'Directory111' + ParentId = 999 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + ) + Mock 'Get-UMSDirectoryRecursive' { $DirectoryColl } + + Get-UMSDirectoryRecursive -Id 99 -DirectoryColl $DirectoryColl + + It 'Assert Get-UMSDirectoryRecursive is called exactly 1 time' { + $AMCParams = @{ + CommandName = 'Get-UMSDirectoryRecursive' + Times = 1 + Exactly = $true + } + Assert-MockCalled @AMCParams + } + } + #> + + #<# + Context "ParameterSetName Directory" { + + $Script:Result = '' + + $DirectoryColl = @( + [pscustomobject]@{ + Id = 99 + Name = 'Directory1' + ParentId = 9 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 999 + Name = 'Directory11' + ParentId = 99 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 9999 + Name = 'Directory111' + ParentId = 999 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 8888 + Name = 'Directory888' + ParentId = 888 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + ) + + It "doesn't throw" { + { $Script:Result = Get-UMSDirectoryRecursive -Id 99 -DirectoryColl $DirectoryColl } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result should have type pscustomobject' { + $Result | Should -HaveType ([pscustomobject]) + } + + It 'Result should have 3 elements' { + @($Result).Count | Should BeExactly 3 + } + + It 'Result.Id should mot contain 8888' { + $Result.Id | Should Not Contain 8888 + } + + It 'Result[0].Id should be exactly 99' { + $Result[0].Id | Should Be 99 + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + } + + Context "ParameterSetName Element" { + + $Script:Result = '' + + $DirectoryColl = @( + [pscustomobject]@{ + Id = 99 + Name = 'Directory1' + ParentId = 9 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 999 + Name = 'Directory11' + ParentId = 99 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + }, + [pscustomobject]@{ + Id = 9999 + Name = 'Directory111' + ParentId = 999 + MovedToBin = 'False' + ObjectType = 'tcdirectory' + } + ) + $ElementColl = @( + [pscustomobject]@{ + Id = 11 + ObjectType = 'tc' + UnitId = '112233445566' + Mac = '112233445566' + Name = 'Element1' + ParentId = 99 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + }, + [pscustomobject]@{ + Id = 111 + ObjectType = 'tc' + UnitId = '223344556677' + Mac = '223344556677' + Name = 'Element11' + ParentId = 999 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + }, + [pscustomobject]@{ + Id = 1111 + ObjectType = 'tc' + UnitId = '334455667788' + Mac = '334455667788' + Name = 'Element111' + ParentId = 9999 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + }, + [pscustomobject]@{ + Id = 8888 + ObjectType = 'tc' + UnitId = '445566778899' + Mac = '445566778899' + Name = 'Element888' + ParentId = 888 + FirmwareId = 2 + LastIp = '' + MovedToBin = 'False' + } + ) + + It "doesn't throw" { + { $Script:Result = Get-UMSDirectoryRecursive -Id 99 -DirectoryColl $DirectoryColl -ElementColl $ElementColl } | Should Not Throw + } + + It 'Result should have type pscustomobject' { + $Result | Should -HaveType ([pscustomobject]) + } + + It 'Result should have 3 elements' { + @($Result).Count | Should BeExactly 3 + } + + It 'Result.Id should mot contain 8888' { + $Result.Id | Should Not Contain 8888 + } + + It 'Result[0].Name should be Element1' { + $Result[0].Name | Should Be 'Element1' + } + + It 'Result[0].Id should be 11' { + $Result[0].Id | Should Be 11 + } + + It 'Result[0].ObjectType should be tc' { + $Result[0].ObjectType | Should be 'tc' + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + } + + Context "Error Handling" { + + $Script:Result = '' + Write-Host $Result + + Mock 'Get-UMSDirectoryRecursive' { throw 'Error' } + + It 'should throw Error' { + { $Script:Result = Get-UMSDirectoryRecursive -Id 99 -DirectoryColl @{ } -ElementColl @{ } } | Should throw 'Error' + } + + It 'Result should be null or empty' { + $Script:Result | Should BeNullOrEmpty + } + } + } +} + +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False + } + + $WebSession = New-UMSAPICookie + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default + + It "doesn't throw" { + $Params1 = $TestCfg.Params1 + $Params1.Add('DirectoryColl', (Get-UMSDeviceDirectory)) + { $Script:Result = @( + Get-UMSDirectoryRecursive @Params1 + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ParameterSetName Element" { + + $Script:Result = '' + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Element + + It "doesn't throw" { + $Params1 = $TestCfg.Params1 + $Params1.Add('DirectoryColl', (Get-UMSDeviceDirectory)) + $Params1.Add('ElementColl', (Get-UMSDevice)) + { $Script:Result = @( + Get-UMSDirectoryRecursive @Params1 + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + +} \ No newline at end of file diff --git a/Tests/Get-UMSFirmware.Tests.ps1 b/Tests/Get-UMSFirmware.Tests.ps1 index 5c2691a..9c9531b 100644 --- a/Tests/Get-UMSFirmware.Tests.ps1 +++ b/Tests/Get-UMSFirmware.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSFirmware Should not throw' { { Get-UMSFirmware } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ FwResource = @{ id = '2' @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSFirmware - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -97,7 +90,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName ID" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ id = '2' product = 'IGEL OS 11' @@ -109,9 +102,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSFirmware -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -136,10 +129,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSFirmware } | should throw 'Error' + It 'should throw Error' { + { Get-UMSFirmware } | Should throw 'Error' } It 'Result should be null or empty' { @@ -149,26 +142,22 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSFirmware[0].id $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } $WebSession = New-UMSAPICookie -Credential $Credential @@ -176,7 +165,9 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { { $Script:Result = Get-UMSFirmware } | Should Not Throw @@ -186,20 +177,31 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Product should have type [String]' { + $Result[0].Product | Should -HaveType [String] } - It "Result.Id should be exactly $($UMS.UMSFirmware[0].id)" { - $Result.Id | Should -BeExactly $UMS.UMSFirmware[0].id + It 'Result[0].Version should have type [Version]' { + $Result[0].Version | Should -HaveType [Version] } - It 'Result.Version should have type [String]' { - $Result.Version | Should -HaveType [String] + It 'Result[0].FirmwareType should have type [String]' { + $Result[0].FirmwareType | Should -HaveType [String] } - It "Result.Version should be exactly $($UMS.UMSFirmware[0].Version)" { - $Result.Version | Should -BeExactly $UMS.UMSFirmware[0].Version + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Get-UMSProfile.Tests.ps1 b/Tests/Get-UMSProfile.Tests.ps1 index 5307117..2469b8d 100644 --- a/Tests/Get-UMSProfile.Tests.ps1 +++ b/Tests/Get-UMSProfile.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSProfile Should not throw' { { Get-UMSProfile } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ SyncRoot = @{ firmwareID = '2' @@ -72,9 +65,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSProfile - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -104,7 +97,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName ID" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ firmwareID = '2' isMasterProfile = 'false' @@ -119,9 +112,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSProfile -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -150,10 +143,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSProfile } | should throw 'Error' + It 'should throw Error' { + { Get-UMSProfile } | Should throw 'Error' } It 'Result should be null or empty' { @@ -163,57 +156,65 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfile[0].id $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Get-UMSProfile } | Should Not Throw + { $Script:Result = @( + Get-UMSProfile + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It "Result.Id should be exactly $($UMS.UMSProfile[0].id)" { - $Result.Id | Should -BeExactly $UMS.UMSProfile[0].id + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] } - It 'Result.Name should have type [String]' { - $Result.Name | Should -HaveType [String] + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] } - It "Result.Name should be exactly $($UMS.UMSProfile[0].Name)" { - $Result.Name | Should -BeExactly $UMS.UMSProfile[0].Name + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSProfileAssignment.Tests.ps1 b/Tests/Get-UMSProfileAssignment.Tests.ps1 index 7531f3a..4d6ab94 100644 --- a/Tests/Get-UMSProfileAssignment.Tests.ps1 +++ b/Tests/Get-UMSProfileAssignment.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'Directory' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSProfileAssignment Should not throw' { { Get-UMSProfileAssignment } | Should -Not -Throw @@ -56,7 +49,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName Device" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ SyncRoot = @{ @@ -76,9 +69,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSProfileAssignment -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -104,7 +97,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName Directory" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ SyncRoot = @{ @@ -124,9 +117,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSProfileAssignment -Id 2 -Directory - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -151,10 +144,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSProfileAssignment } | should throw 'Error' + It 'should throw Error' { + { Get-UMSProfileAssignment } | Should throw 'Error' } It 'Result should be null or empty' { @@ -164,59 +157,97 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileAssignment[0].id - $ReceiverID = $UMS.UMSProfileAssignment[0].ReceiverID $PSDefaultParameterValues = @{ - '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - 'Get-UMSProfileAssignment:Directory' = $true + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Get-UMSProfileAssignment } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSProfileAssignment @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].ReceiverType should have type [String]' { + $Result[0].ReceiverType | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ParameterSetName Directory" { + + $Script:Result = '' + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Directory + + It "doesn't throw" { + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSProfileAssignment @Params1 + ) } | Should Not Throw } - It "Result.Id should be exactly $Id)" { - $Result.Id | Should -BeExactly $Id + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It 'Result.ReceiverID should have type [Int]' { - $Result.ReceiverID | Should -HaveType [Int] + It 'Result[0].ReceiverType should have type [String]' { + $Result[0].ReceiverType | Should -HaveType [String] } - It "Result.ReceiverID should be exactly $ReceiverID" { - $Result.ReceiverID | Should -BeExactly $ReceiverID + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSProfileDirectory.Tests.ps1 b/Tests/Get-UMSProfileDirectory.Tests.ps1 index 1bbd9fe..64d228f 100644 --- a/Tests/Get-UMSProfileDirectory.Tests.ps1 +++ b/Tests/Get-UMSProfileDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Filter', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSProfileDirectory Should not throw' { { Get-UMSProfileDirectory } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ SyncRoot = @{ id = '2' @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSProfileDirectory - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -97,7 +90,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSetName ID" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ id = '2' name = 'ProfileName' @@ -109,9 +102,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSProfileDirectory -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -137,7 +130,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Filter children" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ DirectoryChildren = @( @{ @@ -156,7 +149,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { objectType = 'profiledirectory' } } - Mock 'New-UMSFilterString' {} + Mock 'New-UMSFilterString' { } $Result = Get-UMSProfileDirectory -Id 2 -Filter children @@ -169,9 +162,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled @AMCParams } - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -196,10 +189,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSProfileDirectory } | should throw 'Error' + It 'should throw Error' { + { Get-UMSProfileDirectory } | Should throw 'Error' } It 'Result should be null or empty' { @@ -209,59 +202,104 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileDirectory[0].id - $ObjectType = $UMS.UMSProfileDirectory[0].DirectoryChildren.ObjectType $PSDefaultParameterValues = @{ - '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - 'Get-UMSProfileDirectory:Filter' = 'children' + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } - $WebSession = New-UMSAPICookie -Credential $Credential + $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default + + It "doesn't throw" { + { $Script:Result = @( + Get-UMSProfileDirectory + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ParameterSetName Children" { + + $Script:Result = '' + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Children It "doesn't throw" { - { $Script:Result = Get-UMSProfileDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Get-UMSProfileDirectory @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { $Result | Should not BeNullOrEmpty } - It 'Result.Id should have type [Int]' { - $Result.Id | Should -HaveType [Int] + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] } - It "Result.Id should be exactly $Id)" { - $Result.Id | Should -BeExactly $Id + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] } - It 'Result.DirectoryChildren.ObjectType should have type [String]' { - $Result.DirectoryChildren.ObjectType | Should -HaveType [String] + It 'Result[0].MovedToBin should have type [Bool]' { + $Result[0].MovedToBin | Should -HaveType [Bool] } - It "Result.DirectoryChildren.ObjectType should be exactly $ObjectType" { - $Result.DirectoryChildren.ObjectType | Should -BeExactly $ObjectType + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } + } \ No newline at end of file diff --git a/Tests/Get-UMSStatus.Tests.ps1 b/Tests/Get-UMSStatus.Tests.ps1 index c8ec080..7e7fd74 100644 --- a/Tests/Get-UMSStatus.Tests.ps1 +++ b/Tests/Get-UMSStatus.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Get-UMSStatus Should not throw' { { Get-UMSStatus } | Should -Not -Throw @@ -54,7 +47,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { [pscustomobject]@{ rmGuiServerVersion = '6.01.100' buildNumber = '40023' @@ -67,9 +60,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Get-UMSStatus - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -94,10 +87,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Get-UMSStatus } | should throw 'Error' + It 'should throw Error' { + { Get-UMSStatus } | Should throw 'Error' } It 'Result should be null or empty' { @@ -107,34 +100,31 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $RmGuiServerVersion = $UMS.UMSStatus.RmGuiServerVersion - $BuildNumber = $UMS.UMSStatus.BuildNumber $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } - $WebSession = New-UMSAPICookie -Credential $Credential $PSDefaultParameterValues += @{ - '*-UMS*:WebSession' = $WebSession + '*-UMS*:WebSession' = New-UMSAPICookie } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { { $Script:Result = Get-UMSStatus } | Should Not Throw @@ -144,20 +134,39 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result | Should not BeNullOrEmpty } - It 'Result.RmGuiServerVersion should have type [String]' { - $Result.RmGuiServerVersion | Should -HaveType [String] + It 'Result.RmGuiServerVersion[0] should have type [Version]' { + $Result.RmGuiServerVersion[0] | Should -HaveType [Version] + } + + It 'Result.BuildNumber[0] should have type [Int]' { + $Result.BuildNumber[0] | Should -HaveType [Int] + } + + It 'Result.activeMQVersion[0] should have type [Version]' { + $Result.activeMQVersion[0] | Should -HaveType [Version] + } + + It 'Result.derbyVersion[0] should have type [Version]' { + $Result.derbyVersion[0] | Should -HaveType [Version] } - It "Result.RmGuiServerVersion should be exactly $RmGuiServerVersion" { - $Result.RmGuiServerVersion | Should -BeExactly $RmGuiServerVersion + It 'Result.serverUUID[0] should have type [Char]' { + $Result.serverUUID[0] | Should -HaveType [Char] } - It 'Result.BuildNumber should have type [Int]' { - $Result.BuildNumber | Should -HaveType [Int] + It 'Result.server[0] should have type [Char]' { + $Result.server[0] | Should -HaveType [Char] } - It "Result.BuildNumber should be exactly $BuildNumber" { - $Result.BuildNumber | Should -BeExactly $BuildNumber + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Invoke-UMSRestMethod.Tests.ps1 b/Tests/Invoke-UMSRestMethod.Tests.ps1 new file mode 100644 index 0000000..aebf4b8 --- /dev/null +++ b/Tests/Invoke-UMSRestMethod.Tests.ps1 @@ -0,0 +1,155 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { + + Context "Basics" { + + It "Is valid Powershell (Has no script errors)" { + $Content = Get-Content -Path ( '{0}\Private\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop + $ErrorColl = $Null + $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) + $ErrorColl | Should -HaveCount 0 + } + + InModuleScope $Script:ModuleName { + + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys + $KnownParameters = 'WebSession', 'SecurityProtocol', 'Uri', 'Body', 'ContentType', 'Headers', 'Method' + + It "Should contain our specific parameters" { + (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + } + } + } + + InModuleScope $Script:ModuleName { + + $PSDefaultParameterValues = @{ + #'*:WebSession' = New-MockObject -Type 'System.Management.Automation.PSCustomObject' + '*:WebSession' = New-MockObject -Type 'Microsoft.PowerShell.Commands.WebRequestSession' + '*:SecurityProtocol' = 'Tls12' + #'*:Uri' = 'Uri' + '*:Uri' = 'https://igelrmserver/api/' + #'*:Body' = 'Body' + #'*:ContentType' = 'ContentType' + #'*:Headers' = @{ } + '*:Method' = 'Get' + } + + Context "Desktop General Execution" { + + Mock 'Invoke-RestMethod' { + [pscustomobject]@{ } + } + + It "Invoke-UMSRestMethod Should not throw" { + { Invoke-UMSRestMethod } | Should -Not -Throw + } + + It "Invoke-UMSRestMethod -Method 'nonexisting' -ErrorAction Stop Should throw" { + { Invoke-UMSRestMethod -Method 'nonexisting' -ErrorAction Stop } | Should -Throw + } + + } + + Switch (Get-Variable -Name PSEdition -ValueOnly) + { + 'Desktop' + { + + Context "Desktop Desktop:Invoke-UMSRestMethod" { + + Mock 'Get-Variable' { + 'Desktop' + } + + Mock 'Invoke-RestMethod' { + [pscustomobject]@{ Test = 'Test' } + } + + $Result = Invoke-UMSRestMethod + + It 'Assert Invoke-RestMethod is called exactly 1 time' { + $AMCParams = @{ + CommandName = 'Invoke-RestMethod' + Times = 1 + Exactly = $true + } + Assert-MockCalled @AMCParams + } + + It 'Result should have type PSCustomObject' { + $Result | Should -HaveType ([PSCustomObject]) + } + + It 'Result should have 1 element' { + @($Result).Count | Should BeExactly 1 + } + + It "Result.Test should be exactly 'Test'" { + $Result.Test | Should BeExactly 'Test' + } + } + Mock 'Get-Variable' { + 'Desktop' + } + } + 'Core' + { + Mock 'Get-Variable' { + 'Core' + } + Context "Core Invoke-RestMethod" { + + Mock 'Invoke-RestMethod' { + [pscustomobject]@{ Test = 'Test' } + } + + $Result = Invoke-UMSRestMethod + + It 'Assert Invoke-RestMethod is called exactly 1 time' { + $AMCParams = @{ + CommandName = 'Invoke-RestMethod' + Times = 1 + Exactly = $true + } + Assert-MockCalled @AMCParams + } + + It 'Result should have type PSCustomObject' { + $Result | Should -HaveType ([PSCustomObject]) + } + + It 'Result should have 1 element' { + @($Result).Count | Should BeExactly 1 + } + + It "Result.Test should be exactly 'Test'" { + $Result.Test | Should BeExactly 'Test' + } + } + } + } + + Context "Mock an exception" { + + Mock 'Invoke-RestMethod' { + [System.Net.WebException]::new('400') | + Add-Member -NotePropertyName Response -PassThru -Force -NotePropertyValue ( + [PSCustomObject]@{ StatusCode = [System.Net.HttpStatusCode]::BadRequest } + ) # work in progress + } + + It Invoke-UMSRestMethod' should throw' -Skip { + { Invoke-UMSRestMethod } | Should Throw 'some error' + } # makes no sense without above + } + + } +} diff --git a/Tests/Invoke-UMSRestMethodWebSession.Tests.ps1 b/Tests/Invoke-UMSRestMethodWebSession.Tests.ps1 deleted file mode 100644 index c7e9932..0000000 --- a/Tests/Invoke-UMSRestMethodWebSession.Tests.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) -$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) -$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf -$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) - -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } - - Context "Basics" { - - It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Private\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop - $ErrorColl = $Null - $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) - $ErrorColl | Should -HaveCount 0 - } - - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys - $KnownParameters = 'WebSession', 'SecurityProtocol', 'Uri', 'Body', 'ContentType', 'Headers', 'Method' - - It "Should contain our specific parameters" { - (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count - } - } -} diff --git a/Tests/Move-UMSDevice.Tests.ps1 b/Tests/Move-UMSDevice.Tests.ps1 index 548d3e4..9788336 100644 --- a/Tests/Move-UMSDevice.Tests.ps1 +++ b/Tests/Move-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'DestId' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Move-UMSDevice -Id 2 -DestId 2 Should not throw' { { Move-UMSDevice -Id 2 -DestId 2 } | Should -Not -Throw @@ -52,7 +45,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ id = '2' @@ -63,9 +56,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Move-UMSDevice -Id 2 -DestId 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -91,13 +84,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Move-UMSDevice -Id 2 -DestId 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -110,7 +103,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It 'Move-UMSDevice -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop Should throw' { { Move-UMSDevice -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -123,28 +116,22 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[0].Id - $DestId = $UMS.UMSDevice[0].DestId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:DestId' = $DestId + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } $WebSession = New-UMSAPICookie @@ -152,10 +139,21 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Move-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + $Params3 = $TestCfg.Params3 + $Params4 = $TestCfg.Params4 + { $Script:Result = @( + Move-UMSDevice @Params1 + Move-UMSDevice @Params2 + Move-UMSDevice @Params3 + Move-UMSDevice @Params4 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -166,12 +164,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'successful.'" { - $Result[0].Message | Should -BeExactly 'successful.' + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Move-UMSDeviceDirectory.Tests.ps1 b/Tests/Move-UMSDeviceDirectory.Tests.ps1 index a77d154..1555c7b 100644 --- a/Tests/Move-UMSDeviceDirectory.Tests.ps1 +++ b/Tests/Move-UMSDeviceDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'DestId' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Move-UMSDeviceDirectory -Id 2 -DestId 2 Should not throw' { { Move-UMSDeviceDirectory -Id 2 -DestId 2 } | Should -Not -Throw @@ -52,7 +45,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ id = '2' @@ -63,9 +56,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Move-UMSDeviceDirectory -Id 2 -DestId 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -91,13 +84,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Move-UMSDeviceDirectory -Id 2 -DestId 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -110,7 +103,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It 'Move-UMSDeviceDirectory -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop Should throw' { { Move-UMSDeviceDirectory -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -123,28 +116,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDeviceDirectory[0].Id - $DestId = $UMS.UMSDeviceDirectory[0].DestId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:DestId' = $DestId + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -152,10 +140,17 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Move-UMSDeviceDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + { $Script:Result = @( + Move-UMSDeviceDirectory @Params1 + Move-UMSDeviceDirectory @Params2 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -166,12 +161,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'successful.'" { - $Result[0].Message | Should -BeExactly 'successful.' + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Move-UMSProfile.Tests.ps1 b/Tests/Move-UMSProfile.Tests.ps1 index 8d2deff..86d2765 100644 --- a/Tests/Move-UMSProfile.Tests.ps1 +++ b/Tests/Move-UMSProfile.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'DestId' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Move-UMSProfile -Id 2 -DestId 2 Should not throw' { { Move-UMSProfile -Id 2 -DestId 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ id = '2' @@ -62,9 +55,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Move-UMSProfile -Id 2 -DestId 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -90,13 +83,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Move-UMSProfile -Id 2 -DestId 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -109,7 +102,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It 'Move-UMSProfile -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop Should throw' { { Move-UMSProfile -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -122,28 +115,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfile[0].Id - $DestId = $UMS.UMSProfile[0].DestId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:DestId' = $DestId + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -151,10 +139,13 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Move-UMSProfile } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = Move-UMSProfile @Params1 } | Should Not Throw } It 'Result should not be null or empty' { @@ -165,12 +156,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'successful.'" { - $Result[0].Message | Should -BeExactly 'successful' + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Move-UMSProfileDirectory.Tests.ps1 b/Tests/Move-UMSProfileDirectory.Tests.ps1 index cd7f122..815e89d 100644 --- a/Tests/Move-UMSProfileDirectory.Tests.ps1 +++ b/Tests/Move-UMSProfileDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'DestId' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It 'Move-UMSProfileDirectory -Id 2 -DestId 2 Should not throw' { { Move-UMSProfileDirectory -Id 2 -DestId 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ id = '2' @@ -62,9 +55,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Move-UMSProfileDirectory -Id 2 -DestId 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -90,13 +83,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Move-UMSProfileDirectory -Id 2 -DestId 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -109,7 +102,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It 'Move-UMSProfileDirectory -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop Should throw' { { Move-UMSProfileDirectory -Id 2 -DestId 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -122,28 +115,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileDirectory[0].Id - $DestId = $UMS.UMSProfileDirectory[0].DestId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:DestId' = $DestId + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -151,10 +139,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Move-UMSProfileDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Move-UMSProfileDirectory @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -165,12 +158,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'successful.'" { - $Result[0].Message | Should -BeExactly 'successful.' + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/New-UMSAPICookie.Tests.ps1 b/Tests/New-UMSAPICookie.Tests.ps1 index be0dfb9..8ef6ce3 100644 --- a/Tests/New-UMSAPICookie.Tests.ps1 +++ b/Tests/New-UMSAPICookie.Tests.ps1 @@ -2,52 +2,53 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'Credential', 'ApiVersion', 'SecurityProtocol' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } InModuleScope $Script:ModuleName { - <# + $User = "User" + $PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force $PSDefaultParameterValues = @{ - '*-UMS*:Computername' = 'igelrmserver.acme.org' - '*:Credential' = New-MockObject -Type 'System.Management.Automation.PSCredential' + '*:Credential' = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PassWord + '*:Computername' = 'igelrmserver.acme.org' } Context "General Execution" { - New-UMSAPICookie -Credential $Credential + Mock 'Invoke-UMSRestMethod' { + ( + [pscustomobject]@{ + message = 'JSESSIONID=3FB2F3F6A089FE9029DFD6DAFEF146DC' + } + ) + } + It "New-UMSAPICookie" { { New-UMSAPICookie } | Should -Not -Throw } - It 'New-UMSAPICookie -ApiVersion 10 Stop Should throw' { + It 'New-UMSAPICookie -ApiVersion 10 -ErrorAction Stop Should throw' { { New-UMSAPICookie -ApiVersion 10 -ErrorAction Stop } | Should -Throw } @@ -55,7 +56,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'JSESSIONID=3FB2F3F6A089FE9029DFD6DAFEF146DC' @@ -65,76 +66,68 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = New-UMSAPICookie - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } Assert-MockCalled @AMCParams } - It 'Result should have type pscustomobject' { - $Result | Should -HaveType ([pscustomobject]) + It 'Result should have type Microsoft.Powershell.Commands.Webrequestsession' { + $Result | Should -HaveType ([Microsoft.Powershell.Commands.Webrequestsession]) } It 'Result should have 1 element' { @($Result).Count | Should BeExactly 1 } - It 'Result[0] should have type [pscustomobject]' { - $Result[0] | Should -HaveType [pscustomobject] - } - - It 'Result[0].Id should be exactly 2' { - $Result[0].Id | Should BeExactly 2 + It 'Result[0].Cookies should have type [System.Net.CookieContainer]' { + $Result[0].Cookies | Should -HaveType [System.Net.CookieContainer] } - It 'Result[0].Id should have type [Int]' { - $Result[0].Id | Should -HaveType [Int] + It 'Result[0].Cookies.Count should be exactly 1' { + $Result[0].Cookies.Count | Should BeExactly 1 } - It "Result[0].Message should be exactly '1 asssignments successfully assigned.'" { - $Result[0].Message | Should BeExactly '1 asssignments successfully assigned.' - } } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} - it 'should throw Error' { - { New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | should throw 'Error' - } + Mock 'Invoke-RestMethod' { throw 'Error' } - It 'Result should be null or empty' { - $Result | Should BeNullOrEmpty - } + It 'should throw Error' -Skip { + { 'New-UMSAPICookie -ErrorAction Stop' } | Should throw 'Error' + } # cant get to throw + + It 'Result should be null or empty' -Skip { + New-UMSAPICookie | Should BeNullOrEmpty + } # only useful with above working } - #> + } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { It "doesn't throw" { { $Script:Result = New-UMSAPICookie } | Should Not Throw @@ -151,5 +144,22 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { It "Result.GetType().Name should be exactly WebRequestSession" { $Result.GetType().Name | Should -BeExactly 'WebRequestSession' } + + It 'Result[0].Cookies should have type [System.Net.CookieContainer]' { + $Result[0].Cookies | Should -HaveType [System.Net.CookieContainer] + } + + It 'Result[0].Cookies.Count should be exactly 1' { + $Result[0].Cookies.Count | Should BeExactly 1 + } + + It "Result[0].Cookies.GetCookies('https://{0}' -f $($Cfg.Computername)).Name should have type [String]" { + $Result[0].Cookies.GetCookies('https://{0}' -f $($Cfg.Computername)).Name | Should -HaveType [String] + } + + It "Result[0].Cookies.GetCookies('https://{0}' -f $($Cfg.Computername)).Name should be exactly JSESSIONID" { + $Result[0].Cookies.GetCookies('https://{0}' -f $($Cfg.Computername)).Name | Should BeExactly 'JSESSIONID' + } + } } \ No newline at end of file diff --git a/Tests/New-UMSDevice.Tests.ps1 b/Tests/New-UMSDevice.Tests.ps1 index 5ed473f..d2462c9 100644 --- a/Tests/New-UMSDevice.Tests.ps1 +++ b/Tests/New-UMSDevice.Tests.ps1 @@ -2,34 +2,27 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Mac', 'FirmwareId', 'Name', 'ParentId', 'Site', 'Department', 'CostCenter', 'LastIP', 'Comment', 'AssetId', 'InserviceDate', 'SerialNumber' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -43,7 +36,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "New-UMSDevice -Mac '001122334455' -FirmwareId 2 -LastIP '192.168.0.1' Should not throw" { { New-UMSDevice -Mac '001122334455' -FirmwareId 2 -LastIP '192.168.0.1' } | Should -Not -Throw @@ -52,7 +45,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Thin client successfully inserted.' @@ -65,9 +58,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = New-UMSDevice -Mac '001122334455' -FirmwareId 2 -LastIP '192.168.0.1' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -93,13 +86,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = New-UMSDevice -Mac '001122334455' -FirmwareId 2 -LastIP '192.168.0.1' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -112,7 +105,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "New-UMSDevice -Mac '001122334455' -FirmwareId 2 -LastIP '192.168.0.1' -ApiVersion 10 -ErrorAction Stop Should throw" { { New-UMSDevice -Mac '001122334455' -FirmwareId 2 -LastIP '192.168.0.1' -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -125,32 +118,22 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Name = $UMS.UMSDevice[2].NameNew - $Mac = $UMS.UMSDevice[2].MacNew - $FirmwareId = $UMS.UMSDevice[2].FirmwareIdNew - $ParentId = $UMS.UMSDevice[2].ParentId $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Name' = $Name - '*-UMS*:Mac' = $Mac - '*-UMS*:FirmwareId' = $FirmwareId - '*-UMS*:ParentId' = $ParentId + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } $WebSession = New-UMSAPICookie @@ -158,10 +141,17 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = New-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + { $Script:Result = @( + New-UMSDevice @Params1 + New-UMSDevice @Params2 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -172,16 +162,31 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Name should be exactly $Name" { - $Result[0].Name | Should -BeExactly $Name + It 'Result[0].Mac should have type [String]' { + $Result[0].Mac | Should -HaveType [String] } - It "Result[0].Mac should be exactly $Mac" { - $Result[0].Mac | Should -BeExactly $Mac + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].ParentId should be exactly $ParentId" { - $Result[0].ParentId | Should -BeExactly $ParentId + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] } + + It 'Result[0].ParentId should have type [Int]' { + $Result[0].ParentId | Should -HaveType [Int] + } + + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } } \ No newline at end of file diff --git a/Tests/New-UMSDeviceDirectory.Tests.ps1 b/Tests/New-UMSDeviceDirectory.Tests.ps1 index e636d4c..58c0698 100644 --- a/Tests/New-UMSDeviceDirectory.Tests.ps1 +++ b/Tests/New-UMSDeviceDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Name' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "New-UMSDeviceDirectory -Name 'NameNew' Should not throw" { { New-UMSDeviceDirectory -Name 'NameNew' } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Directory successfully inserted.' @@ -63,9 +56,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = New-UMSDeviceDirectory -Name 'NameNew' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -91,13 +84,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = New-UMSDeviceDirectory -Name 'NameNew' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -110,7 +103,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "New-UMSDeviceDirectory -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop Should throw" { { New-UMSDeviceDirectory -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -123,37 +116,35 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Name = $UMS.UMSDeviceDirectory[3].NameNew $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Name' = $Name + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } - $WebSession = New-UMSAPICookie $PSDefaultParameterValues += @{ - '*-UMS*:WebSession' = $WebSession + '*-UMS*:WebSession' = New-UMSAPICookie } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = New-UMSDeviceDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = New-UMSDeviceDirectory @Params1 } | Should Not Throw } It 'Result should not be null or empty' { @@ -164,12 +155,23 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Name should be exactly $Name" { - $Result[0].Name | Should -BeExactly $Name + It "Result[0].Name should have type [String]" { + $Result[0].Name | Should -HaveType [String] + } + + It "Result[0].Message should have type [String]" { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'Directory successfully inserted.'" { - $Result[0].Message | Should -BeExactly 'Directory successfully inserted.' + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/New-UMSFunctionString.Tests.ps1 b/Tests/New-UMSFilterString.Tests.ps1 similarity index 70% rename from Tests/New-UMSFunctionString.Tests.ps1 rename to Tests/New-UMSFilterString.Tests.ps1 index 755be5e..aefc1e3 100644 --- a/Tests/New-UMSFunctionString.Tests.ps1 +++ b/Tests/New-UMSFilterString.Tests.ps1 @@ -2,33 +2,29 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Private\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Private\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys - $KnownParameters = 'Filter' + InModuleScope $Script:ModuleName { - It "Should contain our specific parameters" { - (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | + [object[]]$params = (Get-ChildItem function:\$Content).Parameters.Keys + $KnownParameters = 'Filter' + + It "Should contain our specific parameters" { + (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + } } } @@ -37,7 +33,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { It "New-UMSFilterString -Filter 'short' Should not throw" { - { New-UMSFilterString -Filter 'short'} | Should -Not -Throw + { New-UMSFilterString -Filter 'short' } | Should -Not -Throw } It "New-UMSFilterString -Filter 'nonexisting' -ErrorAction Stop Should throw" { diff --git a/Tests/New-UMSProfileAssignment.Tests.ps1 b/Tests/New-UMSProfileAssignment.Tests.ps1 index 110437e..782c701 100644 --- a/Tests/New-UMSProfileAssignment.Tests.ps1 +++ b/Tests/New-UMSProfileAssignment.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'ReceiverId', 'ReceiverType' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc'" { { New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "tc" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = '1 asssignments successfully assigned' @@ -65,9 +58,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,7 +94,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "tcdirectory" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = '1 asssignments successfully assigned' @@ -111,9 +104,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = $Result = New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tcdirectory' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -147,13 +140,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -166,10 +159,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | should throw 'Error' + It 'should throw Error' { + { New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | Should throw 'Error' } It 'Result should be null or empty' { @@ -179,30 +172,22 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileAssignment[0].Id - $ReceiverId = $UMS.UMSProfileAssignment[0].ReceiverIdNew - $ReceiverType = $UMS.UMSProfileAssignment[0].ReceiverTypeNew $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:ReceiverId' = $ReceiverId - '*-UMS*:ReceiverType' = $ReceiverType + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } $WebSession = New-UMSAPICookie @@ -210,10 +195,17 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = New-UMSProfileAssignment } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + { $Script:Result = @( + New-UMSProfileAssignment @Params1 + New-UMSProfileAssignment @Params2 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -224,12 +216,27 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].ReceiverId should be exactly $ReceiverId" { - $Result[0].ReceiverId | Should -BeExactly $ReceiverId + It 'Result[0].ReceiverId should have type [Int]' { + $Result[0].ReceiverId | Should -HaveType [Int] } + + It 'Result[0].ReceiverType should have type [String]' { + $Result[0].ReceiverType | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } } \ No newline at end of file diff --git a/Tests/New-UMSProfileDirectory.Tests.ps1 b/Tests/New-UMSProfileDirectory.Tests.ps1 index f2bc91e..46c09cc 100644 --- a/Tests/New-UMSProfileDirectory.Tests.ps1 +++ b/Tests/New-UMSProfileDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Name' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "New-UMSProfileDirectory -Name 'NameNew' Should not throw" { { New-UMSProfileDirectory -Name 'NameNew' } | Should -Not -Throw @@ -50,7 +43,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Directory successfully inserted.' @@ -62,9 +55,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = New-UMSProfileDirectory -Name 'NameNew' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -90,13 +83,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = New-UMSProfileDirectory -Name 'NameNew' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -109,7 +102,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "New-UMSProfileDirectory -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop Should throw" { { New-UMSProfileDirectory -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -122,26 +115,22 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Name = $UMS.UMSProfileDirectory[2].NameNew $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Name' = $Name + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol } $WebSession = New-UMSAPICookie @@ -149,10 +138,13 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = New-UMSProfileDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = New-UMSProfileDirectory @Params1 } | Should Not Throw } It 'Result should not be null or empty' { @@ -163,8 +155,23 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Name should be exactly $Name" { - $Result[0].Name | Should -BeExactly $Name + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } + + It 'Result[0].Name should have type [String]' { + $Result[0].Name | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } } \ No newline at end of file diff --git a/Tests/PSIGEL.Tests.ps1 b/Tests/PSIGEL.Tests.ps1 index d773258..d47ff75 100644 --- a/Tests/PSIGEL.Tests.ps1 +++ b/Tests/PSIGEL.Tests.ps1 @@ -1,14 +1,15 @@ -$ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) -$ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $ProjectRoot)) -$ModuleName = Split-Path $ModuleRoot -Leaf -$ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $ModuleRoot, $ModuleName) +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force Describe "General project validation: $ModuleName" { Context 'Basic Module Testing' { $ScriptColl = Get-ChildItem $ModuleRoot -Include *.ps1, *.psm1, *.psd1 -Recurse - $TestCase = $ScriptColl | Foreach-Object { + $TestCase = $ScriptColl | ForEach-Object { @{ File = $_ } @@ -27,7 +28,7 @@ Describe "General project validation: $ModuleName" { } It "Module '$ModuleName' can import cleanly" { - {Import-Module ( '{0}/{1}.psm1' -f $ModuleRoot, $ModuleName) } | Should Not Throw + { Import-Module ( '{0}/{1}.psm1' -f $ModuleRoot, $ModuleName) } | Should Not Throw } } @@ -66,60 +67,60 @@ Describe "General project validation: $ModuleName" { Context 'Public Functions' { $PublicFunctionColl = (Get-ChildItem -Path ('{0}\Public' -f $ModuleRoot) -Filter *.ps1 | - Select-Object -ExpandProperty Name ) -replace '\.ps1$' + Select-Object -ExpandProperty Name ) -replace '\.ps1$' - $TestCase = $PublicFunctionColl | Foreach-Object { + $TestCase = $PublicFunctionColl | ForEach-Object { @{ - FunctionName = $_ + ScriptName = $_ } } - It "Function should be in manifest" -TestCases $TestCase { + It "Function should be in manifest" -TestCases $TestCase { param( - $FunctionName + $ScriptName ) $ManifestFunctionColl = $Manifest.ExportedFunctions.Keys - $FunctionName -in $ManifestFunctionColl | Should Be $true + $ScriptName -in $ManifestFunctionColl | Should Be $true } It 'Proper Number of Functions Exported compared to Manifest' { $ExportedCount = Get-Command -Module $ModuleName -CommandType Function | - Measure-Object | Select-Object -ExpandProperty Count + Measure-Object | Select-Object -ExpandProperty Count $ManifestCount = $Manifest.ExportedFunctions.Count $ExportedCount | Should be $ManifestCount } It 'Proper Number of Functions Exported compared to Files' { $ExportedCount = Get-Command -Module $ModuleName -CommandType Function | - Measure-Object | Select-Object -ExpandProperty Count + Measure-Object | Select-Object -ExpandProperty Count $FileCount = Get-ChildItem -Path ('{0}\Public' -f $ModuleRoot) -Filter *.ps1 | - Measure-Object | Select-Object -ExpandProperty Count + Measure-Object | Select-Object -ExpandProperty Count $ExportedCount | Should be $FileCount } } Context 'Private Functions' { $PrivateFunctionColl = (Get-ChildItem -Path ('{0}\Private' -f $ModuleRoot) -Filter *.ps1 | - Select-Object -ExpandProperty Name ) -replace '\.ps1$' - $TestCase = $PrivateFunctionColl | Foreach-Object { + Select-Object -ExpandProperty Name ) -replace '\.ps1$' + $TestCase = $PrivateFunctionColl | ForEach-Object { @{ - FunctionName = $_ + ScriptName = $_ } } - It "Private function is not directly accessible outside the module" -TestCases $TestCase { + It "Private function is not directly accessible outside the module" -TestCases $TestCase { param( - $FunctionName + $ScriptName ) - { . ('\{0}' -f $FunctionName) } | Should Throw + { . ('\{0}' -f $ScriptName) } | Should Throw } } Context 'Exported Aliases' { It 'Proper Number of Aliases Exported compared to Manifest' { $ExportedCount = Get-Command -Module $ModuleName -CommandType Alias | - Measure-Object | Select-Object -ExpandProperty Count + Measure-Object | Select-Object -ExpandProperty Count $ManifestCount = $Manifest.ExportedAliases.Count $ExportedCount | Should be $ManifestCount @@ -127,10 +128,10 @@ Describe "General project validation: $ModuleName" { It 'Proper Number of Aliases Exported compared to Files' { $AliasCount = Get-ChildItem -Path "$ModuleRoot\Public" -Filter *.ps1 | - Select-String "New-Alias" | Measure-Object | Select-Object -ExpandProperty Count + Select-String "New-Alias" | Measure-Object | Select-Object -ExpandProperty Count $ManifestCount = $Manifest.ExportedAliases.Count - $AliasCount | Should be $ManifestCount + $AliasCount | Should be $ManifestCount } } } @@ -144,14 +145,14 @@ Describe "$ModuleName ScriptAnalyzer" -Tag 'Compliance' { $ScriptAnalyzerErrorColl += Invoke-ScriptAnalyzer -Path "$ModuleRoot\Public" @PSScriptAnalyzerSettingColl $ScriptAnalyzerErrorColl += Invoke-ScriptAnalyzer -Path "$ModuleRoot\Private" @PSScriptAnalyzerSettingColl $PrivateFunctionColl = Get-ChildItem -Path "$ModuleRoot\Private" -Filter *.ps1 | - Select-Object -ExpandProperty Name + Select-Object -ExpandProperty Name $PublicFunctionColl = Get-ChildItem -Path "$ModuleRoot\Public" -Filter *.ps1 | - Select-Object -ExpandProperty Name + Select-Object -ExpandProperty Name $AllFunctionColl = ($PrivateFunctionColl + $PublicFunctionColl) | Sort-Object $FunctionWithErrorColl = $ScriptAnalyzerErrorColl.ScriptName | Sort-Object -Unique if ($ScriptAnalyzerErrorColl) { - $TestCase = $ScriptAnalyzerErrorColl | Foreach-Object { + $TestCase = $ScriptAnalyzerErrorColl | ForEach-Object { @{ RuleName = $_.RuleName ScriptName = $_.ScriptName @@ -161,7 +162,7 @@ Describe "$ModuleName ScriptAnalyzer" -Tag 'Compliance' { } } $FunctionWithoutErrorColl = Compare-Object -ReferenceObject $AllFunctionColl -DifferenceObject $FunctionWithErrorColl | - Select-Object -ExpandProperty InputObject + Select-Object -ExpandProperty InputObject Context 'ScriptAnalyzer Testing' { It "Function should not use on line " -TestCases $TestCase { param( @@ -181,7 +182,7 @@ Describe "$ModuleName ScriptAnalyzer" -Tag 'Compliance' { } Context 'Successful ScriptAnalyzer Testing' { - $TestCase = $FunctionWithoutErrorColl | Foreach-Object { + $TestCase = $FunctionWithoutErrorColl | ForEach-Object { @{ ScriptName = $_ } diff --git a/Tests/Pester.ps1 b/Tests/Pester.ps1 index 1356e2e..3c743b8 100644 --- a/Tests/Pester.ps1 +++ b/Tests/Pester.ps1 @@ -1,85 +1,77 @@ param ( - [ValidateSet('All', 'UnitTests', 'IntegrationTests')] + [ValidateSet('UnitTests', 'IntegrationTests')] [String] - #$Tags = 'All' - #$Tags = 'UnitTests' - $Tags = 'IntegrationTests' + $Tags, + + [String[]] + $Show = ('Header', 'Summary', 'Failed'), + + [Switch] + $EnableExit = $false ) -$ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) -$ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $ProjectRoot)) +$DSC = [IO.Path]::DirectorySeparatorChar +$ProjectRoot = Resolve-Path ('{1}{0}..' -f $DSC, $PSScriptRoot) +$ModuleRoot = Split-Path (Resolve-Path ('{1}{0}*{0}*.psm1' -f $DSC, $ProjectRoot)) $ModuleName = Split-Path $ModuleRoot -Leaf -$OutputPath = '{0}\Tests\Data' -f $ProjectRoot - +Import-Module ( '{1}{0}{2}.psm1' -f $DSC, $Script:ModuleRoot, $Script:ModuleName) -Force -$UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $ProjectRoot) | - ConvertFrom-Json -$Password = Get-Content $UMS.CredPath | ConvertTo-SecureString -$Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) +$Cfg = Import-PowerShellDataFile -Path ('{1}{0}Tests{0}Config.psd1' -f $DSC, $Script:ProjectRoot) -$PSDefaultParameterValues = @{ - '*:Computername' = $UMS.Computername - '*-UMS*:TCPPort' = [Int]$UMS.TCPPort - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Confirm' = $false - 'Invoke-Pester:Show' = 'Failed' +if ($PSEdition -eq 'Desktop') +{ + $OutputPath = '{1}{0}Tests{0}Data{0}{2}{0}' -f $DSC, $ProjectRoot, $Cfg.OutputPath.Desktop } - -<# -$IgelRmGuiServerService = Get-Service -Name 'IGELRMGUIServer' -switch ($IgelRmGuiServerService) +elseif ($IsWindows -and $PSEdition -eq 'Core') +{ + $OutputPath = '{1}{0}Tests{0}Data{0}{2}{0}' -f $DSC, $ProjectRoot, $Cfg.OutputPath.CoreW10 + Import-Module ('{0}\PowerShell\7\Modules\CimCmdlets\CimCmdlets.psd1' -f [Environment]::GetEnvironmentVariable('ProgramFiles')) -Force + Import-Module -Name Pester -Force + #Import-Module C:\Users\fheiland\Documents\WindowsPowerShell\Modules\Assert\Assert.psd1 +} +elseif ($IsLinux) +{ + $OutputPath = '{1}{0}Tests{0}Data{0}{2}{0}' -f $DSC, $ProjectRoot, $Cfg.OutputPath.CoreWSL +} +else { - $false + $OutputPath = '{1}{0}Tests{0}Data{0}{2}{0}' -f $DSC, $ProjectRoot +} +if ($Tags -eq 'IntegrationTests') +{ + if ($IsLinux) { - throw "Service $IgelRmGuiServerService not found!" + $Credential = Import-Clixml -Path $Cfg.CredPathWsl } - {$_.Status -eq 'Stopped'} + else { - "Stopped" - $i = 0 - $IgelRmGuiServerService | Start-Service -ErrorAction Stop - do - { - Start-Sleep -Seconds 3 - $i++ - if ($i -ge 10) - { - throw "TCPPort $UMS.TCPPort not responding!" - } - } - until ((Test-NetConnection -Port $UMS.TCPPort).TcpTestSucceeded -eq $true ) + $Credential = Import-Clixml -Path $Cfg.CredPath + } + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $false } -} -#> -$WebSession = New-UMSAPICookie -Credential $Credential -$PSDefaultParameterValues += @{ - '*-UMS*:WebSession' = $WebSession -} + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = (New-UMSAPICookie) + } -Invoke-Pester -Script ('{0}\Tests\{1}.Tests.ps1' -f $ProjectRoot, $ModuleName) -OutputFile ('{0}\{1}.Tests.xml' -f $OutputPath, $ModuleName) +} -foreach ($Function in $UMS.TestOrder.Public) +foreach ($Test in $Cfg.Tests) { - $IVPParams = @{ - Script = '{0}\Tests\{1}.Tests.ps1' -f $ProjectRoot, $Function - OutputFile = '{0}\{1}.Tests.xml' -f $OutputPath, $Function - } - switch ($Tags) + $IVPParams = @{ } + $IVPParams.Add('Tags', $Tags) + $IVPParams.Add('Show', $Show) + $IVPParams.Add('EnableExit', $EnableExit) + $IVPParams.Add('Script', ('{1}{0}Tests{0}{2}.Tests.ps1' -f $DSC, $ProjectRoot, $Test.Name)) + $IVPParams.Add('Outputfile', ('{1}{0}{2}.Tests.xml' -f $DSC, $OutputPath, $Test.Name)) + if (($Test.CodeCoveragePath) -and ($Tags -ne 'IntegrationTests')) { - 'All' - { - $IVPParams.CodeCoverage = '{0}\{1}\Public\{2}.ps1' -f $ProjectRoot, $ModuleName, $Function - } - 'UnitTests' - { - $IVPParams.Tag = 'UnitTests' - $IVPParams.CodeCoverage = '{0}\{1}\Public\{2}.ps1' -f $ProjectRoot, $ModuleName, $Function - } - 'IntegrationTests' - { - $IVPParams.Tag = 'IntegrationTests' - } + $IVPParams.Add('CodeCoverage', ('{1}{0}{2}{0}{3}{0}{4}.ps1' -f $DSC, $ProjectRoot, $ModuleName, $Test.CodeCoveragePath, $Test.Name)) } Invoke-Pester @IVPParams } diff --git a/Tests/Pipeline.UMSDevice.Tests.ps1 b/Tests/Pipeline.UMSDevice.Tests.ps1 new file mode 100644 index 0000000..a6267c5 --- /dev/null +++ b/Tests/Pipeline.UMSDevice.Tests.ps1 @@ -0,0 +1,150 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False + } + + $WebSession = New-UMSAPICookie + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ValueFromPipeline" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipeline + + It "doesn't throw" { + $NewParams = $TestCfg.NewParams + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = [pscustomobject]$NewParams | + New-UMSDevice | Tee-Object -Variable 'NewUMSDevice' | + Move-UMSDevice @MoveParams | Tee-Object -Variable 'MoveUMSDevice' | + Update-UMSDevice @UpdateParams | Tee-Object -Variable 'UpdateUMSDevice' | + Get-UMSDevice | Tee-Object -Variable 'GetUMSDevice' | + Start-UMSDevice | Tee-Object -Variable 'StartUMSDevice' | + Send-UMSDeviceSetting | Tee-Object -Variable 'SendUMSDeviceSetting' | + Restart-UMSDevice | Tee-Object -Variable 'RestartUMSDevice' | + Stop-UMSDevice | Tee-Object -Variable 'StopUMSDevice' | + Reset-UMSDevice | Tee-Object -Variable 'ResetUMSDevice' | + Remove-UMSDevice | Tee-Object -Variable 'RemoveUMSDevice' + $NewUMSDevice + $MoveUMSDevice + $UpdateUMSDevice + $GetUMSDevice + $StartUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $SendUMSDeviceSettings | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $RestartUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $StopUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $ResetUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $RemoveUMSDevice + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + + } + + Context "ValueFromPipelineByPropertyName" { + + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipelineByPropertyName + + It "doesn't throw" { + $NewParams = $TestCfg.NewParams + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + { $Script:Result = @( + $null = ((((((((($NewParams.Mac | + New-UMSDevice -FirmwareId $NewParams.FirmwareId -Name $NewParams.Name | Tee-Object -Variable 'NewUMSDevice').Id | + Move-UMSDevice @MoveParams | Tee-Object -Variable 'MoveUMSDevice').Id | + Update-UMSDevice @UpdateParams | Tee-Object -Variable 'UpdateUMSDevice').Id | + Get-UMSDevice | Tee-Object -Variable 'GetUMSDevice').Id | + Start-UMSDevice | Tee-Object -Variable 'StartUMSDevice').Id | + Send-UMSDeviceSetting | Tee-Object -Variable 'SendUMSDeviceSetting').Id | + Restart-UMSDevice | Tee-Object -Variable 'RestartUMSDevice').Id | + Stop-UMSDevice | Tee-Object -Variable 'StopUMSDevice').Id | + Reset-UMSDevice | Tee-Object -Variable 'ResetUMSDevice').Id | + Remove-UMSDevice | Tee-Object -Variable 'RemoveUMSDevice' + $NewUMSDevice + $MoveUMSDevice + $UpdateUMSDevice + $GetUMSDevice + $StartUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $SendUMSDeviceSettings | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $RestartUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $StopUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $ResetUMSDevice | Select-Object -Property * -ExcludeProperty 'ExecId', 'ExecTime' + $RemoveUMSDevice + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + + } + +} \ No newline at end of file diff --git a/Tests/Pipeline.UMSDeviceDirectory.Tests.ps1 b/Tests/Pipeline.UMSDeviceDirectory.Tests.ps1 new file mode 100644 index 0000000..cee7fb9 --- /dev/null +++ b/Tests/Pipeline.UMSDeviceDirectory.Tests.ps1 @@ -0,0 +1,126 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False + } + + $WebSession = New-UMSAPICookie + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ValueFromPipeline" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipeline + + It "doesn't throw" { + $NewParams = $TestCfg.NewParams + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = [pscustomobject]$NewParams | + New-UMSDeviceDirectory | Tee-Object -Variable 'NewUMSDeviceDirectory' | + Move-UMSDeviceDirectory @MoveParams | Tee-Object -Variable 'MoveUMSDeviceDirectory' | + Update-UMSDeviceDirectory @UpdateParams | Tee-Object -Variable 'UpdateUMSDeviceDirectory' | + Remove-UMSDeviceDirectory | Tee-Object -Variable 'RemoveUMSDeviceDirectory' + $NewUMSDeviceDirectory + $MoveUMSDeviceDirectory + $UpdateUMSDeviceDirectory + $RemoveUMSDeviceDirectory + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + + } + + Context "ValueFromPipelineByPropertyName" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipelineByPropertyName + + It "doesn't throw" { + $NewParams = $TestCfg.NewParams + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + { $Script:Result = @( + #<# + $null = ((($NewParams.Name | + New-UMSDeviceDirectory | Tee-Object -Variable 'NewUMSDeviceDirectory').Id | + Move-UMSDeviceDirectory @MoveParams | Tee-Object -Variable 'MoveUMSDeviceDirectory').Id | + Update-UMSDeviceDirectory @UpdateParams | Tee-Object -Variable 'UpdateUMSDeviceDirectory').Id | + Remove-UMSDeviceDirectory | Tee-Object -Variable 'RemoveUMSDeviceDirectory' + $NewUMSDeviceDirectory + $MoveUMSDeviceDirectory + $UpdateUMSDeviceDirectory + $RemoveUMSDeviceDirectory + #> + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + + } +} diff --git a/Tests/Pipeline.UMSProfile.Tests.ps1 b/Tests/Pipeline.UMSProfile.Tests.ps1 new file mode 100644 index 0000000..572b4ec --- /dev/null +++ b/Tests/Pipeline.UMSProfile.Tests.ps1 @@ -0,0 +1,117 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False + } + + $WebSession = New-UMSAPICookie + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ValueFromPipeline" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipeline + + It "doesn't throw" { + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = [pscustomobject]$MoveParams | + Move-UMSProfile -DestId $MoveParams.DestId | Tee-Object -Variable 'MoveUMSProfile' | + Update-UMSProfile @UpdateParams | Tee-Object -Variable 'UpdateUMSProfile' | + Remove-UMSProfile | Tee-Object -Variable 'RemoveUMSProfile' + $MoveUMSProfile + $UpdateUMSProfile + $RemoveUMSProfile + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + + Context "ValueFromPipelineByPropertyName" { + + $Script:Result + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipelineByPropertyName + + It "doesn't throw" { + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = (($MoveParams.Id | + Move-UMSProfile -DestId $MoveParams.DestId | Tee-Object -Variable 'MoveUMSProfile').Id | + Update-UMSProfile @UpdateParams | Tee-Object -Variable 'UpdateUMSProfile').Id | + Remove-UMSProfile | Tee-Object -Variable 'RemoveUMSProfile' + $MoveUMSProfile + $UpdateUMSProfile + $RemoveUMSProfile + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } + +} \ No newline at end of file diff --git a/Tests/Pipeline.UMSProfileAssignment.Tests.ps1 b/Tests/Pipeline.UMSProfileAssignment.Tests.ps1 new file mode 100644 index 0000000..dacde0c --- /dev/null +++ b/Tests/Pipeline.UMSProfileAssignment.Tests.ps1 @@ -0,0 +1,115 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False + } + + $WebSession = New-UMSAPICookie + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ValueFromPipeline" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipeline + + It "doesn't throw" { + $NewAssignmentParams = $TestCfg.NewAssignmentParams + $RemoveAssignmentParams = $TestCfg.RemoveAssignmentParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = [pscustomobject]$NewAssignmentParams | + New-UMSProfileAssignment -ReceiverId $NewAssignmentParams.ReceiverId -ReceiverType $NewAssignmentParams.ReceiverType | Tee-Object -Variable 'NewUMSProfileAssignment' | + Remove-UMSProfileAssignment -ReceiverId $RemoveAssignmentParams.ReceiverId -ReceiverType $RemoveAssignmentParams.ReceiverType | Tee-Object -Variable 'RemoveUMSProfileAssignment' + $NewUMSProfileAssignment + $RemoveUMSProfileAssignment + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + } + + Context "ValueFromPipelineByPropertyName" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipelineByPropertyName + + It "doesn't throw" { + $NewAssignmentParams = $TestCfg.NewAssignmentParams + $RemoveAssignmentParams = $TestCfg.RemoveAssignmentParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = (($NewAssignmentParams.Id | + New-UMSProfileAssignment -ReceiverId $NewAssignmentParams.ReceiverId -ReceiverType $NewAssignmentParams.ReceiverType | Tee-Object -Variable 'NewUMSProfileAssignment').Id | + Remove-UMSProfileAssignment -ReceiverId $RemoveAssignmentParams.ReceiverId -ReceiverType $RemoveAssignmentParams.ReceiverType | Tee-Object -Variable 'RemoveUMSProfileAssignment').Id + $NewUMSProfileAssignment + $RemoveUMSProfileAssignment + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + + } + +} \ No newline at end of file diff --git a/Tests/Pipeline.UMSProfileDirectory.Tests.ps1 b/Tests/Pipeline.UMSProfileDirectory.Tests.ps1 new file mode 100644 index 0000000..160abbb --- /dev/null +++ b/Tests/Pipeline.UMSProfileDirectory.Tests.ps1 @@ -0,0 +1,124 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False + } + + $WebSession = New-UMSAPICookie + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ValueFromPipeline" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipeline + + It "doesn't throw" { + $NewParams = $TestCfg.NewParams + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + Write-Host $Params1.Mac + { $Script:Result = @( + $null = [pscustomobject]$NewParams | + New-UMSProfileDirectory | Tee-Object -Variable 'NewUMSProfileDirectory' | + Move-UMSProfileDirectory @MoveParams | Tee-Object -Variable 'MoveUMSProfileDirectory' | + Update-UMSProfileDirectory @UpdateParams | Tee-Object -Variable 'UpdateUMSProfileDirectory' | + Remove-UMSProfileDirectory | Tee-Object -Variable 'RemoveUMSProfileDirectory' + $NewUMSProfileDirectory + $MoveUMSProfileDirectory + $UpdateUMSProfileDirectory + $RemoveUMSProfileDirectory + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + } + + Context "ValueFromPipelineByPropertyName" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.ValueFromPipelineByPropertyName + + It "doesn't throw" { + $NewParams = $TestCfg.NewParams + $MoveParams = $TestCfg.MoveParams + $UpdateParams = $TestCfg.UpdateParams + + { $Script:Result = @( + $null = ((($NewParams.Name | + New-UMSProfileDirectory | Tee-Object -Variable 'NewUMSProfileDirectory').Id | + Move-UMSProfileDirectory @MoveParams | Tee-Object -Variable 'MoveUMSProfileDirectory').Id | + Update-UMSProfileDirectory @UpdateParams | Tee-Object -Variable 'UpdateUMSProfileDirectory').Id | + Remove-UMSProfileDirectory | Tee-Object -Variable 'RemoveUMSProfileDirectory' + $NewUMSProfileDirectory + $MoveUMSProfileDirectory + $UpdateUMSProfileDirectory + $RemoveUMSProfileDirectory + ) } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result[0].Id should have type [Int]' { + $Result[0].Id | Should -HaveType [Int] + } + + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + $Result = '' + } + +} \ No newline at end of file diff --git a/Tests/Remove-UMSAPICookie.Tests.ps1 b/Tests/Remove-UMSAPICookie.Tests.ps1 new file mode 100644 index 0000000..17a2821 --- /dev/null +++ b/Tests/Remove-UMSAPICookie.Tests.ps1 @@ -0,0 +1,76 @@ +$Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) +$Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) +$Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf +$Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force + +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { + + Context "Basics" { + + It "Is valid Powershell (Has no script errors)" { + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop + $ErrorColl = $Null + $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) + $ErrorColl | Should -HaveCount 0 + } + + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys + $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession' + + It "Should contain our specific parameters" { + (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + } + } + + <# + No further UnitTesting atm: + https://github.com/pester/Pester/issues/706 - Mocking Classes not supported in Pester + #> +} + +#<# +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath + } + + $PSDefaultParameterValues = @{ + '*-UMS*:Credential' = $Credential + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + } + + $WebSession = New-UMSAPICookie -Credential $Credential + $PSDefaultParameterValues += @{ + '*-UMS*:WebSession' = $WebSession + } + + Context "ParameterSetName Default" { + + It "doesn't throw" { + { $Script:Result = Remove-UMSAPICookie } | Should Not Throw + } + + It 'Result should not be null or empty' { + $Result | Should not BeNullOrEmpty + } + + It 'Result should have type [String]' { + $Result | Should -HaveType [String] + } + + It "Result.Length should be 32" { + $Result.Length | Should -BeExactly 32 + } + } +} \ No newline at end of file diff --git a/Tests/Remove-UMSDevice.Tests.ps1 b/Tests/Remove-UMSDevice.Tests.ps1 index 6e39420..cd780e4 100644 --- a/Tests/Remove-UMSDevice.Tests.ps1 +++ b/Tests/Remove-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'Online' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Remove-UMSDevice -Id 2 Should not throw" { { Remove-UMSDevice -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParmeterSet Offline" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Offline deletion successful' @@ -61,9 +54,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSDevice -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -93,7 +86,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSet Online" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ CommandExecList = ( @@ -111,9 +104,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSDevice -Id 2 -Online - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -143,13 +136,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Remove-UMSDevice -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -162,7 +155,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Remove-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Remove-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -175,28 +168,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[0].Id - $Mac = $UMS.UMSDevice[0].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -204,10 +192,17 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Remove-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + { $Script:Result = @( + Remove-UMSDevice @Params1 + Remove-UMSDevice @Params2 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -218,12 +213,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'Offline deletion successful.'" { - $Result[0].Message | Should -BeExactly 'Offline deletion successful.' + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Remove-UMSDeviceDirectory.Tests.ps1 b/Tests/Remove-UMSDeviceDirectory.Tests.ps1 index 3558486..40b43b2 100644 --- a/Tests/Remove-UMSDeviceDirectory.Tests.ps1 +++ b/Tests/Remove-UMSDeviceDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Remove-UMSDeviceDirectory -Id 2 Should not throw" { { Remove-UMSDeviceDirectory -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Deletion successful.' @@ -61,9 +54,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSDeviceDirectory -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -93,13 +86,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Remove-UMSDeviceDirectory -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -112,7 +105,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Remove-UMSDeviceDirectory -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Remove-UMSDeviceDirectory -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -125,27 +118,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDeviceDirectory[2].Id $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -153,10 +142,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Remove-UMSDeviceDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Remove-UMSDeviceDirectory @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -167,12 +161,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'Deletion successful.'" { - $Result[0].Message | Should -BeExactly 'Deletion successful.' + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Remove-UMSProfile.Tests.ps1 b/Tests/Remove-UMSProfile.Tests.ps1 index bfb98cb..a70fe05 100644 --- a/Tests/Remove-UMSProfile.Tests.ps1 +++ b/Tests/Remove-UMSProfile.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Remove-UMSProfile -Id 2 Should not throw" { { Remove-UMSProfile -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Deleted profile with id 2' @@ -61,9 +54,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSProfile -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -93,13 +86,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Remove-UMSProfile -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -112,7 +105,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Remove-UMSProfile -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Remove-UMSProfile -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -125,27 +118,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfile[1].Id $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -153,10 +142,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Remove-UMSProfile } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Remove-UMSProfile @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -167,12 +161,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'Deleted profile.'" { - $Result[0].Message | Should -BeExactly 'Deleted profile.' + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Remove-UMSProfileAssignment.Tests.ps1 b/Tests/Remove-UMSProfileAssignment.Tests.ps1 index 648c0f4..93f53a3 100644 --- a/Tests/Remove-UMSProfileAssignment.Tests.ps1 +++ b/Tests/Remove-UMSProfileAssignment.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'ReceiverId', 'ReceiverType' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' Should not throw" { { Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "tc" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'deleted profile assignment' @@ -61,9 +54,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -97,7 +90,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "tcdirectory" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'deleted profile assignment' @@ -107,9 +100,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tcdirectory' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -143,13 +136,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tcdirectory' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -162,7 +155,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' -ApiVersion 10 -ErrorAction Stop Should throw" { { Remove-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -175,31 +168,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileAssignment[1].Id - $ReceiverId = $UMS.UMSProfileAssignment[1].ReceiverId - $ReceiverType = $UMS.UMSProfileAssignment[1].ReceiverType $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:ReceiverId' = $ReceiverId - '*-UMS*:ReceiverType' = $ReceiverType - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -207,10 +192,17 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Remove-UMSProfileAssignment } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + { $Script:Result = @( + Remove-UMSProfileAssignment @Params1 + Remove-UMSProfileAssignment @Params2 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -221,12 +213,27 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'deleted profile assignment.'" { - $Result[0].Message | Should -BeExactly 'deleted profile assignment.' + It 'Result[0].ReceiverId should have type [Int]' { + $Result[0].ReceiverId | Should -HaveType [Int] } + + It 'Result[0].ReceiverType should have type [String]' { + $Result[0].ReceiverType | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } + } + } } \ No newline at end of file diff --git a/Tests/Remove-UMSProfileDirectory.Tests.ps1 b/Tests/Remove-UMSProfileDirectory.Tests.ps1 index 8b7ecf8..9f2c9b9 100644 --- a/Tests/Remove-UMSProfileDirectory.Tests.ps1 +++ b/Tests/Remove-UMSProfileDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Remove-UMSProfileDirectory -Id 2 Should not throw" { { Remove-UMSProfileDirectory -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Deletion successful.' @@ -61,9 +54,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Remove-UMSProfileDirectory -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -93,13 +86,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Remove-UMSProfileDirectory -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -112,7 +105,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Remove-UMSProfileDirectory -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Remove-UMSProfileDirectory -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -125,27 +118,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileDirectory[3].Id $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -153,10 +142,13 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Remove-UMSProfileDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = Remove-UMSProfileDirectory @Params1 } | Should Not Throw } It 'Result should not be null or empty' { @@ -167,12 +159,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Message should be exactly 'Deletion successful.'" { - $Result[0].Message | Should -BeExactly 'Deletion successful.' + It "Result should be Equivalent to Expected" { + $Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Reset-UMSDevice.Tests.ps1 b/Tests/Reset-UMSDevice.Tests.ps1 index 41365d4..41dae4c 100644 --- a/Tests/Reset-UMSDevice.Tests.ps1 +++ b/Tests/Reset-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Reset-UMSDevice -Id 2 Should not throw" { { Reset-UMSDevice -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ CommandExecList = ( @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Reset-UMSDevice -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Reset-UMSDevice -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,7 +113,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Reset-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Reset-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[1].Id - $Mac = $UMS.UMSDevice[1].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Reset-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Reset-UMSDevice @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,16 +169,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Mac should be exactly $Mac" { - $Result[0].Mac | Should -BeExactly $Mac + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } - It "Result[0].Message should be exactly 'Connection refused: connect.'" { - $Result[0].Message | Should -BeExactly 'Connection refused: connect.' - } } } \ No newline at end of file diff --git a/Tests/Restart-UMSDevice.Tests.ps1 b/Tests/Restart-UMSDevice.Tests.ps1 index 4d06dec..54f537c 100644 --- a/Tests/Restart-UMSDevice.Tests.ps1 +++ b/Tests/Restart-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Restart-UMSDevice -Id 2 Should not throw" { { Restart-UMSDevice -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ CommandExecList = ( @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Restart-UMSDevice -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Restart-UMSDevice -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,7 +113,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Restart-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Restart-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[1].Id - $Mac = $UMS.UMSDevice[1].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Restart-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Restart-UMSDevice @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,16 +169,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Mac should be exactly $Mac" { - $Result[0].Mac | Should -BeExactly $Mac + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } - It "Result[0].Message should be exactly 'Connection refused: connect.'" { - $Result[0].Message | Should -BeExactly 'Connection refused: connect.' - } } } \ No newline at end of file diff --git a/Tests/Send-UMSDeviceSetting.Tests.ps1 b/Tests/Send-UMSDeviceSetting.Tests.ps1 index df4f707..6e4c57b 100644 --- a/Tests/Send-UMSDeviceSetting.Tests.ps1 +++ b/Tests/Send-UMSDeviceSetting.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Send-UMSDeviceSetting -Id 2 Should not throw" { { Send-UMSDeviceSetting -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ CommandExecList = ( @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Send-UMSDeviceSetting -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Send-UMSDeviceSetting -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,7 +113,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Send-UMSDeviceSetting -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Send-UMSDeviceSetting -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[1].Id - $Mac = $UMS.UMSDevice[1].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Send-UMSDeviceSetting } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Send-UMSDeviceSetting @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,16 +169,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Mac should be exactly $Mac" { - $Result[0].Mac | Should -BeExactly $Mac + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } - It "Result[0].Message should be exactly 'Connection refused: connect.'" { - $Result[0].Message | Should -BeExactly 'Connection refused: connect.' - } } } \ No newline at end of file diff --git a/Tests/Start-UMSDevice.Tests.ps1 b/Tests/Start-UMSDevice.Tests.ps1 index c223da8..7d031d7 100644 --- a/Tests/Start-UMSDevice.Tests.ps1 +++ b/Tests/Start-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Start-UMSDevice -Id 2 Should not throw" { { Start-UMSDevice -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ CommandExecList = ( @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Start-UMSDevice -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Start-UMSDevice -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,7 +113,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Start-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Start-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[1].Id - $Mac = $UMS.UMSDevice[1].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Start-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Start-UMSDevice @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,16 +169,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Mac should be exactly $Mac" { - $Result[0].Mac | Should -BeExactly $Mac + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } - It "Result[0].Message should be exactly 'OK.'" { - $Result[0].Message | Should -BeExactly 'OK.' - } } } \ No newline at end of file diff --git a/Tests/Stop-UMSDevice.Tests.ps1 b/Tests/Stop-UMSDevice.Tests.ps1 index 3ef2edc..aa4f633 100644 --- a/Tests/Stop-UMSDevice.Tests.ps1 +++ b/Tests/Stop-UMSDevice.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$Params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$Params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $Params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Stop-UMSDevice -Id 2 Should not throw" { { Stop-UMSDevice -Id 2 } | Should -Not -Throw @@ -51,7 +44,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ CommandExecList = ( @@ -69,9 +62,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Stop-UMSDevice -Id 2 - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Stop-UMSDevice -Id 2 -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,7 +113,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } It "Stop-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop Should throw" { { Stop-UMSDevice -Id 2 -ApiVersion 10 -ErrorAction Stop } | Should -Throw @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[1].Id - $Mac = $UMS.UMSDevice[1].Mac $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Confirm' = $false + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Stop-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Stop-UMSDevice @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,16 +169,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Id should be exactly $Id" { - $Result[0].Id | Should -BeExactly $Id + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] } - It "Result[0].Mac should be exactly $Mac" { - $Result[0].Mac | Should -BeExactly $Mac + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } - It "Result[0].Message should be exactly 'Connection refused: connect.'" { - $Result[0].Message | Should -BeExactly 'Connection refused: connect.' - } } } \ No newline at end of file diff --git a/Tests/UMS.json b/Tests/UMS.json deleted file mode 100644 index 71c2e2d..0000000 --- a/Tests/UMS.json +++ /dev/null @@ -1,218 +0,0 @@ -[ - { - "Computername": "localhost", - "TCPPort": "8443", - "User": "igelums", - "Credpath": "C:\\Credentials\\UMSRmdb.cred", - "SecurityProtocol": "Tls12", - "Prefix": "P_", - "TCPrefix": "TC", - "TCDirPrefix": "TCDir", - "ProfileDirPrefix": "ProfileDir", - "TestOrder": { - "Public": [ - "Get-UMSFirmware", - "Get-UMSProfile", - "Get-UMSProfileDirectory", - "Get-UMSProfileAssignment", - "Get-UMSStatus", - "Get-UMSDevice", - "Get-UMSDeviceAssignment", - "Get-UMSDeviceDirectory", - "Get-UMSDeviceDirectoryAssignment", - "Start-UMSDevice", - "Send-UMSDeviceSetting", - "Restart-UMSDevice", - "Stop-UMSDevice", - "Update-UMSProfile", - "Update-UMSProfileDirectory", - "Update-UMSDevice", - "Update-UMSDeviceDirectory", - "Move-UMSProfile", - "Move-UMSProfileDirectory", - "Move-UMSDevice", - "Move-UMSDeviceDirectory", - "New-UMSProfileAssignment", - "New-UMSProfileDirectory", - "New-UMSDevice", - "New-UMSDeviceDirectory", - "Remove-UMSProfileAssignment", - "Remove-UMSProfile", - "Remove-UMSProfileDirectory", - "Remove-UMSDevice", - "Remove-UMSDeviceDirectory", - "Reset-UMSDevice" - ], - "Private": [] - }, - "UMSFirmware": [ - { - "Id": "2", - "Version": "11.01.100.01" - }, - { - "Id": "3", - "Version": "10.05.500.01" - } - ], - "UMSProfile": [ - { - "Id": "463", - "DestId": "456", - "Name": "P_Profile01", - "NameUpdate": "P_Profile01_Update" - }, - { - "Id": "464", - "DestId": "455", - "Name": "P_Profile02" - } - ], - "UMSProfileAssignment": [ - { - "Id": "463", - "ReceiverID": "457", - "ReceiverType": "tcdirectory", - "ReceiverIdNew": "462", - "ReceiverTypeNew": "tc" - }, - { - "Id": "464", - "ReceiverID": "461", - "ReceiverType": "tc" - } - ], - "UMSProfileDirectory": [ - { - "Id": "455", - "DestId": "456", - "Name": "P_ProfileDir01", - "NameUpdate": "P_ProfileDir01_Update", - "ParentId": "-2", - "DirectoryChildren": { - "ObjectType": "profile", - "Id": "463" - } - }, - { - "Id": "456", - "Name": "P_ProfileDir02", - "NameUpdate": "P_ProfileDir02_Update", - "ParentId": "-2", - "DirectoryChildren": { - "ObjectType": "profile", - "Id": "464" - } - }, - { - "NameNew": "P_ProfileDir03" - }, - { - "Id": "632", - "Name": "P_ProfileDir04" - } - ], - "UMSStatus": [ - { - "RmGuiServerVersion": "6.01.100", - "BuildNumber": "40023" - } - ], - "UMSDevice": [ - { - "Id": "461", - "ObjectType": "tc", - "Mac": "001122334455", - "Name": "P_TC01", - "ParentId": "457", - "DestId": "458", - "Comment": "Comment", - "Online": "false", - "ShadowSecret": { - "certificate": "", - "password": "99cbbd4d-3292-4df5-9564-85976cdd0ceb" - } - }, - { - "Id": "462", - "ObjectType": "tc", - "Mac": "112233445566", - "Name": "P_TC02", - "ParentId": "458", - "DestId": "457", - "Comment": "Comment", - "CommentUpdate": "Comment_Update", - "Online": "false", - "ShadowSecret": { - "certificate": "", - "password": "a9484d4b-6fb9-4f60-82fb-114a5eafdd24" - } - }, - { - "NameNew": "P_TC03", - "MacNew": "223344556677", - "FirmwareIdNew": "2", - "ParentId": "457" - } - ], - "UMSDeviceAssignment": [ - { - "Id": "461", - "ReceiverId": "461", - "ReceiverType": "tc", - "AssigneeId": "464", - "AssigneeType": "profile", - "AssignmentPosition": "0" - }, - { - "Id": "461", - "ReceiverId": "457", - "ReceiverType": "tcdirectory", - "AssigneeId": "463", - "AssigneeType": "profile", - "AssignmentPosition": "1" - } - ], - "UMSDeviceDirectory": [ - { - "Id": "457", - "Name": "P_TCDir01", - "ParentId": "-1", - "DestId": "458", - "DirectoryChildren": { - "ObjectType": "tc", - "Id": "461" - } - }, - { - "Id": "458", - "Name": "P_TCDir02", - "NameUpdate": "P_TCDir02_Update", - "ParentId": "-1", - "DestId": "629", - "DirectoryChildren": { - "ObjectType": "tc", - "Id": "462" - } - }, - { - "Id": "629", - "Name": "P_TCDir03", - "ParentId": "-1" - }, - { - "NameNew": "P_TCDir04" - } - ], - "UMSDeviceDirectoryAssignment": [ - { - "Id": "457", - "ReceiverID": "457", - "ReceiverType": "tcdirectory", - "AssigneeId": "463", - "AssigneeType": "profile", - "AssignmentPosition": "0" - } - ] - } -] \ No newline at end of file diff --git a/Tests/Update-UMSDevice.Tests.ps1 b/Tests/Update-UMSDevice.Tests.ps1 index 5d8a857..0e89959 100644 --- a/Tests/Update-UMSDevice.Tests.ps1 +++ b/Tests/Update-UMSDevice.Tests.ps1 @@ -2,34 +2,27 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'Name', 'Site', 'Department', 'CostCenter', 'LastIP', 'Comment', 'AssetId', 'InserviceDate', 'SerialNumber' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -42,7 +35,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Update-UMSDevice -Id 2 -Name 'NameNew' Should not throw" { { Update-UMSDevice -Id 2 -Name 'NameNew' } | Should -Not -Throw @@ -60,7 +53,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "ParameterSet Set" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Update successful' @@ -78,13 +71,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Comment = 'NewComment' AssetId = 'NewAssetId' InserviceDate = 'NewInserviceDate' - SerialNumber = '0123456789012345678' + SerialNumber = '012345678901234567' } $Result = Update-UMSDevice @Params - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -118,13 +111,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Update-UMSDevice -Id 2 -Name 'NameNew' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -137,10 +130,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it "Update-UMSDevice -Id 2 -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop should throw Error" { - { Update-UMSDevice -Id 2 -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop } | should -Throw + It "Update-UMSDevice -Id 2 -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop should throw Error" { + { Update-UMSDevice -Id 2 -Name 'NameNew' -ApiVersion 10 -ErrorAction Stop } | Should -Throw } It 'Result should be null or empty' { @@ -151,28 +144,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDevice[1].Id - $CommentUpdate = $UMS.UMSDevice[1].CommentUpdate $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Comment' = $CommentUpdate + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -180,10 +168,21 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Update-UMSDevice } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + $Params3 = $TestCfg.Params3 + $Params4 = $TestCfg.Params4 + { $Script:Result = @( + Update-UMSDevice @Params1 + Update-UMSDevice @Params2 + Update-UMSDevice @Params3 + Update-UMSDevice @Params4 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -194,8 +193,18 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Message should be exactly 'Update successful.'" { - $Result[0].Message | Should -BeExactly 'Update successful.' + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } } \ No newline at end of file diff --git a/Tests/Update-UMSDeviceDirectory.Tests.ps1 b/Tests/Update-UMSDeviceDirectory.Tests.ps1 index 1f0fdef..f30b74b 100644 --- a/Tests/Update-UMSDeviceDirectory.Tests.ps1 +++ b/Tests/Update-UMSDeviceDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'Name' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Update-UMSDeviceDirectory -Id 2 -Name 'NameNew' Should not throw" { { Update-UMSDeviceDirectory -Id 2 -Name 'NameNew' } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Updated directory successfully.' @@ -65,9 +58,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Update-UMSDeviceDirectory -Id 2 -Name 'NameNew' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Update-UMSDeviceDirectory -Id 2 -Name 'NameNew' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,10 +113,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Update-UMSDeviceDirectory -Id 2 -Name 'NameNew' } | should throw 'Error' + It 'should throw Error' { + { Update-UMSDeviceDirectory -Id 2 -Name 'NameNew' } | Should throw 'Error' } It 'Result should be null or empty' { @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSDeviceDirectory[1].Id - $NameUpdate = $UMS.UMSDeviceDirectory[1].NameUpdate $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Name' = $NameUpdate + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,17 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Update-UMSDeviceDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + $Params2 = $TestCfg.Params2 + { $Script:Result = @( + Update-UMSDeviceDirectory @Params1 + Update-UMSDeviceDirectory @Params2 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,8 +171,19 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Message should be exactly 'Updated directory successfully.'" { - $Result[0].Message | Should -BeExactly 'Updated directory successfully.' + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } + } } \ No newline at end of file diff --git a/Tests/Update-UMSProfile.Tests.ps1 b/Tests/Update-UMSProfile.Tests.ps1 index 7fc0077..9653463 100644 --- a/Tests/Update-UMSProfile.Tests.ps1 +++ b/Tests/Update-UMSProfile.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'Name' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Update-UMSProfile -Id 2 -Name 'NameNew' Should not throw" { { Update-UMSProfile -Id 2 -Name 'NameNew' } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Update successful' @@ -65,9 +58,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Update-UMSProfile -Id 2 -Name 'NameNew' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Update-UMSProfile -Id 2 -Name 'NameNew' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,10 +113,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | should throw 'Error' + It 'should throw Error' { + { New-UMSProfileAssignment -Id 2 -ReceiverId 2 -ReceiverType 'tc' } | Should throw 'Error' } It 'Result should be null or empty' { @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfile[0].Id - $NameUpdate = $UMS.UMSProfile[0].NameUpdate $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Name' = $NameUpdate + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Update-UMSProfile } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Update-UMSProfile @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,8 +169,18 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Message should be exactly 'Update successful.'" { - $Result[0].Message | Should -BeExactly 'Update successful.' + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } } \ No newline at end of file diff --git a/Tests/Update-UMSProfileDirectory.Tests.ps1 b/Tests/Update-UMSProfileDirectory.Tests.ps1 index a52c342..aa7ed6e 100644 --- a/Tests/Update-UMSProfileDirectory.Tests.ps1 +++ b/Tests/Update-UMSProfileDirectory.Tests.ps1 @@ -2,33 +2,26 @@ $Script:ProjectRoot = Resolve-Path ('{0}\..' -f $PSScriptRoot) $Script:ModuleRoot = Split-Path (Resolve-Path ('{0}\*\*.psm1' -f $Script:ProjectRoot)) $Script:ModuleName = Split-Path $Script:ModuleRoot -Leaf $Script:ModuleManifest = Resolve-Path ('{0}/{1}.psd1' -f $Script:ModuleRoot, $Script:ModuleName) -$Script:FunctionName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) +$Script:ScriptName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Import-Module ( '{0}/{1}.psm1' -f $Script:ModuleRoot, $Script:ModuleName) -Force -Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { - - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } - } +Describe "$Script:ScriptName Unit Tests" -Tag 'UnitTests' { Context "Basics" { It "Is valid Powershell (Has no script errors)" { - $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:FunctionName) -ErrorAction Stop + $Content = Get-Content -Path ( '{0}\Public\{1}.ps1' -f $Script:ModuleRoot, $Script:ScriptName) -ErrorAction Stop $ErrorColl = $Null $Null = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ErrorColl) $ErrorColl | Should -HaveCount 0 } - [object[]]$params = (Get-ChildItem function:\$Script:FunctionName).Parameters.Keys + [object[]]$params = (Get-ChildItem function:\$Script:ScriptName).Parameters.Keys $KnownParameters = 'Computername', 'TCPPort', 'ApiVersion', 'SecurityProtocol', 'WebSession', 'Id', 'Name' It "Should contain our specific parameters" { (@(Compare-Object -ReferenceObject $KnownParameters -DifferenceObject $params -IncludeEqual | - Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count + Where-Object SideIndicator -eq "==").Count) | Should Be $KnownParameters.Count } } @@ -41,7 +34,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "General Execution" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } It "Update-UMSProfileDirectory -Id 2 -Name 'NameNew' Should not throw" { { Update-UMSProfileDirectory -Id 2 -Name 'NameNew' } | Should -Not -Throw @@ -55,7 +48,7 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "All" { - Mock 'Invoke-UMSRestMethodWebSession' { + Mock 'Invoke-UMSRestMethod' { ( [pscustomobject]@{ message = 'Updated directory successfully.' @@ -65,9 +58,9 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { $Result = Update-UMSProfileDirectory -Id 2 -Name 'NameNew' - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 1 time' { + It 'Assert Invoke-UMSRestMethod is called exactly 1 time' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 1 Exactly = $true } @@ -101,13 +94,13 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { Context "Whatif" { - Mock 'Invoke-UMSRestMethodWebSession' {} + Mock 'Invoke-UMSRestMethod' { } $Result = Update-UMSProfileDirectory -Id 2 -Name 'NameNew' -WhatIf - It 'Assert Invoke-UMSRestMethodWebSession is called exactly 0 times' { + It 'Assert Invoke-UMSRestMethod is called exactly 0 times' { $AMCParams = @{ - CommandName = 'Invoke-UMSRestMethodWebSession' + CommandName = 'Invoke-UMSRestMethod' Times = 0 Exactly = $true } @@ -120,10 +113,10 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } Context "Error Handling" { - Mock 'Invoke-UMSRestMethodWebSession' {throw 'Error'} + Mock 'Invoke-UMSRestMethod' { throw 'Error' } - it 'should throw Error' { - { Update-UMSProfileDirectory -Id 2 -Name 'NameNew' } | should throw 'Error' + It 'should throw Error' { + { Update-UMSProfileDirectory -Id 2 -Name 'NameNew' } | Should throw 'Error' } It 'Result should be null or empty' { @@ -133,28 +126,23 @@ Describe "$Script:FunctionName Unit Tests" -Tag 'UnitTests' { } } -Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { - BeforeAll { - if ($null -ne $Result) - { - Clear-Variable -Name $Result - } +Describe "$Script:ScriptName Integration Tests" -Tag "IntegrationTests" { + $Cfg = Import-PowerShellDataFile -Path ('{0}\Tests\Config.psd1' -f $Script:ProjectRoot) + if ($IsLinux) + { + $Credential = Import-Clixml -Path $Cfg.CredPathWsl + } + else + { + $Credential = Import-Clixml -Path $Cfg.CredPath } - - $UMS = Get-Content -Raw -Path ('{0}\Tests\UMS.json' -f $Script:ProjectRoot) | - ConvertFrom-Json - $CredPath = $UMS.CredPath - $Password = Get-Content $CredPath | ConvertTo-SecureString - $Credential = New-Object System.Management.Automation.PSCredential($UMS.User, $Password) - $Id = $UMS.UMSProfileDirectory[0].Id - $NameUpdate = $UMS.UMSProfileDirectory[0].NameUpdate $PSDefaultParameterValues = @{ '*-UMS*:Credential' = $Credential - '*-UMS*:Computername' = $UMS.Computername - '*-UMS*:SecurityProtocol' = $UMS.SecurityProtocol - '*-UMS*:Id' = $Id - '*-UMS*:Name' = $NameUpdate + '*-UMS*:Computername' = $Cfg.Computername + '*-UMS*:TCPPort' = $Cfg.TCPPort + '*-UMS*:SecurityProtocol' = $Cfg.SecurityProtocol + '*-UMS*:Confirm' = $False } $WebSession = New-UMSAPICookie @@ -162,10 +150,15 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { '*-UMS*:WebSession' = $WebSession } - Context "ParameterSetName All" { + Context "ParameterSetName Default" { + + $TestCfg = (($Cfg.Tests).where{ $_.Name -eq $ScriptName }).ParameterSets.Default It "doesn't throw" { - { $Script:Result = Update-UMSProfileDirectory } | Should Not Throw + $Params1 = $TestCfg.Params1 + { $Script:Result = @( + Update-UMSProfileDirectory @Params1 + ) } | Should Not Throw } It 'Result should not be null or empty' { @@ -176,8 +169,18 @@ Describe "$Script:FunctionName Integration Tests" -Tag "IntegrationTests" { $Result[0].Id | Should -HaveType [Int] } - It "Result[0].Message should be exactly 'Updated directory successfully.'" { - $Result[0].Message | Should -BeExactly 'Updated directory successfully.' + It 'Result[0].Message should have type [String]' { + $Result[0].Message | Should -HaveType [String] + } + + It "Result should be Equivalent to Expected" { + [array]$Expected = foreach ($item In $TestCfg.Expected) + { + New-Object psobject -Property $item + } + Assert-Equivalent -Actual $Result -Expected $Expected -Options @{ + ExcludedPaths = $TestCfg.Options.ExcludedPaths + } } } } \ No newline at end of file