@@ -7,11 +7,14 @@ Import-Module -Name "$modulePath\$moduleName" -Force
7
7
8
8
Describe ' Start-ScriptLogger' {
9
9
10
+ Mock Get-Date { return [DateTime ]::new(2010 , 12 , 06 , 18 , 20 , 22 ) } - ModuleName $moduleName
11
+
10
12
$defaultEnabled = $true
11
13
$defaultPath = " $PSScriptRoot \Start-ScriptLogger.Tests.ps1.log"
12
14
$defaultFormat = ' {0:yyyy-MM-dd} {0:HH:mm:ss} {1} {2} {3,-11} {4}'
13
15
$defaultLevel = ' Verbose'
14
16
$defaultEncoding = ' UTF8'
17
+ $defaultRotation = ' None'
15
18
$defaultLogFile = $true
16
19
$defaultEventLog = $true
17
20
$defaultConsole = $true
@@ -28,6 +31,7 @@ Describe 'Start-ScriptLogger' {
28
31
$scriptLogger.Format | Should - Be $defaultFormat
29
32
$scriptLogger.Level | Should - Be $defaultLevel
30
33
$scriptLogger.Encoding | Should - Be $defaultEncoding
34
+ $scriptLogger.Rotation | Should - Be $defaultRotation
31
35
$scriptLogger.LogFile | Should - Be $defaultLogFile
32
36
$scriptLogger.EventLog | Should - Be $defaultEventLog
33
37
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
@@ -48,13 +52,15 @@ Describe 'Start-ScriptLogger' {
48
52
$scriptLogger.Format | Should - Be $defaultFormat
49
53
$scriptLogger.Level | Should - Be $defaultLevel
50
54
$scriptLogger.Encoding | Should - Be $defaultEncoding
55
+ $scriptLogger.Rotation | Should - Be $defaultRotation
51
56
$scriptLogger.LogFile | Should - Be $defaultLogFile
52
57
$scriptLogger.EventLog | Should - Be $defaultEventLog
53
58
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
54
59
}
55
60
56
61
It ' should return a valid value for the parameter format' {
57
62
63
+ # Arrange
58
64
$expectedFormat = ' {4} {3} {2} {1} {0}'
59
65
60
66
# Act
@@ -67,13 +73,15 @@ Describe 'Start-ScriptLogger' {
67
73
$scriptLogger.Format | Should - Be $expectedFormat
68
74
$scriptLogger.Level | Should - Be $defaultLevel
69
75
$scriptLogger.Encoding | Should - Be $defaultEncoding
76
+ $scriptLogger.Rotation | Should - Be $defaultRotation
70
77
$scriptLogger.LogFile | Should - Be $defaultLogFile
71
78
$scriptLogger.EventLog | Should - Be $defaultEventLog
72
79
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
73
80
}
74
81
75
82
It ' should return a valid value for the parameter log level' {
76
83
84
+ # Arrange
77
85
$expectedLevel = ' Error'
78
86
79
87
# Act
@@ -86,13 +94,15 @@ Describe 'Start-ScriptLogger' {
86
94
$scriptLogger.Format | Should - Be $defaultFormat
87
95
$scriptLogger.Level | Should - Be $expectedLevel
88
96
$scriptLogger.Encoding | Should - Be $defaultEncoding
97
+ $scriptLogger.Rotation | Should - Be $defaultRotation
89
98
$scriptLogger.LogFile | Should - Be $defaultLogFile
90
99
$scriptLogger.EventLog | Should - Be $defaultEventLog
91
100
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
92
101
}
93
102
94
103
It ' should return a valid value for the parameter encoding' {
95
104
105
+ # Arrange
96
106
$expectedEncoding = ' UTF8'
97
107
98
108
# Act
@@ -105,6 +115,96 @@ Describe 'Start-ScriptLogger' {
105
115
$scriptLogger.Format | Should - Be $defaultFormat
106
116
$scriptLogger.Level | Should - Be $defaultLevel
107
117
$scriptLogger.Encoding | Should - Be $expectedEncoding
118
+ $scriptLogger.Rotation | Should - Be $defaultRotation
119
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
120
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
121
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
122
+ }
123
+
124
+ It ' should return a valid value for the parameter rotation hourly' {
125
+
126
+ # Arrange
127
+ $expectedRotation = ' Hourly'
128
+ $expectedPath = " $PSScriptRoot \Start-ScriptLogger.Tests.ps1.2010120618.log"
129
+
130
+ # Act
131
+ $scriptLogger = Start-ScriptLogger - Rotation $expectedRotation - PassThru
132
+
133
+ # Assert
134
+ $scriptLogger | Should -Not - BeNullOrEmpty
135
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
136
+ $scriptLogger.Path | Should - Be $expectedPath
137
+ $scriptLogger.Format | Should - Be $defaultFormat
138
+ $scriptLogger.Level | Should - Be $defaultLevel
139
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
140
+ $scriptLogger.Rotation | Should - Be $expectedRotation
141
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
142
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
143
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
144
+ }
145
+
146
+
147
+ It ' should return a valid value for the parameter rotation daily' {
148
+
149
+ # Arrange
150
+ $expectedRotation = ' Daily'
151
+ $expectedPath = " $PSScriptRoot \Start-ScriptLogger.Tests.ps1.20101206.log"
152
+
153
+ # Act
154
+ $scriptLogger = Start-ScriptLogger - Rotation $expectedRotation - PassThru
155
+
156
+ # Assert
157
+ $scriptLogger | Should -Not - BeNullOrEmpty
158
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
159
+ $scriptLogger.Path | Should - Be $expectedPath
160
+ $scriptLogger.Format | Should - Be $defaultFormat
161
+ $scriptLogger.Level | Should - Be $defaultLevel
162
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
163
+ $scriptLogger.Rotation | Should - Be $expectedRotation
164
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
165
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
166
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
167
+ }
168
+
169
+ It ' should return a valid value for the parameter rotation monthly' {
170
+
171
+ # Arrange
172
+ $expectedRotation = ' Monthly'
173
+ $expectedPath = " $PSScriptRoot \Start-ScriptLogger.Tests.ps1.201012.log"
174
+
175
+ # Act
176
+ $scriptLogger = Start-ScriptLogger - Rotation $expectedRotation - PassThru
177
+
178
+ # Assert
179
+ $scriptLogger | Should -Not - BeNullOrEmpty
180
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
181
+ $scriptLogger.Path | Should - Be $expectedPath
182
+ $scriptLogger.Format | Should - Be $defaultFormat
183
+ $scriptLogger.Level | Should - Be $defaultLevel
184
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
185
+ $scriptLogger.Rotation | Should - Be $expectedRotation
186
+ $scriptLogger.LogFile | Should - Be $defaultLogFile
187
+ $scriptLogger.EventLog | Should - Be $defaultEventLog
188
+ $scriptLogger.ConsoleOutput | Should - Be $defaultConsole
189
+ }
190
+
191
+ It ' should return a valid value for the parameter rotation yearly' {
192
+
193
+ # Arrange
194
+ $expectedRotation = ' Yearly'
195
+ $expectedPath = " $PSScriptRoot \Start-ScriptLogger.Tests.ps1.2010.log"
196
+
197
+ # Act
198
+ $scriptLogger = Start-ScriptLogger - Rotation $expectedRotation - PassThru
199
+
200
+ # Assert
201
+ $scriptLogger | Should -Not - BeNullOrEmpty
202
+ $scriptLogger.Enabled | Should - Be $defaultEnabled
203
+ $scriptLogger.Path | Should - Be $expectedPath
204
+ $scriptLogger.Format | Should - Be $defaultFormat
205
+ $scriptLogger.Level | Should - Be $defaultLevel
206
+ $scriptLogger.Encoding | Should - Be $defaultEncoding
207
+ $scriptLogger.Rotation | Should - Be $expectedRotation
108
208
$scriptLogger.LogFile | Should - Be $defaultLogFile
109
209
$scriptLogger.EventLog | Should - Be $defaultEventLog
110
210
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
@@ -122,6 +222,7 @@ Describe 'Start-ScriptLogger' {
122
222
$scriptLogger.Format | Should - Be $defaultFormat
123
223
$scriptLogger.Level | Should - Be $defaultLevel
124
224
$scriptLogger.Encoding | Should - Be $defaultEncoding
225
+ $scriptLogger.Rotation | Should - Be $defaultRotation
125
226
$scriptLogger.LogFile | Should - Be $false
126
227
$scriptLogger.EventLog | Should - Be $defaultEventLog
127
228
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
@@ -139,6 +240,7 @@ Describe 'Start-ScriptLogger' {
139
240
$scriptLogger.Format | Should - Be $defaultFormat
140
241
$scriptLogger.Level | Should - Be $defaultLevel
141
242
$scriptLogger.Encoding | Should - Be $defaultEncoding
243
+ $scriptLogger.Rotation | Should - Be $defaultRotation
142
244
$scriptLogger.LogFile | Should - Be $defaultLogFile
143
245
$scriptLogger.EventLog | Should - Be $false
144
246
$scriptLogger.ConsoleOutput | Should - Be $defaultConsole
@@ -156,6 +258,7 @@ Describe 'Start-ScriptLogger' {
156
258
$scriptLogger.Format | Should - Be $defaultFormat
157
259
$scriptLogger.Level | Should - Be $defaultLevel
158
260
$scriptLogger.Encoding | Should - Be $defaultEncoding
261
+ $scriptLogger.Rotation | Should - Be $defaultRotation
159
262
$scriptLogger.LogFile | Should - Be $defaultLogFile
160
263
$scriptLogger.EventLog | Should - Be $defaultEventLog
161
264
$scriptLogger.ConsoleOutput | Should - Be $false
0 commit comments