Skip to content

Commit

Permalink
working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Windos committed Jan 13, 2024
1 parent ad3e8b6 commit ab6429c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 69 deletions.
37 changes: 36 additions & 1 deletion Tests/BurntToast.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,46 @@
Describe 'BurntToast Module' {
Context 'meta validation' {
It 'should import functions' {
(Get-Module BurntToast).ExportedFunctions.Count | Should -Be 25
(Get-Module BurntToast).ExportedFunctions.Count | Should -Be 21
}

It 'should import aliases' {
(Get-Module BurntToast).ExportedAliases.Count | Should -Be 1
}
}

Context 'Importing on Unsupported Operating Systems' {
It 'throws when importing on operating systems older than Windows 10' {
$env:BurntToastPesterNotWindows10 = $true

if (Get-Module -Name 'BurntToast') {
Remove-Module -Name 'BurntToast'
}

if ($ENV:BURNTTOAST_MODULE_ROOT) {
{Import-Module $ENV:BURNTTOAST_MODULE_ROOT -Force} | Should -Throw -ExpectedMessage 'This version of BurntToast will only work on Windows 10.*'
} else {
{Import-Module "$PSScriptRoot/../src/BurntToast.psd1" -Force} | Should -Throw -ExpectedMessage 'This version of BurntToast will only work on Windows 10.*'
}
}

It 'throws when importing on Windows 10 builds older than the Anniversary Update' {
$env:BurntToastPesterNotAnniversaryUpdate = $true

if (Get-Module -Name 'BurntToast') {
Remove-Module -Name 'BurntToast'
}

if ($ENV:BURNTTOAST_MODULE_ROOT) {
{Import-Module $ENV:BURNTTOAST_MODULE_ROOT -Force} | Should -Throw -ExpectedMessage 'This version of BurntToast will only work on Windows 10 Creators Update (15063) and above.*'
} else {
{Import-Module "$PSScriptRoot/../src/BurntToast.psd1" -Force} | Should -Throw -ExpectedMessage 'This version of BurntToast will only work on Windows 10 Creators Update (15063) and above.*'
}
}

AfterEach {
$env:BurntToastPesterNotWindows10 = $null
$env:BurntToastPesterNotAnniversaryUpdate = $null
}
}
}
22 changes: 12 additions & 10 deletions Tests/Get-BTHeader.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# Helper function needs to be in the global scope so it can be used in mocks
# Note - This may not work in Pester 5+
Function Global:New-MockNotification(
$HeaderId = (New-GUID).ToString(),
$HeaderTitle = (New-GUID).ToString(),
$HeaderArguments = '',
$HeaderActivation = 'protocol'
) {
$Content = @"
BeforeAll {
Function Global:New-MockNotification(
$HeaderId = (New-GUID).ToString(),
$HeaderTitle = (New-GUID).ToString(),
$HeaderArguments = '',
$HeaderActivation = 'protocol'
) {
$Content = @"
<?xml version="1.0" encoding="UTF-8"?>
<toast>
<visual>
Expand All @@ -20,9 +21,10 @@ Function Global:New-MockNotification(
<header id="$HeaderId" title="$HeaderTitle" arguments="$HeaderArguments" activationType="$HeaderActivation" />
</toast>
"@
$XMLContent = [Windows.Data.Xml.Dom.XmlDocument]::new()
$XmlContent.LoadXml($Content)
[Windows.UI.Notifications.ToastNotification]::new($XMLContent)
$XMLContent = [Windows.Data.Xml.Dom.XmlDocument]::new()
$XmlContent.LoadXml($Content)
[Windows.UI.Notifications.ToastNotification]::new($XMLContent)
}
}

Describe 'Get-BTHeader' {
Expand Down
58 changes: 0 additions & 58 deletions Tests/_BurntToast.Tests.ps1

This file was deleted.

0 comments on commit ab6429c

Please sign in to comment.