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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:09:37+00:00 2026-05-31T23:09:37+00:00

i created the following sample method in business logic layer. my database doesn’t allow

  • 0

i created the following sample method in business logic layer. my database doesn’t allow nulls for name and parent columns:

public void Insert(string catName, long catParent)
{
    EntityContext con = new EntityContext();
    Category cat = new Category();
    cat.Name = catName;
    cat.Parent = catParent;
    con.Category.AddObject(cat);
    con.SaveChanges();
}

so i unit test this and test for empty name and empty parent will fail. to get around that issue i have to refactor the Insert mathod as following:

public void Insert(string catName, long catParent)
{
    //added to pass the test
    if(string.IsNullOrEmpty(catName)) throw new InvalidOperationException("wrong action. name is empty.");
    long parent;
    if(long.TryParse(catParent, out parent) == false) throw new InvalidOperationException("wrong action. parent didn't parsed.");
    //real bussiness logic
    EntityContext con = new EntityContext();
    Category cat = new Category();
    cat.Name = catName;
    cat.Parent = parent;
    con.Category.AddObject(cat);
    con.SaveChanges();
}

my entire bussiness layer are simple calls to database. so now i’m validating the data again! i already planned to do my validation in UI and test that kind of stuff in UI test units. what should i test in my bussiness logic method other than validation related tasks? and if there is nothing to be unit tested why everybody says “unit test all the layers” and things like that which i found a lot online?

  • 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-31T23:09:39+00:00Added an answer on May 31, 2026 at 11:09 pm

    The techniques involved in testing are those that you break down your program into smaller parts (smaller components or even classes) and test those small parts. As you assemble those parts together, you make less comprehensive tests — the smaller parts are already proven to work — until you have a functional, tested program, which then you give to users for “user tests”.

    It’s preferable to test smaller parts because:

    1. It’s simpler to write the tests. You’ll need less data, you only setup one object, you have to inject less dependencies.

    2. It’s easier to figure out what to test. You know the failing conditions from a simple reading of the code (or, better yet, from the technical specification).

    Now, how can you guarantee that you business layer, simple as it’s, is correctly implemented? Even a simple database insert can fail if badly written. Besides, how can you protected yourself from changes? Right know, the code works, but what will happen in the future if the database is changed or someone update the business logic.

    However, and this is important, you actually don’t need to test everything. Use your intuition (which is also called experience) to understand what needs testing and what doesn’t. If you method is simple enough, just make sure the client code is correctly tested.

    Finally, you’ve said that all your validation will occur in the UI. The business layer should be able to validate the data in order to increase reuse in your application. Fail to do that and whenever you or whoever make changes in your code in the future might create new UI and forget to add the required validations.

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

Sidebar

Related Questions

I have created a sample dylib with add(int,int) method. I kept this dylib in
I created a sample application using android sqlite database, my requirements are How can
I created a simple Apache server module following a sample hello world module I
I created the following simple PL/SQL stored procedure example to ask a specific question.
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
I've created a simple .NET MVC project, following the walkthrougth on MSDN.com. I'm confused
I cannot figure out why the following simple program doesn't (create) and then write
My business has a method which creates a MailMessage from an email. The method
We've got the following code sample: big_static_data = { key1 : { subkey1 :
I have created a sample application where I want to do scrolling, but I

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.