Use a custom data source reader

Tosca Data Integrity allows you to work with data sources that it doesn't support out-of the-box. You can integrate your own custom data source reader into Tosca Data Integrity to perform row-by-row comparisons or to load data into the caching database.

Tricentis recommends that you only use this approach if you have the technical knowledge to write a custom implementation.

Prerequisites

To create a custom data source reader and use it with Tosca Data Integrity, you must meet the following requirements:

  • Your customization must be based on .NetStandard 2.0. Customizations are only supported for Windows execution.

  • You must reference the Tricentis.DataIntegrity.GenericDataSource.dll. You can find this DLL in the directory $ToscaDataIntegrity_Home.

  • You must implement Interface ICustomDataReader as shown in the sample code below.

  • You must copy and paste your DLL files and all possible dependencies into the Custom Data Readers folder.

Integrate your custom data source reader

To integrate your custom data source reader into Tosca Data Integrity, follow the steps below:

  1. Go to C:\Program Files (x86)\TRICENTIS\Tosca Testsuite\Data Integrity.

  2. Copy and paste your DLL files and possible dependencies into the Custom Data Readers folder.

  3. Close and restart the Tosca Data Integrity Executor.

    You must always close and restart whenever you add files to the Custom Data Readers folder.

  4. To connect to your custom data source, populate the Custom Data Reader TestStepValues in your TestStep. For detailed information on how to do so, see the following chapters:

See which DLLs the Data Integrity Executor loads

The Tosca Data Integrity Executor loads the DLL files the first time it executes a Row by Row Comparison TestCase that uses a custom data source or target. The Executor log can show you which DLL files it loaded at run-time. To enable this option, follow the steps below:

  1. Open the Tosca Data Integrity Executor.

  2. Click Tools->Options.

  3. In the subsequent Options dialog, select Show debug messages.

Sample code of a custom data source reader

The following sample code depicts a custom data source reader for CSV files that allows you to a run row-by-row comparison with CSV files as source and target.

If you want to use the sample code as a template for your own custom data reader, you can copy it from here.

Copy
using System;
using System.Collections.Generic;
using System.IO;
using Tricentis.DataIntegrity.GenericDataSource;
namespace CustomReaderExtension
{
    [DataSourceReader("CustomCSVReader")]
    public class CustomCSVReaderExample : ICustomDataReader {
        public IDictionary<string, string> parameters;
        public StreamReader fileStream;
        public void Initialize(IDictionary<string, string> parameters) {
            this.parameters = parameters;
        }
        public void Connect() {
            fileStream = new StreamReader(parameters["FilePath"]);
        }
        public string[] GetColumnNames() {
            return ReadLine();
        }
        public string[] GetNextRow() {
            return ReadLine();
        }
        public bool HasMoreRows() {
            return !fileStream.EndOfStream;
        }
        public void Cancel() {
            //Not implemented, filereader will only be closed.
        }
        public void Disconnect() {
            fileStream.Close();
        }
        public string[] ReadLine() { 
            return fileStream.ReadLine().Split(',');
        }
    }
}

The sample code contains some functions that your custom data source reader should also contain to make the Row by Row Comparison work. Let's take a look at the most important lines:

  • ClassAtrributeName contains the name of the application. You add this name in the Class Attribute Name TestStepValue and Tosca Data Integrity uses it to distinguish between different custom implementations.

  • The Initialize method allows the application to receive key-value pairs and store the information that it gets from the TestStep locally. For example, the key is FilePath and the value is the actual file path D:\TestFile.csv.

  • The Connect method allows the application to create a connection. For example, to open a specific file and store the reference to it locally.

  • The Cancel method ensures that the application doesn't get stuck in case the reading operation has to be canceled.