Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:37:02+00:00 2026-06-12T14:37:02+00:00

I am writing unit tests for web services testing. I have added a service

  • 0

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.

enter image description here

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.

enter image description here

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:37:03+00:00Added an answer on June 12, 2026 at 2:37 pm

    You are already doing it, DataSource attribute 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 (ProcId perhaps), which you’ll retrieve together with row data and assert against at the end:

    // ...
    var VID = testContextInstance.DataRow["VID"].ToString();
    var expectedResult = testContextInstance.DataRow["ExpectedResult"].ToString();
    var isVisit = new Service.ISVisit()
    {
        CID = Cid,
        MNum = MNumber,
        VCode = VID
    };
    
    // ...
    
    Assert.AreEqual(expectedResult, first.Proc.ProcID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started writing web services in Delphi 2010 and am unit testing to
I had to start writing some unit tests, using QualityTools.UnitTestFramework, for a web service
I have been having a query regarding writing unit tests for web methods which
I'm in the process of writing unit tests for a JEE5 web service. The
I have been writing unit tests using NUnit and Moq with my Silverlight code
I’ve been writing unit tests in strongly typed languages and I have a fair
More precisely does writing unit tests consider as BDD practice? Does unite testing consider
I'm writing some unit tests and I have a lot of functions of the
I'm writing unit tests for an MVC web app, and I've been getting null
I am writing unit tests for our main product and have one concern: how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.