Hi all,
I recently introduced three handy 'Utility Methods' for the handling of TVerificationResultCollection objects in my branch lp:christian-k/openpetraorg/dev_20140107_DataAccess_Change_Error_Handling. Those Methods are now available to anyone as that Branch has been merged into trunk.
b bool TVerificationHelper.IsNullOrOnlyNonCritical(TVerificationResultCollection AVerificationResult)[/b]
This Method is a helpful shortcut for the evaluation of a TVerificationResultCollection that got returned from somewhere, e.g. as an out Argument from a Method. It replaces a boiler-plate if-else block (with two if-conditions) in any place where it is used and has got a 'speaking name', hence it is easy to see what is checked where it is used.
b CommonNunitFunctions.EnsureNullOrEmptyVerificationResult(TVerificationResultColection AVerificationResult, string string AMessage = "")[/b]
In a NUnit Test context this Method is a helpful shortcut for the evaluation of a TVerificationResultCollection that got returned from somewhere, e.g. as an out Argument from a Method that a NUnit test called. It replaces a boiler-plate if-else block (with two if-conditions) in any place where it is used and has got a 'speaking name', hence it is easy to see what is checked where it is used. Moreover, the Assert.Fail that it generates is standardised (but can be further customised with AMessage.)
b CommonNunitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(TVerificationResultColection AVerificationResult, string string AMessage = "")[/b]
Similar to (2), but this is about finding out whether the TVerificationResultCollection holds at least one Cricital Error. If if does then that Method not only Asserts, but also logs the TVerificationResult to the log file using the .BuildVerificationResultString() Method.
I hope you find those Methods helpful! They certainly save a few lines of boiler-plate code everywhere where they are used and hence not only reduce the potential for introducing potential errors by inadvertently coding those checks wrongly, but enhance the readability of our code.
I used those Methods already when I refactored code in my branch, so you will see them being used already.
Enjoy using these Methods!
Kind regards,
ChristianK