I have following method prepared for unit tests and i know it will always run for-each loop, is there a way to get rid of second return statement?
public Enums.GYRStatus GetStatusForTransformer(
string factoryCode,
Enums.Technology technology,
string transformerType,
int transformerSize,
string transformerModel)
{
fakeStandardsAndSizesFictionary = new Dictionary<Tuple<string,
Enums.Technology,
string, int, string>, int>()
{
{ Tuple.Create("SELUD", Technology.CVT,"---", 0, ""), 1} };
}
foreach (var pair in fakeStandardsAndSizesFictionary)
{
if (pair.Key.Item1 == factoryCode &&
pair.Key.Item2 == technology &&
pair.Key.Item3 == transformerType &&
pair.Key.Item4 == transformerSize &&
pair.Key.Item5 == transformerModel)
return (Enums.GYRStatus)pair.Value;
}
return (Enums.GYRStatus)1; // second return never used
}
You can replace
return (Enums.GYRStatus)1;
with
throw new InvalidOperationException();
It also looks more correct semantically, assuming that this place should never be reached.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With