Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 225273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:23:50+00:00 2026-05-11T19:23:50+00:00

I have a lump of code that looks a bit like this: If mode

  • 0

I have a lump of code that looks a bit like this:

If mode = DiaryMode.Admin Then
    modeObject = DBNull.Value
ElseIf mode = DiaryMode.Academy Then
    modeObject = ApplicationSettings.Academy
ElseIf mode = DiaryMode.Scouting Then
    modeObject = ApplicationSettings.Scouting
Else
    Throw New NotSupportedException()
End If

The idea of the check is to prep some values for passing into a database call.

There are two questions, is the Else worth the effort? The intention is to prevent future extensions of the enum causing the code to return squify results.

If the code is valid, I’d like to be able to unit test the behaviour, if it’s worth having it’s worth testing. How might I go about doing that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:23:50+00:00Added an answer on May 11, 2026 at 7:23 pm

    If your business requirements state that no other DiaryMode is acceptable, then an else statement is a perfectly fine use to prevent future extension on your DiaryMode enum.

    As for testing, that gets a little bit trickier. I would test all valid states (Admin, Academy, and Scouting) for sure. However, you can’t really set the mode to an enum value that doesn’t exist, and that would be the only way to throw the NotsupportedException. I might look into trying to write a test that would verify that the enum only carries the enumerations your expecting.

    You could do that by doing something like this:

    Enum.GetNames(typeof(DiaryMode))
    

    and then verifying each name.

    To sum up, you’d have 4 tests from what I’ve described.

    • Admin test
    • Academy test
    • Scouting test
    • Test that checks all the names in the DiaryMode enum
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store some data that looks a little like this: xyz 123
lets say i have this lump of HTML: <div class=container> <span class=title>Heading 1</span> This
Have piece of code like below: var workStream = new MemoryStream(); var doc =
Have some dates in my local Oracle 11g database that are in this format:
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
I have a big lump of binary data in a char[] array which I
Have you guys had any experiences (positive or negative) by placing your source code/solution
I have the following xml <Values> <New> <value>110</value> <date>2009-10-15</date> </New> <Previous> <value>100</value> <date>2010-10-15</date> </Previous>
Sorry for the bad question title. Let's say that I have DateRange class that
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.