2022-10-23 13:28:55 -05:00
|
|
|
#region Configurable Variables
|
|
|
|
|
|
|
|
<#
|
|
|
|
.NOTES
|
|
|
|
Use this section to configure testing variables. IE if the number of tabs change in the GUI update that variable here.
|
|
|
|
All variables need to be global to be passed between contexts
|
|
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
$global:FormName = "Chris Titus Tech's Windows Utility"
|
|
|
|
|
|
|
|
#endregion Configurable Variables
|
|
|
|
|
|
|
|
#region Load Variables needed for testing
|
|
|
|
|
|
|
|
#Config Files
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:configs = @{}
|
|
|
|
|
|
|
|
(
|
|
|
|
"applications",
|
|
|
|
"tweaks",
|
|
|
|
"preset",
|
|
|
|
"feature"
|
|
|
|
) | ForEach-Object {
|
|
|
|
$global:configs["$PSItem"] = Get-Content .\config\$PSItem.json | ConvertFrom-Json
|
|
|
|
}
|
2022-10-23 13:28:55 -05:00
|
|
|
|
|
|
|
#GUI
|
|
|
|
$global:inputXML = get-content MainWindow.xaml
|
|
|
|
$global:inputXML = $global:inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
|
|
|
|
[xml]$global:XAML = $global:inputXML
|
|
|
|
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
|
|
|
$global:reader = (New-Object System.Xml.XmlNodeReader $global:xaml)
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:Form = [Windows.Markup.XamlReader]::Load( $global:reader )
|
|
|
|
$global:xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name "Global:WPF$($_.Name)" -Value $global:Form.FindName($_.Name) -Scope global }
|
2022-10-23 13:28:55 -05:00
|
|
|
|
|
|
|
#Variables to compare GUI to config files
|
2022-11-14 15:48:10 -06:00
|
|
|
$Global:GUIFeatureCount = ( $global:configs.feature.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"}).count
|
|
|
|
$Global:GUIApplicationCount = ($global:configs.applications.install.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"}).count
|
|
|
|
$Global:GUITweaksCount = ($global:configs.tweaks.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"}).count
|
2022-10-23 13:28:55 -05:00
|
|
|
|
|
|
|
#dotsource original script to pull in all variables and ensure no errors
|
|
|
|
$script = Get-Content .\winutil.ps1
|
2022-11-14 15:48:10 -06:00
|
|
|
$output = $script[0..($script.count - 3)] | Out-File .\pester.ps1
|
2022-10-23 13:28:55 -05:00
|
|
|
|
|
|
|
#endregion Load Variables needed for testing
|
|
|
|
|
|
|
|
#===========================================================================
|
2022-11-14 15:48:10 -06:00
|
|
|
# Tests - Config Files
|
2022-10-23 13:28:55 -05:00
|
|
|
#===========================================================================
|
|
|
|
|
2022-11-14 15:48:10 -06:00
|
|
|
Describe "Config Files" {
|
2022-10-23 13:28:55 -05:00
|
|
|
Context "Application installs" {
|
|
|
|
It "Imports with no errors" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:configs.Applications | should -Not -BeNullOrEmpty
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Json should be in correct format" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$winget = $global:configs.applications.install.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
2022-10-23 13:28:55 -05:00
|
|
|
$winget.name | should -BeLike "*Install*"
|
|
|
|
$winget.winget | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "Preset" {
|
|
|
|
It "Imports with no errors" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:configs.preset | should -Not -BeNullOrEmpty
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Json should be in correct format" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$preset = $global:configs.preset.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
2022-10-23 13:28:55 -05:00
|
|
|
$preset.name | should -Not -BeNullOrEmpty
|
|
|
|
$preset.Value | should -BeLike "*Tweaks*"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "feature" {
|
|
|
|
It "Imports with no errors" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:configs.feature | should -Not -BeNullOrEmpty
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Json should be in correct format" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$feature = $global:configs.feature.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
2022-10-23 13:28:55 -05:00
|
|
|
$feature.name | should -BeLike "*Feature*"
|
|
|
|
$feature.Value | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "tweaks" {
|
|
|
|
It "Imports with no errors" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:configs.tweaks | should -Not -BeNullOrEmpty
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Json should be in correct format" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$tweaks = $global:configs.tweaks.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
2022-10-23 13:28:55 -05:00
|
|
|
$tweaks.name | should -BeLike "*Tweaks*"
|
|
|
|
$tweaks.Value.registry | should -Not -BeNullOrEmpty
|
|
|
|
$tweaks.Value.Service | should -Not -BeNullOrEmpty
|
|
|
|
$tweaks.Value.ScheduledTask | should -Not -BeNullOrEmpty
|
|
|
|
$tweaks.Value.Appx | should -Not -BeNullOrEmpty
|
|
|
|
$tweaks.Value.InvokeScript | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
It "Original Values should be set" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$tweaks = $global:configs.tweaks.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
2022-10-23 13:28:55 -05:00
|
|
|
|
|
|
|
Foreach($tweak in $tweaks){
|
|
|
|
if($tweak.value.registry){
|
|
|
|
|
|
|
|
$values = $tweak.value | Select-Object -ExpandProperty registry
|
|
|
|
|
|
|
|
Foreach ($value in $values){
|
|
|
|
$value.OriginalValue | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($tweak.value.Service){
|
|
|
|
|
|
|
|
$values = $tweak.value | Select-Object -ExpandProperty Service
|
|
|
|
|
|
|
|
Foreach ($value in $values){
|
|
|
|
$value.OriginalType | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($tweak.value.ScheduledTask){
|
|
|
|
|
|
|
|
$values = $tweak.value | Select-Object -ExpandProperty ScheduledTask
|
|
|
|
|
|
|
|
Foreach ($value in $values){
|
|
|
|
$value.OriginalState | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#===========================================================================
|
|
|
|
# Tests - GUI
|
|
|
|
#===========================================================================
|
|
|
|
|
|
|
|
Describe "GUI" {
|
|
|
|
Context "XML" {
|
|
|
|
It "Imports with no errors" {
|
|
|
|
$global:XAML | should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
It "Title should be $global:FormName" {
|
|
|
|
$global:XAML.window.Title | should -Be $global:FormName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "Form" {
|
|
|
|
It "Imports with no errors" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:Form | should -Not -BeNullOrEmpty
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Title should match XML" {
|
2022-11-14 15:48:10 -06:00
|
|
|
$global:Form.title | should -Be $global:XAML.window.Title
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Features should be $Global:GUIFeatureCount" {
|
2022-11-14 15:48:10 -06:00
|
|
|
(get-variable | Where-Object {$psitem.name -like "*feature*" -and $psitem.value.GetType().name -eq "CheckBox"}).count | should -Be $Global:GUIFeatureCount
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Applications should be $Global:GUIApplicationCount" {
|
2022-11-14 15:48:10 -06:00
|
|
|
(get-variable | Where-Object {$psitem.name -like "*install*" -and $psitem.value.GetType().name -eq "CheckBox"}).count | should -Be $Global:GUIApplicationCount
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
It "Tweaks should be $Global:GUITweaksCount" {
|
2022-11-14 15:48:10 -06:00
|
|
|
(get-variable | Where-Object {$psitem.name -like "*tweaks*" -and $psitem.value.GetType().name -eq "CheckBox"}).count | should -Be $Global:GUITweaksCount
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#===========================================================================
|
|
|
|
# Tests - GUI
|
|
|
|
#===========================================================================
|
|
|
|
|
|
|
|
Describe "GUI Functions" {
|
|
|
|
|
|
|
|
It "GUI should load with no errors" {
|
|
|
|
. .\pester.ps1
|
|
|
|
$WPFTab1BT | should -Not -BeNullOrEmpty
|
|
|
|
$WPFundoall | should -Not -BeNullOrEmpty
|
|
|
|
$WPFPanelDISM | should -Not -BeNullOrEmpty
|
|
|
|
$WPFPanelAutologin | should -Not -BeNullOrEmpty
|
|
|
|
$WPFUpdatesdefault | should -Not -BeNullOrEmpty
|
|
|
|
$WPFFixesUpdate | should -Not -BeNullOrEmpty
|
|
|
|
$WPFUpdatesdisable | should -Not -BeNullOrEmpty
|
|
|
|
$WPFUpdatessecurity | should -Not -BeNullOrEmpty
|
|
|
|
$WPFFeatureInstall | should -Not -BeNullOrEmpty
|
|
|
|
$WPFundoall | should -Not -BeNullOrEmpty
|
|
|
|
$WPFDisableDarkMode | should -Not -BeNullOrEmpty
|
|
|
|
$WPFEnableDarkMode | should -Not -BeNullOrEmpty
|
|
|
|
$WPFtweaksbutton | should -Not -BeNullOrEmpty
|
|
|
|
$WPFminimal | should -Not -BeNullOrEmpty
|
|
|
|
$WPFlaptop | should -Not -BeNullOrEmpty
|
|
|
|
$WPFdesktop | should -Not -BeNullOrEmpty
|
|
|
|
$WPFInstallUpgrade | should -Not -BeNullOrEmpty
|
|
|
|
$WPFinstall | should -Not -BeNullOrEmpty
|
|
|
|
}
|
2022-11-14 15:48:10 -06:00
|
|
|
|
|
|
|
It "Get-CheckBoxes Install should return data" {
|
|
|
|
. .\pester.ps1
|
|
|
|
|
2022-11-29 17:27:36 -06:00
|
|
|
$TestCheckBoxes = @(
|
|
|
|
"WPFInstallvc2015_32"
|
|
|
|
"WPFInstallvscode"
|
|
|
|
"WPFInstallgit"
|
|
|
|
)
|
|
|
|
|
|
|
|
$OutputResult = New-Object System.Collections.Generic.List[System.Object]
|
|
|
|
$TestCheckBoxes | ForEach-Object {
|
|
|
|
|
|
|
|
$global:configs.applications.Install.$psitem.winget -split ";" | ForEach-Object {
|
|
|
|
$OutputResult.Add($psitem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$OutputResult = Sort-Object -InputObject $OutputResult
|
|
|
|
|
|
|
|
$TestCheckBoxes | ForEach-Object {(Get-Variable $PSItem).value.ischecked = $true}
|
|
|
|
$Output = Get-CheckBoxes -Group WPFInstall | Sort-Object
|
|
|
|
$Output | should -Not -BeNullOrEmpty -Because "Output did not containe applications to install"
|
|
|
|
$Output | Should -Not -Be $OutputResult -Because "Output contains duplicate values"
|
|
|
|
$Output | Should -Be $($OutputResult | Select-Object -Unique | Sort-Object) -Because "Output doesn't match"
|
|
|
|
$TestCheckBoxes | ForEach-Object {(Get-Variable $PSItem).value.ischecked | should -be $false}
|
2022-11-14 15:48:10 -06:00
|
|
|
}
|
2022-10-23 13:28:55 -05:00
|
|
|
}
|