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?