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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:19:55+00:00 2026-06-12T06:19:55+00:00

I have to make a program that basically reads x lines from a file

  • 0

I have to make a program that basically reads x lines from a file and then tries to find it in the db then take some of the info in the file and update the info of the row in the db.

If all else fails insert it as a new row in db.

So basically alot of inserting and updating.

I trying to unit test as I am updating a lot of fields I want to make sure that each piece of info is going to right spot(ie not email address is being set with firstname or something like that).

However I am not sure how to do it as I see this being the program method

// get records from file

foreach record in file
{
   db record = find if it is in db

   if(record != null)
   {
        if(do another logic check)
         {
             // update record
         }
         else if(do another logic check)
         { 
            // update record
         }
        else
        {
           // do some more logic 

            if(do another check)
             {
               // update record
             }
        }
   }
   else
   {
      // do some more logic checks and do inserts.
   }
}

I see this in a void method with maybe some private methods(for say update record part). Now how should I be unit testing this? I want to unit test the first if(do another logic check) and if say some record I send in meets those conditions.

However since those would be private methods I can’t unit test them, right now I don’t see the the method returning anything since it will go through hundreds of records and I probably will be printing out most of stuff into a error log file or something.

the code I showed you is in a service layer. I would mock out the db method calls with moq.

The application is a console app.

Any suggestions how I could better break this up so I could check the logic?

  • 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-12T06:19:57+00:00Added an answer on June 12, 2026 at 6:19 am

    You could mock db calls, also you could mock record type and pass mocked inside method

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

Sidebar

Related Questions

I have been trying, in vain, to make a program that reads text out
I have written a program that reads in a File object (really an XML
I have a program that reads in serial information from a device and that
I basically, for this assignment, have to make a mini-program that randomly generates a
I have a Flash program that needs to make url requests to send data
I need to make the program which have one form that contains PNG image
I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and
I am new in java. I try to make a program and I have
I am trying to make a simple program with SFML. So far I have
So I have a huge program and decided I should make one of the

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.