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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:36:27+00:00 2026-05-22T21:36:27+00:00

Consider an implementation of the Repository Pattern (or similar). I’ll try to keep the

  • 0

Consider an implementation of the Repository Pattern (or similar). I’ll try to keep the example/illustration as succinct as possible:

interface IRepository<T>
{
    void Add(T entity);
}

public class Repository<T> : IRepository<T>
{
    public void Add(T entity)
    {
        // Some logic to add the entity to the repository here.
    }
}

In this particular implementation, the Repository is defined by an interface IRepository to have one method which adds an entity to the repository, thus making Repository dependant upon the generic type T (also, the Repository must be implicitly dependant upon another type TDataAccessLayer, since the abstraction is the entire point of the Repository Pattern. This dependency, however, is not currently readily available). At this point, from what I understand so far, I have two options: Unit Testing and Integration Testing.

Where Integration Testing may be assumed to have a greater number of moving parts, I would much rather initially Unit Test in order to as least verify a baseline functionality. However, without creating some sort of “entity” property (of generic type T), I can see no way of asserting that any logic is actually performed within the Add() method of the Repository implementation.

Is there, perhaps, a middle ground somewhere between Unit Testing and Integration Testing which allows (through Reflection or some other means) to verify that specific points of execution have been reached within a tested unit?

The only explanation I’ve come up with for this particular issue is to further abstract the Data Access Layer from the repository, resulting in the Add() method accepting not only an entity argument but also a Data Access argument. This seems to me like it might defeat the purpose of the Repository Pattern, however, since the consumer of the Repository must now know about the Data Access Layer.

With regard to request for examples:

(1) And in regard to Unit Testing, I’m not sure something like a Repository could actually be Unit Tested with my understanding of current testing techniques. Because a Repository is an abstraction (wrapper) around a specific Data Access Layer, it seems that the only method of verification would be an Integration Test? (Granted, a Repository Interface may not be tied to any specific DAL, but any implemented Repository must surely be tied to a specific DAL implementation, therefore the need to be able to test that the Add() method actually performs some work).

(2) And in regard to Integration Testing, the test, as I understand the technique, would verify the Add() method performing work by actually calling the Add() method (which should add a record to the repository) and then check to see that the data was actually added to the repository (or perhaps database in a specific scenario). This may look something like:

[TestMethod]
public void Add()
{
    Repository<Int32> repository = new Repository<Int32>();
    Int32 testData = 10;

    repository.Add(testData);

    // Intended to illustrate the point succinctly. Perhaps the repository Get() method would not
    // be called (and a DBCommand unrelated to the repository issued instead). However, assuming the
    // Get() method to have been previously verified, this could work.
    Assert.IsTrue(testData == repository.Get(testData));
}

So, in this instance, assuming the repository is a wrapper around some database logic layer, the database is actually hit twice during the test (once during insert, and once during retrieve).

Now, what I could see being useful, would be a technique for verifying that a certain execution path is taken during runtime. An example could be that if a non-null reference is passed in, verify execution path A is taken, and if a null reference is passed in, verify execution path B is taken. Also, perhaps one could verify that particular LINQ query was to be executed. Therefore, the database is never actually hit during the test (allowing prototyping and development of an implementation without any actual DAL in place).

  • 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-05-22T21:36:28+00:00Added an answer on May 22, 2026 at 9:36 pm

    It sounds like you’re describing the testing of an implementation detail rather than fulfillment of the requirements of a pattern by an implementor of the pattern. It doesn’t matter if “specific points of execution” have been reached within the tested unit, it only matters if the concrete implementor upholds the contract of the interface. It’s perfectly acceptable for tests to create a T entity for testing purposes, that’s what mocks are for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have what I'd consider a standard .NET MVC3 Repository pattern project that I've
Consider an implementation of the Entity Framework in a DAL assembly. I am needing
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the following implementation of a function to compute factorial: [1] (define fac-tail (lambda
Consider a MyForm class that contains a shadowed implementation of Show() . It also
Consider the following as a reference implementation: /* calculates (a * b) / c
Consider the (highly simplified) following case: class Dispatcher { public: receive() {/*implementation*/}; // callback
Consider the following simple polymorphism ... class Parent { public: someFunc() { /* implementation
I think there is a problem in php's OOP implementation. EDIT: Consider more illustrative

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.