In the last email, I was considering a function that would do all the comparisons of the before and after values of the FieldChanges dictionary in the AuditEventDetails object and the Input dictionary I created. This would return a Boolean. It sounds good as I say it and it will reduce our super long Assert.IsTrue line to a simple function call.
I’m starting with this function I used to just compare 1 field. Now I want to just take the two dictionaries as arguments and compare the inputs with the results, looping through. Again, here is what I started with:
First I’ll change the name of the function to something more sensible: FieldInputsMatchResults.
Now, I will remove the first argument and just leave the two dictionaries:
In order to keep the code compiling, I Dim’med the FieldName variable in the function as a variant. And now to loop over dctInputs and make sure the expected results are in the dctResults.
Not too bad. I’m looping, but at the first set that doesn’t fully match I set the retVal to false and end the loop.
I think this is still a bit heavy on lines and variable names, so I’m going to do another helper function to extract the old and new matches comparison. Here’s what I got:
I think overall that’s a bit cleaner and my functions are closer to doing just one thing. And finally I can finish off my Test function refactor like this. And I like this a lot more:
All right! Next time I will look at potentially using the new functions to rewrite the old tests if needed. I might be able to clean it up a bit more and make it super easy to write more tests.