Suitable use of Tuple<>, in a unit test?
.net-4.0, c#, tuples, unit-testing
Solution
The Tuple still could work, but if you are wanting to track details about the error codes, I think the code would be more readable and maintainable if you created a simple class to compose the details of the error code and still use a dictionary to keep track of the error code keys.
Dictionary<string, ErrorCodeDetails>
Problem
Whilst writing a set of unit tests (for an existing legacy component), I wanted a way to associate a list of error codes (which will be returned by a service that I have mocked), and a list of corresponding error messages (which my component under test will return). It seems that using a `List<Tuple<string, string>>` is a nice simple way to define this association. ``` var errorCodesAndMessages = new List<Tuple<string, string>> { Tuple.Create("CODE1", "Error message 1"), Tuple.Create("CODE2", "Error message 2") // etc... }; ``` In my unit test I can then loop through the `errorCodesAndMessages`, setting up my mocked service to return the nth error code, and asserting that the component under test returns the nth error message. Is this a good use of — or an abuse of — `Tuple<>`? Edit Responses have suggested that `Dictionary<string, string>` would be better in this scenario. I have to agree. However, what if (for some reason) we needed to associate three pieces of data (e.g. an error code, user-displayed error message and technical error message) Would this then be a good use of `Tuple<>`? ``` Tuple.Create("CODE1", "User error message", "Technical error message") ```