Skip to content

Commit 6d03c5d

Browse files
committed
- Finished adding unit tests.
- Made sure the Build number is rolled down when using the BuildSystemsBuildId parameter.
1 parent ee153c6 commit 6d03c5d

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

Set-ProjectFilesClickOnceVersion.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Param
7575
[int]$BuildSystemsBuildId = -1,
7676

7777
[Parameter(Mandatory=$false,HelpMessage="Use and increment the Revision part of the version number stored in the project file.",ParameterSetName="UseFilesRevision")]
78+
[Alias("IncrementRevision")]
7879
[switch]$IncrementProjectFilesRevision = $false,
7980

8081
[Parameter(Mandatory=$false,HelpMessage="When the switch is provided, the ClickOnce Minimum Required Version will be updated to this new version.")]
@@ -230,20 +231,20 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
230231
throw "The version number '$appVersion' does not seem to have valid Major.Minor.Build version parts."
231232
}
232233
$majorMinor = $majorMinorBuildMatch.Groups["MajorMinor"].Value
233-
$build = $majorMinorBuildMatch.Groups["Build"].Value
234-
$revision = -1
234+
[int]$build = $majorMinorBuildMatch.Groups["Build"].Value
235+
[int]$revision = -1
235236

236237
# If a Revision was specified in the Version, get it.
237238
if (![string]::IsNullOrWhiteSpace($majorMinorBuildMatch.Groups["Revision"]))
238239
{
239-
$revision = $majorMinorBuildMatch.Groups["Revision"]
240+
$revision = [int]::Parse($majorMinorBuildMatch.Groups["Revision"])
240241
}
241242

242243
# If we should be using the BuildSystemsBuildId for the Build and Revision.
243244
if ($BuildSystemsBuildId -gt -1)
244245
{
245246
# Use a calculation for the Build and Revision to prevent the Revision value from being too large, and to increment the Build value as the BuildSystemsBuildId continues to grow larger.
246-
$build = [int]($BuildSystemsBuildId / $maxVersionPartValueAllowed)
247+
$build = [int][Math]::Floor($BuildSystemsBuildId / $maxVersionPartValueAllowed)
247248
$revision = $BuildSystemsBuildId % $maxVersionPartValueAllowed
248249
}
249250

@@ -287,6 +288,7 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
287288
Set-XmlNodesElementTextValue -xml $xml -node $clickOncePropertyGroup -elementName 'ApplicationRevision' -textValue $revision.ToString()
288289
if ($UpdateMinimumRequiredVersionToCurrentVersion)
289290
{
291+
Write-Output "Updating minimum required version to be '$newVersionNumber'."
290292
Set-XmlNodesElementTextValue -xml $xml -node $clickOncePropertyGroup -elementName 'MinimumRequiredVersion' -textValue "$newVersionNumber"
291293
Set-XmlNodesElementTextValue -xml $xml -node $clickOncePropertyGroup -elementName 'UpdateRequired' -textValue 'true'
292294
Set-XmlNodesElementTextValue -xml $xml -node $clickOncePropertyGroup -elementName 'UpdateEnabled' -textValue 'true'

Tests/RunTests.ps1

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,35 @@ function RunScriptWithParameters($parameters)
2828
$output = Invoke-Expression -Command "$($global:runScriptExpression) $parameters"
2929
if ($output -imatch $global:versionNumberAtEndOfOutputRegex)
3030
{
31-
return $matches["Version"]
31+
try
32+
{
33+
return $matches["Version"]
34+
}
35+
# If $output contains multiple lines, it will be treated as a collection instead of a string and $matches will not be defined, so catch that case.
36+
catch { return $output }
3237
}
3338
return $output
3439
}
3540

3641
$testNumber = 0
42+
# Some tests are dependent on the order in which they are ran, which isn't ideal, but good enough for now.
3743

38-
Write-Host ("{0}. Explicitly set version number..." -f ++$testNumber)
44+
Write-Host ("{0}. Use version number parameter..." -f ++$testNumber)
3945
$output = RunScriptWithParameters "-Version '1.2.3.4'"
4046
if ($output -eq '1.2.3.4') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
4147

42-
Write-Host ("{0}. Explicitly set version number..." -f ++$testNumber)
48+
Write-Host ("{0}. Use Build Id parameter..." -f ++$testNumber)
4349
$output = RunScriptWithParameters "-BuildSystemsBuildId 1234"
44-
if ($output -eq '1.2.0.1234') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
50+
if ($output -eq '1.2.0.1234') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
51+
52+
Write-Host ("{0}. Use Build Id parameter greater than the max value to make sure build is set properly..." -f ++$testNumber)
53+
$output = RunScriptWithParameters "-BuildSystemsBuildId 123456"
54+
if ($output -eq '1.2.1.57921') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
55+
56+
Write-Host ("{0}. Use IncrementProjectFilesRevision parameter..." -f ++$testNumber)
57+
$output = RunScriptWithParameters "-IncrementProjectFilesRevision"
58+
if ($output -eq '1.2.1.57922') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
59+
60+
Write-Host ("{0}. Use version number parameter and update minimum required version..." -f ++$testNumber)
61+
$output = RunScriptWithParameters "-Version '5.6.7.8' -UpdateMinimumRequiredVersionToCurrentVersion"
62+
if ($output.Contains("Updating minimum required version to be '5.6.7.8'.")) { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }

0 commit comments

Comments
 (0)