Hi I'm working on a c# MVC code first project. I've started the project and have created the Models, database frontend etc.
Now my attention has come to writing something that can read an excel document and import the data into my database.
This is a bit of a fiddly task, to say the least - so I did start making a unit test in my test project. This worked fine reading the excel and getting the values but because it didn't have access to the Context(database) wasn't enough to finish the job.
So I made a new controller/action in my MVC project and copied the start of the code in. I then wrote the bits with writing the information to the database. This then caused issues. So I changed the action into a test method and the controller into a test class. Then I could output whatever I wanted using the Trace commands and find out what was going on.
Is this the right thing to do? Maybe if it works remove the testClass/testMethod once I'm happy and then return an action? I'm thinking about doing this perhaps if I have other files I need to process in this fashion.
How do other people tackle this problem?
Thanks, when you say an extra class doing the excel stuff. I'm using EPPlus to read the excel and that's doing just fine for me.
Just talking to my college and basically I shouldn't be using the test methods as a form of debug and instead using the VS debugger. Which after a bit of tutorial seems to be the way.