Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,


I am writing a test case and i want to write a test case for a function having a datatable as parameter.

How i can achieve it?

My purpose is that i want to check whether certain columns exists in the datatable. So i can create a datatable, add columns and pass the datatable as parameter like this,

C#
DataTable dtExcel = new DataTable();
         DataColumn dtColumn = new DataColumn();

         dtColumn.ColumnName = "ID";
         dtExcel.Columns.Add(dtColumn);

         dtColumn = new DataColumn();
         dtColumn.ColumnName = "SyncID";
         dtExcel.Columns.Add(dtColumn);

         dtColumn = new DataColumn();
         dtColumn.ColumnName = "SyncRefDateTime";
         dtExcel.Columns.Add(dtColumn);

         dtColumn = new DataColumn();
         dtColumn.ColumnName = "Changed Date";
         dtExcel.Columns.Add(dtColumn);

         var validateExcel = objWISyncForm.ValidateExcel(dtExcel);



THe validate excel returns a bool value , how can i check with assert statement ?
Posted
Updated 1-Apr-14 20:30pm
v4
Comments
Maciej Los 2-Apr-14 2:16am    
var validateExcel = objWISyncForm.ValidateExcel(dtExcel); - What kind of result should ValidateExcel function return?
It looks like you want to return IEnumerable or IQuerable object.
Don't you know how to declare function or what?
ValidateExcel(DataTable dt)
Arjun Menon U.K 2-Apr-14 2:33am    
Sorry for not being clear. It just checks whether the dt contains the specified columns nothing much. One more question(may be a dumb question) , i have written test case for this function. Is there any sync between test case & code. Or we create test case only to check whether the function fails if any modifications is done on the function?
Maciej Los 2-Apr-14 3:00am    
I'm not sure what you mean by "test case". Please, describe your issue in details.
Arjun Menon U.K 2-Apr-14 3:07am    
I have a wind form project. I have added a unit test project. I am writing test case for some functions inside my project. One such function is ValidateExcel.But ValidateExcel function has a datatable as parameter. When i call the ValidateExcel from unit test class i have to provide the parameter and i am asking whether the code i wrote above is sufficient ...
Maciej Los 2-Apr-14 3:27am    
I know what you want to do, but i'm interesting what "unit test" means in this case. What ValidateExcel function should do? The answer on question "is that sufficient?" depends on it.

1 solution

Creating the datatable line by line in code is one possiblility. You could also serialize a datatable, add that to your project (as a file, or embedded as a resource), and then load it in your test function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900