diff --git a/iothub/service/src/DigitalTwin/DigitalTwinClient.cs b/iothub/service/src/DigitalTwin/DigitalTwinClient.cs index 03b558b0d6..6d288ead12 100644 --- a/iothub/service/src/DigitalTwin/DigitalTwinClient.cs +++ b/iothub/service/src/DigitalTwin/DigitalTwinClient.cs @@ -21,6 +21,14 @@ public class DigitalTwinClient : IDisposable private readonly IotHubGatewayServiceAPIs _client; private readonly DigitalTwin _protocolLayer; + /// + /// Creates an instance of , provided for unit testing purposes only. + /// Use the CreateFromConnectionString method to create an instance to use the client. + /// + public DigitalTwinClient() + { + } + /// /// Initializes a new instance of the class. /// The IoT hub's connection string. @@ -34,7 +42,6 @@ public static DigitalTwinClient CreateFromConnectionString(string connectionStri return new DigitalTwinClient(iotHubConnectionString.HttpsEndpoint, sharedAccessKeyCredential, handlers); } - private DigitalTwinClient(Uri uri, IotServiceClientCredentials credentials, params DelegatingHandler[] handlers) { var httpMessageHandler = HttpClientHelper.CreateDefaultHttpMessageHandler(null, uri, ServicePointHelpers.DefaultConnectionLeaseTimeout); @@ -96,7 +103,7 @@ private static HttpMessageHandler CreateHttpHandlerPipeline(HttpMessageHandler h /// The Id of the digital twin. /// The cancellation token. /// The application/json digital twin and the http response. - public async Task> GetDigitalTwinAsync(string digitalTwinId, CancellationToken cancellationToken = default) + public virtual async Task> GetDigitalTwinAsync(string digitalTwinId, CancellationToken cancellationToken = default) { using HttpOperationResponse response = await _protocolLayer.GetDigitalTwinWithHttpMessagesAsync(digitalTwinId, null, cancellationToken) .ConfigureAwait(false); @@ -118,10 +125,10 @@ public async Task> GetDigitalTwi /// The optional settings for this request. /// The cancellationToken. /// The http response. - public Task> UpdateDigitalTwinAsync( - string digitalTwinId, - string digitalTwinUpdateOperations, - DigitalTwinUpdateRequestOptions requestOptions = default, + public virtual Task> UpdateDigitalTwinAsync( + string digitalTwinId, + string digitalTwinUpdateOperations, + DigitalTwinUpdateRequestOptions requestOptions = default, CancellationToken cancellationToken = default) { return _protocolLayer.UpdateDigitalTwinWithHttpMessagesAsync(digitalTwinId, digitalTwinUpdateOperations, requestOptions?.IfMatch, null, cancellationToken); @@ -136,20 +143,20 @@ public Task> UpdateDigital /// The optional settings for this request. /// The cancellationToken. /// The application/json command invocation response and the http response. - public async Task> InvokeCommandAsync( - string digitalTwinId, - string commandName, - string payload = default, - DigitalTwinInvokeCommandRequestOptions requestOptions = default, + public virtual async Task> InvokeCommandAsync( + string digitalTwinId, + string commandName, + string payload = default, + DigitalTwinInvokeCommandRequestOptions requestOptions = default, CancellationToken cancellationToken = default) { using HttpOperationResponse response = await _protocolLayer.InvokeRootLevelCommandWithHttpMessagesAsync( - digitalTwinId, - commandName, - payload, - requestOptions?.ConnectTimeoutInSeconds, - requestOptions?.ResponseTimeoutInSeconds, - null, + digitalTwinId, + commandName, + payload, + requestOptions?.ConnectTimeoutInSeconds, + requestOptions?.ResponseTimeoutInSeconds, + null, cancellationToken) .ConfigureAwait(false); return new HttpOperationResponse @@ -171,22 +178,22 @@ public async TaskThe optional settings for this request. /// The cancellationToken. /// The application/json command invocation response and the http response. - public async Task> InvokeComponentCommandAsync( - string digitalTwinId, - string componentName, - string commandName, - string payload = default, - DigitalTwinInvokeCommandRequestOptions requestOptions = default, + public virtual async Task> InvokeComponentCommandAsync( + string digitalTwinId, + string componentName, + string commandName, + string payload = default, + DigitalTwinInvokeCommandRequestOptions requestOptions = default, CancellationToken cancellationToken = default) { using HttpOperationResponse response = await _protocolLayer.InvokeComponentCommandWithHttpMessagesAsync( - digitalTwinId, - componentName, - commandName, - payload, - requestOptions?.ConnectTimeoutInSeconds, - requestOptions?.ResponseTimeoutInSeconds, - null, + digitalTwinId, + componentName, + commandName, + payload, + requestOptions?.ConnectTimeoutInSeconds, + requestOptions?.ResponseTimeoutInSeconds, + null, cancellationToken) .ConfigureAwait(false); return new HttpOperationResponse diff --git a/iothub/service/src/JobClient/JobClient.cs b/iothub/service/src/JobClient/JobClient.cs index 21cf370e2d..317b8a99de 100644 --- a/iothub/service/src/JobClient/JobClient.cs +++ b/iothub/service/src/JobClient/JobClient.cs @@ -30,7 +30,8 @@ public class JobClient : IDisposable private IHttpClientHelper _httpClientHelper; /// - /// Creates an instance of . + /// Creates an instance of , provided for unit testing purposes only. + /// Use the CreateFromConnectionString method to create an instance to use the client. /// public JobClient() { diff --git a/iothub/service/src/RegistryManager.cs b/iothub/service/src/RegistryManager.cs index 7451180c38..77398d3d94 100644 --- a/iothub/service/src/RegistryManager.cs +++ b/iothub/service/src/RegistryManager.cs @@ -62,7 +62,8 @@ public class RegistryManager : IDisposable private IHttpClientHelper _httpClientHelper; /// - /// Creates an instance of . + /// Creates an instance of , provided for unit testing purposes only. + /// Use the CreateFromConnectionString method to create an instance to use the client. /// public RegistryManager() { diff --git a/iothub/service/src/ServiceClient.cs b/iothub/service/src/ServiceClient.cs index 4790d2b676..5416ad59d8 100644 --- a/iothub/service/src/ServiceClient.cs +++ b/iothub/service/src/ServiceClient.cs @@ -64,7 +64,8 @@ public class ServiceClient : IDisposable internal readonly IotHubConnection Connection; /// - /// Creates an instance of . + /// Creates an instance of , provided for unit testing purposes only. + /// Use the CreateFromConnectionString method to create an instance to use the client. /// public ServiceClient() {