My next test will be to make a single change to a field’s value from “start” to “end” and verify that the name of that field and those values are returned.
Me – last time
And away we go. A failing test to change the field’s value from one known value to another and make sure we have added an entry to log the change to our collection of change dictionaries for each BeforeUpdate event.
In the GivenFormAuditor module I will add a test called WhenTextFieldChangesBeforeAndAfterValuesAreReturned.
Made a copy of the last test and updated it. Here is the code I came up with:
'@TestMethod("Verify Changes")
Private Sub WhenTextFieldChangesBeforeAndAfterValuesAreReturned()
Dim testFormAuditor As FormAuditor
Dim testCollection As New Collection
ChangeTestText "BeforeValue"
Set testFormAuditor = New FormAuditor
ChangeTestText "AfterValue"
Set testCollection = testFormAuditor.ListOfChanges
With testCollection.Item(0).FieldChanges(0)
Assert.IsTrue .OldValue = "BeforeValue" And .NewValue = "AfterValue"
End With
End Sub
Does the test compile? Yes.
Does the test fail? It does not get to the assert because I don’t have a dictionary with a FieldChanges element. Actually the way I wrote that, it’s all wrong anyway. Apparently with the way I have the db configured, the collection index starts at 1 not 0, so I got an index does not exist error. I already regret putting a dictionary in a dictionary. Instead, I want to use an object for each BeforeUpdate event record. So here’s a quick object that will help me. I’ll call it AuditEventDetails.
Option Compare Database
Option Explicit
Public FieldChanges As New Scripting.Dictionary
Ooh, and just realized I’ll also need another object I will call AuditFieldChange which is also simple and will look like this:
Option Compare Database
Option Explicit
Public OldValue As Variant, NewValue As Variant
I guess I could potentially declare these as User Defined Types as well, at least the AuditFieldChange, but I’ll think about that later.
Now my test needs a few minor tweaks:
'@TestMethod("Verify Changes")
Private Sub WhenTextFieldChangesBeforeAndAfterValuesAreReturned()
Dim testFormAuditor As FormAuditor
Dim testCollection As New Collection
ChangeTestText "BeforeValue"
Set testFormAuditor = New FormAuditor
ChangeTestText "AfterValue"
Set testCollection = testFormAuditor.ListOfChanges
With testCollection.Item(1).FieldChanges("TestText")
Assert.IsTrue .OldValue = "BeforeValue" And .NewValue = "AfterValue"
End With
End Sub
The test still doesn’t get to the Assert yet because I’m only currently populating my returned collection with strings.
But how quickly the time flies… I think tomorrow I’ll get this test passing.