From c75a92a264b5d67336f6847f9487ebfaccac271d Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 12 Jan 2019 15:16:00 +1300 Subject: [PATCH 1/7] Fix Archive test failures and forward port changes from xPSDesiredStateConfiguration --- .gitattributes | 2 + .gitignore | 1 - .vscode/analyzersettings.psd1 | 53 +++ .vscode/settings.json | 14 + DscResources/CommonResourceHelper.psm1 | 20 +- DscResources/MSFT_Archive/MSFT_Archive.psm1 | 140 ++++++-- .../en-US/MSFT_Archive.strings.psd1 | 107 +++--- README.md | 66 ++-- .../MSFT_Archive.EndToEnd.Tests.ps1 | 310 +++++++++--------- .../MSFT_Archive.Integration.Tests.ps1 | 259 ++++++++------- appveyor.yml | 31 +- 11 files changed, 615 insertions(+), 388 deletions(-) create mode 100644 .gitattributes create mode 100644 .vscode/analyzersettings.psd1 create mode 100644 .vscode/settings.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3f56544 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text eol=crlf +*.exe binary diff --git a/.gitignore b/.gitignore index 5f4aabe..b03606a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ DSCResource.Tests -*.vscode diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 new file mode 100644 index 0000000..be415e4 --- /dev/null +++ b/.vscode/analyzersettings.psd1 @@ -0,0 +1,53 @@ +@{ + <# + For the custom rules to work, the DscResource.Tests repo must be + cloned. It is automatically clone as soon as any unit or + integration tests are run. + #> + CustomRulePath = '.\DSCResource.Tests\DscResource.AnalyzerRules' + + IncludeRules = @( + # DSC Resource Kit style guideline rules. + 'PSAvoidDefaultValueForMandatoryParameter', + 'PSAvoidDefaultValueSwitchParameter', + 'PSAvoidInvokingEmptyMembers', + 'PSAvoidNullOrEmptyHelpMessageAttribute', + 'PSAvoidUsingCmdletAliases', + 'PSAvoidUsingComputerNameHardcoded', + 'PSAvoidUsingDeprecatedManifestFields', + 'PSAvoidUsingEmptyCatchBlock', + 'PSAvoidUsingInvokeExpression', + 'PSAvoidUsingPositionalParameters', + 'PSAvoidShouldContinueWithoutForce', + 'PSAvoidUsingWMICmdlet', + 'PSAvoidUsingWriteHost', + 'PSDSCReturnCorrectTypesForDSCFunctions', + 'PSDSCStandardDSCFunctionsInResource', + 'PSDSCUseIdenticalMandatoryParametersForDSC', + 'PSDSCUseIdenticalParametersForDSC', + 'PSMisleadingBacktick', + 'PSMissingModuleManifestField', + 'PSPossibleIncorrectComparisonWithNull', + 'PSProvideCommentHelp', + 'PSReservedCmdletChar', + 'PSReservedParams', + 'PSUseApprovedVerbs', + 'PSUseCmdletCorrectly', + 'PSUseOutputTypeCorrectly', + 'PSAvoidGlobalVars', + 'PSAvoidUsingConvertToSecureStringWithPlainText', + 'PSAvoidUsingPlainTextForPassword', + 'PSAvoidUsingUsernameAndPasswordParams', + 'PSDSCUseVerboseMessageInDSCResource', + 'PSShouldProcess', + 'PSUseDeclaredVarsMoreThanAssignments', + 'PSUsePSCredentialType', + + <# + This is to test all the DSC Resource Kit custom rules. + The name of the function-blocks of each custom rule start + with 'Measure*'. + #> + 'Measure-*' + ) +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0969e57 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "powershell.codeFormatting.openBraceOnSameLine": false, + "powershell.codeFormatting.newLineAfterOpenBrace": false, + "powershell.codeFormatting.newLineAfterCloseBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenParen": true, + "powershell.codeFormatting.whitespaceAroundOperator": true, + "powershell.codeFormatting.whitespaceAfterSeparator": true, + "powershell.codeFormatting.ignoreOneLineBlock": false, + "powershell.codeFormatting.preset": "Custom", + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" +} diff --git a/DscResources/CommonResourceHelper.psm1 b/DscResources/CommonResourceHelper.psm1 index f1ceee0..f1f9d3a 100644 --- a/DscResources/CommonResourceHelper.psm1 +++ b/DscResources/CommonResourceHelper.psm1 @@ -4,12 +4,12 @@ #> function Test-IsNanoServer { - [OutputType([Boolean])] + [OutputType([System.Boolean])] [CmdletBinding()] param () $isNanoServer = $false - + if (Test-CommandExists -Name 'Get-ComputerInfo') { $computerInfo = Get-ComputerInfo -ErrorAction 'SilentlyContinue' @@ -37,13 +37,13 @@ function Test-IsNanoServer #> function Test-CommandExists { - [OutputType([Boolean])] + [OutputType([System.Boolean])] [CmdletBinding()] - param + param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] $Name + [System.String] $Name ) $command = Get-Command -Name $Name -ErrorAction 'SilentlyContinue' @@ -67,12 +67,12 @@ function New-InvalidArgumentException ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $Message, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $ArgumentName ) @@ -102,10 +102,12 @@ function New-InvalidOperationException [CmdletBinding()] param ( + [Parameter()] [ValidateNotNullOrEmpty()] - [String] + [System.String] $Message, + [Parameter()] [ValidateNotNull()] [System.Management.Automation.ErrorRecord] $ErrorRecord @@ -155,7 +157,7 @@ function Get-LocalizedData ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $ResourceName ) diff --git a/DscResources/MSFT_Archive/MSFT_Archive.psm1 b/DscResources/MSFT_Archive/MSFT_Archive.psm1 index 19a95a1..3ceea92 100644 --- a/DscResources/MSFT_Archive/MSFT_Archive.psm1 +++ b/DscResources/MSFT_Archive/MSFT_Archive.psm1 @@ -53,7 +53,7 @@ if (-not (Test-IsNanoServer)) Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. - + If a file does not match it will be considered not present. The default value is false. @@ -113,7 +113,7 @@ function Get-TargetResource if ($PSBoundParameters.ContainsKey('Checksum') -and -not $Validate) { $errorMessage = $script:localizedData.ChecksumSpecifiedAndValidateFalse -f $Checksum, $Path, $Destination - New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage + New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage } $archiveState = @{ @@ -185,7 +185,7 @@ function Get-TargetResource .SYNOPSIS Expands the archive (.zip) file at the specified path to the specified destination or removes the expanded archive (.zip) file at the specified path from the specified - destination. + destination. .PARAMETER Path The path to the archive file that should be expanded to or removed from the specified @@ -209,7 +209,7 @@ function Get-TargetResource Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. - + If the file does not match and Ensure is specified as Present and Force is not specified, the resource will throw an error that the file at the destination cannot be overwritten. If the file does not match and Ensure is specified as Present and Force is specified, the @@ -292,7 +292,7 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('Checksum') -and -not $Validate) { $errorMessage = $script:localizedData.ChecksumSpecifiedAndValidateFalse -f $Checksum, $Path, $Destination - New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage + New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage } $psDrive = $null @@ -308,7 +308,7 @@ function Set-TargetResource Assert-DestinationDoesNotExistAsFile -Destination $Destination Write-Verbose -Message ($script:localizedData.SettingArchiveState -f $Path, $Destination) - + $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = $Path Destination = $Destination @@ -391,7 +391,7 @@ function Set-TargetResource Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. - + If a file does not match it will be considered not present. The default value is false. @@ -830,7 +830,7 @@ function Test-ChecksumIsSha [String] $Checksum ) - + return ($Checksum.Length -ge 'SHA'.Length) -and ($Checksum.Substring(0, 3) -ieq 'SHA') } @@ -939,6 +939,43 @@ function Test-FileHashMatchesArchiveEntryHash return $fileHashMatchesArchiveEntryHash } +<# + .SYNOPSIS + Retrieves the timestamp of the specified file for the specified checksum method + and returns it as a checksum. + + .PARAMETER File + The file to retrieve the timestamp of. + + .PARAMETER Checksum + The checksum method to retrieve the timestamp checksum for. + + .NOTES + The returned string is file timestamp normalized to the format specified in + ConvertTo-CheckSumFromDateTime. +#> +function Get-ChecksumFromFileTimestamp +{ + [OutputType([System.String])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.IO.FileInfo] + $File, + + [Parameter(Mandatory = $true)] + [ValidateSet('CreatedDate', 'ModifiedDate')] + [System.String] + $Checksum + ) + + $timestamp = Get-TimestampForChecksum @PSBoundParameters + + return ConvertTo-ChecksumFromDateTime -Date $timestamp +} + <# .SYNOPSIS Retrieves the timestamp of the specified file for the specified checksum method. @@ -962,22 +999,80 @@ function Get-TimestampForChecksum [Parameter(Mandatory = $true)] [ValidateSet('CreatedDate', 'ModifiedDate')] - [String] + [System.String] $Checksum ) - $relevantTimestamp = $null - if ($Checksum -ieq 'CreatedDate') { - $relevantTimestamp = $File.CreationTime.DateTime + $relevantTimestamp = 'CreationTime' } elseif ($Checksum -ieq 'ModifiedDate') { - $relevantTimestamp = $File.LastWriteTime.DateTime + $relevantTimestamp = 'LastWriteTime' } - return $relevantTimestamp + return Get-TimestampFromFile -File $File -Timestamp $relevantTimestamp +} + +<# + .SYNOPSIS + Retrieves a timestamp of the specified file. + + .PARAMETER File + The file to retrieve the timestamp from. + + .PARAMETER Timestamp + The timestamp attribute to retrieve. +#> +function Get-TimestampFromFile +{ + [OutputType([System.Datetime])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.IO.FileInfo] + $File, + + [Parameter(Mandatory = $true)] + [ValidateSet('CreationTime', 'LastWriteTime')] + [System.String] + $Timestamp + ) + + return $File.$Timestamp.DateTime +} + +<# + .SYNOPSIS + Converts a datetime object into the format used for a + checksum. + + .PARAMETER Date + The date to use to generate the checksum. + + .NOTES + The returned date is normalized to the General (G) date format. + https://technet.microsoft.com/en-us/library/ee692801.aspx + + Because the General (G) is localization specific a non-localization + specific format such as ISO9660 could be used in future. +#> +function ConvertTo-ChecksumFromDateTime +{ + [OutputType([System.String])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.DateTime] + $Date + ) + + return Get-Date -Date $Date -Format 'G' } <# @@ -1063,11 +1158,12 @@ function Test-FileMatchesArchiveEntryByChecksum } else { - $fileTimestampForChecksum = Get-TimestampForChecksum -File $File -Checksum $Checksum + $fileTimestampForChecksum = Get-ChecksumFromFileTimestamp -File $File -Checksum $Checksum $archiveEntryLastWriteTime = Get-ArchiveEntryLastWriteTime -ArchiveEntry $ArchiveEntry + $archiveEntryLastWriteTimeChecksum = ConvertTo-CheckSumFromDateTime -Date $archiveEntryLastWriteTime - if ([DateTime]$fileTimestampForChecksum -eq [DateTime]$archiveEntryLastWriteTime) + if ($fileTimestampForChecksum.Equals($archiveEntryLastWriteTimeChecksum)) { Write-Verbose -Message ($script:localizedData.FileMatchesArchiveEntryByChecksum -f $File.FullName, $archiveEntryFullName, $Checksum) @@ -1278,12 +1374,14 @@ function Copy-ArchiveEntryToDestination $DestinationPath ) - Write-Verbose -Message ($script:localizedData.CopyingArchiveEntryToDestination -f $DestinationPath) - $archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $ArchiveEntry + Write-Verbose -Message ($script:localizedData.CopyingArchiveEntryToDestination -f $archiveEntryFullName, $DestinationPath) + if (Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName) { + Write-Verbose -Message ($script:localizedData.CreatingArchiveEntryDirectory -f $DestinationPath) + $null = New-Item -Path $DestinationPath -ItemType 'Directory' } else @@ -1425,7 +1523,7 @@ function Expand-ArchiveToDestination $overwriteArchiveEntry = $false } } - + if ($overwriteArchiveEntry) { if ($Force) @@ -1452,7 +1550,7 @@ function Expand-ArchiveToDestination <# .SYNOPSIS Removes the specified directory from the specified destination path. - + .PARAMETER Directory The partial path under the destination path of the directory to remove. @@ -1580,7 +1678,7 @@ function Remove-ArchiveFromDestination elseif ((-not $archiveEntryIsDirectory) -and $itemAtDestinationIsFile) { $removeArchiveEntry = $true - + if ($PSBoundParameters.ContainsKey('Checksum')) { $removeArchiveEntry = Test-FileMatchesArchiveEntryByChecksum -File $itemAtDestination -ArchiveEntry $archiveEntry -Checksum $Checksum diff --git a/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 b/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 index f78a400..be6af64 100644 --- a/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 +++ b/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 @@ -1,57 +1,58 @@ # Localized MSFT_Archive.strings.psd1 ConvertFrom-StringData @' - RetrievingArchiveState = Retrieving the state of the archive with path {0} and destination {1}... - SettingArchiveState = Setting the state of the archive with path {0} and destination {1}... - ArchiveStateSet = The state of the archive with path {0} and destination {1} has been set. - TestingArchiveState = Testing whether or not the state of the archive with path {0} and destination {1} matches the desired state... - - PathAccessiblePSDriveNotNeeded = The path {0} is accessible. A new PSDrive is not needed. - CreatingPSDrive = Creating a PSDrive to access the path {0} with permissions from the user {1}... - RemovingPSDrive = Removing the mounted PSDrive {0}... - - DestinationExists = A directory already exists at the destination path {0}. - DestinationDoesNotExist = A directory does not exist at the destination path {0}. - CreatingDirectoryAtDestination = Creating the root directory at the destination path {0}... - - TestingIfArchiveExistsAtDestination = Testing if the archive at the destination path {0} exists... - ArchiveExistsAtDestination = The archive at path {0} exists at the destination {1}. - ArchiveDoesNotExistAtDestination = The archive at path {0} does not exist at the destination {1}. - - OpeningArchive = Opening the archive at path {0}... - ClosingArchive = Closing the archive at path {0}... - - OpeningArchiveEntry = Opening the archive entry {0}... - - ItemWithArchiveEntryNameExists = An item with the same name as the archive entry exists at the destination path {0}. - ItemWithArchiveEntryNameDoesNotExist = An item with the same name as the archive entry does not exist at the destination path {0}. - ItemWithArchiveEntryNameIsNotDirectory = The item at the destination path {0} has the same name as a directory archive entry but is not a directory. - ItemWithArchiveEntryNameIsNotFile = The item at the destination path {0} has the same name as a file archive entry but is not a file. - - TestingIfFileMatchesArchiveEntryByChecksum = Testing if the file at {0} matches the archive entry at {1} by the checksum method {2}... - ComparingHashes = Comparing the hash of the file at {0} to the hash of the archive entry at {1} with the hash algorithm {2}... - FileMatchesArchiveEntryByChecksum = The file at {0} matches the archive entry at {1} by the checksum method {2}. - FileDoesNotMatchArchiveEntryByChecksum = The file at {0} does not match the archive entry at {1} by the checksum method {2}. - - ExpandingArchiveToDestination = Expanding the archive at {0} to the destination {1}... - CreatingParentDirectory = Creating an archive entry parent directory at the path {0}... - OverwritingItem = Overwriting the item at the path {0}... - CopyingArchiveEntryToDestination = Copying the corresponding archive entry to the path {0}... - - RemovingArchiveFromDestination = Removing archive from the destination path {0}... - RemovingDirectory = Removing the directory at path {0}... - RemovingFile = Removing the file at path {0}... - CouldNotRemoveItemOfIncorrectType = The file at {0} does not match the item type (file, directory, or other) or the archive entry at {1}, so it will not be removed. - ArchiveRemovedFromDestination = Archive removed from the destination path {0}. - - ChecksumSpecifiedAndValidateFalse = The Checksum parameter was specified as {0} but the Validate parameter is set to false for the archive with path {1} and destination {2}. Please specify the Validate parameter as true to use the Checksum parameter. - PathDoesNotContainValidPSDriveRoot = The path {0} cannot be accessed because it does not contain any directories to use as the root of a PSDrive. - ErrorCreatingPSDrive = An error occurred while attempting to create a PSDrive to access the path {0} under the user {1}. - PathDoesNotExistAsLeaf = The path {0} does not exist or is not a path leaf. - DestinationExistsAsFile = A file exists at the desintation path {0}. - ErrorOpeningArchive = An error occurred while attempting to open the archive at path {0}. - ErrorCopyingFromArchiveToDestination = An error occurred while attempting copy from the archive to the destination path {0}. - DirectoryIsNotEmpty = The directory at path {0} is not empty, so it will not be removed. - ErrorComparingHashes = An error occurred while comparing the hash of the file at {0} to the archive entry {1} with the hash algorithm {2}. - ForceNotSpecifiedToOverwriteItem = An item already exists at {0} that does not match the item in the archive at {1}, but the Force parameter has not been specified to overwrite this item. + RetrievingArchiveState = Retrieving the state of the archive with path "{0}" and destination "{1}"... + SettingArchiveState = Setting the state of the archive with path "{0}" and destination "{1}"... + ArchiveStateSet = The state of the archive with path "{0}" and destination "{1}" has been set. + TestingArchiveState = Testing whether or not the state of the archive with path "{0}" and destination "{1}" matches the desired state... + + PathAccessiblePSDriveNotNeeded = The path "{0}" is accessible. A new PSDrive is not needed. + CreatingPSDrive = Creating a PSDrive to access the path "{0}" with permissions from the user "{1}"... + RemovingPSDrive = Removing the mounted PSDrive "{0}"... + + DestinationExists = A directory already exists at the destination path "{0}". + DestinationDoesNotExist = A directory does not exist at the destination path "{0}". + CreatingDirectoryAtDestination = Creating the root directory at the destination path "{0}"... + + TestingIfArchiveExistsAtDestination = Testing if the archive at the destination path "{0}" exists... + ArchiveExistsAtDestination = The archive at path "{0}" exists at the destination "{1}". + ArchiveDoesNotExistAtDestination = The archive at path "{0}" does not exist at the destination "{1}". + + OpeningArchive = Opening the archive at path "{0}"... + ClosingArchive = Closing the archive at path "{0}"... + + OpeningArchiveEntry = Opening the archive entry "{0}"... + + ItemWithArchiveEntryNameExists = An item with the same name as the archive entry exists at the destination path "{0}". + ItemWithArchiveEntryNameDoesNotExist = An item with the same name as the archive entry does not exist at the destination path "{0}". + ItemWithArchiveEntryNameIsNotDirectory = The item at the destination path "{0}" has the same name as a directory archive entry but is not a directory. + ItemWithArchiveEntryNameIsNotFile = The item at the destination path "{0}" has the same name as a file archive entry but is not a file. + + TestingIfFileMatchesArchiveEntryByChecksum = Testing if the file at "{0}" matches the archive entry at "{1}" by the checksum method "{2}"... + ComparingHashes = Comparing the hash of the file at "{0}" to the hash of the archive entry at "{1}" with the hash algorithm "{2}"... + FileMatchesArchiveEntryByChecksum = The file at "{0}" matches the archive entry at "{1}" by the checksum method "{2}". + FileDoesNotMatchArchiveEntryByChecksum = The file at "{0}" does not match the archive entry at "{1}" by the checksum method "{2}". + + ExpandingArchiveToDestination = Expanding the archive at "{0}" to the destination "{1}"... + CreatingParentDirectory = Creating an archive entry parent directory at the path "{0}"... + OverwritingItem = Overwriting the item at the path "{0}"... + CreatingArchiveEntryDirectory = Creating an archive entry directory "{0}"... + CopyingArchiveEntryToDestination = Copying the archive entry "{0}" to the destination path "{1}"... + + RemovingArchiveFromDestination = Removing archive from the destination path "{0}"... + RemovingDirectory = Removing the directory at path "{0}"... + RemovingFile = Removing the file at path "{0}"... + CouldNotRemoveItemOfIncorrectType = The file at "{0}" does not match the item type (file, directory, or other) or the archive entry at "{1}", so it will not be removed. + ArchiveRemovedFromDestination = Archive removed from the destination path "{0}". + + ChecksumSpecifiedAndValidateFalse = The Checksum parameter was specified as "{0}" but the Validate parameter is set to false for the archive with path "{1}" and destination "{2}". Please specify the Validate parameter as true to use the Checksum parameter. + PathDoesNotContainValidPSDriveRoot = The path "{0}" cannot be accessed because it does not contain any directories to use as the root of a PSDrive. + ErrorCreatingPSDrive = An error occurred while attempting to create a PSDrive to access the path "{0}" under the user "{1}". + PathDoesNotExistAsLeaf = The path "{0}" does not exist or is not a path leaf. + DestinationExistsAsFile = A file exists at the desintation path "{0}". + ErrorOpeningArchive = An error occurred while attempting to open the archive at path "{0}". + ErrorCopyingFromArchiveToDestination = An error occurred while attempting copy from the archive to the destination path "{0}". + DirectoryIsNotEmpty = The directory at path "{0}" is not empty, so it will not be removed. + ErrorComparingHashes = An error occurred while comparing the hash of the file at "{0}" to the archive entry "{1}" with the hash algorithm "{2}". + ForceNotSpecifiedToOverwriteItem = An item already exists at "{0}" that does not match the item in the archive at "{1}", but the Force parameter has not been specified to overwrite this item. '@ diff --git a/README.md b/README.md index b0f2a6d..e985010 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,7 @@ None #### Read-Only Properties from Get-TargetResource None - + #### Examples * [Create a new User](https://github.com/PowerShell/PSDscResources/blob/master/Examples/Sample_User_CreateUser.ps1) @@ -577,6 +577,32 @@ The following parameters will be the same for each process in the set: ### Unreleased +* Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration): + * xArchive + * Fix end-to-end tests. + * Update integration tests to meet Pester 4.0.0 standards. + * Update end-to-end tests to meet Pester 4.0.0 standards. + * Update unit and integration tests to meet Pester 4.0.0 standards. + * Wrapped all verbose message parameters with quotes to make identifying + actual paths possible. + * Refactored date/time checksum code to improve testability and ensure + tests can run on machines with localized datetime formats that are not + US. + * Fix 'Get-ArchiveEntryLastWriteTime' to return `[datetime]`. + * Improved verbose logging to make debugging path issues easier. +* Added .gitattributes file to ensure CRLF settings are configured correctly + for the repository. +* Updated '.vscode\settings.json' to refer to AnalyzerSettings.psd1 so that + custom syntax problems are highlighted in Visual Studio Code. +* Fixed style guideline violations in `CommonResourceHelper.psm1`. +* Updated 'appveyor.yml' to meet more recent standards. +* Removed OS image version from 'appveyor.yml' to use default image + ([Issue #127](https://github.com/PowerShell/PSDscResources/issues/127). +* Removed code to install WMF5.1 from 'appveyor.yml' because it is already + installed in AppVeyor images ([Issue #128](https://github.com/PowerShell/PSDscResources/issues/128). +* Removed .vscode from .gitignore so that Visual Studio code environment + settings can be committed. + ### 2.9.0.0 * Added Description and Parameter description for composite resources @@ -584,46 +610,46 @@ The following parameters will be the same for each process in the set: ### 2.8.0.0 * Archive: - * Added handling of directory archive entries that end with a foward slash - * Removed formatting of LastWriteTime timestamp and updated comparison of timestamps to handle dates in different formats + * Added handling of directory archive entries that end with a foward slash + * Removed formatting of LastWriteTime timestamp and updated comparison of timestamps to handle dates in different formats * WindowsProcess: - * Fix unreliable tests + * Fix unreliable tests * Updated Test-IsNanoServer to return false if Get-ComputerInfo fails * Registry: - * Fixed bug when using the full registry drive name (e.g. HKEY\_LOCAL\_MACHINE) and using a key name that includes a drive with forward slashes (e.g. C:/) + * Fixed bug when using the full registry drive name (e.g. HKEY\_LOCAL\_MACHINE) and using a key name that includes a drive with forward slashes (e.g. C:/) ### 2.7.0.0 * MsiPackage - * Parse installation date from registry using invariant culture. - * Fix a bug in unit test failing, when regional setting differs from English-US. + * Parse installation date from registry using invariant culture. + * Fix a bug in unit test failing, when regional setting differs from English-US. ### 2.6.0.0 * Archive: - * Fixed a minor bug in the unit tests where sometimes the incorrect DateTime format was used. + * Fixed a minor bug in the unit tests where sometimes the incorrect DateTime format was used. * Added MsiPackage ### 2.5.0.0 * Enable codecov.io code coverage reporting * Group - * Added support for domain based group members on Nano server. + * Added support for domain based group members on Nano server. * Added the Archive resource * Update Test-IsNanoServer cmdlet to properly test for a Nano server rather than the core version of PowerShell * Registry - * Fixed bug where an error was thrown when running Get-DscConfiguration if the registry already existed + * Fixed bug where an error was thrown when running Get-DscConfiguration if the registry already existed ### 2.4.0.0 * Cleaned User * Updated User to have non-dependent unit tests. * Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration): - * WindowsProcess: Minor updates to integration tests - * Registry: Fixed support for forward slashes in registry key names + * WindowsProcess: Minor updates to integration tests + * Registry: Fixed support for forward slashes in registry key names * Group: - * Group members in the "NT Authority", "BuiltIn" and "NT Service" scopes should now be resolved without an error. If you were seeing the errors "Exception calling ".ctor" with "4" argument(s): "Server names cannot contain a space character."" or "Exception calling ".ctor" with "2" argument(s): "Server names cannot contain a space character."", this fix should resolve those errors. If you are still seeing one of the errors, there is probably another local scope we need to add. Please let us know. - * The resource will no longer attempt to resolve group members if Members, MembersToInclude, and MembersToExclude are not specified. + * Group members in the "NT Authority", "BuiltIn" and "NT Service" scopes should now be resolved without an error. If you were seeing the errors "Exception calling ".ctor" with "4" argument(s): "Server names cannot contain a space character."" or "Exception calling ".ctor" with "2" argument(s): "Server names cannot contain a space character."", this fix should resolve those errors. If you are still seeing one of the errors, there is probably another local scope we need to add. Please let us know. + * The resource will no longer attempt to resolve group members if Members, MembersToInclude, and MembersToExclude are not specified. * Added Environment ### 2.3.0.0 @@ -633,16 +659,16 @@ The following parameters will be the same for each process in the set: ### 2.2.0.0 * WindowsFeature: - * Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell). - * Updated unit tests. + * Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell). + * Updated unit tests. * Added WindowsProcess * CommonTestHelper: - * Added Get-AppVeyorAdministratorCredential. - * Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop'. + * Added Get-AppVeyorAdministratorCredential. + * Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop'. * Service: - * Updated resource module, unit tests, integration tests, and examples to reflect the changes made in xPSDesiredStateConfiguration. + * Updated resource module, unit tests, integration tests, and examples to reflect the changes made in xPSDesiredStateConfiguration. * Group: - * Updated resource module, examples, and integration tests to reflect the changes made in xPSDesiredStateConfiguration. + * Updated resource module, examples, and integration tests to reflect the changes made in xPSDesiredStateConfiguration. * Added Script. * Added GroupSet, ServiceSet, WindowsFeatureSet, WindowsOptionalFeatureSet, and ProcessSet. * Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop' to Group, Service, User, WindowsFeature, WindowsOptionalFeature, WindowsPackageCab. diff --git a/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 index a00738c..674c8e4 100644 --- a/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 @@ -134,47 +134,48 @@ Describe 'Archive End to End Tests' { $null = Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment } - Context 'Expand an archive to a destination that does not yet exist' { + Context 'When expanding an archive to a destination that does not yet exist' { $configurationName = 'ExpandArchiveToNonExistentDestination' $destination = Join-Path -Path $TestDrive -ChildPath 'NonExistentDestinationForExpand' It 'Destination should not exist before configuration' { - Test-Path -Path $destination | Should Be $false + Test-Path -Path $destination | Should -Be $false } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Present' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Expand an archive to an existing destination with items that are not in the archive' { + Context 'When expanding an archive to an existing destination with items that are not in the archive' { $configurationName = 'ExpandArchiveToDestinationWithOtherItems' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithOtherItemsForExpand' @@ -198,7 +199,7 @@ Describe 'Archive End to End Tests' { $otherItems[$otherFilePath] = $otherFileContent It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -210,17 +211,17 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory before configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file before configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected content before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } @@ -229,26 +230,27 @@ Describe 'Archive End to End Tests' { Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Present' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -260,27 +262,27 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory after configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file after configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected after before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - - Context 'Expand an archive to an existing destination that already contains the same archive files' { + + Context 'When expanding an archive to an existing destination that already contains the same archive files' { $configurationName = 'ExpandArchiveToDestinationWithArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveForExpand' @@ -289,45 +291,46 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Present' + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Expand an archive to a destination that contains archive files that do not match by the specified SHA Checksum without Force specified' { + Context 'When expanding an archive to a destination that contains archive files that do not match by the specified SHA Checksum without Force specified' { $configurationName = 'ExpandArchiveToDestinationWithMismatchingArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMismatchingArchiveWithSHANoForceForExpand' @@ -336,15 +339,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } $archiveParameters = @{ @@ -354,39 +357,40 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $false + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } It 'Should compile and run configuration and throw an error for attempting to overwrite files without Force specified' { # We don't know which file will throw the error, so we will only check that an error was thrown rather than checking the specific error message - { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } It 'Should return false from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } } - Context 'Expand an archive to a destination that contains archive files that do not match by the specified SHA Checksum with Force specified' { + Context 'When expanding an archive to a destination that contains archive files that do not match by the specified SHA Checksum with Force specified' { $configurationName = 'ExpandArchiveToDestinationWithMismatchingArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMismatchingArchiveWithSHAAndForceForExpand' @@ -395,15 +399,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } $archiveParameters = @{ @@ -413,38 +417,39 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Expand an archive to a destination that contains archive files that match by the specified SHA Checksum' { + Context 'When expanding an archive to a destination that contains archive files that match by the specified SHA Checksum' { $configurationName = 'ExpandArchiveToDestinationWithMatchingArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveWithSHAForExpand' @@ -453,15 +458,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } $archiveParameters = @{ @@ -471,38 +476,39 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - - Context 'Remove an expanded archive from an existing destination that contains only the expanded archive' { + + Context 'When removing an expanded archive from an existing destination that contains only the expanded archive' { $configurationName = 'RemoveArchiveAtDestinationWithArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveForRemove' @@ -511,45 +517,46 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an expanded archive from an existing destination that contains the expanded archive and other files' { + Context 'When removing an expanded archive from an existing destination that contains the expanded archive and other files' { $configurationName = 'RemoveArchiveAtDestinationWithArchiveAndOtherFiles' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveAndOtherFilesForRemove' @@ -575,7 +582,7 @@ Describe 'Archive End to End Tests' { $otherItems[$otherFilePath] = $otherFileContent It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -587,45 +594,46 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory before configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file before configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected content before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -637,112 +645,114 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory before configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file before configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected content before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an expanded archive from an existing destination that does not contain any archive files' { + Context 'When removing an expanded archive from an existing destination that does not contain any archive files' { $configurationName = 'RemoveArchiveAtDestinationWithoutArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'EmptyDestinationForRemove' $null = New-Item -Path $destination -ItemType 'Directory' It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an expanded archive from a destination that does not exist' { + Context 'When removing an expanded archive from a destination that does not exist' { $configurationName = 'RemoveArchiveFromMissingDestination' $destination = Join-Path -Path $TestDrive -ChildPath 'NonexistentDestinationForRemove' It 'Destination should not exist before configuration' { - Test-Path -Path $destination | Should Be $false + Test-Path -Path $destination | Should -Be $false } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should not exist after configuration' { - Test-Path -Path $destination | Should Be $false + Test-Path -Path $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an archive from a destination that contains archive files that do not match by the specified SHA Checksum' { + Context 'When removing an archive from a destination that contains archive files that do not match by the specified SHA Checksum' { $configurationName = 'RemoveArchiveFromDestinationWithMismatchingArchiveWithSHA' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMismatchingArchiveWithSHAForRemove' @@ -751,15 +761,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } $archiveParameters = @{ @@ -769,38 +779,39 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an archive from a destination that contains archive files that match by the specified SHA Checksum' { + Context 'When removing an archive from a destination that contains archive files that match by the specified SHA Checksum' { $configurationName = 'RemoveArchiveFromDestinationWithMatchingArchiveWithSHA' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveWithSHAForRemove' @@ -809,11 +820,11 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure and contents of destination should match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } $archiveParameters = @{ @@ -823,30 +834,31 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return false from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } } diff --git a/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 b/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 index 06aea9c..d3562aa 100644 --- a/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 @@ -29,7 +29,7 @@ Describe 'Archive Integration Tests' { $null = Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment } - Context 'Expand a basic archive' { + Context 'When expanding a basic archive' { $zipFileName = 'BasicArchive1' $subfolderName = 'Folder1' @@ -46,35 +46,35 @@ Describe 'Archive Integration Tests' { $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } } - Context 'Remove a basic archive' { + Context 'When removing a basic archive' { $zipFileName = 'BasicArchive2' $subfolderName = 'Folder1' @@ -93,35 +93,35 @@ Describe 'Archive Integration Tests' { $null = Expand-Archive -Path $zipFilePath -DestinationPath $destinationDirectoryPath -Force It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } } - Context 'Expand an archive with nested directories' { + Context 'When expanding an archive with nested directories' { $zipFileName = 'NestedArchive1' $zipFileStructure = @{ @@ -164,35 +164,35 @@ Describe 'Archive Integration Tests' { $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } } - Context 'Remove an archive with nested directories' { + Context 'When removing an archive with nested directories' { $zipFileName = 'NestedArchive2' $zipFileStructure = @{ @@ -237,35 +237,35 @@ Describe 'Archive Integration Tests' { $null = Expand-Archive -Path $zipFilePath -DestinationPath $destinationDirectoryPath -Force It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } } - Context 'Expand an archive when another archive with the same timestamp exists in the same folder' { + Context 'When expanding an archive when another archive with the same timestamp exists in the same folder' { $zipFileName1 = 'SameTimestamp1' $zipFileStructure1 = @{ @@ -295,51 +295,51 @@ Describe 'Archive Integration Tests' { $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false for specified archive before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true for specified archive before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return false for other archive with same timestamp with before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true for other archive with same timestamp before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true for specified archive after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false for specified archive after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false for other archive with same timestamp with before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true for other archive with same timestamp before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $true } } - Context 'Remove an archive with an extra file in a nested directory' { + Context 'When removing an archive with an extra file in a nested directory' { $zipFileName = 'NestedArchiveWithAdd' $zipFileStructure = @{ @@ -371,44 +371,44 @@ Describe 'Archive Integration Tests' { $null = Set-Content -Path $newFilePath -Value 'Fake text' It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Extra file should be present before Set-TargetResource' { - Test-Path -Path $newFilePath | Should Be $true + Test-Path -Path $newFilePath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } - + It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Extra file should be present after Set-TargetResource' { - Test-Path -Path $newFilePath | Should Be $true + Test-Path -Path $newFilePath | Should -Be $true } } - + $possibleChecksumValues = @( 'SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate' ) - + $zipFileName = 'ChecksumWithModifiedFile' $fileToEditName = 'File1' $fileNotToEditName = 'File2' @@ -422,8 +422,8 @@ Describe 'Archive Integration Tests' { $zipFileSourcePath = $zipFilePath.Replace('.zip', '') foreach ($possibleChecksumValue in $possibleChecksumValues) - { - Context "Expand an archive with an edited file, Validate and Force specified, and Checksum specified as $possibleChecksumValue" { + { + Context "When expanding an archive with an edited file, Validate and Force specified, and Checksum specified as $possibleChecksumValue" { $destinationDirectoryName = 'ExpandModifiedArchiveWithCheck' $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName @@ -431,6 +431,7 @@ Describe 'Archive Integration Tests' { # This foreach loop with the Open-Archive call is needed to set the timestamps of the files at the destination correctly $destinationChildItems = Get-ChildItem -Path $destinationDirectoryPath -Recurse -File + foreach ($destinationChildItem in $destinationChildItems) { $correspondingZipItemPath = $destinationChildItem.FullName.Replace($destinationDirectoryPath + '\', '') @@ -438,7 +439,9 @@ Describe 'Archive Integration Tests' { try { - $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript {$_.FullName -eq $correspondingZipItemPath } + $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript { + $_.FullName -eq $correspondingZipItemPath + } $archiveEntryLastWriteTime = $matchingArchiveEntry.LastWriteTime.DateTime } finally @@ -451,19 +454,23 @@ Describe 'Archive Integration Tests' { } It 'Test-TargetResource with Ensure as Present should return true before file edit' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before file edit' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } $fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName It 'File to edit should exist at the destination before Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } + $fileBeforeEdit = Get-Item -Path $fileToEditPath + $lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime + $creationTimeBeforeEdit = $fileBeforeEdit.CreationTime + $null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) @@ -471,65 +478,65 @@ Describe 'Archive Integration Tests' { $fileAfterEdit = Get-Item -Path $fileToEditPath It 'Edited file at the destination should have different content than the same file in the archive before Set-TargetResource' { - Get-Content -Path $fileToEditPath -Raw | Should Not Be ($zipFileStructure[$fileToEditName] + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Not -Be ($zipFileStructure[$fileToEditName] + "`r`n") } It 'Edited file at the destination should have different last write time than the same file in the archive before Set-TargetResource' { - [DateTime]($fileAfterEdit.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive before Set-TargetResource' { - $fileAfterEdit.CreationTime | Should Not Be $archiveEntryLastWriteTime + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue -Force $true } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue -Force $true } | Should -Not -Throw } + $fileAfterSetTargetResource = Get-Item -Path $fileToEditPath + It 'Edited file should exist at the destination after Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } It 'Edited file at the destination should have the same content as the same file in the archive after Set-TargetResource' { - Get-Content -Path $fileToEditPath -Raw | Should Be ($zipFileStructure[$fileToEditName] + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Be ($zipFileStructure[$fileToEditName] + "`r`n") } - $fileAfterSetTargetResource = Get-Item -Path $fileToEditPath - It 'Edited file at the destination should have the same last write time as the same file in the archive after Set-TargetResource' { - [DateTime]($fileAfterSetTargetResource.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $true + $fileAfterSetTargetResource.LastWriteTime | Should -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have the same creation time as last write time of the the same file in the archive after Set-TargetResource' { - [DateTime]($fileAfterSetTargetResource.CreationTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $true + $fileAfterSetTargetResource.CreationTime | Should -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } } - Context "Expand an archive with an edited file, Validate specfied, Force not specified, and Checksum specified as $possibleChecksumValue" { + Context "When expanding an archive with an edited file, Validate specfied, Force not specified, and Checksum specified as $possibleChecksumValue" { $destinationDirectoryName = 'ExpandModifiedArchiveWithCheckFail' $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName @@ -537,6 +544,7 @@ Describe 'Archive Integration Tests' { # This foreach loop with the Open-Archive call is needed to set the timestamps of the files at the destination correctly $destinationChildItems = Get-ChildItem -Path $destinationDirectoryPath -Recurse -File + foreach ($destinationChildItem in $destinationChildItems) { $correspondingZipItemPath = $destinationChildItem.FullName.Replace($destinationDirectoryPath + '\', '') @@ -544,7 +552,9 @@ Describe 'Archive Integration Tests' { try { - $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript {$_.FullName -eq $correspondingZipItemPath } + $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript { + $_.FullName -eq $correspondingZipItemPath + } $archiveEntryLastWriteTime = $matchingArchiveEntry.LastWriteTime.DateTime } finally @@ -557,19 +567,23 @@ Describe 'Archive Integration Tests' { } It 'Test-TargetResource with Ensure as Present should return true before file edit' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before file edit' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } $fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName It 'File to edit should exist at the destination before Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } + $fileBeforeEdit = Get-Item -Path $fileToEditPath + $lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime + $creationTimeBeforeEdit = $fileBeforeEdit.CreationTime + $null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) @@ -577,35 +591,33 @@ Describe 'Archive Integration Tests' { $fileAfterEdit = Get-Item -Path $fileToEditPath It 'Edited file at the destination should have different content than the same file in the archive before Set-TargetResource' { - Get-Content -Path $fileToEditPath -Raw | Should Not Be ($zipFileStructure[$fileToEditName] + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Not -Be ($zipFileStructure[$fileToEditName] + "`r`n") } It 'Edited file at the destination should have different last write time than the same file in the archive before Set-TargetResource' { - [DateTime]($fileAfterEdit.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive before Set-TargetResource' { - $fileAfterEdit.CreationTime.DateTime -eq $archiveEntryLastWriteTime | Should Be $false + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } - It 'Set-TargetResource should throw an error that the resource cannot overwrite the destination without Force specified' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should Throw - } + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should -Throw } - Context "Remove an archive with an edited file, Validate specified, and Checksum specified as $possibleChecksumValue" { + Context "When removing an archive with an edited file, Validate specified, and Checksum specified as $possibleChecksumValue" { $destinationDirectoryName = 'RemoveModifiedArchiveWithCheck' $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName @@ -613,6 +625,7 @@ Describe 'Archive Integration Tests' { # This foreach loop with the Open-Archive call is needed to set the timestamps of the files at the destination correctly $destinationChildItems = Get-ChildItem -Path $destinationDirectoryPath -Recurse -File + foreach ($destinationChildItem in $destinationChildItems) { $correspondingZipItemPath = $destinationChildItem.FullName.Replace($destinationDirectoryPath + '\', '') @@ -620,7 +633,9 @@ Describe 'Archive Integration Tests' { try { - $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript {$_.FullName -eq $correspondingZipItemPath } + $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript { + $_.FullName -eq $correspondingZipItemPath + } $archiveEntryLastWriteTime = $matchingArchiveEntry.LastWriteTime.DateTime } finally @@ -633,86 +648,90 @@ Describe 'Archive Integration Tests' { } It 'Test-TargetResource with Ensure as Present should return true before file edit' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before file edit' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } $fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName It 'File to edit should exist at the destination before Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } + $fileBeforeEdit = Get-Item -Path $fileToEditPath + $lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime + $creationTimeBeforeEdit = $fileBeforeEdit.CreationTime + $null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force - $null = Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) - $null = Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) + Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) + Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) $fileAfterEdit = Get-Item -Path $fileToEditPath It 'Edited file at the destination should have the edited content' { - Get-Content -Path $fileToEditPath -Raw | Should Be ('Different false text' + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Be ('Different false text' + "`r`n") } It 'Edited file at the destination should have different last write time than the same file in the archive after file edit and before Set-TargetResource' { - [DateTime]($fileAfterEdit.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive after file edit before Set-TargetResource' { - $fileAfterEdit.CreationTime.DateTime -eq $archiveEntryLastWriteTime | Should Be $false + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should -Not -Throw } + $fileAfterSetTargetResource = Get-Item -Path $fileToEditPath + It 'Edited file should exist at the destination after Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } It 'Edited file at the destination should have the edited content' { - Get-Content -Path $fileToEditPath -Raw | Should Be ('Different false text' + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Be ('Different false text' + "`r`n") } - $fileAfterSetTargetResource = Get-Item -Path $fileToEditPath - It 'Edited file at the destination should have different last write time than the same file in the archive after Set-TargetResource' { - [DateTime]($fileAfterSetTargetResource.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive after Set-TargetResource' { - $fileAfterSetTargetResource.CreationTime.DateTime -eq $archiveEntryLastWriteTime | Should Be $false + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } } } - Context 'Archive name contains a bracket' { + Context 'When expanding an archive when the archive name contains a bracket' { $zipFileName = 'ReturnCorrectValue[' $zipFileStructure = @{ @@ -726,15 +745,15 @@ Describe 'Archive Integration Tests' { $destination = Join-Path -Path $TestDrive -ChildPath 'ArchiveNameWithBracket' It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should -Not -Throw } It 'Get-TargetResource should not throw' { - { $null = Get-TargetResource -Path $zipFilePath -Destination $destination } | Should Not Throw + { $null = Get-TargetResource -Path $zipFilePath -Destination $destination } | Should -Not -Throw } It 'Test-TargetResource should not throw' { - { $null = Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should Not Throw + { $null = Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should -Not -Throw } } } diff --git a/appveyor.yml b/appveyor.yml index 4f75df0..1ad961f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,21 +2,12 @@ # environment configuration # #---------------------------------# version: 2.4.{build}.0 -os: Visual Studio 2015 install: - git clone https://github.com/PowerShell/DscResource.Tests - - ps: Import-Module -Name .\Tests\TestHelpers\WMF5Dot1Installation.psm1 -Force - - ps: Install-Wmf5Dot1 - - ps: Start-Sleep 5 - - ps: Restart-Computer -Force - - ps: Start-Sleep 5 - - ps: Write-Verbose -Message "Returned after restart with PSVersion $($PSVersionTable.PSVersion)" -Verbose - - ps: if ($PSVersionTable.PSVersion -lt [Version] '5.1') - { - throw 'WMF 5.1 install failed' - } - - ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - - ps: Invoke-AppveyorInstallTask + - ps: | + $moduleName = 'PSDscResources' + Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" + Invoke-AppveyorInstallTask #---------------------------------# # build configuration # @@ -30,13 +21,23 @@ build: false test_script: - ps: | - Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo + Invoke-AppveyorTestScriptTask ` + -Type 'Default' ` + -CodeCoverage ` + -CodeCovIo ` + -DisableConsistency ` + -ExcludeTag @() + +after_test: + - ps: | + Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" + Invoke-AppveyorAfterTestTask ` + -ResourceModuleName $moduleName #---------------------------------# # deployment configuration # #---------------------------------# -# scripts to run before deployment deploy_script: - ps: | Invoke-AppveyorAfterTestTask From 60e474c814d4f824b5ee0349996481b6d0a6ff3c Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 12 Jan 2019 17:13:51 +1300 Subject: [PATCH 2/7] Updated unit archive unit tests and added new ones from xPSDesiredStateConfiguration --- Tests/Unit/MSFT_Archive.Tests.ps1 | 949 ++++++++++++++++-------------- 1 file changed, 518 insertions(+), 431 deletions(-) diff --git a/Tests/Unit/MSFT_Archive.Tests.ps1 b/Tests/Unit/MSFT_Archive.Tests.ps1 index aabb51d..1cf72c4 100644 --- a/Tests/Unit/MSFT_Archive.Tests.ps1 +++ b/Tests/Unit/MSFT_Archive.Tests.ps1 @@ -46,7 +46,7 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Test-ArchiveExistsAtDestination' -MockWith { return $false } Mock -CommandName 'Remove-PSDrive' -MockWith { } - Context 'Checksum specified and Validate not specified' { + Context 'When checksum specified and Validate not specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -55,44 +55,44 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for Checksum specified while Validate is false' { $errorMessage = $script:localizedData.ChecksumSpecifiedAndValidateFalse -f $getTargetResourceParameters.Checksum, $getTargetResourceParameters.Path, $getTargetResourceParameters.Destination - { $null = Get-TargetResource @getTargetResourceParameters } | Should Throw $errorMessage + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Throw $errorMessage } } - Context 'Invalid archive path specified' { + Context 'When invalid archive path specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should throw an error for invalid archive path' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Throw $testInvalidArchivePathErrorMessage + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Throw $testInvalidArchivePathErrorMessage } } Mock -CommandName 'Assert-PathExistsAsLeaf' -MockWith { } - Context 'Invalid destination specified' { + Context 'When invalid destination specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should throw an error for invalid destination' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Throw $testInvalidDestinationErrorMessage + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Throw $testInvalidDestinationErrorMessage } } Mock -CommandName 'Assert-DestinationDoesNotExistAsFile' -MockWith { } - Context 'Valid archive path and destination specified and destination does not exist' { + Context 'When valid archive path and destination specified and destination does not exist' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -127,7 +127,7 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to test if the specified archive exists at the specified destination' { - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -Exactly 0 -Scope 'Context' } It 'Should not attempt to remove a mounted PSDrive' { @@ -137,27 +137,27 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Absent' { - $getTargetResourceResult.Ensure | Should Be 'Absent' + $getTargetResourceResult.Ensure | Should -Be 'Absent' } } - Context 'Valid archive path and destination specified, destination does not exist, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination does not exist, Validate specified as true, and Checksum specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -166,7 +166,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -201,7 +201,7 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to test if the specified archive exists at the specified destination' { - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -Exactly 0 -Scope 'Context' } It 'Should not attempt to remove a mounted PSDrive' { @@ -211,36 +211,36 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Absent' { - $getTargetResourceResult.Ensure | Should Be 'Absent' + $getTargetResourceResult.Ensure | Should -Be 'Absent' } } Mock -CommandName 'Test-Path' -MockWith { return $true } - Context 'Valid archive path and destination specified, destination exists, and archive is not expanded at destination' { + Context 'When valid archive path and destination specified, destination exists, and archive is not expanded at destination' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -282,7 +282,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect } - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove a mounted PSDrive' { @@ -292,27 +292,27 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Absent' { - $getTargetResourceResult.Ensure | Should Be 'Absent' + $getTargetResourceResult.Ensure | Should -Be 'Absent' } } - Context 'Valid archive path and destination specified, destination exists, archive is not expanded at destination, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination exists, archive is not expanded at destination, Validate specified as true, and Checksum specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -321,7 +321,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -364,7 +364,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $checksumParameterCorrect } - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove a mounted PSDrive' { @@ -374,36 +374,36 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Absent' { - $getTargetResourceResult.Ensure | Should Be 'Absent' + $getTargetResourceResult.Ensure | Should -Be 'Absent' } } Mock -CommandName 'Test-ArchiveExistsAtDestination' -MockWith { return $true } - Context 'Valid archive path and destination specified, destination exists, and archive is expanded at destination' { + Context 'When valid archive path and destination specified, destination exists, and archive is expanded at destination' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -445,7 +445,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect } - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove a mounted PSDrive' { @@ -455,27 +455,27 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Present' { - $getTargetResourceResult.Ensure | Should Be 'Present' + $getTargetResourceResult.Ensure | Should -Be 'Present' } } - Context 'Valid archive path and destination specified, destination exists, archive is expanded at destination, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination exists, archive is expanded at destination, Validate specified as true, and Checksum specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -484,7 +484,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -527,7 +527,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $checksumParameterCorrect } - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove a mounted PSDrive' { @@ -537,27 +537,27 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Present' { - $getTargetResourceResult.Ensure | Should Be 'Present' + $getTargetResourceResult.Ensure | Should -Be 'Present' } } - Context 'Valid archive path and destination specified, destination exists, archive is expanded at destination, and credential specified' { + Context 'When valid archive path and destination specified, destination exists, archive is expanded at destination, and credential specified' { $getTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -565,7 +565,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Get-TargetResource @getTargetResourceParameters } | Should Not Throw + { $null = Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw } It 'Should mount a PSDrive' { @@ -614,7 +614,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect } - Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Test-ArchiveExistsAtDestination' -ParameterFilter $testArchiveExistsAtDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should remove the mounted PSDrive' { @@ -631,27 +631,27 @@ Describe 'Archive Unit Tests' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters It 'Should return a Hashtable' { - $getTargetResourceResult -is [Hashtable] | Should Be $true + $getTargetResourceResult -is [Hashtable] | Should -Be $true } It 'Should return a Hashtable with 3 properties' { - $getTargetResourceResult.Keys.Count | Should Be 3 + $getTargetResourceResult.Keys.Count | Should -Be 3 } It 'Should return a Hashtable with the Path property as the specified path' { - $getTargetResourceResult.Path | Should Be $getTargetResourceParameters.Path + $getTargetResourceResult.Path | Should -Be $getTargetResourceParameters.Path } It 'Should return a Hashtable with the Destination property as the specified destination' { - $getTargetResourceResult.Destination | Should Be $getTargetResourceParameters.Destination + $getTargetResourceResult.Destination | Should -Be $getTargetResourceParameters.Destination } It 'Should return a Hashtable with the Ensure property as Present' { - $getTargetResourceResult.Ensure | Should Be 'Present' + $getTargetResourceResult.Ensure | Should -Be 'Present' } } } - + Describe 'Set-TargetResource' { $testPSDrive = @{ Root = 'Test PSDrive Name' @@ -670,7 +670,7 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'New-Item' -MockWith { } Mock -CommandName 'Remove-PSDrive' -MockWith { } - Context 'Checksum specified and Validate not specified' { + Context 'When checksum specified and Validate not specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -679,37 +679,37 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for Checksum specified while Validate is false' { $errorMessage = $script:localizedData.ChecksumSpecifiedAndValidateFalse -f $setTargetResourceParameters.Checksum, $setTargetResourceParameters.Path, $setTargetResourceParameters.Destination - { Set-TargetResource @setTargetResourceParameters } | Should Throw $errorMessage + { Set-TargetResource @setTargetResourceParameters } | Should -Throw $errorMessage } } - Context 'Invalid archive path specified' { + Context 'When invalid archive path specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should throw an error for invalid archive path' { - { Set-TargetResource @setTargetResourceParameters } | Should Throw $testInvalidArchivePathErrorMessage + { Set-TargetResource @setTargetResourceParameters } | Should -Throw $testInvalidArchivePathErrorMessage } } Mock -CommandName 'Assert-PathExistsAsLeaf' -MockWith { } - Context 'Invalid destination specified' { + Context 'When invalid destination specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' } It 'Should throw an error for invalid destination' { - { Set-TargetResource @setTargetResourceParameters } | Should Throw $testInvalidDestinationErrorMessage + { Set-TargetResource @setTargetResourceParameters } | Should -Throw $testInvalidDestinationErrorMessage } } Mock -CommandName 'Assert-DestinationDoesNotExistAsFile' -MockWith { } - Context 'Valid archive path and destination specified, destination does not exist, and Ensure specified as Present' { + Context 'When valid archive path and destination specified, destination does not exist, and Ensure specified as Present' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -717,7 +717,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -759,7 +759,7 @@ Describe 'Archive Unit Tests' { return $pathParameterCorrect -and $itemTypeParameterCorrect } - Assert-MockCalled -CommandName 'New-Item' -ParameterFilter $newItemParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -ParameterFilter $newItemParameterFilter -Exactly 1 -Scope 'Context' } It 'Should expand the archive to the specified destination' { @@ -771,7 +771,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $forceParameterCorrect } - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -783,11 +783,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination does not exist, and Ensure specified as Absent' { + Context 'When valid archive path and destination specified, destination does not exist, and Ensure specified as Absent' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -795,7 +795,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -830,11 +830,11 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should not attempt to expand the archive to the specified destination' { - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -846,11 +846,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination does not exist, Ensure specified as Present, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination does not exist, Ensure specified as Present, Validate specified as true, and Checksum specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -860,7 +860,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -902,7 +902,7 @@ Describe 'Archive Unit Tests' { return $pathParameterCorrect -and $itemTypeParameterCorrect } - Assert-MockCalled -CommandName 'New-Item' -ParameterFilter $newItemParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -ParameterFilter $newItemParameterFilter -Exactly 1 -Scope 'Context' } It 'Should expand the archive to the specified destination based on the specified Checksum method' { @@ -915,7 +915,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $checksumParameterCorrect -and $forceParameterCorrect } - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -927,11 +927,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination does not exist, Ensure specified as Absent, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination does not exist, Ensure specified as Absent, Validate specified as true, and Checksum specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -941,7 +941,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -976,11 +976,11 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should not attempt to expand the archive to the specified destination' { - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -992,13 +992,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } Mock -CommandName 'Test-Path' -MockWith { return $true } - Context 'Valid archive path and destination specified, destination exists, and Ensure specified as Present' { + Context 'When valid archive path and destination specified, destination exists, and Ensure specified as Present' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1006,7 +1006,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -1041,7 +1041,7 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should expand the archive to the specified destination' { @@ -1053,7 +1053,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $forceParameterCorrect } - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -1065,11 +1065,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination exists, and Ensure specified as Absent' { + Context 'When valid archive path and destination specified, destination exists, and Ensure specified as Absent' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1077,7 +1077,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -1112,11 +1112,11 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should not attempt to expand the archive to the specified destination' { - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' } It 'Should remove the content of the opened archive from the directory at the specified destination' { @@ -1135,11 +1135,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination exists, Ensure specified as Present, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination exists, Ensure specified as Present, Validate specified as true, and Checksum specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1149,7 +1149,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -1184,7 +1184,7 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should expand the archive to the specified destination based on the specified Checksum method' { @@ -1197,7 +1197,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $checksumParameterCorrect -and $forceParameterCorrect } - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -1209,11 +1209,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination exists, Ensure specified as Absent, Validate specified as true, and Checksum specified' { + Context 'When valid archive path and destination specified, destination exists, Ensure specified as Absent, Validate specified as true, and Checksum specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1223,7 +1223,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should not attempt to mount a PSDrive' { @@ -1258,11 +1258,11 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should not attempt to expand the archive to the specified destination' { - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -Exactly 0 -Scope 'Context' } It 'Should remove the content of the opened archive from the directory at the specified destination' { @@ -1282,11 +1282,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } - Context 'Valid archive path and destination specified, destination exists, and credential specified' { + Context 'When valid archive path and destination specified, destination exists, and credential specified' { $setTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1294,7 +1294,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Set-TargetResource @setTargetResourceParameters } | Should Not Throw + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw } It 'Should mount a PSDrive' { @@ -1336,7 +1336,7 @@ Describe 'Archive Unit Tests' { } It 'Should not attempt to create a new directory at the specified destination' { - Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' + Assert-MockCalled -CommandName 'New-Item' -Exactly 0 -Scope 'Context' } It 'Should expand the archive to the specified destination' { @@ -1348,7 +1348,7 @@ Describe 'Archive Unit Tests' { return $archiveSourcePathParameterCorrect -and $destinationParameterCorrect -and $forceParameterCorrect } - Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' + Assert-MockCalled -CommandName 'Expand-ArchiveToDestination' -ParameterFilter $expandArchiveToDestinationParameterFilter -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove the content of the opened archive from the directory at the specified destination' { @@ -1367,7 +1367,7 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Set-TargetResource @setTargetResourceParameters | Should Be $null + Set-TargetResource @setTargetResourceParameters | Should -Be $null } } } @@ -1375,7 +1375,7 @@ Describe 'Archive Unit Tests' { Describe 'Test-TargetResource' { Mock -CommandName 'Get-TargetResource' -MockWith { return @{ Ensure = 'Absent' } } - Context 'Archive with specified path is not expanded at the specified destination and Ensure is specified as Present' { + Context 'When archive with specified path is not expanded at the specified destination and Ensure is specified as Present' { $testTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1383,7 +1383,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-TargetResource @testTargetResourceParameters } | Should Not Throw + { $null = Test-TargetResource @testTargetResourceParameters } | Should -Not -Throw } It 'Should retrieve the state of the specified archive' { @@ -1398,11 +1398,11 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-TargetResource @testTargetResourceParameters | Should Be $false + Test-TargetResource @testTargetResourceParameters | Should -Be $false } } - Context 'Archive with specified path is not expanded at the specified destination and Ensure is specified as Absent' { + Context 'When archive with specified path is not expanded at the specified destination and Ensure is specified as Absent' { $testTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1410,7 +1410,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-TargetResource @testTargetResourceParameters } | Should Not Throw + { $null = Test-TargetResource @testTargetResourceParameters } | Should -Not -Throw } It 'Should retrieve the state of the specified archive' { @@ -1425,13 +1425,13 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-TargetResource @testTargetResourceParameters | Should Be $true + Test-TargetResource @testTargetResourceParameters | Should -Be $true } } Mock -CommandName 'Get-TargetResource' -MockWith { return @{ Ensure = 'Present' } } - Context 'Archive with specified path is expanded at the specified destination and Ensure is specified as Present' { + Context 'When archive with specified path is expanded at the specified destination and Ensure is specified as Present' { $testTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1439,7 +1439,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-TargetResource @testTargetResourceParameters } | Should Not Throw + { $null = Test-TargetResource @testTargetResourceParameters } | Should -Not -Throw } It 'Should retrieve the state of the specified archive' { @@ -1454,11 +1454,11 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-TargetResource @testTargetResourceParameters | Should Be $true + Test-TargetResource @testTargetResourceParameters | Should -Be $true } } - Context 'Archive with specified path is expanded at the specified destination and Ensure is specified as Absent' { + Context 'When archive with specified path is expanded at the specified destination and Ensure is specified as Absent' { $testTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1466,7 +1466,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-TargetResource @testTargetResourceParameters } | Should Not Throw + { $null = Test-TargetResource @testTargetResourceParameters } | Should -Not -Throw } It 'Should retrieve the state of the specified archive' { @@ -1481,11 +1481,11 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-TargetResource @testTargetResourceParameters | Should Be $false + Test-TargetResource @testTargetResourceParameters | Should -Be $false } } - Context 'Archive with specified path is expanded at the specified destination, Validate and Checksum specified, and Ensure is specified as Present' { + Context 'When archive with specified path is expanded at the specified destination, Validate and Checksum specified, and Ensure is specified as Present' { $testTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1495,7 +1495,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-TargetResource @testTargetResourceParameters } | Should Not Throw + { $null = Test-TargetResource @testTargetResourceParameters } | Should -Not -Throw } It 'Should retrieve the state of the specified archive' { @@ -1512,11 +1512,11 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-TargetResource @testTargetResourceParameters | Should Be $true + Test-TargetResource @testTargetResourceParameters | Should -Be $true } } - Context 'Archive with specified path is expanded at the specified destination, Credential specified, and Ensure is specified as Present' { + Context 'When archive with specified path is expanded at the specified destination, Credential specified, and Ensure is specified as Present' { $testTargetResourceParameters = @{ Path = 'TestPath' Destination = 'TestDestination' @@ -1525,7 +1525,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-TargetResource @testTargetResourceParameters } | Should Not Throw + { $null = Test-TargetResource @testTargetResourceParameters } | Should -Not -Throw } It 'Should retrieve the state of the specified archive' { @@ -1541,7 +1541,7 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-TargetResource @testTargetResourceParameters | Should Be $true + Test-TargetResource @testTargetResourceParameters | Should -Be $true } } } @@ -1551,14 +1551,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'New-Guid' -MockWith { return $script:testGuid } Mock -CommandName 'Invoke-NewPSDrive' -MockWith { throw 'Test error from New-PSDrive' } - Context 'Specified path is already accessible' { + Context 'When specified path is already accessible' { $mountPSDriveWithCredentialParameters = @{ Path = 'TestPath' Credential = $script:testCredential } It 'Should not throw' { - { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should Not Throw + { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should -Not -Throw } It 'Should test if the given path is already accessible' { @@ -1566,7 +1566,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $mountPSDriveWithCredentialParameters.Path return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Test-Path' -ParameterFilter $testPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -1581,13 +1581,13 @@ Describe 'Archive Unit Tests' { $mountPSDriveWithCredentialResult = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters It 'Should return null' { - $mountPSDriveWithCredentialResult | Should Be $null + $mountPSDriveWithCredentialResult | Should -Be $null } } - Mock -CommandName 'Test-Path' -MockWith {return $false } + Mock -CommandName 'Test-Path' -MockWith { return $false } - Context 'Specified path is not accessible, path contains a backslash but does not end with a backslash, and new PSDrive creation fails' { + Context 'When specified path is not accessible, path contains a backslash but does not end with a backslash, and new PSDrive creation fails' { $mountPSDriveWithCredentialParameters = @{ Path = 'Test\Path' Credential = $script:testCredential @@ -1596,14 +1596,14 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for failed PSDrive creation' { $expectedPath = $mountPSDriveWithCredentialParameters.Path.Substring(0, $mountPSDriveWithCredentialParameters.Path.IndexOf('\')) $expectedErrorMessage = $script:localizedData.ErrorCreatingPSDrive -f $expectedPath, $mountPSDriveWithCredentialParameters.Credential.UserName - { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should Throw $expectedErrorMessage + { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should -Throw $expectedErrorMessage } } $expectedPSDrive = New-MockObject -Type 'System.Management.Automation.PSDriveInfo' Mock -CommandName 'Invoke-NewPSDrive' -MockWith { return $expectedPSDrive } - Context 'Specified path is not accessible, path contains a backslash but does not end with a backslash, and new PSDrive creation succeeds' { + Context 'When specified path is not accessible, path contains a backslash but does not end with a backslash, and new PSDrive creation succeeds' { $mountPSDriveWithCredentialParameters = @{ Path = 'Test\Path' Credential = $script:testCredential @@ -1612,7 +1612,7 @@ Describe 'Archive Unit Tests' { $expectedPSDrivePath = $mountPSDriveWithCredentialParameters.Path.Substring(0, $mountPSDriveWithCredentialParameters.Path.IndexOf('\')) It 'Should not throw' { - { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should Not Throw + { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should -Not -Throw } It 'Should test if the given path is already accessible' { @@ -1620,7 +1620,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $mountPSDriveWithCredentialParameters.Path return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Test-Path' -ParameterFilter $testPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -1645,18 +1645,18 @@ Describe 'Archive Unit Tests' { $mountPSDriveWithCredentialResult = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters It 'Should return the PSDrive outputted from New-PSDrive' { - $mountPSDriveWithCredentialResult | Should Be $expectedPSDrive + $mountPSDriveWithCredentialResult | Should -Be $expectedPSDrive } } - Context 'Specified path is not accessible, path ends with a backslash, and new PSDrive creation succeeds' { + Context 'When specified path is not accessible, path ends with a backslash, and new PSDrive creation succeeds' { $mountPSDriveWithCredentialParameters = @{ Path = 'TestPath\' Credential = $script:testCredential } It 'Should not throw' { - { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should Not Throw + { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should -Not -Throw } It 'Should test if the given path is already accessible' { @@ -1664,7 +1664,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $mountPSDriveWithCredentialParameters.Path return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Test-Path' -ParameterFilter $testPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -1689,11 +1689,11 @@ Describe 'Archive Unit Tests' { $mountPSDriveWithCredentialResult = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters It 'Should return the PSDrive outputted from New-PSDrive' { - $mountPSDriveWithCredentialResult | Should Be $expectedPSDrive + $mountPSDriveWithCredentialResult | Should -Be $expectedPSDrive } } - Context 'Specified path is not accessible and path does not contain a backslash' { + Context 'When specified path is not accessible and path does not contain a backslash' { $mountPSDriveWithCredentialParameters = @{ Path = 'TestPath' Credential = $script:testCredential @@ -1701,7 +1701,7 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for an invalid path' { $expectedErrorMessage = $script:localizedData.PathDoesNotContainValidPSDriveRoot -f $mountPSDriveWithCredentialParameters.Path - { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should Throw $expectedErrorMessage + { $null = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters } | Should -Throw $expectedErrorMessage } } } @@ -1709,13 +1709,13 @@ Describe 'Archive Unit Tests' { Describe 'Assert-PathExistsAsLeaf' { Mock -CommandName 'Test-Path' -MockWith { return $true } - Context 'Path exists as a leaf' { + Context 'When path exists as a leaf' { $assertPathExistsAsLeafParameters = @{ Path = 'TestPath' } It 'Should not throw' { - { Assert-PathExistsAsLeaf @assertPathExistsAsLeafParameters } | Should Not Throw + { Assert-PathExistsAsLeaf @assertPathExistsAsLeafParameters } | Should -Not -Throw } It 'Should test if path exists as a leaf' { @@ -1732,14 +1732,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Test-Path' -MockWith { return $false } - Context 'Path does not exist' { + Context 'When path does not exist' { $assertPathExistsAsLeafParameters = @{ Path = 'TestPath' } It 'Should throw an error for non-existent path' { $expectedErrorMessage = $script:localizedData.PathDoesNotExistAsLeaf -f $assertPathExistsAsLeafParameters.Path - { Assert-PathExistsAsLeaf @assertPathExistsAsLeafParameters } | Should Throw $expectedErrorMessage + { Assert-PathExistsAsLeaf @assertPathExistsAsLeafParameters } | Should -Throw $expectedErrorMessage } } } @@ -1747,13 +1747,13 @@ Describe 'Archive Unit Tests' { Describe 'Assert-DestinationDoesNotExistAsFile' { Mock -CommandName 'Get-Item' -MockWith { return $null } - Context 'Item at destination does not exist' { + Context 'When item at destination does not exist' { $assertDestinationDoesNotExistAsFileParameters = @{ Destination = 'TestDestination' } It 'Should not throw' { - { Assert-DestinationDoesNotExistAsFile @assertDestinationDoesNotExistAsFileParameters } | Should Not Throw + { Assert-DestinationDoesNotExistAsFile @assertDestinationDoesNotExistAsFileParameters } | Should -Not -Throw } It 'Should retrieve item at destination' { @@ -1769,13 +1769,13 @@ Describe 'Archive Unit Tests' { $directoryItem = New-Object -TypeName 'System.IO.DirectoryInfo' -ArgumentList @( 'TestDirectory' ) Mock -CommandName 'Get-Item' -MockWith { return $directoryItem } - Context 'Item at destination exists as a directory' { + Context 'When item at destination exists as a directory' { $assertDestinationDoesNotExistAsFileParameters = @{ Destination = 'TestDestination' } It 'Should not throw' { - { Assert-DestinationDoesNotExistAsFile @assertDestinationDoesNotExistAsFileParameters } | Should Not Throw + { Assert-DestinationDoesNotExistAsFile @assertDestinationDoesNotExistAsFileParameters } | Should -Not -Throw } It 'Should retrieve item at destination' { @@ -1789,66 +1789,67 @@ Describe 'Archive Unit Tests' { } $fileItem = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( 'TestFile' ) + Mock -CommandName 'Get-Item' -MockWith { return $fileItem } - Context 'Item at destination exists as a file' { + Context 'When item at destination exists as a file' { $assertDestinationDoesNotExistAsFileParameters = @{ Destination = 'TestDestination' } It 'Should throw error for file at destination' { $expectedErrorMessage = $script:localizedData.DestinationExistsAsFile -f $assertDestinationDoesNotExistAsFileParameters.Destination - { Assert-DestinationDoesNotExistAsFile @assertDestinationDoesNotExistAsFileParameters } | Should Throw $expectedErrorMessage + { Assert-DestinationDoesNotExistAsFile @assertDestinationDoesNotExistAsFileParameters } | Should -Throw $expectedErrorMessage } } } Describe 'Test-ChecksumIsSha' { - Context 'Specified checksum method name is a SHA method name' { + Context 'When specified checksum method name is a SHA method name' { $testChecksumIsShaParameters = @{ Checksum = 'SHA-256' } It 'Should not throw' { - { $null = Test-ChecksumIsSha @testChecksumIsShaParameters } | Should Not Throw + { $null = Test-ChecksumIsSha @testChecksumIsShaParameters } | Should -Not -Throw } $testChecksumIsShaResult = Test-ChecksumIsSha @testChecksumIsShaParameters It 'Should return true' { - $testChecksumIsShaResult | Should Be $true + $testChecksumIsShaResult | Should -Be $true } } - Context 'Specified checksum method name is not a SHA method name' { + Context 'When specified checksum method name is not a SHA method name' { $testChecksumIsShaParameters = @{ Checksum = 'CreatedDate' } It 'Should not throw' { - { $null = Test-ChecksumIsSha @testChecksumIsShaParameters } | Should Not Throw + { $null = Test-ChecksumIsSha @testChecksumIsShaParameters } | Should -Not -Throw } $testChecksumIsShaResult = Test-ChecksumIsSha @testChecksumIsShaParameters It 'Should return false' { - $testChecksumIsShaResult | Should Be $false + $testChecksumIsShaResult | Should -Be $false } } - Context 'Specified checksum method name is less than 3 characters' { + Context 'When specified checksum method name is less than 3 characters' { $testChecksumIsShaParameters = @{ Checksum = 'AB' } It 'Should not throw' { - { $null = Test-ChecksumIsSha @testChecksumIsShaParameters } | Should Not Throw + { $null = Test-ChecksumIsSha @testChecksumIsShaParameters } | Should -Not -Throw } $testChecksumIsShaResult = Test-ChecksumIsSha @testChecksumIsShaParameters It 'Should return false' { - $testChecksumIsShaResult | Should Be $false + $testChecksumIsShaResult | Should -Be $false } } } @@ -1857,15 +1858,15 @@ Describe 'Archive Unit Tests' { $convertToPowerShellHashAlgorithmNameParameters = @{ DscHashAlgorithmName = 'SHA-256' } - + It 'Should not throw' { - { $null = ConvertTo-PowerShellHashAlgorithmName @convertToPowerShellHashAlgorithmNameParameters } | Should Not Throw + { $null = ConvertTo-PowerShellHashAlgorithmName @convertToPowerShellHashAlgorithmNameParameters } | Should -Not -Throw } $convertToPowerShellHashAlgorithmNameResult = ConvertTo-PowerShellHashAlgorithmName @convertToPowerShellHashAlgorithmNameParameters It 'Should return the specified algorithm name without the hyphen' { - $convertToPowerShellHashAlgorithmNameResult | Should Be 'SHA256' + $convertToPowerShellHashAlgorithmNameResult | Should -Be 'SHA256' } } @@ -1883,46 +1884,46 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Get-FileHash' -MockWith { throw 'Error retrieving hash'} Mock -CommandName 'Close-Stream' -MockWith { } - Context 'Opening the specified archive entry fails' { + Context 'When opening the specified archive entry fails' { $testFileHashMatchesArchiveEntryHashParameters = @{ FilePath = 'TestPath' ArchiveEntry = $mockArchiveEntry HashAlgorithmName = 'SHA-256' - } - + } + It 'Should throw error for failure while opening archive entry' { $expectedErrorMessage = $script:localizedData.ErrorComparingHashes -f $testFileHashMatchesArchiveEntryHashParameters.FilePath, $testArchiveEntryFullName, $testFileHashMatchesArchiveEntryHashParameters.HashAlgorithmName - { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should Throw $expectedErrorMessage + { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should -Throw $expectedErrorMessage } } Mock -CommandName 'Open-ArchiveEntry' -MockWith { return $mockFileStream } - Context 'Opening a stream to the specified file fails' { + Context 'When opening a stream to the specified file fails' { $testFileHashMatchesArchiveEntryHashParameters = @{ FilePath = 'TestPath' ArchiveEntry = $mockArchiveEntry HashAlgorithmName = 'SHA-256' - } - + } + It 'Should throw error for failure while opening a stream to the file' { $expectedErrorMessage = $script:localizedData.ErrorComparingHashes -f $testFileHashMatchesArchiveEntryHashParameters.FilePath, $testArchiveEntryFullName, $testFileHashMatchesArchiveEntryHashParameters.HashAlgorithmName - { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should Throw $expectedErrorMessage + { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should -Throw $expectedErrorMessage } } Mock -CommandName 'New-Object' -MockWith { return $mockFileStream } - Context 'Retrieving the file hash fails' { + Context 'When retrieving the file hash fails' { $testFileHashMatchesArchiveEntryHashParameters = @{ FilePath = 'TestPath' ArchiveEntry = $mockArchiveEntry HashAlgorithmName = 'SHA-256' - } - + } + It 'Should throw error for failure to retrieve the file hash or archive entry hash' { $expectedErrorMessage = $script:localizedData.ErrorComparingHashes -f $testFileHashMatchesArchiveEntryHashParameters.FilePath, $testArchiveEntryFullName, $testFileHashMatchesArchiveEntryHashParameters.HashAlgorithmName - { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should Throw $expectedErrorMessage + { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should -Throw $expectedErrorMessage } } @@ -1933,15 +1934,15 @@ Describe 'Archive Unit Tests' { } } - Context 'File hash matches archive entry hash' { + Context 'When file hash matches archive entry hash' { $testFileHashMatchesArchiveEntryHashParameters = @{ FilePath = 'TestPath' ArchiveEntry = $mockArchiveEntry HashAlgorithmName = 'SHA-256' - } - + } + It 'Should not throw' { - { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should Not Throw + { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should -Not -Throw } It 'Should convert the specified DSC hash algorithm name to a PowerShell hash algorithm name' { @@ -1964,7 +1965,7 @@ Describe 'Archive Unit Tests' { It 'Should open a stream to the specified file' { $expectedArgumentList = @( $testFileHashMatchesArchiveEntryHashParameters.FilePath, [System.IO.FileMode]::Open ) - + $newObjectParameterFilter = { $typeNameParameterCorrect = $TypeName -eq 'System.IO.FileStream' $argumentListParameterCorrect = $null -eq (Compare-Object -ReferenceObject $expectedArgumentList -DifferenceObject $ArgumentList) @@ -1975,7 +1976,7 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'New-Object' -ParameterFilter $newObjectParameterFilter -Exactly 1 -Scope 'Context' } - + It 'Should retrieve the hashes of the specified file and the specified archive entry with the specified hash algorithm name' { $getFileHashParameterFilter = { @@ -1998,7 +1999,7 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters | Should Be $true + Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters | Should -Be $true } } @@ -2023,15 +2024,15 @@ Describe 'Archive Unit Tests' { } } - Context 'File hash does not match archive entry hash' { + Context 'When file hash does not match archive entry hash' { $testFileHashMatchesArchiveEntryHashParameters = @{ FilePath = 'TestPath' ArchiveEntry = $mockArchiveEntry HashAlgorithmName = 'SHA-256' - } - + } + It 'Should not throw' { - { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should Not Throw + { $null = Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters } | Should -Not -Throw } It 'Should convert the specified DSC hash algorithm name to a PowerShell hash algorithm name' { @@ -2054,7 +2055,7 @@ Describe 'Archive Unit Tests' { It 'Should open a stream to the specified file' { $expectedArgumentList = @( $testFileHashMatchesArchiveEntryHashParameters.FilePath, [System.IO.FileMode]::Open ) - + $newObjectParameterFilter = { $typeNameParameterCorrect = $TypeName -eq 'System.IO.FileStream' $argumentListParameterCorrect = $null -eq (Compare-Object -ReferenceObject $expectedArgumentList -DifferenceObject $ArgumentList) @@ -2065,8 +2066,6 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'New-Object' -ParameterFilter $newObjectParameterFilter -Exactly 1 -Scope 'Context' } - - It 'Should retrieve the hashes of the specified file and the specified archive entry with the specified hash algorithm name' { $getFileHashParameterFilter = { $inputStreamParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockFileStream -DifferenceObject $InputStream) @@ -2089,44 +2088,132 @@ Describe 'Archive Unit Tests' { It 'Should return false' { $script:timesGetFileHashCalled = 0 - Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters | Should Be $false + Test-FileHashMatchesArchiveEntryHash @testFileHashMatchesArchiveEntryHashParameters | Should -Be $false } } } - Describe 'Get-TimestampForChecksum' { - # This is the actual file info of this file since we cannot set the properties of mock objects + Describe 'Get-ChecksumFromFileTimestamp' { $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) $testFileCreationTime = $testFileInfo.CreationTime.DateTime $testFileLastWriteTime = $testFileInfo.LastWriteTime.DateTime + $testFileCreationTimeChecksum = (Get-Date -Date $testFileCreationTime -Format 'G') + $testFileLastWriteTimeChecksum = (Get-Date -Date $testFileLastWriteTime -Format 'G') + + Context 'When checksum specified as CreatedDate' { + $getChecksumFromFileTimestampParameters = @{ + File = $testFileInfo + Checksum = 'CreatedDate' + } + + It 'Should not throw' { + { $null = Get-ChecksumFromFileTimestamp @getChecksumFromFileTimestampParameters } | Should -Not -Throw + } + + It 'Should return the creation time of the file as a Checksum' { + Get-ChecksumFromFileTimestamp @getChecksumFromFileTimestampParameters | Should -Be $testFileCreationTimeChecksum + } + } - Context 'Checksum specified as CreatedDate' { + Context 'When checksum specified as ModifiedDate' { + $getChecksumFromFileTimestampParameters = @{ + File = $testFileInfo + Checksum = 'ModifiedDate' + } + + It 'Should not throw' { + { $null = Get-ChecksumFromFileTimestamp @getChecksumFromFileTimestampParameters } | Should -Not -Throw + } + + It 'Should return the last write time of the file' { + Get-ChecksumFromFileTimestamp @getChecksumFromFileTimestampParameters | Should -Be $testFileLastWriteTimeChecksum + } + } + } + + Describe 'Get-TimestampForChecksum' { + $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) + + Context 'When checksum specified as CreatedDate' { $getTimestampForChecksumParameters = @{ File = $testFileInfo Checksum = 'CreatedDate' } It 'Should not throw' { - { $null = Get-TimestampForChecksum @getTimestampForChecksumParameters } | Should Not Throw + { $null = Get-TimestampForChecksum @getTimestampForChecksumParameters } | Should -Not -Throw } - It 'Should return the creation time of the file' { - Get-TimestampForChecksum @getTimestampForChecksumParameters | Should Be $testFileCreationTime + It 'Should return the creation time of the file as a Checksum' { + Get-TimestampForChecksum @getTimestampForChecksumParameters | Should -Be $testFileInfo.CreationTime.DateTime } } - Context 'Checksum specified as ModifiedDate' { + Context 'When checksum specified as ModifiedDate' { $getTimestampForChecksumParameters = @{ File = $testFileInfo Checksum = 'ModifiedDate' } It 'Should not throw' { - { $null = Get-TimestampForChecksum @getTimestampForChecksumParameters } | Should Not Throw + { $null = Get-TimestampForChecksum @getTimestampForChecksumParameters } | Should -Not -Throw } It 'Should return the last write time of the file' { - Get-TimestampForChecksum @getTimestampForChecksumParameters | Should Be $testFileLastWriteTime + Get-TimestampForChecksum @getTimestampForChecksumParameters | Should -Be $testFileInfo.LastWriteTime.DateTime + } + } + } + + Describe 'Get-TimestampFromFile' { + $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) + + Context 'When Timestamp specified as CreationTime' { + $getTimestampFromFileParameters = @{ + File = $testFileInfo + Timestamp = 'CreationTime' + } + + It 'Should not throw' { + { $null = Get-TimestampFromFile @getTimestampFromFileParameters } | Should -Not -Throw + } + + It 'Should return the creation time of the file as a Checksum' { + Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.CreationTime.DateTime + } + } + + Context 'When Timestamp specified as LastWriteTime' { + $getTimestampFromFileParameters = @{ + File = $testFileInfo + Timestamp = 'LastWriteTime' + } + + It 'Should not throw' { + { $null = Get-TimestampFromFile @getTimestampFromFileParameters } | Should -Not -Throw + } + + It 'Should return the creation time of the file as a Checksum' { + Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.LastWriteTime.DateTime + } + } + } + + Describe 'ConvertTo-CheckSumFromDateTime' { + $testDate = Get-Date + $testDateFromChecksum = (Get-Date -Date $testDate -Format 'G') + + Context 'When called with a datetime object set to now' { + $convertToCheckSumFromDateTimeParameters = @{ + Date = $testDate + } + + It 'Should not throw' { + { $null = ConvertTo-CheckSumFromDateTime @convertToCheckSumFromDateTimeParameters } | Should -Not -Throw + } + + It 'Should return the date normalized to a string using format of ''G''' { + ConvertTo-CheckSumFromDateTime @convertToCheckSumFromDateTimeParameters | Should -Be $testDateFromChecksum } } } @@ -2148,7 +2235,7 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Get-TimestampForChecksum' -MockWith { return $testTimestampFromChecksum } Mock -CommandName 'Get-ArchiveEntryLastWriteTime' -MockWith { return $testArchiveEntryLastWriteTime } - Context 'Specified checksum method is not a SHA method and file timestamp from checksum does not match archive entry last write time' { + Context 'When specified checksum method is not a SHA method and file timestamp from checksum does not match archive entry last write time' { $testFileMatchesArchiveEntryByChecksumParameters = @{ File = $testFileInfo ArchiveEntry = $mockArchiveEntry @@ -2156,7 +2243,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should Not Throw + { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should -Not -Throw } It 'Should retrieve the full name of the archive entry' { @@ -2202,13 +2289,13 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should Be $false + Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should -Be $false } } Mock -CommandName 'Get-TimestampForChecksum' -MockWith { return $testArchiveEntryLastWriteTime } - Context 'Specified checksum method is not a SHA method and file timestamp from checksum matches archive entry last write time' { + Context 'When specified checksum method is not a SHA method and file timestamp from checksum matches archive entry last write time' { $testFileMatchesArchiveEntryByChecksumParameters = @{ File = $testFileInfo ArchiveEntry = $mockArchiveEntry @@ -2216,7 +2303,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should Not Throw + { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should -Not -Throw } It 'Should retrieve the full name of the archive entry' { @@ -2262,13 +2349,13 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should Be $true + Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should -Be $true } } Mock -CommandName 'Test-ChecksumIsSha' -MockWith { return $true } - Context 'Specified checksum method is a SHA method and file hash does not match archive entry hash' { + Context 'When specified checksum method is a SHA method and file hash does not match archive entry hash' { $testFileMatchesArchiveEntryByChecksumParameters = @{ File = $testFileInfo ArchiveEntry = $mockArchiveEntry @@ -2276,7 +2363,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should Not Throw + { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should -Not -Throw } It 'Should retrieve the full name of the archive entry' { @@ -2318,13 +2405,13 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should Be $false + Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should -Be $false } } Mock -CommandName 'Test-FileHashMatchesArchiveEntryHash' -MockWith { return $true } - Context 'Specified checksum method is a SHA method and file hash matches archive entry hash' { + Context 'When specified checksum method is a SHA method and file hash matches archive entry hash' { $testFileMatchesArchiveEntryByChecksumParameters = @{ File = $testFileInfo ArchiveEntry = $mockArchiveEntry @@ -2332,7 +2419,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should Not Throw + { $null = Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters } | Should -Not -Throw } It 'Should retrieve the full name of the archive entry' { @@ -2374,13 +2461,13 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should Be $true + Test-FileMatchesArchiveEntryByChecksum @testFileMatchesArchiveEntryByChecksumParameters | Should -Be $true } } } Describe 'Test-ArchiveEntryIsDirectory' { - Context 'Archive entry name does not contain a backslash or a foward slash' { + Context 'When archive entry name does not contain a backslash or a foward slash' { $testArchiveEntryNameIsDirectoryPathParameters = @{ ArchiveEntryName = 'TestArchiveEntryName' } @@ -2394,7 +2481,7 @@ Describe 'Archive Unit Tests' { } } - Context 'Archive entry name contains a backslash but does not end with a backslash' { + Context 'When archive entry name contains a backslash but does not end with a backslash' { $testArchiveEntryNameIsDirectoryPathParameters = @{ ArchiveEntryName = 'TestArchive\EntryName' } @@ -2408,7 +2495,7 @@ Describe 'Archive Unit Tests' { } } - Context 'Archive entry name contains a foward slash but does not end with a foward slash' { + Context 'When archive entry name contains a foward slash but does not end with a foward slash' { $testArchiveEntryNameIsDirectoryPathParameters = @{ ArchiveEntryName = 'TestArchive/EntryName' } @@ -2421,8 +2508,8 @@ Describe 'Archive Unit Tests' { Test-ArchiveEntryIsDirectory @testArchiveEntryNameIsDirectoryPathParameters | Should Be $false } } - - Context 'Archive entry name ends with a backslash' { + + Context 'When archive entry name ends with a backslash' { $testArchiveEntryNameIsDirectoryPathParameters = @{ ArchiveEntryName = 'TestArchiveEntryName\' } @@ -2436,7 +2523,7 @@ Describe 'Archive Unit Tests' { } } - Context 'Archive entry name ends with a forward slash' { + Context 'When archive entry name ends with a forward slash' { $testArchiveEntryNameIsDirectoryPathParameters = @{ ArchiveEntryName = 'TestArchiveEntryName/' } @@ -2459,7 +2546,7 @@ Describe 'Archive Unit Tests' { $mockArchiveEntry = New-MockObject -Type 'System.IO.Compression.ZipArchiveEntry' $mockFile = New-MockObject -Type 'System.IO.FileInfo' $mockDirectory = New-MockObject -Type 'System.IO.DirectoryInfo' - + Mock -CommandName 'Open-Archive' -MockWith { return $mockArchive } Mock -CommandName 'Get-ArchiveEntries' -MockWith { return @( $mockArchiveEntry ) } Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } @@ -2469,14 +2556,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -MockWith { return $false } Mock -CommandName 'Close-Archive' -MockWith { } - Context 'Archive entry is a directory and does not exist at destination' { + Context 'When archive entry is a directory and does not exist at destination' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -2510,7 +2597,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2544,20 +2631,20 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Get-Item' -MockWith { return $mockFile } - Context 'Archive entry is a directory and item with the same name exists at the destination but is a file' { + Context 'When archive entry is a directory and item with the same name exists at the destination but is a file' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -2591,7 +2678,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2630,20 +2717,20 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Get-Item' -MockWith { return 'NotAFileOrADirectory' } - Context 'Archive entry is a directory and item with the same name exists at the destination but is not a file or a directory' { + Context 'When archive entry is a directory and item with the same name exists at the destination but is not a file or a directory' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -2677,7 +2764,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2716,13 +2803,13 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Get-Item' -MockWith { return $mockDirectory } - Context 'Archive entry is a directory and directory with the same name exists at the destination' { + Context 'When archive entry is a directory and directory with the same name exists at the destination' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -2734,7 +2821,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -2768,7 +2855,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2807,21 +2894,21 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $true + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $true } } Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } Mock -CommandName 'Get-Item' -MockWith { return $null } - Context 'Archive entry is a file and does not exist at destination' { + Context 'When archive entry is a file and does not exist at destination' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -2855,7 +2942,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2889,20 +2976,20 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Get-Item' -MockWith { return $mockDirectory } - Context 'Archive entry is a file and item with the same name exists at the destination but is a directory' { + Context 'When archive entry is a file and item with the same name exists at the destination but is a directory' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -2936,7 +3023,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -2975,20 +3062,20 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Get-Item' -MockWith { return 'NotAFileOrADirectory' } - Context 'Archive entry is a file and item with the same name exists at the destination but is not a file or a directory' { + Context 'When archive entry is a file and item with the same name exists at the destination but is not a file or a directory' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3022,7 +3109,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3061,20 +3148,20 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Get-Item' -MockWith { return $mockFile } - Context 'Archive entry is a file, file with the same name exists at the destination, and a checksum method is not specified' { + Context 'When archive entry is a file, file with the same name exists at the destination, and a checksum method is not specified' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3108,7 +3195,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3147,11 +3234,11 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $true + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $true } } - Context 'Archive entry is a file, file with the same name exists at the destination, and files do not match by the specified checksum method' { + Context 'When archive entry is a file, file with the same name exists at the destination, and files do not match by the specified checksum method' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -3159,7 +3246,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3193,7 +3280,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3240,13 +3327,13 @@ Describe 'Archive Unit Tests' { } It 'Should return false' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $false + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $false } } Mock -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -MockWith { return $true } - Context 'Archive entry is a file, file with the same name exists at the destination, and files match by the specified checksum method' { + Context 'When archive entry is a file, file with the same name exists at the destination, and files match by the specified checksum method' { $testArchiveExistsAtDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -3254,7 +3341,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should Not Throw + { Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3288,7 +3375,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $testArchiveExistsAtDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3335,7 +3422,7 @@ Describe 'Archive Unit Tests' { } It 'Should return true' { - Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should Be $true + Test-ArchiveExistsAtDestination @testArchiveExistsAtDestinationParameters | Should -Be $true } } } @@ -3368,14 +3455,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Get-ArchiveEntryLastWriteTime' -MockWith { return $testArchiveEntryLastWriteTime } Mock -CommandName 'Set-ItemProperty' -MockWith { } - Context 'Archive entry is a directory' { + Context 'When archive entry is a directory' { $copyArchiveEntryToDestinationParameters = @{ ArchiveEntry = $mockArchiveEntry DestinationPath = 'TestDestinationPath' } It 'Should not throw' { - { Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters } | Should Not Throw + { Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters } | Should -Not -Throw } It 'Should retrieve the full name of the specified archive entry' { @@ -3440,7 +3527,7 @@ Describe 'Archive Unit Tests' { It 'Should not attempt to retrieve the last write time of the specified archive entry' { Assert-MockCalled -CommandName 'Get-ArchiveEntryLastWriteTime' -Exactly 0 -Scope 'Context' } - + It 'Should not attempt to set the last write time of the file at the specified destination' { $setItemPropertyParameterFilter = { $nameParameterIsLastWriteTime = $Name -eq 'LastWriteTime' @@ -3469,13 +3556,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters | Should Be $null + Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters | Should -Be $null } } Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } - Context 'Archive entry is not a directory and copying from stream to stream fails' { + Context 'When archive entry is not a directory and copying from stream to stream fails' { $copyArchiveEntryToDestinationParameters = @{ ArchiveEntry = $mockArchiveEntry DestinationPath = 'TestDestinationPath' @@ -3483,20 +3570,20 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for failed copy from the file stream to the archive entry stream' { $expectedErrorMessage = $script:localizedData.ErrorCopyingFromArchiveToDestination -f $copyArchiveEntryToDestinationParameters.DestinationPath - { Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters } | Should Throw $expectedErrorMessage + { Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters } | Should -Throw $expectedErrorMessage } } Mock -CommandName 'Copy-FromStreamToStream' -MockWith { } - Context 'Archive entry is not a directory and copying from stream to stream succeeds' { + Context 'When archive entry is not a directory and copying from stream to stream succeeds' { $copyArchiveEntryToDestinationParameters = @{ ArchiveEntry = $mockArchiveEntry DestinationPath = 'TestDestinationPath' } It 'Should not throw' { - { Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters } | Should Not Throw + { Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters } | Should -Not -Throw } It 'Should retrieve the full name of the specified archive entry' { @@ -3584,7 +3671,7 @@ Describe 'Archive Unit Tests' { Assert-MockCalled -CommandName 'Get-ArchiveEntryLastWriteTime' -ParameterFilter $getArchiveEntryLastWriteTimeParameterFilter -Exactly 1 -Scope 'Context' } - + It 'Should set the last write time of the file at the specified destination' { $setItemPropertyParameterFilter = { $nameParameterIsLastWriteTime = $Name -eq 'LastWriteTime' @@ -3622,12 +3709,12 @@ Describe 'Archive Unit Tests' { } It 'Should not return' { - Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters | Should Be $null + Copy-ArchiveEntryToDestination @copyArchiveEntryToDestinationParameters | Should -Be $null } } } - Describe 'Expand-ArchiveToDestination' { + Describe 'Expand-ArchiveToDestination' { $testArchiveEntryFullName = 'TestArchiveEntryFullName' $testItemPathAtDestination = 'TestItemPathAtDestination' $testParentDirectoryPath = 'TestParentDirectoryPath' @@ -3636,7 +3723,7 @@ Describe 'Archive Unit Tests' { $mockArchiveEntry = New-MockObject -Type 'System.IO.Compression.ZipArchiveEntry' $mockFile = New-MockObject -Type 'System.IO.FileInfo' $mockDirectory = New-MockObject -Type 'System.IO.DirectoryInfo' - + Mock -CommandName 'Open-Archive' -MockWith { return $mockArchive } Mock -CommandName 'Get-ArchiveEntries' -MockWith { return @( $mockArchiveEntry ) } Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } @@ -3651,14 +3738,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Remove-Item' -MockWith { } Mock -CommandName 'Close-Archive' -MockWith { } - Context 'Archive entry is a directory and does not exist at destination' { + Context 'When archive entry is a directory and does not exist at destination' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3692,7 +3779,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3733,10 +3820,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -3758,13 +3845,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockFile } - Context 'Archive entry is a directory, item with the same name exists at the destination but is a file, and Force is not specified' { + Context 'When archive entry is a directory, item with the same name exists at the destination but is a file, and Force is not specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -3772,11 +3859,11 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Throw $errorMessage } } - Context 'Archive entry is a directory, item with the same name exists at the destination but is a file, and Force is specified' { + Context 'When archive entry is a directory, item with the same name exists at the destination but is a file, and Force is specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -3784,7 +3871,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3818,7 +3905,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3859,10 +3946,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -3875,7 +3962,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -3889,13 +3976,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return 'NotAFileOrADirectory' } - Context 'Archive entry is a directory, item with the same name exists at the destination but is not a file or a directory, and Force is not specified' { + Context 'When archive entry is a directory, item with the same name exists at the destination but is not a file or a directory, and Force is not specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -3903,11 +3990,11 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Throw $errorMessage } } - Context 'Archive entry is a directory, item with the same name exists at the destination but is not a file or a directory, and Force is specified' { + Context 'When archive entry is a directory, item with the same name exists at the destination but is not a file or a directory, and Force is specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -3915,7 +4002,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -3949,7 +4036,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -3990,10 +4077,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -4006,7 +4093,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -4020,20 +4107,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockDirectory } - Context 'Archive entry is a directory and directory with the same name exists at the destination' { + Context 'When archive entry is a directory and directory with the same name exists at the destination' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4067,7 +4154,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4126,21 +4213,21 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Test-ArchiveEntryIsDirectory' -MockWith { return $false } Mock -CommandName 'Get-Item' -MockWith { return $null } - Context 'Archive entry is a file and does not exist at destination and the parent directory of the file does not exist' { + Context 'When archive entry is a file and does not exist at destination and the parent directory of the file does not exist' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4174,7 +4261,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4226,7 +4313,7 @@ Describe 'Archive Unit Tests' { return $pathParameterCorrect -and $itemTypeParameterCorrect } - + Assert-MockCalled -CommandName 'New-Item' -ParameterFilter $newItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -4234,10 +4321,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -4259,20 +4346,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Test-Path' -MockWith { return $true } - Context 'Archive entry is a file and does not exist at destination and the parent directory of the file exists' { + Context 'When archive entry is a file and does not exist at destination and the parent directory of the file exists' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4306,7 +4393,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4359,10 +4446,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -4384,13 +4471,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockDirectory } - Context 'Archive entry is a file, item with the same name exists at the destination but is a directory, and Force is not specified' { + Context 'When archive entry is a file, item with the same name exists at the destination but is a directory, and Force is not specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4398,11 +4485,11 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Throw $errorMessage } } - Context 'Archive entry is a file, item with the same name exists at the destination but is a directory, and Force is specified' { + Context 'When archive entry is a file, item with the same name exists at the destination but is a directory, and Force is specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4410,7 +4497,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4444,7 +4531,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4485,10 +4572,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -4501,7 +4588,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -4515,13 +4602,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return 'NotAFileOrADirectory' } - Context 'Archive entry is a file, item with the same name exists at the destination but is not a file or a directory, and Force is not specified' { + Context 'When archive entry is a file, item with the same name exists at the destination but is not a file or a directory, and Force is not specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4529,11 +4616,11 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Throw $errorMessage } } - Context 'Archive entry is a file, item with the same name exists at the destination but is not a file or a directory, and Force is specified' { + Context 'When archive entry is a file, item with the same name exists at the destination but is not a file or a directory, and Force is specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4541,7 +4628,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4575,7 +4662,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4616,10 +4703,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -4632,7 +4719,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -4646,20 +4733,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockFile } - Context 'Archive entry is a file, file with the same name exists at the destination, and a checksum method is not specified' { + Context 'When archive entry is a file, file with the same name exists at the destination, and a checksum method is not specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4693,7 +4780,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4752,11 +4839,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } - Context 'Archive entry is a file, file with the same name exists at the destination, files do not match by the specified checksum method, and Force is not specified' { + Context 'When archive entry is a file, file with the same name exists at the destination, files do not match by the specified checksum method, and Force is not specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4765,11 +4852,11 @@ Describe 'Archive Unit Tests' { It 'Should throw an error for attempting to overwrite an existing item without specifying the Force parameter' { $errorMessage = $script:localizedData.ForceNotSpecifiedToOverwriteItem -f $testItemPathAtDestination, $testArchiveEntryFullName - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Throw $errorMessage + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Throw $errorMessage } } - Context 'Archive entry is a file, file with the same name exists at the destination, files do not match by the specified checksum method, and Force is specified' { + Context 'When archive entry is a file, file with the same name exists at the destination, files do not match by the specified checksum method, and Force is specified' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4778,7 +4865,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4812,7 +4899,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4853,10 +4940,10 @@ Describe 'Archive Unit Tests' { $copyArchiveEntryToDestinationParameterFilter = { $archiveEntryParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mockArchiveEntry -DifferenceObject $ArchiveEntry) $destinationPathParameterCorrect = $DestinationPath -eq $testItemPathAtDestination - + return $archiveEntryParameterCorrect -and $destinationPathParameterCorrect } - + Assert-MockCalled -CommandName 'Copy-ArchiveEntryToDestination' -ParameterFilter $copyArchiveEntryToDestinationParameterFilter -Exactly 1 -Scope 'Context' } @@ -4868,8 +4955,8 @@ Describe 'Archive Unit Tests' { return $fileParameterCorrect -and $archiveEntryParameterCorrect -and $checksumParameterCorrect } - - Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -ParameterFilter $testFileMatchesArchiveEntryByChecksumParameterFilter -Exactly 1 -Scope 'Context' + + Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 1 -Scope 'Context' } It 'Should remove the existing item at the desired path of the archive entry at the destination' { @@ -4877,7 +4964,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -4891,13 +4978,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } Mock -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -MockWith { return $true } - Context 'Archive entry is a file, file with the same name exists at the destination, and files match by the specified checksum method' { + Context 'When archive entry is a file, file with the same name exists at the destination, and files match by the specified checksum method' { $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -4905,7 +4992,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should Not Throw + { Expand-ArchiveToDestination @expandArchiveToDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -4939,7 +5026,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $expandArchiveToDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -4988,7 +5075,7 @@ Describe 'Archive Unit Tests' { return $fileParameterCorrect -and $archiveEntryParameterCorrect -and $checksumParameterCorrect } - + Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -ParameterFilter $testFileMatchesArchiveEntryByChecksumParameterFilter -Exactly 1 -Scope 'Context' } @@ -5006,7 +5093,7 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should Be $null + Expand-ArchiveToDestination @expandArchiveToDestinationParameters | Should -Be $null } } } @@ -5022,14 +5109,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Get-ChildItem' -MockWith { return $null } Mock -CommandName 'Remove-Item' -MockWith { } - Context 'Specified directory does not exist at the specified destination' { + Context 'When specified directory does not exist at the specified destination' { $removeDirectoryFromDestination = @{ Directory = @( 'TestDirectory' ) Destination = 'TestDestination' } It 'Should not throw' { - { Remove-DirectoryFromDestination @removeDirectoryFromDestination } | Should Not Throw + { Remove-DirectoryFromDestination @removeDirectoryFromDestination } | Should -Not -Throw } It 'Should sort the specified list of directories' { @@ -5051,7 +5138,7 @@ Describe 'Archive Unit Tests' { return $pathParameterCorrect -and $childPathParameterCorrect } - + Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -5073,20 +5160,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-DirectoryFromDestination @removeDirectoryFromDestination | Should Be $null + Remove-DirectoryFromDestination @removeDirectoryFromDestination | Should -Be $null } } Mock -CommandName 'Test-Path' -MockWith { return $true } - Context 'Specified directory exists at the specified destination and does not have child items' { + Context 'When specified directory exists at the specified destination and does not have child items' { $removeDirectoryFromDestination = @{ Directory = @( 'TestDirectory' ) Destination = 'TestDestination' } It 'Should not throw' { - { Remove-DirectoryFromDestination @removeDirectoryFromDestination } | Should Not Throw + { Remove-DirectoryFromDestination @removeDirectoryFromDestination } | Should -Not -Throw } It 'Should sort the specified list of directories' { @@ -5108,7 +5195,7 @@ Describe 'Archive Unit Tests' { return $pathParameterCorrect -and $childPathParameterCorrect } - + Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -5140,20 +5227,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-DirectoryFromDestination @removeDirectoryFromDestination | Should Be $null + Remove-DirectoryFromDestination @removeDirectoryFromDestination | Should -Be $null } } Mock -CommandName 'Get-ChildItem' -MockWith { return $testDirectoryChildItem } - Context 'Specified directory exists at the specified destination and has child items' { + Context 'When specified directory exists at the specified destination and has child items' { $removeDirectoryFromDestination = @{ Directory = @( 'TestDirectory' ) Destination = 'TestDestination' } It 'Should not throw' { - { Remove-DirectoryFromDestination @removeDirectoryFromDestination } | Should Not Throw + { Remove-DirectoryFromDestination @removeDirectoryFromDestination } | Should -Not -Throw } It 'Should sort the specified list of directories' { @@ -5175,7 +5262,7 @@ Describe 'Archive Unit Tests' { return $pathParameterCorrect -and $childPathParameterCorrect } - + Assert-MockCalled -CommandName 'Join-Path' -ParameterFilter $joinPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -5202,11 +5289,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-DirectoryFromDestination @removeDirectoryFromDestination | Should Be $null + Remove-DirectoryFromDestination @removeDirectoryFromDestination | Should -Be $null } } } - + Describe 'Remove-ArchiveFromDestination' { $testArchiveEntryFullName = 'TestArchiveEntryFullName' $testItemPathAtDestination = 'TestItemPathAtDestination' @@ -5216,7 +5303,7 @@ Describe 'Archive Unit Tests' { $mockArchiveEntry = New-MockObject -Type 'System.IO.Compression.ZipArchiveEntry' $mockFile = New-MockObject -Type 'System.IO.FileInfo' $mockDirectory = New-MockObject -Type 'System.IO.DirectoryInfo' - + Mock -CommandName 'Open-Archive' -MockWith { return $mockArchive } Mock -CommandName 'Get-ArchiveEntries' -MockWith { return @( $mockArchiveEntry ) } Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } @@ -5229,14 +5316,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Remove-DirectoryFromDestination' -MockWith { } Mock -CommandName 'Close-Archive' -MockWith { } - Context 'Archive entry is a directory and does not exist at destination' { + Context 'When archive entry is a directory and does not exist at destination' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5270,7 +5357,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5321,20 +5408,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockFile } - Context 'Archive entry is a directory, item with the same name exists at the destination but is a file' { + Context 'When archive entry is a directory, item with the same name exists at the destination but is a file' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5368,7 +5455,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5419,20 +5506,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return 'NotAFileOrADirectory' } - Context 'Archive entry is a directory and item with the same name exists at the destination but is not a file or a directory' { + Context 'When archive entry is a directory and item with the same name exists at the destination but is not a file or a directory' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5466,7 +5553,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5517,20 +5604,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockDirectory } - Context 'Archive entry is a directory and directory with the same name exists at the root of the destination' { + Context 'When archive entry is a directory and directory with the same name exists at the root of the destination' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5564,7 +5651,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5603,7 +5690,7 @@ Describe 'Archive Unit Tests' { $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } - + Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -5636,7 +5723,7 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } @@ -5647,14 +5734,14 @@ Describe 'Archive Unit Tests' { } } - Context 'Archive entry is a directory and directory with the same name exists within a parent directory at the destination' { + Context 'When archive entry is a directory and directory with the same name exists within a parent directory at the destination' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5688,7 +5775,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5727,7 +5814,7 @@ Describe 'Archive Unit Tests' { $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } - + Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -5751,7 +5838,7 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } @@ -5759,14 +5846,14 @@ Describe 'Archive Unit Tests' { Mock -CommandName 'Get-Item' -MockWith { return $null } Mock -CommandName 'Split-Path' -MockWith { return $null } - Context 'Archive entry is a file and does not exist at destination' { + Context 'When archive entry is a file and does not exist at destination' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5800,7 +5887,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5851,20 +5938,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockDirectory } - Context 'Archive entry is a file and item with the same name exists at the destination but is a directory' { + Context 'When archive entry is a file and item with the same name exists at the destination but is a directory' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5898,7 +5985,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -5949,20 +6036,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return 'NotAFileOrADirectory' } - Context 'Archive entry is a file and item with the same name exists at the destination but is not a file or a directory' { + Context 'When archive entry is a file and item with the same name exists at the destination but is not a file or a directory' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -5996,7 +6083,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -6047,20 +6134,20 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Get-Item' -MockWith { return $mockFile } - Context 'Archive entry is a file, file with the same name exists at the root of the destination, and a checksum method is not specified' { + Context 'When archive entry is a file, file with the same name exists at the root of the destination, and a checksum method is not specified' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -6094,7 +6181,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -6128,7 +6215,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -6138,7 +6225,7 @@ Describe 'Archive Unit Tests' { $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } - + Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -6165,7 +6252,7 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } @@ -6176,14 +6263,14 @@ Describe 'Archive Unit Tests' { } } - Context 'Archive entry is a file, file with the same name exists within a parent directory at the destination, and a checksum method is not specified' { + Context 'When archive entry is a file, file with the same name exists within a parent directory at the destination, and a checksum method is not specified' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -6217,7 +6304,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -6251,7 +6338,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -6261,7 +6348,7 @@ Describe 'Archive Unit Tests' { $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } - + Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -6294,11 +6381,11 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } - Context 'Archive entry is a file, file with the same name exists at the destination, and files do not match by the specified checksum method' { + Context 'When archive entry is a file, file with the same name exists at the destination, and files do not match by the specified checksum method' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -6306,7 +6393,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -6340,7 +6427,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -6373,8 +6460,8 @@ Describe 'Archive Unit Tests' { return $fileParameterCorrect -and $archiveEntryParameterCorrect -and $checksumParameterCorrect } - - Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -ParameterFilter $testFileMatchesArchiveEntryByChecksumParameterFilter -Exactly 1 -Scope 'Context' + + Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 1 -Scope 'Context' } It 'Should not attempt to remove an existing file at the desired path of the archive entry at the destination' { @@ -6399,13 +6486,13 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } Mock -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -MockWith { return $true } - Context 'Archive entry is a file, file with the same name exists at the destination, and files match by the specified checksum method' { + Context 'When archive entry is a file, file with the same name exists at the destination, and files match by the specified checksum method' { $removeArchiveFromDestinationParameters = @{ ArchiveSourcePath = 'TestArchiveSourcePath' Destination = 'TestDestination' @@ -6413,7 +6500,7 @@ Describe 'Archive Unit Tests' { } It 'Should not throw' { - { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should Not Throw + { Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters } | Should -Not -Throw } It 'Should open the archive' { @@ -6447,7 +6534,7 @@ Describe 'Archive Unit Tests' { $joinPathParameterFilter = { $pathParameterCorrect = $Path -eq $removeArchiveFromDestinationParameters.Destination $childPathParameterCorrect = $ChildPath -eq $testArchiveEntryFullName - + return $pathParameterCorrect -and $childPathParameterCorrect } @@ -6480,8 +6567,8 @@ Describe 'Archive Unit Tests' { return $fileParameterCorrect -and $archiveEntryParameterCorrect -and $checksumParameterCorrect } - - Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -ParameterFilter $testFileMatchesArchiveEntryByChecksumParameterFilter -Exactly 1 -Scope 'Context' + + Assert-MockCalled -CommandName 'Test-FileMatchesArchiveEntryByChecksum' -Exactly 1 -Scope 'Context' } It 'Should remove the file at the desired path of the archive entry at the destination' { @@ -6489,7 +6576,7 @@ Describe 'Archive Unit Tests' { $literalPathParameterCorrect = $LiteralPath -eq $testItemPathAtDestination return $literalPathParameterCorrect } - + Assert-MockCalled -CommandName 'Remove-Item' -ParameterFilter $removeItemParameterFilter -Exactly 1 -Scope 'Context' } @@ -6499,7 +6586,7 @@ Describe 'Archive Unit Tests' { $parentParameterCorrect = $Parent -eq $true return $pathParameterCorrect -and $parentParameterCorrect } - + Assert-MockCalled -CommandName 'Split-Path' -ParameterFilter $splitPathParameterFilter -Exactly 1 -Scope 'Context' } @@ -6532,7 +6619,7 @@ Describe 'Archive Unit Tests' { } It 'Should not return anything' { - Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should Be $null + Remove-ArchiveFromDestination @removeArchiveFromDestinationParameters | Should -Be $null } } } From 1f4888dd6eec36f197bd9cdaf41dd1c1bec232cf Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 12 Jan 2019 18:25:00 +1300 Subject: [PATCH 3/7] Clean up README.MD links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e985010..bb55002 100644 --- a/README.md +++ b/README.md @@ -597,9 +597,9 @@ The following parameters will be the same for each process in the set: * Fixed style guideline violations in `CommonResourceHelper.psm1`. * Updated 'appveyor.yml' to meet more recent standards. * Removed OS image version from 'appveyor.yml' to use default image - ([Issue #127](https://github.com/PowerShell/PSDscResources/issues/127). + ([Issue #127](https://github.com/PowerShell/PSDscResources/issues/127)). * Removed code to install WMF5.1 from 'appveyor.yml' because it is already - installed in AppVeyor images ([Issue #128](https://github.com/PowerShell/PSDscResources/issues/128). + installed in AppVeyor images ([Issue #128](https://github.com/PowerShell/PSDscResources/issues/128)). * Removed .vscode from .gitignore so that Visual Studio code environment settings can be committed. From cf681adc2eff3a7cd981463f94c40f4c78b32599 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 19 Jan 2019 15:52:16 +1100 Subject: [PATCH 4/7] Correct Get-TimestampFromFile to actually return DateTime --- DscResources/MSFT_Archive/MSFT_Archive.psm1 | 2 +- README.md | 5 +++-- Tests/Unit/MSFT_Archive.Tests.ps1 | 14 ++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/DscResources/MSFT_Archive/MSFT_Archive.psm1 b/DscResources/MSFT_Archive/MSFT_Archive.psm1 index 3ceea92..f477867 100644 --- a/DscResources/MSFT_Archive/MSFT_Archive.psm1 +++ b/DscResources/MSFT_Archive/MSFT_Archive.psm1 @@ -1042,7 +1042,7 @@ function Get-TimestampFromFile $Timestamp ) - return $File.$Timestamp.DateTime + return $File.$Timestamp } <# diff --git a/README.md b/README.md index bb55002..69ab2c4 100644 --- a/README.md +++ b/README.md @@ -583,8 +583,9 @@ The following parameters will be the same for each process in the set: * Update integration tests to meet Pester 4.0.0 standards. * Update end-to-end tests to meet Pester 4.0.0 standards. * Update unit and integration tests to meet Pester 4.0.0 standards. - * Wrapped all verbose message parameters with quotes to make identifying - actual paths possible. + * Wrapped all path and identifier strings in verbose messages with + quotes to make it easier to identify the limit of the string when + debugging. * Refactored date/time checksum code to improve testability and ensure tests can run on machines with localized datetime formats that are not US. diff --git a/Tests/Unit/MSFT_Archive.Tests.ps1 b/Tests/Unit/MSFT_Archive.Tests.ps1 index 1cf72c4..c520483 100644 --- a/Tests/Unit/MSFT_Archive.Tests.ps1 +++ b/Tests/Unit/MSFT_Archive.Tests.ps1 @@ -2095,10 +2095,8 @@ Describe 'Archive Unit Tests' { Describe 'Get-ChecksumFromFileTimestamp' { $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) - $testFileCreationTime = $testFileInfo.CreationTime.DateTime - $testFileLastWriteTime = $testFileInfo.LastWriteTime.DateTime - $testFileCreationTimeChecksum = (Get-Date -Date $testFileCreationTime -Format 'G') - $testFileLastWriteTimeChecksum = (Get-Date -Date $testFileLastWriteTime -Format 'G') + $testFileCreationTimeChecksum = (Get-Date -Date $testFileInfo.CreationTime -Format 'G') + $testFileLastWriteTimeChecksum = (Get-Date -Date $testFileInfo.LastWriteTime -Format 'G') Context 'When checksum specified as CreatedDate' { $getChecksumFromFileTimestampParameters = @{ @@ -2145,7 +2143,7 @@ Describe 'Archive Unit Tests' { } It 'Should return the creation time of the file as a Checksum' { - Get-TimestampForChecksum @getTimestampForChecksumParameters | Should -Be $testFileInfo.CreationTime.DateTime + Get-TimestampForChecksum @getTimestampForChecksumParameters | Should -Be $testFileInfo.CreationTime } } @@ -2160,7 +2158,7 @@ Describe 'Archive Unit Tests' { } It 'Should return the last write time of the file' { - Get-TimestampForChecksum @getTimestampForChecksumParameters | Should -Be $testFileInfo.LastWriteTime.DateTime + Get-TimestampForChecksum @getTimestampForChecksumParameters | Should -Be $testFileInfo.LastWriteTime } } } @@ -2179,7 +2177,7 @@ Describe 'Archive Unit Tests' { } It 'Should return the creation time of the file as a Checksum' { - Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.CreationTime.DateTime + Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.CreationTime } } @@ -2194,7 +2192,7 @@ Describe 'Archive Unit Tests' { } It 'Should return the creation time of the file as a Checksum' { - Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.LastWriteTime.DateTime + Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.LastWriteTime } } } From 0242063403226533de2a1bffcbf9b5de012f17fa Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 19 Jan 2019 16:01:15 +1100 Subject: [PATCH 5/7] Convert Archive unit tests to use TestDrive --- Tests/Unit/MSFT_Archive.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Unit/MSFT_Archive.Tests.ps1 b/Tests/Unit/MSFT_Archive.Tests.ps1 index c520483..90b5378 100644 --- a/Tests/Unit/MSFT_Archive.Tests.ps1 +++ b/Tests/Unit/MSFT_Archive.Tests.ps1 @@ -2094,7 +2094,7 @@ Describe 'Archive Unit Tests' { } Describe 'Get-ChecksumFromFileTimestamp' { - $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) + $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $TestDrive ) $testFileCreationTimeChecksum = (Get-Date -Date $testFileInfo.CreationTime -Format 'G') $testFileLastWriteTimeChecksum = (Get-Date -Date $testFileInfo.LastWriteTime -Format 'G') @@ -2130,7 +2130,7 @@ Describe 'Archive Unit Tests' { } Describe 'Get-TimestampForChecksum' { - $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) + $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $TestDrive ) Context 'When checksum specified as CreatedDate' { $getTimestampForChecksumParameters = @{ @@ -2164,7 +2164,7 @@ Describe 'Archive Unit Tests' { } Describe 'Get-TimestampFromFile' { - $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) + $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $TestDrive ) Context 'When Timestamp specified as CreationTime' { $getTimestampFromFileParameters = @{ @@ -2224,7 +2224,7 @@ Describe 'Archive Unit Tests' { $mockArchiveEntry = New-MockObject -Type 'System.IO.Compression.ZipArchiveEntry' # This is the actual file info of this file since we cannot set the properties of mock objects - $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $PSScriptRoot ) + $testFileInfo = New-Object -TypeName 'System.IO.FileInfo' -ArgumentList @( $TestDrive ) $testFileFullName = $testFileInfo.FullName Mock -CommandName 'Get-ArchiveEntryFullName' -MockWith { return $testArchiveEntryFullName } From 68cdc85e1060c7a2ef3963d3ba8b54522ce7e1bf Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 19 Jan 2019 22:46:25 +1100 Subject: [PATCH 6/7] Correct the name of xArchive unit test --- Tests/Unit/MSFT_Archive.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_Archive.Tests.ps1 b/Tests/Unit/MSFT_Archive.Tests.ps1 index 90b5378..e1572c1 100644 --- a/Tests/Unit/MSFT_Archive.Tests.ps1 +++ b/Tests/Unit/MSFT_Archive.Tests.ps1 @@ -2191,7 +2191,7 @@ Describe 'Archive Unit Tests' { { $null = Get-TimestampFromFile @getTimestampFromFileParameters } | Should -Not -Throw } - It 'Should return the creation time of the file as a Checksum' { + It 'Should return the last write time of the file as a Checksum' { Get-TimestampFromFile @getTimestampFromFileParameters | Should -Be $testFileInfo.LastWriteTime } } From e4f011e99954ed008119f59fe1a04e557e40e43d Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 20 Jan 2019 19:27:31 +1100 Subject: [PATCH 7/7] Update CommonResourceHelper and ResourceHelper tests to Pester 4 standards --- README.md | 4 ++++ Tests/Unit/CommonResourceHelper.Tests.ps1 | 28 +++++++++++------------ Tests/Unit/ResourceSetHelper.Tests.ps1 | 20 ++++++++-------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 69ab2c4..8cb271a 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,10 @@ The following parameters will be the same for each process in the set: ### Unreleased +* Update `CommonResourceHelper` unit tests to meet Pester 4.0.0 + standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)). +* Update `ResourceHelper` unit tests to meet Pester 4.0.0 + standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)). * Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration): * xArchive * Fix end-to-end tests. diff --git a/Tests/Unit/CommonResourceHelper.Tests.ps1 b/Tests/Unit/CommonResourceHelper.Tests.ps1 index 62953f1..241c18f 100644 --- a/Tests/Unit/CommonResourceHelper.Tests.ps1 +++ b/Tests/Unit/CommonResourceHelper.Tests.ps1 @@ -34,7 +34,7 @@ Describe 'CommonResourceHelper Unit Tests' { Context 'Get-ComputerInfo command exists and succeeds' { Context 'Computer OS type is Server and OS server level is NanoServer' { It 'Should not throw' { - { $null = Test-IsNanoServer } | Should Not Throw + { $null = Test-IsNanoServer } | Should -Not -Throw } It 'Should test if the Get-ComputerInfo command exists' { @@ -50,7 +50,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return true' { - Test-IsNanoServer | Should Be $true + Test-IsNanoServer | Should -Be $true } } @@ -58,7 +58,7 @@ Describe 'CommonResourceHelper Unit Tests' { Mock -CommandName 'Get-ComputerInfo' -MockWith { return $testComputerInfoServerNotNano } It 'Should not throw' { - { $null = Test-IsNanoServer } | Should Not Throw + { $null = Test-IsNanoServer } | Should -Not -Throw } It 'Should test if the Get-ComputerInfo command exists' { @@ -74,7 +74,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return false' { - Test-IsNanoServer | Should Be $false + Test-IsNanoServer | Should -Be $false } } @@ -82,7 +82,7 @@ Describe 'CommonResourceHelper Unit Tests' { Mock -CommandName 'Get-ComputerInfo' -MockWith { return $testComputerInfoNotServer } It 'Should not throw' { - { $null = Test-IsNanoServer } | Should Not Throw + { $null = Test-IsNanoServer } | Should -Not -Throw } It 'Should test if the Get-ComputerInfo command exists' { @@ -98,7 +98,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return false' { - Test-IsNanoServer | Should Be $false + Test-IsNanoServer | Should -Be $false } } } @@ -107,7 +107,7 @@ Describe 'CommonResourceHelper Unit Tests' { Mock -CommandName 'Get-ComputerInfo' -MockWith { return $null } It 'Should not throw' { - { $null = Test-IsNanoServer } | Should Not Throw + { $null = Test-IsNanoServer } | Should -Not -Throw } It 'Should test if the Get-ComputerInfo command exists' { @@ -123,7 +123,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return false' { - Test-IsNanoServer | Should Be $false + Test-IsNanoServer | Should -Be $false } } @@ -131,7 +131,7 @@ Describe 'CommonResourceHelper Unit Tests' { Mock -CommandName 'Test-CommandExists' -MockWith { return $false } It 'Should not throw' { - { $null = Test-IsNanoServer } | Should Not Throw + { $null = Test-IsNanoServer } | Should -Not -Throw } It 'Should test if the Get-ComputerInfo command exists' { @@ -147,7 +147,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return false' { - Test-IsNanoServer | Should Be $false + Test-IsNanoServer | Should -Be $false } } } @@ -159,7 +159,7 @@ Describe 'CommonResourceHelper Unit Tests' { Context 'Get-Command returns the command' { It 'Should not throw' { - { $null = Test-CommandExists -Name $testCommandName } | Should Not Throw + { $null = Test-CommandExists -Name $testCommandName } | Should -Not -Throw } It 'Should retrieve the command with the specified name' { @@ -171,7 +171,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return true' { - Test-CommandExists -Name $testCommandName | Should Be $true + Test-CommandExists -Name $testCommandName | Should -Be $true } } @@ -179,7 +179,7 @@ Describe 'CommonResourceHelper Unit Tests' { Mock -CommandName 'Get-Command' -MockWith { return $null } It 'Should not throw' { - { $null = Test-CommandExists -Name $testCommandName } | Should Not Throw + { $null = Test-CommandExists -Name $testCommandName } | Should -Not -Throw } It 'Should retrieve the command with the specified name' { @@ -191,7 +191,7 @@ Describe 'CommonResourceHelper Unit Tests' { } It 'Should return false' { - Test-CommandExists -Name $testCommandName | Should Be $false + Test-CommandExists -Name $testCommandName | Should -Be $false } } } diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 548dd5e..6459b9c 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -21,7 +21,7 @@ InModuleScope 'ResourceSetHelper' { $keyParameterName = 'Name' $commonParameterString = New-ResourceSetCommonParameterString -KeyParameterName $keyParameterName -Parameters $parameters - $commonParameterString | Should Be "CommonStringParameter1 = `"CommonParameter1`"`r`n" + $commonParameterString | Should -Be "CommonStringParameter1 = `"CommonParameter1`"`r`n" } It 'Should return string containing one variable reference for one credential common parameter' { @@ -36,7 +36,7 @@ InModuleScope 'ResourceSetHelper' { $keyParameterName = 'Name' $commonParameterString = New-ResourceSetCommonParameterString -KeyParameterName $keyParameterName -Parameters $parameters - $commonParameterString | Should Be "CommonCredentialParameter1 = `$CommonCredentialParameter1`r`n" + $commonParameterString | Should -Be "CommonCredentialParameter1 = `$CommonCredentialParameter1`r`n" } It 'Should return string containing all parameters for two string common parameters and two int common parameters' { @@ -51,10 +51,10 @@ InModuleScope 'ResourceSetHelper' { $keyParameterName = 'Name' $commonParameterString = New-ResourceSetCommonParameterString -KeyParameterName $keyParameterName -Parameters $parameters - $commonParameterString.Contains("CommonStringParameter1 = `"CommonParameter1`"`r`n") | Should Be $true - $commonParameterString.Contains("CommonStringParameter2 = `"CommonParameter2`"`r`n") | Should Be $true - $commonParameterString.Contains("CommonIntParameter1 = `$CommonIntParameter1`r`n") | Should Be $true - $commonParameterString.Contains("CommonIntParameter2 = `$CommonIntParameter2`r`n") | Should Be $true + $commonParameterString.Contains("CommonStringParameter1 = `"CommonParameter1`"`r`n") | Should -Be $true + $commonParameterString.Contains("CommonStringParameter2 = `"CommonParameter2`"`r`n") | Should -Be $true + $commonParameterString.Contains("CommonIntParameter1 = `$CommonIntParameter1`r`n") | Should -Be $true + $commonParameterString.Contains("CommonIntParameter2 = `$CommonIntParameter2`r`n") | Should -Be $true } } @@ -69,7 +69,7 @@ InModuleScope 'ResourceSetHelper' { It 'Should return string with module import and one resource for one key value' { $resourceString = New-ResourceSetConfigurationString @newResourceSetConfigurationStringParams - $resourceString | Should Be ("Import-DscResource -Name ResourceName -ModuleName ModuleName`r`n" + ` + $resourceString | Should -Be ("Import-DscResource -Name ResourceName -ModuleName ModuleName`r`n" + ` "ResourceName Resource0`r`n{`r`nName = `"KeyValue1`"`r`n$($newResourceSetConfigurationStringParams['CommonParameterString'])}`r`n") } @@ -77,7 +77,7 @@ InModuleScope 'ResourceSetHelper' { It 'Should return string with module import and two resources for two key values' { $resourceString = New-ResourceSetConfigurationString @newResourceSetConfigurationStringParams - $resourceString | Should Be ("Import-DscResource -Name ResourceName -ModuleName ModuleName`r`n" + ` + $resourceString | Should -Be ("Import-DscResource -Name ResourceName -ModuleName ModuleName`r`n" + ` "ResourceName Resource0`r`n{`r`nName = `"KeyValue1`"`r`n$($newResourceSetConfigurationStringParams['CommonParameterString'])}`r`n" + ` "ResourceName Resource1`r`n{`r`nName = `"KeyValue2`"`r`n$($newResourceSetConfigurationStringParams['CommonParameterString'])}`r`n") } @@ -104,11 +104,11 @@ InModuleScope 'ResourceSetHelper' { $newResourceSetConfigurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams It 'Should return a ScriptBlock' { - $newResourceSetConfigurationScriptBlock -is [ScriptBlock] | Should Be $true + $newResourceSetConfigurationScriptBlock -is [ScriptBlock] | Should -Be $true } It 'Should return ScriptBlock of string returned from New-ResourceSetConfigurationString' { - $newResourceSetConfigurationScriptBlock | Should Match ([ScriptBlock]::Create($configurationString)) + $newResourceSetConfigurationScriptBlock | Should -Match ([ScriptBlock]::Create($configurationString)) } It 'Should call New-ResourceSetConfigurationString with the correct ModuleName' {