Hi all, here is my question, as an example suppose i have a method to convert some types. something like this:
/// <summary>
/// Convierte el valor del objeto especificado a un valor equivalente de {T}.
/// </summary>
/// <typeparam name="T">El tipo del valor a regresar.</typeparam>
/// <param name="source">
/// Un objeto <see cref="string"/> con el valor a convertir.
/// </param>
/// <returns>
/// Un valor equivalente de <paramref name="source"/> de tipo {T} cuando la
/// conversión se puede realizar, el valor por defecto de {T} en caso contrario.
/// </returns>
/// <exception cref="Exception">
/// Cuando <paramref name="source"/> no es un valor valido para {T}.
/// </exception>
/// <exception cref="FormatException">
/// Cuando <paramref name="source"/> no es un valor valido para {T}.
/// </exception>
/// <exception cref="NotSupportedException">
/// Cuando no se puede realizar la conversión.
/// </exception>
/// <exception cref="ArgumentNullException">
/// Cuando <paramref name="source"/> es <see langword="null"/>.
/// </exception>
/// <example>
public static T ToGeneric<T>(this string source) where T : IComparable {
if(source == null) {
throw new ArgumentNullException("source","Cant be null"); //just as an example
}
TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
return ((T)converter.ConvertFrom(source));
}
As yo can see I documented every posible exception in the method, but only one (ArgumentNullException) is throwed by me.
I use my documentation as a base to create my TestCases, so in this case I would create 5 Test Cases, one for each exception and one for the correct case.
My questions if that the correct way to do it? If I follow my pattern sooner or later I will have a bunch of test for IO stuff that won't add any value. The only option I have thought is just document the exceptions that I create inside my method and also test only that, but some programmers at my work are not very good and they might get confused why the method is throwing a NotSupportedException if the parameter is not null (they speak Spanish by the way so reading the exception message is a bit harder for them)
Ho do you handle this kind of thing, document everything or just the things you actually do.
Thanks for your time.