user2527020
user2527020

Reputation:

How do I mock an ADO connection?

I'm trying to figure out how to mock a TADOConnection (working with Delpi XE2 and SQL server). The thing is that for unit testing I'd like to be able to fake out the connection and populate the datasets with static data instead of data from the database. So that when I do this,

ADOQuery.Connection := FakeADOConn;  
ADOQuery.SQL.Add(SQLStr);

, there would just be a lookup, matching SQLStr to some predefined data in a textfile (I'm thinking XML).

Textfile -> FakeTADOConnection -> TADODataset -> Data source -> Data Control

However when I've googled I've not been able to find anything on the topic, which makes me suspicious that I'm completely off, and this whole thing is a stupid idea.

So could someone explain to me how one go about faking a ADO connection or, alternatively, why wanting to do so is a ridiculous idea?

Upvotes: 0

Views: 401

Answers (2)

AlexSC
AlexSC

Reputation: 1923

Declare a class like this:

type
  TMockADOConnection = class(TInterfacedObject, IADOConnection)
    // Declare here all the interface methods
  end;

Then you will have to implement all the IADOConnection interface methods.

Upvotes: 1

Paul Mitchell
Paul Mitchell

Reputation: 3281

I think you might find the Repository Pattern useful here.

Upvotes: 1

Related Questions