Untitled
function Check-WinServer() { [CmdletBinding()] Param () $osName = (Get-ComputerInfo).OsName if ($osName.ToLower().Contains('windows server')) { return $true } return $false } Describe 'Check-WinServer' { It "Should return true if the OS Name contains 'Windows Server'" { # Mocking Get-ComputerInfo Mock -CommandName Get-ComputerInfo -MockWith { return @{ OsName = "Windows Server" } } $result = Check-WinServer $result | Should -Be $true } It "Should return false if OS Name does not contain 'Windows Server'" { # Mocking Get-ComputerInfo Mock -CommandName Get-ComputerInfo -MockWith { return @{ OsName = "Windows" } } $result = Check-WinServer $result | Should -Be $false } It "Should return false if OS Name is empty" { # Mocking Get-ComputerInfo Mock -CommandName Get-ComputerInfo -MockWith { return @{ OsName = "" } } $result = Check-WinServer $result | Should -Be $false } }
Leave a Comment