-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRulesTests.bas
292 lines (198 loc) · 7.3 KB
/
RulesTests.bas
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
Attribute VB_Name = "RulesTests"
Sub Run_All_Tests()
FindInFolders_Tests
Find_or_Create_Folder_Tests
AddToFavorites_Tests
ExtractTicketID_Tests
End Sub
' --------------------------------------------------------------------------------
Sub FindInFolders_Tests()
Const FUNCTION_NAME = "FindInFolders"
Debug.Print FUNCTION_NAME
FindInFolders_returns_reference_to_a_folder_that_matches_name
FindInFolders_returns_nothing_if_folder_does_not_exist
End Sub
Sub FindInFolders_returns_reference_to_a_folder_that_matches_name()
Const TEST_NAME = "returns_reference_to_a_folder_that_matches_name"
Debug.Print vbTab + TEST_NAME
' arrange
Dim Folder As Outlook.MAPIFolder
Dim FolderName As String: FolderName = "RITM0123456"
'act
Set Folder = Find_or_Create_Folder(FolderName)
' assert
Debug.Assert Folder.Name = FolderName
'
Set Folder = Nothing
End Sub
Sub FindInFolders_returns_nothing_if_folder_does_not_exist()
Const TEST_NAME = "returns_nothing_if_folder_does_not_exist"
Debug.Print vbTab + TEST_NAME
' arrange
Dim Folder As Outlook.MAPIFolder
Dim FolderName As String: FolderName = "RITM0000000"
'act
Set Folder = Find_or_Create_Folder(FolderName)
' assert
Debug.Assert (Folder Is Nothing)
'
Set Folder = Nothing
End Sub
' --------------------------------------------------------------------------------
Sub Find_or_Create_Folder_Tests()
Const FUNCTION_NAME = "Find_or_Create_Folder"
Debug.Print FUNCTION_NAME
Find_or_Create_Folder_returns_an_existing_folder
Find_or_Create_Folder_returns_a_new_folder
End Sub
Sub Find_or_Create_Folder_returns_an_existing_folder()
Const TEST_NAME = "Find_or_Create_Folder_returns_an_existing_folder"
Debug.Print vbTab + TEST_NAME
' arrange
Dim Folder As Outlook.MAPIFolder
Dim FolderName As String: FolderName = "RITM0123456"
'act
Set Folder = Find_or_Create_Folder(FolderName)
' assert
Debug.Assert Not Folder Is Nothing
'
Set Folder = Nothing
End Sub
Sub Find_or_Create_Folder_returns_a_new_folder()
Const TEST_NAME = "Find_or_Create_Folder_returns_a_new_folder"
Debug.Print vbTab + TEST_NAME
' arrange
Dim Folder As Outlook.MAPIFolder
Dim FolderName As String: FolderName = "RITM0000000"
'act
Set Folder = Find_or_Create_Folder(FolderName)
' assert
Debug.Assert Not Folder Is Nothing
'
Set Folder = Nothing
End Sub
' --------------------------------------------------------------------------------
Sub AddToFavorites_Tests()
Const FUNCTION_NAME = "AddToFavorites"
Debug.Print FUNCTION_NAME
AddToFavorites_creates_a_folder_favorite
End Sub
Sub AddToFavorites_creates_a_folder_favorite()
Const TEST_NAME = "creates a folder favorite"
Debug.Print vbTab + TEST_NAME
' arrange
Dim Folder As Outlook.MAPIFolder
Dim FolderName As String: FolderName = "RITM0000000"
'act
Set Folder = Find_or_Create_Folder(FolderName)
Set Favorite = AddToFavorites(Folder)
' assert
Debug.Assert Not Favorite Is Nothing
'
Set Folder = Nothing
End Sub
' --------------------------------------------------------------------------------
Sub ExtractTicketID_Tests()
Const FUNCTION_NAME = "ExtractTicketID"
Debug.Print FUNCTION_NAME
ExtractTicketID_locates_a_RITM_in_the_mail_item
End Sub
Sub ExtractTicketID_locates_a_RITM_in_the_mail_item()
Const TEST_NAME = "locates a RITM # in the mail item"
Debug.Print vbTab + TEST_NAME
'arrange
Dim RITM As String: RITM = "RITM0123456"
Dim scenario(2, 4)
scenario(0, 0) = "RITM found in subject"
scenario(0, 1) = RITM
scenario(0, 2) = "lorem " & RITM & " ipsum"
scenario(0, 3) = "lorem ipsum"
scenario(1, 0) = "RITM found in body"
scenario(1, 1) = RITM
scenario(1, 2) = "lorem ipsum"
scenario(1, 3) = "lorem " & RITM & " ipsum"
scenario(2, 0) = "RITM NOT found in subject or body"
scenario(2, 1) = vbNullString
scenario(2, 2) = "lorem ipsum"
scenario(2, 3) = "lorem ipsum"
Dim i As Integer
For i = 0 To 2
'act
Dim MailItem As Outlook.MailItem
Dim Subject As String: Subject = scenario(i, 2)
Dim Body As String: Body = scenario(i, 3)
Set MailItem = CreateMailItem("[email protected]", Subject, Body)
'act
actual = ExtractTicketID(MailItem)
'assert
Debug.Print "-----" & i & "-----"
Debug.Print "Test: " & scenario(i, 0)
Debug.Print "Actual: " & actual
Debug.Print "Expected: " & scenario(i, 1)
Debug.Assert actual = scenario(i, 1)
' tidy
MailItem.Delete
Set MailItem = Nothing
Next
End Sub
' --------------------------------------------------------------------------------
Sub ProcessMailItem_Tests()
Const FUNCTION_NAME = "ProcessMailItem"
Debug.Print FUNCTION_NAME
ProcessMailItem_moves_a_message_with_a_RITM_in_the_subject_to_the_corresponding_folder
End Sub
Sub ProcessMailItem_moves_a_message_with_a_RITM_in_the_subject_to_the_corresponding_folder()
Const TEST_NAME = "moves a message with a RITM # in the subject to the corresponding folder"
Debug.Print vbTab + TEST_NAME
'arrange
Dim RITM As String: RITM = "RITM0000000"
Dim Inbox As Outlook.MAPIFolder
Set Inbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Dim Dummy As Outlook.MailItem
Set Dummy = CreateMailItem("[email protected]", "ticket " & RITM & " was assigned to you.", "lorem ipsum")
'Dim Target As Outlook.MAPIFolder
'Set Target = Find_or_Create_Folder(RITM)
'act
'Dummy.Move Target
ProcessMailItem Dummy
'assert
'Dim filter As String: filter = "[Subject] = '" + RITM + "'"
'Debug.Assert Not Target.Items.Find(filter) Is Nothing
'clean
Set Target = Nothing
Set Dummy = Nothing
Set Inbox = Nothing
End Sub
Sub ProcessMailItem_moves_a_message_with_a_RITM_in_the_body_to_the_corresponding_folder()
Const TEST_NAME = "moves a message with a RITM # in the body to the corresponding folder"
Debug.Print vbTab + TEST_NAME
'arrange
Dim RITM As String: RITM = "RITM7777777"
Dim Inbox As Outlook.MAPIFolder
Set Inbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Dim Dummy As Outlook.MailItem
Set Dummy = CreateMailItem("[email protected]", "lorem ipsum", RITM)
Dim Target As Outlook.MAPIFolder
Set Target = Find_or_Create_Folder(RITM)
'act
Dummy.Move Target
'assert
Dim filter As String: filter = "[Body] = '" + RITM + "'"
Debug.Assert Not Target.Items.Find(filter) Is Nothing
'clean
Set Target = Nothing
Set Dummy = Nothing
Set Inbox = Nothing
End Sub
Function CreateMailItem(Recipient As String, Subject As String, Body As String)
Dim oMailItem As Outlook.MailItem
Set oMailItem = Application.CreateItem(olMailItem)
With oMailItem
.Subject = Subject
.BodyFormat = olFormatPlain
.Body = Body
.Recipients.Add Recipient
.Display
End With
Set CreateMailItem = oMailItem
End Function