Skip to content

Commit

Permalink
ConvertTo-DotNetVersionClass
Browse files Browse the repository at this point in the history
Add ValueFromPipelineByPropertyName, add tests
  • Loading branch information
aaronparker committed Sep 23, 2024
1 parent 62fc09c commit c929ef4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions Evergreen/Public/ConvertTo-DotNetVersionClass.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function ConvertTo-DotNetVersionClass {
Mandatory = $true,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
HelpMessage = "A version string to convert to a standard .NET compliant version class.")]
[System.String] $Version
)
Expand Down
32 changes: 32 additions & 0 deletions tests/Public/ConvertTo-DotNetVersionClass.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<#
.SYNOPSIS
Public Pester function tests.
#>
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This OK for the tests files.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification = "Outputs to log host.")]
param ()

BeforeDiscovery {
}

BeforeAll {
}

Describe -Tag "Convert" -Name "ConvertTo-DotNetVersionClass" {
BeforeAll {
$App = Get-EvergreenApp -Name "MicrosoftOneDrive"
}

It "Should return a valid .NET version class" {
{ $App[0] | ConvertTo-DotNetVersionClass } | Should -BeOfType [System.Version]
}

It "Should return a string for a version number that fails to convert" {
{ ConvertTo-DotNetVersionClass -Version "v22-build1" } | Should -BeOfType [System.String]
}

It "Should return the expected string when converting a version string" {
ConvertTo-DotNetVersionClass -Version "v22-build1" | Should -BeExactly "1185050.991806090049.0.0"
}
}

0 comments on commit c929ef4

Please sign in to comment.