Create the C# Results API client

Example 1

In this example, we generate a PDF report for test result name “MyFirstTest” and then we retrieve the byte array.

using Neotys.CommonAPI.Data;
using Neotys.ResultsAPI.Client;
using Neotys.ResultsAPI.Model;

namespace TestResultsAPI
{
class GenerateAndDownloadReportExample
	{
    		static void Main(string[] args)
    		{
        			 IResultsAPIClient client = ResultsAPIClientFactory.NewClient("http://localhost:7400/Results/v1/Service.svc/");

           			 // Create the params to generate a report, based on test result "MyFirstTest" and format PDF
           			 GenerateReportParams generateReportParams = new GenerateReportParamsBuilder().testResultName("MyFirstTest").format(Format.PDF).Build();

           			 // Trigger the generation of the report and retrieve the report Id
            			string reportId = client.GenerateReport(generateReportParams);

            			// Download the report from the id
           			 BinaryData reportBinary = client.DownloadReport(new DownloadReportParams(reportId));

    }
}
}

Example 2

In this example, we generate a RTF comparison report for test results named “MyTest1” and “MyTest2”, we wait 3 seconds for the generation, and then we download the file on disk (folder C:\tmp).

using Neotys.ResultsAPI.Client;
using Neotys.ResultsAPI.Model;
using System;

namespace TestResultsAPI
{
	class GenerateAndSaveComparisonReportExample
	{
    	static void Main(string[] args)
    	{
        	// Instanciate ResultsAPIClient by specifying the connection URL
            	IResultsAPIClient client = ResultsAPIClientFactory.NewClient("http://localhost:7400/Results/v1/Service.svc/");

            	// Create the params to generate a report, based on test result "MyFirstTest" and format PDF
            	GenerateReportParams generateReportParams = new GenerateReportParamsBuilder().comparisonReport(true).testResultName("MyTest1").otherTestResultName("MyTest2").format(Format.RTF).Build();

            	// Trigger the generation of the report and retrieve the report Id
           	 string reportId = client.GenerateReport(generateReportParams);

            	// Download the report from the id
           	 string destinationFolder = "C:/temp";
           	 client.SaveReport(new DownloadReportParams(reportId), destinationFolder);

    	}
	}
}