-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19_MethodOverloading.Tests.ps1
More file actions
77 lines (66 loc) · 2.53 KB
/
19_MethodOverloading.Tests.ps1
File metadata and controls
77 lines (66 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 19_MethodOverloading.Tests.ps1
# Pester 5.x tests for OverloadDemo Hash method overloads
using module Pester
Describe "OverloadDemo - Method Overloading Resolution" {
BeforeAll {
. "$PSScriptRoot/19_MethodOverloading.ps1"
$demo = [OverloadDemo]::new()
$helloBytes = [System.Text.Encoding]::UTF8.GetBytes("hello")
$sha256 = [System.Security.Cryptography.SHA256]::Create()
$script:expectedHelloHash = $sha256.ComputeHash($helloBytes)
$sha256.Dispose()
}
Context "Overload 1: Hash([string])" {
It "Hashes string correctly via UTF8 encoding" {
$result = $demo.Hash("hello")
$result | Should -Be $script:expectedHelloHash
}
It "Coerces int to string (42 becomes '42')" {
$result = $demo.Hash(42)
$expected = $demo.Hash("42")
$result | Should -Be $expected
}
}
Context "Overload 2: Hash([byte[]])" {
It "Hashes byte array directly" {
$result = $demo.Hash($helloBytes)
$result | Should -Be $script:expectedHelloHash
}
It "Handles empty byte array" {
$emptyBytes = [byte[]]::new(0)
$result = $demo.Hash($emptyBytes)
$result.Length | Should -Be 32
}
}
Context "Overload 3: Hash([System.IO.Stream])" {
It "Hashes MemoryStream correctly" {
$stream = [System.IO.MemoryStream]::new($helloBytes)
$result = $demo.Hash($stream)
$result | Should -Be $script:expectedHelloHash
}
}
Context "Overload 4: Hash([System.IO.FileInfo])" {
It "Hashes file content correctly" {
$tempFile = [System.IO.Path]::GetTempFileName()
[System.IO.File]::WriteAllText($tempFile, "hello")
$fileInfo = [System.IO.FileInfo]::new($tempFile)
$result = $demo.Hash($fileInfo)
$result | Should -Be $script:expectedHelloHash
Remove-Item $tempFile -Force
}
}
Context "Null Ambiguity Tests (PS 7.4.6 arm64)" {
It "Hash(null) throws ambiguous overload exception" {
$demo = [OverloadDemo]::new()
{ $demo.Hash($null) } | Should -Throw
}
It "Hash([string]$null) hashes empty string" {
$result = $demo.Hash([string]$null)
$emptyStringHash = $demo.Hash("")
$result | Should -Be $emptyStringHash
}
It "Hash([byte[]]$null) throws inside SHA256" {
{ $demo.Hash([byte[]]$null) } | Should -Throw
}
}
}