generated from brianary/PSModuleTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectHtml.Tests.ps1
74 lines (73 loc) · 4.37 KB
/
SelectHtml.Tests.ps1
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
# Pester tests, see https://github.com/Pester/Pester/wiki
Import-LocalizedData -BindingVariable manifest -BaseDirectory ./src/* -FileName (Split-Path $PWD -Leaf)
$psd1 = Resolve-Path ./src/*/bin/Debug/*/*.psd1
if(1 -lt ($psd1 |Measure-Object).Count) {throw "Too many module binaries found: $psd1"}
$module = Import-Module "$psd1" -PassThru -vb
Describe $module.Name {
Context "$($module.Name) module" -Tag Module {
It "Given the module, the version should match the manifest version" {
$module.Version |Should -BeExactly $manifest.ModuleVersion
}
It "Given the module, the DLL file version should match the manifest version" {
(Get-Item "$($module.ModuleBase)\$($module.Name).dll").VersionInfo.FileVersionRaw |
Should -BeLike "$($manifest.ModuleVersion)*"
}
It "Given the module, the DLL product version should match the manifest version" {
(Get-Item "$($module.ModuleBase)\$($module.Name).dll").VersionInfo.ProductVersionRaw |
Should -BeLike "$($manifest.ModuleVersion)*"
} -Pending
It "Given the module, the DLL should have a valid semantic product version" {
$v = (Get-Item "$($module.ModuleBase)\$($module.Name).dll").VersionInfo.ProductVersion
[semver]::TryParse($v, [ref]$null) |Should -BeTrue
} -Pending
}
Context 'Select-Html cmdlet' -Tag Cmdlet,Select-Html {
It "Given XPath '<XPath>' and HTML '<Html>', '<Expected>' should be returned." -TestCases @(
@{ XPath = '//title'; Html = '<!DOCTYPE html><title>Test Title</title><p>'; Expected = 'Test Title' }
@{ XPath = '//title'; Html = '<!DOCTYPE html><title>Other Title</title><p>'; Expected = 'Other Title' }
) {
Param($XPath,$Html,$Expected)
$Html |SelectHtml\Select-Html $XPath -vb |Should -BeExactly $Expected
}
It "Given XPath '<XPath>' and HTML '<Html>', object '<Expected>' should be returned." -TestCases @(
@{ XPath = '/table'; Html = '<table><tbody><tr><th><p><strong>Count</strong></p></th><th><p><strong>Name</strong></p></th>
<th><p><strong>Audience</strong></p></th></tr><tr><td><p>9</p></td><td><p>Accounts</p></td><td><p>Members</p></td></tr>
</tbody></table>'; Expected = [pscustomobject]@{Count=9;Name='Accounts';Audience='Members'} }
) {
Param($XPath,$Html,$Expected)
$selected = $Html |SelectHtml\Select-Html $XPath -vb
$props = $selected.PSObject.Properties.Name
$props |ForEach-Object {$selected.$_ |Should -BeExactly $Expected.$_}
}
It "Given XPath '<XPath>' and file '<Path>', '<Expected>' should be returned." -TestCases @(
@{ XPath = '//title'; Path = "$PSScriptRoot/test/csharp-history.html"; Expected = 'C# History' }
@{ XPath = '//table/thead'; Path = "$PSScriptRoot/test/csharp-history.html"; Expected = '*Feature*' }
) {
Param($XPath,$Path,$Expected)
SelectHtml\Select-Html $XPath -Path $Path -vb |Should -BeLike $Expected
}
It "Given XPath '<XPath>' and file '<Path>', value #<Row> of the result should be '<Expected>'." -TestCases @(
@{ XPath = '//ul[contains(.,"QuickRef")]'; Path = "$PSScriptRoot/test/xslt2.html"; Row = 0; Expected = 'XSLT 2.0 QuickRef*' }
) {
Param($XPath,$Path,$Row,$Expected)
[string[]] $table = SelectHtml\Select-Html $XPath -Path $Path -vb
$table[$Row] |Should -BeLike $Expected
}
It "Given XPath '<XPath>' and file '<Path>', row #<Row> property '<Property>' of the result should be '<Expected>'." -TestCases @(
@{ XPath = '//table'; Path = "$PSScriptRoot/test/csharp-history.html"; Row = 0; Property = 'Feature'; Expected = 'Anonymous methods' }
@{ XPath = '//table'; Path = "$PSScriptRoot/test/csharp-history.html"; Row = 4; Property = 'Version'; Expected = '7.0' }
@{ XPath = '//table'; Path = "$PSScriptRoot/test/csharp-history.html"; Row = 5; Property = 'Released'; Expected = '2010-04-12' }
) {
Param($XPath,$Path,$Row,$Property,$Expected)
[psobject[]] $table = SelectHtml\Select-Html $XPath -Path $Path -vb
$table[$Row].$Property |Should -BeExactly $Expected
}
It "Given XPath '<XPath>' and URL '<Url>', '<Expected>' should be returned." -TestCases @(
@{ XPath = '//section[@id="main_content"]/h1'; Url = 'http://webcoder.info/windowskey.html'; Like = 'Windows Key Shortcuts for Windows*' }
@{ XPath = '//section/p/a'; Url = 'http://webcoder.info/windowskey.html'; Like = 'Windows Key' }
) {
Param($XPath,$Url,$Like)
SelectHtml\Select-Html $XPath -Uri $Url -vb |Should -BeLike $Like
}
}
}.GetNewClosure()