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 7838613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:09:34+00:00 2026-06-02T15:09:34+00:00

The data fields of our column based database are mapped into a DataField class.

  • 0

The data fields of our column based database are mapped into a DataField class. On each data field object the GetValue<T>() method can be invoked.

If T is an illegal type an exception gets thrown. What type should I pass in my unit test, where I test if an exception gets thrown if I pass an illegal type? The next known illegal type which comes in my mind? Or is there an approach with some more abstraction?

public object GetValue<T>()
{
    if (typeof(T) == typeof(string)) return ValueString;
    if (typeof(T) == typeof(int?)) return ValueInt;
    if (typeof(T) == typeof(double?)) return ValueDouble;
    if (typeof(T) == typeof(DateTime?)) return ValueDateTime;
    if (typeof(T) == typeof(bool)) return ValueBoolean == true;

    var ex = new Exception("Following type is not supported: " + typeof(T));
    Log.Error(ex);
    throw ex;
}

So every type but those should throw this exception if they get passed. So I’d need a kind of dummy type, right?

At the moment my unit test looks like this:

[Fact]
public void If_T_is_illegal_type_an_exception_gets_thrown()
{
    _dataField = new DataField(_params);
    Assert.Throws<Exception>(() => _dataField.GetValue<Type>());
}
  • 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-06-02T15:09:35+00:00Added an answer on June 2, 2026 at 3:09 pm

    Remember that unit testing is trying to get through all code paths and ensuring correct behaviour. You should have 6 tests in total: one for each of the 5 valid types, and one with any other type (as you currently have) to cover the final code path. Not sure why you’d need something more abstract.

    You may prefer to use explicit conversions and casting so that this becomes a compile time test rather than run time: http://msdn.microsoft.com/en-us/library/xhbhezf4(v=vs.100).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Salesforce has some built in meta-data fields to describe each Field of each Object.
I want to create a service which will insert provided data into spreadsheet fields
I am populating several fields based on data from the my db. I am
In my database we have fields where the data is not readable. I now
I am using a tool to generate test data for our database. For columns
I'm trying to insert an HTML blob into our sql-server2005 database. I've been using
I need to do some trimming before saving various fields in our database. We're
I am trying to pull data from our Oracle datamart into R using RODBC.
At the risk of sounding foolish, in a scenario where large data fields need
I have to prepare a report which is getting some fields data from conf

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.