Today I had to work with some legacy code. It was originally written in Delphi and then converted line by line to C#. Before changing anything in the code I decided to create unit tests and make sure that I have 100% coverage.
One of the thing I had to do in my unit test is to mock DataTable. Here are the steps I made during mocking.
- Create needed columns in a DataTable.
- Create a new DataRow.
- Assign values to the row.
- Finally add the row to the DataTable.
Repeat steps 2- 4 for each row you want to add to your DataTable.
Here’s the example:
I used Rhino.Mocks as my mocking framework in the example above.