This test I refactored yesterday to use the new functions which all the tests are using.
'@TestMethod("Count Changes")
Private Sub WhenTwoFieldsAreChangedThenReturnTwoEntryListOfChanges()
Dim testFormAuditor As FormAuditor, dctInput As New Scripting.Dictionary
Set testFormAuditor = New FormAuditor
dctInput.Add "TestText", Array("", CStr(Now()))
ChangeFields_ReturnExistingListOfChanges testFormAuditor, dctInput
Set dctInput = New Scripting.Dictionary
dctInput.Add "TestText", Array("", CStr(Now() & " also"))
ChangeFields_ReturnExistingListOfChanges testFormAuditor, dctInput
Assert.AreEqual CLng(2), testFormAuditor.ListOfChanges.Count
End Sub
I want to continue refactoring it because it is unreadable and confusing. I am wanting to run multiple changes over multiple form saves. The multiple form saves is something that no other tests were doing yet. I think the Scripting Dictionary additions are confusing and not clear what I’m doing. I’m going to create a custom function which will take a reference to the dictionary with named parameters that will explain what the values I’m specifying represent.
Here it is, adding more descriptive function names (and also added to support functions included here as well:
'@TestMethod("Count Changes")
Private Sub WhenTwoFieldsAreChangedThenReturnTwoEntryListOfChanges()
Dim testFormAuditor As FormAuditor, dctInput As Scripting.Dictionary
Set testFormAuditor = New FormAuditor
Set dctInput = CreateAndAddToInputDict(FieldToChange:="TestText", ChangeTo:=Now())
ChangeFields_ReturnExistingListOfChanges testFormAuditor, dctInput
Set dctInput = CreateAndAddToInputDict(FieldToChange:="TestText", ChangeTo:=Now() & " also")
ChangeFields_ReturnExistingListOfChanges testFormAuditor, dctInput
Assert.AreEqual CLng(2), testFormAuditor.ListOfChanges.Count
End Sub
Private Sub AddToInputDict(ByRef theDictionary As Scripting.Dictionary, FieldToChange As String, Optional InitialValue As String = "", Optional ChangeTo As String = "")
theDictionary.Add FieldToChange, Array(InitialValue, ChangeTo)
End Sub
Private Function CreateAndAddToInputDict(FieldToChange As String, Optional InitialValue As String = "", Optional ChangeTo As String = "") As Scripting.Dictionary
Dim theDictionary As New Scripting.Dictionary
AddToInputDict theDictionary, FieldToChange, InitialValue, ChangeTo
CreateAndAddToInputDict = theDictionary
End Function
The test method itself I think is much more self documenting as to what I’m trying to do. In fact, I think I’m going to use these new helper functions to make the other tests self explanatory as well. Ok, that’s it for today.