From 33889fb852c959dda2990779360c4674e18f0363 Mon Sep 17 00:00:00 2001 From: Robert Toups Date: Fri, 10 Nov 2023 09:47:53 -0500 Subject: [PATCH] Test initial check in --- Tests/ConvertTo-IPv4.Tests.ps1 | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Tests/ConvertTo-IPv4.Tests.ps1 diff --git a/Tests/ConvertTo-IPv4.Tests.ps1 b/Tests/ConvertTo-IPv4.Tests.ps1 new file mode 100644 index 0000000..9662e34 --- /dev/null +++ b/Tests/ConvertTo-IPv4.Tests.ps1 @@ -0,0 +1,38 @@ +$ModuleName = 'IPv4Toolbox' +$script:FunctionName = 'ConvertTo-IPv4' +$ParentPath = Split-Path -Path $PSScriptRoot -Parent +$ModulePath = Join-Path -Path $ParentPath -ChildPath "$($ModuleName).psm1" +Get-Module -Name $ModuleName | + Remove-Module -Force +Import-Module $ModulePath -Force + +InModuleScope $ModuleName { + Describe 'ConvertTo-IPv4 Tests' { + Context "Basic function unit tests for $FunctionName" -Tags @('Build', 'Unit') { + It 'Converts 3232235777 to the correct IPv4 representation' { + $Integer = 3232235777 + $Result = ConvertTo-IPv4 -Integer $Integer + $ExpectedResult = '192.168.1.1' + $Result | Should -Be $ExpectedResult + } + + It 'Converts 2130706433 to the correct IPv4 representation' { + $Integer = 2130706433 + $Result = ConvertTo-IPv4 -Integer $Integer + $ExpectedResult = '127.0.0.1' + $Result | Should -Be $ExpectedResult + } + + It 'Converts 4294967295 to the correct IPv4 representation' { + $Integer = 4294967295 + $Result = ConvertTo-IPv4 -Integer $Integer + $ExpectedResult = '255.255.255.255' + $Result | Should -Be $ExpectedResult + } + + It 'throws an error for invalid input type' { + { ConvertTo-IPv4 -Integer 'NotAnInteger' } | Should -Throw -ExpectedMessage '*Cannot process argument transformation on parameter ''Integer''. Cannot convert value "NotAnInteger" to type "System.Int64". Error: "The input string ''NotAnInteger'' was not in a correct format."*' + } + } + } +}