1+ Clear-Host
2+ Import-Module - Name Pester - Force
3+ Import-Module .\Photo.Shell\Photo.Shell.psm1 - Force
4+
5+ function Get-TestImage {
6+ param (
7+ [Parameter (Mandatory = $false , Position = 0 )]
8+ [System.Drawing.Imaging.ImageFormat ]$Format = [System.Drawing.Imaging.ImageFormat ]::Png
9+ )
10+ $bitmap = [System.Drawing.Bitmap ]::new(1000 , 800 , [System.Drawing.Imaging.PixelFormat ]::Format32bppPArgb)
11+ $graphics = [System.Drawing.Graphics ]::FromImage($bitmap )
12+ $pen1 = [System.Drawing.Pen ]::new([System.Drawing.Color ]::FromKnownColor([System.Drawing.KnownColor ]::Red), 2 )
13+ $graphics.DrawEllipse ($pen1 , 10 , 10 , 900 , 700 )
14+
15+ $result = [System.IO.MemoryStream ]::new()
16+ $bitmap.Save ($result , $Format )
17+ $result.ToArray ()
18+ }
19+
20+ Describe ' Photo.Shell.Tests' {
21+ Context " Get-ImageCodecInfo" {
22+ $testImage = Get-TestImage
23+ $codecInfo = Get-ImageCodecInfo $testImage
24+
25+ It " should not be null" {
26+ $codecInfo | Should -Not - BeNullOrEmpty
27+ }
28+
29+ It " should have valid type" {
30+ $codecInfo | Should - BeOfType [System.Drawing.Imaging.ImageCodecInfo ]
31+ }
32+
33+ It " given img.<Format>, it returns '<Expected>'" - TestCases @ (
34+ @ { Format = [System.Drawing.Imaging.ImageFormat ]::Png; Expected = ' image/png' }
35+ @ { Format = [System.Drawing.Imaging.ImageFormat ]::Jpeg; Expected = ' image/jpeg' }
36+ @ { Format = [System.Drawing.Imaging.ImageFormat ]::Bmp; Expected = ' image/bmp' }
37+ @ { Format = [System.Drawing.Imaging.ImageFormat ]::Gif; Expected = ' image/gif' }
38+ ) {
39+ param ($Format , $Expected )
40+ $img = Get-TestImage - Format $Format
41+ Get-ImageCodecInfo $img | Select-Object - ExpandProperty MimeType | Should - BeExactly $Expected
42+ }
43+ }
44+ }
0 commit comments