Use a custom data reader
Custom data readers enable Tosca Cloud to read data sources that it doesn't support out of the box. You can create a custom data reader to fit your data source and upload it to Tosca Cloud. That way, you can use this data in Data Integrity tests you create with the Row by Row Comparison module and the Load Data into Caching Database from Customization module.
To create a custom data reader that is compatible with Tosca Cloud, code a DLL file that fits the following requirements:
-
Base your customization on .NetStandard 2.0, so it works for both our Windows execution and Linux execution.
-
Reference the Tricentis.DataIntegrity.GenericDataSource.dll.
After you run a Data Integrity test case on Windows, the Tosca Cloud Launcher downloads this DLL to the directory
%LOCALAPPDATA%\TRICENTIS\Launcher\TBox\<latest TBox version>\Tricentis Tosca Data Integrity.You can also download the DLL here.
-
Specify the class attribute name of your reader under DataSourceReader. Tosca Cloud uses this name to distinguish between different custom readers.
-
Use the
Initializemethod to allow the application to receive key-value pairs for a test step and store the information that it gets from that test step locally. For example, the key is FilePath and the value is the actual file pathD:\TestFile.csv. -
Use the
Connectmethod to allow the application to create a connection. For example, to open a specific file and store the reference to it locally. -
Use the
Cancelmethod to ensure that the application doesn't get stuck if the reading operation has to be canceled. -
Implement
Interface ICustomDataReaderas shown in the following example.
The following sample code depicts a custom data reader for CSV files that allows you to run the row-by-row comparison module with CSV files as source and target.
You can copy the sample code to use as a template for your own custom data reader.
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(',');
}
}
}
To use a custom data reader in your test, you first need to upload it to Tosca Cloud. To do so, follow these steps:
-
Go to
Configurations > Uploads > Custom Data Readers > Upload file.
Note that only users with administrator rights can upload files to Tosca Cloud.
-
Select Custom from the Choose a data reader to upload dropdown menu.
-
Select your custom data reader from your local files.
After you upload a custom data reader, you are able to see it in your Custom data readers list in Tosca Cloud. It is also available to use in all Data Integrity tests you create with the Load Data into Caching Database or Complete Row by Row Comparison modules. To use a custom data reader with these modules, fill out the test step value Custom Data Reader as follows:
-
For Class Attribute Name, enter the name of the reader that is under DataSourceReader in the reader's DLL file.
-
Under Parameters, set up your parameters as they are specified in the reader's DLL file.