I have an extension method that calculates due date based on date period type. The method looks like this:
public static DateTime CalculateDueDate(this DateTime date, OffsetType offsetType, int offset)
{
switch (offsetType)
{
case OffsetType.Days:
return date.AddDays(offset);
case OffsetType.Weeks:
return date.AddWeeks(offset);
case OffsetType.Months:
return date.AddMonths(offset);
default:
throw new ArgumentOutOfRangeException("offsetType", offsetType, null);
}
}
where OffsetType enum has these possible values:
public enum OffsetType
{
Months = 1,
Weeks = 2,
Days = 3
}
How can I make sure that ArgumentOutOfRangeException is thrown when OffsetType enum is not provided (or provided with invalid value)? Do I even need to worry about unit testing that exception if OffsetType parameter is not null?
Aucun commentaire:
Enregistrer un commentaire