Unit Testing

This CDK provides sample projects that you can use as a model to set up unit tests. You can use the unit test projects included with the CDK that work with the sample Connector projects, and adapt the unit test projects to your Connector. The sample unit test projects include tests for metadata, methods, operations, and Connection. See Sample Projects for more information.

The Scribe.Connector.Cdk.Sample.Rest.Sys.Test project uses the Moq mocking library in several of its tests. Moq allows this, or any other project, to mock the data layer when unit testing other areas of the code. For more information about Moq, see https://github.com/Moq/moq4

Unit Testing Process

Complete the following process to develop and run tests:

  • Download the SDK - Connector Toolkit project and extract the Sample Projects.
  • Use the Sample Project unit tests as a guide to create unit tests for your own Connector.
  • Test the code.
  • View the Test Results window for information about the success or failure of the test. For more information, see Reviewing Test Results in the MSDN Library.

    You can build and run the sample Connectors and unit tests included in the CDK. See the TIBCO Scribe® Sample Projects and Testing in the MSDN Library for guidance.

Example Code

TIBCO Scribe® provides extensive unit tests for each of the CDK sample projects. These tests include examples of all expected method inputs and return values for the Scribe.Core.ConnectorApi, IConnector, and IMetadataProvider interfaces.

This example code shows the basics elements of a Connector’s Connect() method for testing purposes. View any of the sample project code for more details.

/// <summary>
        ///This is to test the third-party connection
        /// </summary>
        [TestMethod]
 public void SourceConnectorConnectionValidTest()
        {
 //create a new instance of the sample connector
 var sourceConnector = new SourceConnector();
 
 //setup the initial parameters for data connection
 Dictionary<string, string> properties = 
 new Dictionary<string, string>
            {
                {"Provider", "SQLNCLI10"},
                {"Server", "localhost"},
                {"Database", "ScribeSampleRSSource"},
                {"UserName", "sa"}
            };
 
 //encrypt the connection password using the shared key
 string encryptedPassword = Encryptor.Encrypt_AesManaged("sa", CryptoKey);
            properties.Add("Password", encryptedPassword);
 
 //call the connect method from the connector and pass
 //in the connection properties dictionary
            sourceConnector.Connect(properties);
 
 //do a check that the IsConnected flag is true
 //and the connection has been opened
 Assert.IsTrue(sourceConnector.IsConnected);
        }