@@ -7,155 +7,157 @@ Import-Module -Name "$modulePath\$moduleName" -Force
7
7
8
8
Describe ' Set-ScriptLogger' {
9
9
10
- BeforeAll {
11
-
12
- $DefaultEnabled = $true
13
- $DefaultPath = ' TestDrive:\test.log'
14
- $DefaultFormat = ' {0:yyyy-MM-dd HH:mm:ss} {1} {2} {3} {4}'
15
- $DefaultLevel = ' Information'
16
- $DefaultEncoding = ' UTF8'
17
- $DefaultLogFile = $true
18
- $DefaultEventLog = $true
19
- $DefaultConsole = $true
20
- }
10
+ $defaultEnabled = $true
11
+ $defaultPath = ' TestDrive:\test.log'
12
+ $defaultFormat = ' {0:yyyy-MM-dd HH:mm:ss} {1} {2} {3} {4}'
13
+ $defaultLevel = ' Information'
14
+ $defaultEncoding = ' UTF8'
15
+ $defaultLogFile = $true
16
+ $defaultEventLog = $true
17
+ $defaultConsole = $true
21
18
22
19
BeforeEach {
23
20
24
- Start-ScriptLogger - Path $DefaultPath - Format $DefaultFormat - Level $DefaultLevel
21
+ Start-ScriptLogger - Path $defaultPath - Format $defaultFormat - Level $defaultLevel
25
22
}
26
23
27
- It ' ParameterPath' {
28
-
29
- $ExpectedPath = ' TestDrive:\testnew.log'
24
+ It ' should update the logger path' {
30
25
31
- Set-ScriptLogger - Path $ExpectedPath
26
+ # Arrange
27
+ $expectedPath = ' TestDrive:\testnew.log'
32
28
33
- $ScriptLogger = Get-ScriptLogger
29
+ # Act
30
+ Set-ScriptLogger - Path $expectedPath
34
31
35
- $ScriptLogger | Should Not Be $null
32
+ # Assert
33
+ $scriptLogger = Get-ScriptLogger
36
34
37
- $ScriptLogger.Enabled | Should Be $DefaultEnabled
38
- $ScriptLogger.Path | Should Be $ExpectedPath
39
- $ScriptLogger.Format | Should Be $DefaultFormat
40
- $ScriptLogger.Level | Should Be $DefaultLevel
41
- $ScriptLogger.Encoding | Should Be $DefaultEncoding
42
- $ScriptLogger.LogFile | Should Be $DefaultLogFile
43
- $ScriptLogger.EventLog | Should Be $DefaultEventLog
44
- $ScriptLogger.ConsoleOutput | Should Be $DefaultConsole
35
+ $scriptLogger | Should -Not - BeNullOrEmpty
36
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
37
+ $scriptLogger.Path | Should - Be $expectedPath
38
+ $scriptLogger.Format | Should - Be $defaultFormat
39
+ $scriptLogger.Level | Should - Be $defaultLevel
40
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
41
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
42
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
43
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
45
44
}
46
45
47
- It ' ParameterFormat' {
48
-
49
- $ExpectedFormat = ' {4} {3} {2} {1} {0}'
50
-
51
- Set-ScriptLogger - Format $ExpectedFormat
52
-
53
- $ScriptLogger = Get-ScriptLogger
54
-
55
- $ScriptLogger | Should Not Be $null
56
-
57
- $ScriptLogger.Enabled | Should Be $DefaultEnabled
58
- $ScriptLogger.Path | Should Be $DefaultPath
59
- $ScriptLogger.Format | Should Be $ExpectedFormat
60
- $ScriptLogger.Level | Should Be $DefaultLevel
61
- $ScriptLogger.Encoding | Should Be $DefaultEncoding
62
- $ScriptLogger.LogFile | Should Be $DefaultLogFile
63
- $ScriptLogger.EventLog | Should Be $DefaultEventLog
64
- $ScriptLogger.ConsoleOutput | Should Be $DefaultConsole
46
+ It ' should update the logger format' {
47
+
48
+ # Arrange
49
+ $expectedFormat = ' {4} {3} {2} {1} {0}'
50
+
51
+ # Act
52
+ Set-ScriptLogger - Format $expectedFormat
53
+
54
+ # Assert
55
+ $scriptLogger = Get-ScriptLogger
56
+ $scriptLogger | Should -Not - BeNullOrEmpty
57
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
58
+ $scriptLogger.Path | Should - Be $defaultPath
59
+ $scriptLogger.Format | Should - Be $expectedFormat
60
+ $scriptLogger.Level | Should - Be $defaultLevel
61
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
62
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
63
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
64
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
65
65
}
66
66
67
- It ' ParameterLevel' {
68
-
69
- $ExpectedLevel = ' Error'
70
-
71
- Set-ScriptLogger - Level $ExpectedLevel
72
-
73
- $ScriptLogger = Get-ScriptLogger
74
-
75
- $ScriptLogger | Should Not Be $null
76
-
77
- $ScriptLogger.Enabled | Should Be $DefaultEnabled
78
- $ScriptLogger.Path | Should Be $DefaultPath
79
- $ScriptLogger.Format | Should Be $DefaultFormat
80
- $ScriptLogger.Level | Should Be $ExpectedLevel
81
- $ScriptLogger.Encoding | Should Be $DefaultEncoding
82
- $ScriptLogger.LogFile | Should Be $DefaultLogFile
83
- $ScriptLogger.EventLog | Should Be $DefaultEventLog
84
- $ScriptLogger.ConsoleOutput | Should Be $DefaultConsole
67
+ It ' should update the logger log level' {
68
+
69
+ # Arrange
70
+ $expectedLevel = ' Error'
71
+
72
+ # Act
73
+ Set-ScriptLogger - Level $expectedLevel
74
+
75
+ # Assert
76
+ $scriptLogger = Get-ScriptLogger
77
+ $scriptLogger | Should -Not - BeNullOrEmpty
78
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
79
+ $scriptLogger.Path | Should - Be $defaultPath
80
+ $scriptLogger.Format | Should - Be $defaultFormat
81
+ $scriptLogger.Level | Should - Be $expectedLevel
82
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
83
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
84
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
85
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
85
86
}
86
87
87
- It ' ParameterEncoding' {
88
-
89
- $ExpectedEncoding = ' UTF8'
90
-
91
- Set-ScriptLogger - Encoding $ExpectedEncoding
92
-
93
- $ScriptLogger = Get-ScriptLogger
94
-
95
- $ScriptLogger | Should Not Be $null
96
-
97
- $ScriptLogger.Enabled | Should Be $DefaultEnabled
98
- $ScriptLogger.Path | Should Be $DefaultPath
99
- $ScriptLogger.Format | Should Be $DefaultFormat
100
- $ScriptLogger.Level | Should Be $DefaultLevel
101
- $ScriptLogger.Encoding | Should Be $ExpectedEncoding
102
- $ScriptLogger.LogFile | Should Be $DefaultLogFile
103
- $ScriptLogger.EventLog | Should Be $DefaultEventLog
104
- $ScriptLogger.ConsoleOutput | Should Be $DefaultConsole
88
+ It ' should update the logger encoding' {
89
+
90
+ # Arrange
91
+ $expectedEncoding = ' UTF8'
92
+
93
+ # Act
94
+ Set-ScriptLogger - Encoding $expectedEncoding
95
+
96
+ # Assert
97
+ $scriptLogger = Get-ScriptLogger
98
+ $scriptLogger | Should -Not - BeNullOrEmpty
99
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
100
+ $scriptLogger.Path | Should - Be $defaultPath
101
+ $scriptLogger.Format | Should - Be $defaultFormat
102
+ $scriptLogger.Level | Should - Be $defaultLevel
103
+ $scriptLogger.Encoding | Should - Be $expectedEncoding
104
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
105
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
106
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
105
107
}
106
108
107
- It ' ParameterNoLogFile ' {
108
-
109
- Set-ScriptLogger - LogFile ( -not $DefaultLogFile )
110
-
111
- $ScriptLogger = Get-ScriptLogger
112
-
113
- $ScriptLogger | Should Not Be $null
114
-
115
- $ScriptLogger .Enabled | Should Be $DefaultEnabled
116
- $ScriptLogger .Path | Should Be $DefaultPath
117
- $ScriptLogger .Format | Should Be $DefaultFormat
118
- $ScriptLogger .Level | Should Be $DefaultLevel
119
- $ScriptLogger .Encoding | Should Be $DefaultEncoding
120
- $ScriptLogger .LogFile | Should Not Be $DefaultLogFile
121
- $ScriptLogger .EventLog | Should Be $DefaultEventLog
122
- $ScriptLogger .ConsoleOutput | Should Be $DefaultConsole
109
+ It ' should update the logger no log file option ' {
110
+
111
+ # Act
112
+ Set-ScriptLogger - LogFile ( -not $defaultLogFile )
113
+
114
+ # Assert
115
+ $scriptLogger = Get-ScriptLogger
116
+ $scriptLogger | Should -Not - BeNullOrEmpty
117
+ $scriptLogger .Enabled | Should - Be $defaultEnabled
118
+ $scriptLogger .Path | Should - Be $defaultPath
119
+ $scriptLogger .Format | Should - Be $defaultFormat
120
+ $scriptLogger .Level | Should - Be $defaultLevel
121
+ $scriptLogger .Encoding | Should - Be $defaultEncoding
122
+ $scriptLogger .LogFile | Should - Not - Be $defaultLogFile
123
+ $scriptLogger .EventLog | Should - Be $defaultEventLog
124
+ $scriptLogger .ConsoleOutput | Should - Be $defaultConsole
123
125
}
124
126
125
- It ' ParameterNoEventLog ' {
126
-
127
- Set-ScriptLogger - EventLog ( -not $DefaultEventLog )
128
-
129
- $ScriptLogger = Get-ScriptLogger
130
-
131
- $ScriptLogger | Should Not Be $null
132
-
133
- $ScriptLogger .Enabled | Should Be $DefaultEnabled
134
- $ScriptLogger .Path | Should Be $DefaultPath
135
- $ScriptLogger .Format | Should Be $DefaultFormat
136
- $ScriptLogger .Level | Should Be $DefaultLevel
137
- $ScriptLogger .Encoding | Should Be $DefaultEncoding
138
- $ScriptLogger .LogFile | Should Be $DefaultLogFile
139
- $ScriptLogger .EventLog | Should Not Be $DefaultEventLog
140
- $ScriptLogger .ConsoleOutput | Should Be $DefaultConsole
127
+ It ' should update the logger no event log option ' {
128
+
129
+ # Act
130
+ Set-ScriptLogger - EventLog ( -not $defaultEventLog )
131
+
132
+ # Assert
133
+ $scriptLogger = Get-ScriptLogger
134
+ $scriptLogger | Should -Not - BeNullOrEmpty
135
+ $scriptLogger .Enabled | Should - Be $defaultEnabled
136
+ $scriptLogger .Path | Should - Be $defaultPath
137
+ $scriptLogger .Format | Should - Be $defaultFormat
138
+ $scriptLogger .Level | Should - Be $defaultLevel
139
+ $scriptLogger .Encoding | Should - Be $defaultEncoding
140
+ $scriptLogger .LogFile | Should - Be $defaultLogFile
141
+ $scriptLogger .EventLog | Should - Not - Be $defaultEventLog
142
+ $scriptLogger .ConsoleOutput | Should - Be $defaultConsole
141
143
}
142
144
143
- It ' ParameterNoConsoleOutput ' {
144
-
145
- Set-ScriptLogger - ConsoleOutput ( -not $DefaultConsole )
146
-
147
- $ScriptLogger = Get-ScriptLogger
148
-
149
- $ScriptLogger | Should Not Be $null
150
-
151
- $ScriptLogger .Enabled | Should Be $DefaultEnabled
152
- $ScriptLogger .Path | Should Be $DefaultPath
153
- $ScriptLogger .Format | Should Be $DefaultFormat
154
- $ScriptLogger .Level | Should Be $DefaultLevel
155
- $ScriptLogger .Encoding | Should Be $DefaultEncoding
156
- $ScriptLogger .LogFile | Should Be $DefaultLogFile
157
- $ScriptLogger .EventLog | Should Be $DefaultEventLog
158
- $ScriptLogger .ConsoleOutput | Should Not Be $DefaultConsole
145
+ It ' should update the logger no console option ' {
146
+
147
+ # Act
148
+ Set-ScriptLogger - ConsoleOutput ( -not $defaultConsole )
149
+
150
+ # Assert
151
+ $scriptLogger = Get-ScriptLogger
152
+ $scriptLogger | Should -Not - BeNullOrEmpty
153
+ $scriptLogger .Enabled | Should - Be $defaultEnabled
154
+ $scriptLogger .Path | Should - Be $defaultPath
155
+ $scriptLogger .Format | Should - Be $defaultFormat
156
+ $scriptLogger .Level | Should - Be $defaultLevel
157
+ $scriptLogger .Encoding | Should - Be $defaultEncoding
158
+ $scriptLogger .LogFile | Should - Be $defaultLogFile
159
+ $scriptLogger .EventLog | Should - Be $defaultEventLog
160
+ $scriptLogger .ConsoleOutput | Should - Not - Be $defaultConsole
159
161
}
160
162
161
163
AfterEach {
0 commit comments