How to unit test the default case of an enum based switch statement

Try the following

Assert.IsFalse(Enum.IsDefined(typeof(EnumType), Int32.MaxValue);
Create((EnumType)Int32.MaxValue);

It’s true that any value you pick for the “default” case could one day become a valid value. So simply add a test to guarantee it doesn’t in the same place you check the default.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)