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 7707773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:26:44+00:00 2026-06-01T00:26:44+00:00

We have an n-tier web application that pulls data from SQL Server. Our Data

  • 0

We have an n-tier web application that pulls data from SQL Server. Our Data Access logic returns an SqlDataReader whose data is then used to create our Business objects (a.k.a. Data Transfer objects).

We wish to build unit tests to check our code that interprets the data returned by these SqlDataReader objects to build our Business objects.

It therefore seems necessary to build stubs to replace the SqlDataReader objects during unit testing. As is probably fairly typical, our SqlDataReader objects generally return multiple recordsets, each with multiple rows.

  1. Is this a sensible endeavour?
  2. How should we go about building these stub objects?

Many thanks in advance

Griff

  • 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-01T00:26:45+00:00Added an answer on June 1, 2026 at 12:26 am

    Automated testing is basically always a sensible endeavour 🙂

    Your first step to be able to test this is to have your Data Access logic return an IDataReader instead of an SqlDataReader – SqlDataReader implements IDataReader, so no problems there.

    In your unit tests you can then manually build and populate DataTable objects, and call dataTable.CreateDataReader() to get an IDataReader to pass into the object under test.

    Edit

    To provide your tests with a set of sample data, I’d suggest using an ObjectMother for each data table you use, keeping creation of the data tables in one dedicated place. You can then put methods on each ObjectMethod class to update certain data in a strongly-typed way. For example:

    public class PersonalDetailsBuilder
    {
        private DataTable _dataTable;
    
        public PersonalDetailsBuilder CreateNewTable()
        {
            this._dataTable = new DataTable("CustomerPersonalDetails")
            {
                Columns = 
                {
                    new DataColumn("CustomerId", typeof(int)),
                    new DataColumn("CustomerName", typeof(string))
                }
            };
    
            return this;
        }
    
        public PersonalDetailsBuilder AddStandardData(int numberOfRows = 3)
        {
            foreach (int i in Enumerable.Range(1, numberOfRows + 1))
            {
                this.AddRow(i, "Customer " + i);
            }
    
            return this;
        }
    
        public PersonalDetailsBuilder AddRow(int customerId, string customerName)
        {
            this._dataTable.Rows.Add(customerId, customerName);
    
            return this;
        }
    
        public IDataReader ToDataReader()
        {
            return this._dataTable.CreateDataReader();
        }
    }
    

    …which you could then use like this to get a data reader:

    IDataReader customerDetailsReader = new PersonalDetailsBuilder()
        .CreateNewTable()
        .AddStandardData()
        .AddRow(17, "Customer 17")
        .ToDataReader();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web-app-database 3 tier server setup. Web requests data from app, and
I have a data tier select method that returns a datatable. It's called from
I have a three tier system, SQL Server backend, hand written data access layer,
I have a classic 3-tier ASP.Net 3.5 web application with forms that display business
Background: I have an application that I have nicely separated my interface logic from
I have a three tier web app that produces three separate dlls: Web.UI.dll Web.Application.dll
I have a three-tier application which is installed in corporate environments. With every server
I have created an n-tier solution where I am retrieving related data from a
I have a 3 tier application that requires security authorizations be placed on various
In my web application, I create some framework that use to bind model data

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.