public/SourceQuery.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"

Describe "SourceQuery" -Tag 'Unit' {

    Context 'Runs' {

        $gameservers = [ordered]@{
            # Source
            left4dead2 = @{
                Address = 'l4d.startersclan.com'
                Port = 27015
                Engine = 'Source'
            }
            csgo = @{
                Address = 'cs.startersclan.com'
                Port = 27115
                Engine = 'Source'
            }
            hl2mp = @{
                Address = 'hl.startersclan.com'
                Port = 27215
                Engine = 'Source'
            }
            # Goldsource
            cstrike = @{
                Address = 'cs.startersclan.com'
                Port = 27815
                Engine = 'Goldsource'
            }
            czero = @{
                Address = 'cs.startersclan.com'
                Port = 27615
                Engine = 'Goldsource'
            }
            valve = @{
                Address = 'hl.startersclan.com'
                Port = 27915
                Engine = 'Goldsource'
            }
        }

        It 'Gets info' {
            $type = 'info'
            $ErrorActionPreference = 'Stop'

            foreach ($game in $gameservers.Keys) {
                $params = $gameservers[$game]
                $result = SourceQuery @params -Type $type
                $result | Should -BeOfType [System.Collections.Specialized.OrderedDictionary]
            }

        }

        It 'Gets players' {
            $type = 'players'
            $ErrorActionPreference = 'Stop'

            foreach ($game in $gameservers.Keys) {
                $params = $gameservers[$game]
                $result = SourceQuery @params -Type $type
                $result | Should -BeOfType [System.Collections.Specialized.OrderedDictionary]
            }

        }

        It 'Gets rules' {
            $type = 'rules'
            $ErrorActionPreference = 'Stop'

            foreach ($game in $gameservers.Keys) {
                $params = $gameservers[$game]
                $result = SourceQuery @params -Type $type
                $result | Should -BeOfType [System.Collections.Specialized.OrderedDictionary]
            }

        }

        # Deprecated
        # It 'Gets ping' {
        # $type = 'ping'

        # foreach ($game in $gameservers.Keys) {
        # $params = $gameservers[$game]
        # Write-Host "game: $game"
        # $result = SourceQuery @params -Type $type
        # $result | Should -Not -Be $null
        # }
        # }

    }

}