C# Client
The C# client is compatible with .NET Framework version 4.0 and above.
To use our C# API to generate and download reports, use our DLLs as explained in Create the C# Results API client.
First instantiate a ResultsAPIClient
providing a URL and API key.
Then call method GenerateReport()
to generate a report, and method DownloadReport()
or SaveReport()
to download a report.
Configure the project
In a Visual Studio project, it is necessary to include the DLL files available in the NuGet website.
To configure the project with DLLs from NuGet, follow these steps:
-
Open the project.
-
Open the Solution Explorer.
-
Find the References node in the project tree.
-
Click right and choose Manage NuGet Packages....
-
In the Search field, type: "neotys results".
-
Select dependency name: "NeotysRestResultsAPI".
-
Click the Install button.
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);
}
}
}