forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PesterConfiguration.Tests.ps1
53 lines (47 loc) · 2.67 KB
/
PesterConfiguration.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
Set-StrictMode -Version Latest
Describe "PesterConfiguration.Format.ps1xml" {
BeforeDiscovery {
$configSections = [PesterConfiguration].Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
}
Context "Testing format data for '<_.FullName>'" -ForEach $configSections {
BeforeAll {
$section = $_
$formatData = Get-FormatData -TypeName $_.FullName
$options = @($section.GetProperties() | Where-Object { $_.PropertyType.IsSubclassOf([Pester.Option]) })
}
It 'Has a single view defined of type ListControl' {
$formatData | Should -Not -BeNullOrEmpty
$formatData.FormatViewDefinition.Count | Should -Be 1
$formatData.FormatViewDefinition[0].Name | Should -BeExactly $section.FullName
$formatData.FormatViewDefinition[0].Control | Should -BeOfType [System.Management.Automation.ListControl]
}
It 'View includes all options' {
$propertiesInView = @($formatData.FormatViewDefinition[0].Control.Entries.Items.DisplayEntry | Where-Object ValueType -eq 'Property')
$propertiesInView.Count | Should -Be $options.Count
$missingOptions = $options.Name | Where-Object { $propertiesInView.Value -notcontains $_ }
$missingOptions | Should -Be @()
}
}
Context "Testing format data for 'Pester.Option[T]'" {
BeforeAll {
$formatData = Get-FormatData -TypeName 'Pester.Option'
$options = [Pester.Option[bool]].GetProperties() | Where-Object Name -notin 'IsModified'
}
It 'Has a single view defined of type TableControl' {
$formatData | Should -Not -BeNullOrEmpty
$formatData.FormatViewDefinition.Count | Should -Be 1
$formatData.FormatViewDefinition[0].Name | Should -BeExactly 'Pester.Option'
$formatData.FormatViewDefinition[0].Control | Should -BeOfType [System.Management.Automation.TableControl]
}
It 'View includes all options' {
$propertiesInView = @($formatData.FormatViewDefinition[0].Control.Rows.Columns.DisplayEntry | Where-Object ValueType -EQ 'Property')
$propertiesInView.Count | Should -Be $options.Count
$missingOptions = $options.Name | Where-Object { $propertiesInView.Value -notcontains $_ }
$missingOptions | Should -Be @()
}
It 'View does not include IsModified' {
$propertiesInView = @($formatData.FormatViewDefinition[0].Control.Rows.Columns.DisplayEntry | Where-Object ValueType -EQ 'Property')
$propertiesInView.Value | Should -Not -Contain 'IsModified'
}
}
}