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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:50:56+00:00 2026-05-28T06:50:56+00:00

I have a Currency class which I persist to my database using NHibernate. Currency

  • 0

I have a Currency class which I persist to my database using NHibernate. Currency class looks like this:

public class Currency : Entity
{
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
    public virtual string Symbol { get; set; }        
}

I have written a unit test using [TestCase] like this:

    [TestCase(6,Result = new Currency ({ Code="GBP", Name="British Pound", Symbol="£"}))]
    public Currency CanGetCurrencyById(int id)
    {
        ICurrencyRepo currencies = new RepoFactory().CreateCurrencyRepo(_session);
        Currency c = currencies.GetById<Currency>(id);

        return c;
    }

I know this is wrong but I’m not sure how to write it. Can the result be an object?

  • 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-28T06:50:57+00:00Added an answer on May 28, 2026 at 6:50 am

    Attribute argument (for Result) must be a constant expression. You can’t create objects like you do now.

    Using TestCase attribute is good for testing cases where you need to verify multiple simple inputs/outputs. In your scenarion, you can however do something like this (that is, if you only plan to verify whether id-code mapping is correct):

    [TestCase(6, Result = "GBP")]
    [TestCase(7, Result = "USD")]
    [TestCase(8, Result = "CAD")]
    public string CanGetCurrencyById(int id)
    {
        ICurrencyRepo currencies = new RepoFactory().CreateCurrencyRepo(_session);
        Currency c = currencies.GetById<Currency>(id);
    
        return c.Code;
    }
    

    Also, take a look at TestCase documentation – they provide quite good examples.

    Edit:
    By mapping testing I meant verifying whether your ORM mappings (NHibernate to database) are correct and work as you intended. You usually test that in following scenario:

    1. Create new entity instance with predefined values (eg. Currency)
    2. Start new transaction
    3. Save entity (Save + Flush + Evict combination to ensure NHibernate doesn’t store saved entity in cache anymore)
    4. Retrieve entity
    5. Compare retrieved values with predefined ones
    6. Rollback transaction

    If such test then passes, it more or less tells you that I can save this entity with those values, and I can then retrieved it with the exactly same values. And that’s all you wanted to know – mappings are correct.

    With TestCase attribute tho, verifying correctness of entire objects is quite difficult – it’s meant to test simple stuff. You can use workarounds like suggested in other answer (passing arguments via TestCase) but it quickly becomes unreadable and hard to maintain (imagine entity with 6+ properties to verify).

    I suggest splitting your test into one that verifies whether mapping of id to code is correct (however I see little point in doing that, unless you always plan to have certain ids mapped to certain codes) and other one verifying whether Currency entity is properly mapped to database table.

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

Sidebar

Related Questions

public class Currency{ private Code {get;set;} public Currency(string code){ this.Code = code; } //more
I currently have a Order and image model which look like this: class Order
I have a class certificate which in turn has different objects like TradingMarket is
I have a class that has a method as follows :- public void setCurrencyCode(List<String>
I have an extension method defined like so: public static TSource MaxBy<TSource, TResult>(this IEnumerable<TSource>
I have created a currency fomatter class. I want this to be a util
I have a currency converter application for iphone which uses web service. The web
Hey, I currently have a Currency Format method: private string FormatCurrency(double moneyIn) { CultureInfo
I have a GWT project in which I need to manually specify currency, number
We are using Nhibernate as our data access layer. We have a table of

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.