I am writing unit tests for web services testing. I have added a service reference to the C# unit tests solution and started consuming the classes in the web services for the testing. I have also added an Excel file to provide unit test values.
Below is a example about what I was doing before
[DataSource("System.Data.Odbc"
,"Dsn=Excel Files;dbq=|DataDirectory|\\TestData.xlsx;defaultdir=C:\\TestData;driverid=1046;maxbuffersize=2048;pagetimeout=5"
,"Sheet1$"
,DataAccessMethod.Sequential)
,DeploymentItem("TestProject1\\TestData.xlsx")
,Owner("")
,Description("")
,TestMethod()]
public void test1()
{
try
{
var Service = new Service.ServiceClient();
var Cid = testContextInstance.DataRow["CId"].ToString();
var MNumber = testContextInstance.DataRow["MNumber"].ToString();
var VID = testContextInstance.DataRow["VID"].ToString();
var isVisit = new Service.ISVisit()
{
CID = Cid,
MNum = MNumber,
VCode = VID
};
var first = Service.Medis(isVisit).Cast<Service.ISMedi>().FirstOrDefault();
// Assert
Assert.AreEqual("12345678", first.Proc.ProcID);
}
catch (Exception ex1)
{
if (ex1.InnerException != null)
Debug.WriteLine(ex1.InnerException.Message);
Assert.Fail(ex1.Message);
}
}
This test1 has passed .Medis(), IsVisit are classes in the services. Until now I just had one row in the Excel file and I was able to retrieve the data and test it.

But now the requirement is that if there are more than one row in the excel file, the unit test should loop through each row and test each row to see pass/fail.

Please Help me with this.How to loop through each row in the excel file in and check the test results.How to handle this situation in c# unitesting.Thank you
You are already doing it,
DataSourceattribute runs test once per row in source file. Your problem is asserting results.To solve it, your excel files should also contain some sort of expected result for row column (
ProcIdperhaps), which you’ll retrieve together with row data and assert against at the end: