From 45642437f48b98a946ef2b3bee28bb86f201b497 Mon Sep 17 00:00:00 2001
From: jamdavi <73593426+jamdavi@users.noreply.github.com>
Date: Tue, 7 Dec 2021 18:55:04 -0700
Subject: [PATCH 01/33] doc(client, service): Update documents about the Proxy
property for various clients (#2248)
Update our code docs to better explain proxy settings
---
iothub/device/src/AmqpTransportSettings.cs | 4 +-
iothub/device/src/Http1TransportSettings.cs | 4 +-
iothub/device/src/ITransportSettings.cs | 38 ++++++++++
.../Transport/Mqtt/MqttTransportSettings.cs | 4 +-
iothub/service/src/HttpTransportSettings.cs | 33 ++++++++-
.../src/ServiceClientTransportSettings.cs | 69 ++++++++++++++++++-
6 files changed, 138 insertions(+), 14 deletions(-)
diff --git a/iothub/device/src/AmqpTransportSettings.cs b/iothub/device/src/AmqpTransportSettings.cs
index 59b56192bf..84a427e4eb 100644
--- a/iothub/device/src/AmqpTransportSettings.cs
+++ b/iothub/device/src/AmqpTransportSettings.cs
@@ -156,9 +156,7 @@ public TimeSpan OpenTimeout
///
public X509Certificate2 ClientCertificate { get; set; }
- ///
- /// The proxy
- ///
+ ///
public IWebProxy Proxy { get; set; }
///
diff --git a/iothub/device/src/Http1TransportSettings.cs b/iothub/device/src/Http1TransportSettings.cs
index d8d638d30e..cd8db8a784 100644
--- a/iothub/device/src/Http1TransportSettings.cs
+++ b/iothub/device/src/Http1TransportSettings.cs
@@ -45,9 +45,7 @@ public TransportType GetTransportType()
///
public TimeSpan DefaultReceiveTimeout => s_defaultOperationTimeout;
- ///
- /// Proxy information.
- ///
+ ///
public IWebProxy Proxy { get; set; }
}
}
diff --git a/iothub/device/src/ITransportSettings.cs b/iothub/device/src/ITransportSettings.cs
index e4fccefdc3..2d064751c9 100644
--- a/iothub/device/src/ITransportSettings.cs
+++ b/iothub/device/src/ITransportSettings.cs
@@ -2,6 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
+using System.Net;
+using Microsoft.Azure.Devices.Shared;
namespace Microsoft.Azure.Devices.Client
{
@@ -20,5 +22,41 @@ public interface ITransportSettings
/// The time to wait for a receive operation.
///
TimeSpan DefaultReceiveTimeout { get; }
+
+ ///
+ /// The web proxy that will be used to connect to IoT hub using a web socket connection for AMQP, MQTT, or when using the HTTP protocol.
+ ///
+ ///
+ /// An instance of a class that implements .
+ ///
+ ///
+ /// This setting will be used when the client attempts to connect over web sockets. For example, if the client attempts to connect to IoT hub using or the client will first try over TCP. If that fails, the client will fall back to using web sockets and will use the proxy setting. The setting will also be used when , , or is specified.
+ ///
+ ///
+ /// To set a proxy you must instantiate an instance of the class--or any class that derives from . The snippet below shows a method that returns a device using a proxy that connects to localhost on port 8888.
+ ///
+ /// static DeviceClient GetClientWithProxy()
+ /// {
+ /// try
+ /// {
+ /// var proxyHost = "localhost";
+ /// var proxyPort = 8888;
+ /// // Specify the WebProxy to be used for the web socket connection
+ /// var transportSettings = new AmqpTransportSettings(Microsoft.Azure.Devices.Client.TransportType.Amqp_WebSocket_Only)
+ /// {
+ /// Proxy = new WebProxy(proxyHost, proxyPort)
+ /// };
+ /// var deviceClient = DeviceClient.CreateFromConnectionString("a connection string", new ITransportSettings[] { transportSettings });
+ /// return deviceClient;
+ /// }
+ /// catch (Exception)
+ /// {
+ /// Console.WriteLine("Error creating client.");
+ /// throw;
+ /// }
+ /// }
+ ///
+ ///
+ IWebProxy Proxy { get; set; }
}
}
diff --git a/iothub/device/src/Transport/Mqtt/MqttTransportSettings.cs b/iothub/device/src/Transport/Mqtt/MqttTransportSettings.cs
index 65d46003b9..376d264590 100644
--- a/iothub/device/src/Transport/Mqtt/MqttTransportSettings.cs
+++ b/iothub/device/src/Transport/Mqtt/MqttTransportSettings.cs
@@ -232,9 +232,7 @@ public bool CertificateRevocationCheck
///
public X509Certificate ClientCertificate { get; set; }
- ///
- /// The proxy settings to be used when communicating with IoT Hub.
- ///
+ ///
public IWebProxy Proxy { get; set; }
///
diff --git a/iothub/service/src/HttpTransportSettings.cs b/iothub/service/src/HttpTransportSettings.cs
index 867bee88f6..e829726d11 100644
--- a/iothub/service/src/HttpTransportSettings.cs
+++ b/iothub/service/src/HttpTransportSettings.cs
@@ -20,12 +20,39 @@ public HttpTransportSettings()
}
///
- /// Proxy information.
+ /// The web proxy that will be used to connect to IoT hub when using the HTTP protocol.
///
+ ///
+ /// An instance of a class that implements .
+ ///
///
- /// This is used when a device is on a network that doesn't have direct internet access and needs to access it via a proxy,
- /// especially when MQTT and AMQP ports are disallowed to the internet.
+ /// The class is only used for the or the ; so the proxy set here will only be valid for those clients.
///
+ ///
+ /// To set a proxy you must instantiate an instance of the class--or any class that derives from . The snippet below shows a method that returns a device using a proxy that connects to localhost on port 8888.
+ ///
+ /// static JobClient GetJobClient()
+ /// {
+ /// try
+ /// {
+ /// var proxyHost = "localhost";
+ /// var proxyPort = 8888;
+ /// var transportSettings = new HttpTransportSettings
+ /// {
+ /// Proxy = new WebProxy(proxyHost, proxyPort)
+ /// };
+ /// // Specify the WebProxy to be used for the HTTP connection
+ /// var jobClient = JobClient.CreateFromConnectionString("a connection string", transportSettings);
+ /// return jobClient;
+ /// }
+ /// catch (Exception)
+ /// {
+ /// Console.WriteLine("Error creating client.");
+ /// throw;
+ /// }
+ /// }
+ ///
+ ///
public IWebProxy Proxy { get; set; }
///
diff --git a/iothub/service/src/ServiceClientTransportSettings.cs b/iothub/service/src/ServiceClientTransportSettings.cs
index 0e00bac607..cb559084ed 100644
--- a/iothub/service/src/ServiceClientTransportSettings.cs
+++ b/iothub/service/src/ServiceClientTransportSettings.cs
@@ -21,13 +21,78 @@ public ServiceClientTransportSettings()
}
///
- /// The proxy settings to be used on the AMQP client.
+ /// The web proxy that will be used to connect to IoT hub when using the AMQP over web sockets.
///
+ ///
+ /// An instance of a class that implements .
+ ///
+ ///
+ /// This setting will be used when the client attempts to connect over web sockets. For example, if the client attempts to connect to IoT hub using the client will first try over TCP. If that fails, the client will fall back to using web sockets and will use the proxy setting. This setting is to be used in conjunction with the property.
+ ///
+ ///
+ /// To set a proxy you must instantiate an instance of the class--or any class that derives from . The snippet below shows a method that returns a device using a proxy that connects to localhost on port 8888.
+ ///
+ /// static ServiceClient GetServiceClient()
+ /// {
+ /// try
+ /// {
+ /// var proxyHost = "localhost";
+ /// var proxyPort = 8888;
+ /// var proxy = new WebProxy(proxyHost, proxyPort);
+ /// var transportSettings = new ServiceClientTransportSettings
+ /// {
+ /// AmqpProxy = proxy,
+ /// HttpProxy = proxy
+ /// };
+ /// var serviceClient = ServiceClient.CreateFromConnectionString("a connection string", Microsoft.Azure.Devices.TransportType.Amqp_WebSocket_Only, transportSettings );
+ /// return serviceClient;
+ /// }
+ /// catch (Exception)
+ /// {
+ /// Console.WriteLine("Error creating client.");
+ /// throw;
+ /// }
+ /// }
+ ///
+ ///
public IWebProxy AmqpProxy { get; set; }
///
- /// The proxy settings to be used on the HTTP client.
+ /// The web proxy that will be used to connect to IoT hub when operations must execute over HTTP.
///
+ ///
+ /// An instance of a class that implements .
+ ///
+ ///
+ /// Methods such as are executed over HTTP and not AMQP. This setting will ensure those methods are executed over the specified proxy. This setting is to be used in conjunction with the property.
+ ///
+ ///
+ /// To set a proxy you must instantiate an instance of the class--or any class that derives from . The snippet below shows a method that returns a device using a proxy that connects to localhost on port 8888.
+ ///
+ /// static ServiceClient GetServiceClient()
+ /// {
+ /// try
+ /// {
+ /// var proxyHost = "localhost";
+ /// var proxyPort = 8888;
+ /// var proxy = new WebProxy(proxyHost, proxyPort);
+ /// var transportSettings = new ServiceClientTransportSettings
+ /// {
+ /// AmqpProxy = proxy,
+ /// HttpProxy = proxy
+ /// };
+ /// // Specify the WebProxy to be used for the web socket connection
+ /// var serviceClient = ServiceClient.CreateFromConnectionString("a connection string", Microsoft.Azure.Devices.TransportType.Amqp_WebSocket_Only, transportSettings );
+ /// return serviceClient;
+ /// }
+ /// catch (Exception)
+ /// {
+ /// Console.WriteLine("Error creating client.");
+ /// throw;
+ /// }
+ /// }
+ ///
+ ///
public IWebProxy HttpProxy { get; set; }
///
From 27685d1898e96bf69870adc673baf1a2e9b39407 Mon Sep 17 00:00:00 2001
From: Azad Abbasi
Date: Wed, 8 Dec 2021 23:09:56 +0000
Subject: [PATCH 02/33] Cleanup IDE warnings. From 442 down to 31. (#2254)
---
common/src/Logging.Common.cs | 1 -
.../transport/ProvisioningSasBuilder.cs | 2 +-
common/src/service/HttpClientHelper.cs | 4 +-
common/src/service/StringValidationHelper.cs | 4 +-
e2e/test/GlobalSuppressions.cs | 17 +++++
e2e/test/config/TestConfiguration.IoTHub.cs | 12 ++--
e2e/test/helpers/StorageContainer.cs | 2 +-
e2e/test/helpers/TestDevice.cs | 2 +-
...enticationWithTokenRefreshDisposalTests.cs | 20 +++---
.../ConnectionStatusChangeHandlerTests.cs | 16 ++---
.../DeviceClientX509AuthenticationE2ETests.cs | 8 +--
e2e/test/iothub/DeviceTokenRefreshE2ETests.cs | 8 +--
.../iothub/FileUploadFaultInjectionTests.cs | 2 +-
.../SasCredentialAuthenticationTests.cs | 2 +-
.../TokenCredentialAuthenticationTests.cs | 2 +-
...rityCenterForIoTSecurityMessageE2ETests.cs | 2 +-
...ssageReceiveFaultInjectionPoolAmqpTests.cs | 2 +-
.../messaging/MessageFeedbackE2ETests.cs | 4 +-
.../messaging/MessageReceiveE2ETests.cs | 14 ++---
.../iothub/messaging/MessageSendE2ETests.cs | 34 +++++-----
e2e/test/iothub/method/MethodE2ETests.cs | 12 ++--
.../method/MethodFaultInjectionTests.cs | 2 +-
.../iothub/service/BulkOperationsE2ETests.cs | 38 ++++++------
.../IoTHubCertificateValidationE2ETest.cs | 42 ++++++-------
.../service/IoTHubServiceProxyE2ETests.cs | 22 +++----
e2e/test/iothub/service/PnpServiceTests.cs | 12 ++--
.../iothub/service/RegistryManagerE2ETests.cs | 27 ++++----
.../RegistryManagerExportDevicesTests.cs | 8 +--
.../RegistryManagerImportDevicesTests.cs | 2 +-
.../iothub/service/ServiceClientE2ETests.cs | 10 +--
...qpTests.TwinFaultInjectionPoolAmqpTests.cs | 8 +--
e2e/test/iothub/twin/TwinE2ETests.cs | 62 +++++++++----------
.../iothub/twin/TwinFaultInjectionTests.cs | 12 ++--
...rovisioningCertificateValidationE2ETest.cs | 16 ++---
e2e/test/provisioning/ProvisioningE2ETests.cs | 37 +++++------
.../ProvisioningServiceClientE2ETests.cs | 18 +++---
.../provisioning/ReprovisioningE2ETests.cs | 18 +++---
.../device/src/AuthenticationMethodFactory.cs | 18 +++---
iothub/device/src/ClientFactory.cs | 7 +--
.../Common/Amqp/ClientWebSocketTransport.cs | 4 +-
.../src/Common/Extensions/CommonExtensions.cs | 2 +-
iothub/device/src/Common/Fx.cs | 2 +-
.../device/src/Common/PartialTrustHelpers.cs | 2 +-
.../device/src/Common/ReadOnlyDictionary45.cs | 16 ++---
iothub/device/src/Common/SynchronizedPool.cs | 2 +-
iothub/device/src/Common/TaskHelpers.cs | 2 +-
iothub/device/src/Common/Utils.cs | 2 +-
iothub/device/src/GlobalSuppressions.cs | 36 +++++++++--
iothub/device/src/IotHubClientDiagnostic.cs | 2 +-
.../Transport/HttpUdsMessageHandler.cs | 2 +-
.../AsyncExecution[T].cs | 4 +-
.../Transport/Amqp/AmqpTransportHandler.cs | 4 +-
.../Transport/AmqpIot/AmqpIotSendingLink.cs | 2 +-
.../src/Transport/AmqpIot/AmqpIotTransport.cs | 2 +-
.../src/Transport/DefaultDelegatingHandler.cs | 5 +-
.../src/Transport/ErrorDelegatingHandler.cs | 7 ++-
.../src/Transport/Mqtt/MqttIotHubAdapter.cs | 15 ++---
.../Mqtt/MqttIotHubAdapterFactory.cs | 8 +--
.../Transport/Mqtt/MqttTransportHandler.cs | 2 +-
.../src/Transport/RetryDelegatingHandler.cs | 10 ++-
.../Amqp/LegacyClientWebSocketTransport.cs | 8 +--
.../service/src/Common/IOThreadScheduler.cs | 4 +-
.../src/Common/InternalBufferManager.cs | 4 +-
.../service/src/Common/PartialTrustHelpers.cs | 2 +-
.../src/Common/ReadOnlyDictionary45.cs | 4 +-
.../service/src/Common/SingletonDictionary.cs | 2 +-
.../src/DigitalTwin/DigitalTwinClient.cs | 4 +-
iothub/service/src/GlobalSuppressions.cs | 19 +++++-
.../src/IotHubSasCredentialProperties.cs | 6 +-
iothub/service/src/Message.cs | 2 +-
iothub/service/src/ServiceClient.cs | 18 +++---
iothub/service/src/ServicePointHelpers.cs | 2 +-
.../service/src/net451/Common/ActionItem.cs | 4 +-
.../src/net451/Common/SynchronizedPool.cs | 2 +-
provisioning/device/src/GlobalSuppressions.cs | 14 ++++-
.../Auth/ServiceConnectionStringBuilder.cs | 2 +-
.../service/src/Auth/SharedAccessSignature.cs | 2 +-
.../src/Auth/SharedAccessSignatureBuilder.cs | 2 +-
.../src/Config/BulkEnrollmentOperation.cs | 2 +-
.../src/Config/X509CertificateWithInfo.cs | 2 +-
.../service/src/GlobalSuppressions.cs | 14 ++++-
provisioning/service/src/Query.cs | 2 +-
.../tests/Config/AttestationMechanismTests.cs | 8 +--
.../tests/Config/EnrollmentGroupTests.cs | 2 +-
.../tests/Config/IndividualEnrollmentTests.cs | 6 +-
.../service/tests/Config/QueryResultTests.cs | 18 +++---
.../Config/SymmetricKeyAttestationTest.cs | 4 +-
.../tests/Config/TpmAttestationTests.cs | 14 ++---
.../service/tests/Config/TwinStateTests.cs | 14 ++---
.../tests/Config/X509AttestationTests.cs | 46 +++++++-------
.../Config/X509CertificateWithInfoTests.cs | 2 +-
.../tests/Config/X509CertificatesTests.cs | 4 +-
provisioning/service/tests/TestAssert.cs | 4 +-
.../amqp/src/AmqpAuthStrategySymmetricKey.cs | 2 +-
.../transport/amqp/src/AmqpAuthStrategyTpm.cs | 2 +-
.../transport/amqp/src/GlobalSuppressions.cs | 14 ++++-
.../amqp/src/ProvisioningErrorDetailsAmqp.cs | 2 +-
.../transport/amqp/src/SaslTpmHandler.cs | 16 ++---
.../transport/amqp/src/TaskHelpers.cs | 2 +-
.../ProvisioningErrorDetailsAmqpTests.cs | 10 +--
.../transport/amqp/tests/RetryJitterTests.cs | 4 +-
.../http/src/ApiVersionDelegatingHandler.cs | 2 +-
.../http/src/CertificateChainCredentials.cs | 2 +-
.../http/src/Generated/RuntimeRegistration.cs | 26 ++++----
.../RuntimeRegistrationExtensions.cs | 6 +-
.../transport/http/src/GlobalSuppressions.cs | 14 ++++-
.../src/ProvisioningTransportHandlerHttp.cs | 4 +-
.../http/src/SymmetricKeyCredentials.cs | 2 +-
.../transport/mqtt/src/GlobalSuppressions.cs | 14 ++++-
.../mqtt/src/ProvisioningErrorDetailsMqtt.cs | 2 +-
shared/src/GlobalSuppressions.cs | 14 ++++-
shared/src/TwinCollectionJsonConverter.cs | 2 +-
shared/src/TwinJsonConverter.cs | 2 +-
113 files changed, 579 insertions(+), 466 deletions(-)
create mode 100644 e2e/test/GlobalSuppressions.cs
diff --git a/common/src/Logging.Common.cs b/common/src/Logging.Common.cs
index 5854203881..953a824062 100644
--- a/common/src/Logging.Common.cs
+++ b/common/src/Logging.Common.cs
@@ -399,7 +399,6 @@ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, int off
/// The number of bytes to log.
/// The calling member.
[NonEvent]
- [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "Parameters 'thisOrContextObject' and 'memberName' used in NET451; remove when no longer supported.")]
public static unsafe void DumpBuffer(object thisOrContextObject, IntPtr bufferPtr, int count, [CallerMemberName] string memberName = null)
{
Debug.Assert(bufferPtr != IntPtr.Zero);
diff --git a/common/src/device/provisioning/transport/ProvisioningSasBuilder.cs b/common/src/device/provisioning/transport/ProvisioningSasBuilder.cs
index ddb53688b8..15a502a765 100644
--- a/common/src/device/provisioning/transport/ProvisioningSasBuilder.cs
+++ b/common/src/device/provisioning/transport/ProvisioningSasBuilder.cs
@@ -103,7 +103,7 @@ public static string BuildSasSignature(string keyName, string key, string target
public static string BuildExpiresOn(TimeSpan timeToLive)
{
- DateTime epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
+ var epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime expiresOn = DateTime.UtcNow.Add(timeToLive);
TimeSpan secondsFromBaseTime = expiresOn.Subtract(epochTime);
long seconds = Convert.ToInt64(secondsFromBaseTime.TotalSeconds, CultureInfo.InvariantCulture);
diff --git a/common/src/service/HttpClientHelper.cs b/common/src/service/HttpClientHelper.cs
index 5cddb9f422..55563952a8 100644
--- a/common/src/service/HttpClientHelper.cs
+++ b/common/src/service/HttpClientHelper.cs
@@ -882,10 +882,10 @@ internal static HttpMessageHandler CreateDefaultHttpMessageHandler(IWebProxy web
#pragma warning disable CA2000 // Dispose objects before losing scope (object is returned by this method, so the caller is responsible for disposing it)
#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_0 && !NETCOREAPP1_1
// SocketsHttpHandler is only available in netcoreapp2.1 and onwards
- SocketsHttpHandler httpMessageHandler = new SocketsHttpHandler();
+ var httpMessageHandler = new SocketsHttpHandler();
httpMessageHandler.SslOptions.EnabledSslProtocols = TlsVersions.Instance.Preferred;
#else
- HttpClientHandler httpMessageHandler = new HttpClientHandler();
+ var httpMessageHandler = new HttpClientHandler();
#if !NET451
httpMessageHandler.SslProtocols = TlsVersions.Instance.Preferred;
httpMessageHandler.CheckCertificateRevocationList = TlsVersions.Instance.CertificateRevocationCheck;
diff --git a/common/src/service/StringValidationHelper.cs b/common/src/service/StringValidationHelper.cs
index 3529463e18..09482b20ed 100644
--- a/common/src/service/StringValidationHelper.cs
+++ b/common/src/service/StringValidationHelper.cs
@@ -66,9 +66,9 @@ public static bool IsBase64String(string value)
return false;
}
- var lengthNoPadding = value.Length;
+ int lengthNoPadding = value.Length;
value = value.TrimEnd(Base64Padding);
- var lengthPadding = value.Length;
+ int lengthPadding = value.Length;
if ((lengthNoPadding - lengthPadding) > 2)
{
diff --git a/e2e/test/GlobalSuppressions.cs b/e2e/test/GlobalSuppressions.cs
new file mode 100644
index 0000000000..2a5b12c82b
--- /dev/null
+++ b/e2e/test/GlobalSuppressions.cs
@@ -0,0 +1,17 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+using System.Diagnostics.CodeAnalysis;
+
+[assembly: SuppressMessage(
+ "Style",
+ "IDE1006:Naming Styles",
+ Justification = "Missing Async suffix on test method names. Test method names may be misleading when they have the Async suffix. Additionally, not changing test names help to maintain ADO history.",
+ Scope = "module")]
+[assembly: SuppressMessage(
+ "CodeQuality",
+ "IDE0079:Remove unnecessary suppression",
+ Justification = "Each frameworks consider certain suppressions required by other frameworks unnecessary.",
+ Scope = "module")]
diff --git a/e2e/test/config/TestConfiguration.IoTHub.cs b/e2e/test/config/TestConfiguration.IoTHub.cs
index 2e2a9264ec..a94b6f093b 100644
--- a/e2e/test/config/TestConfiguration.IoTHub.cs
+++ b/e2e/test/config/TestConfiguration.IoTHub.cs
@@ -59,7 +59,7 @@ public static string GetIotHubSharedAccessSignature(TimeSpan timeToLive)
public static X509Certificate2 GetCertificateWithPrivateKey()
{
const string hubPfxCert = "IOTHUB_X509_PFX_CERTIFICATE";
- var cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
+ X509Certificate2 cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubPfxCert} has expired.");
return cert;
}
@@ -67,7 +67,7 @@ public static X509Certificate2 GetCertificateWithPrivateKey()
public static X509Certificate2 GetChainDeviceCertificateWithPrivateKey()
{
const string hubPfxCert = "HUB_CHAIN_DEVICE_PFX_CERTIFICATE";
- var cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
+ X509Certificate2 cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubPfxCert} has expired.");
return cert;
}
@@ -75,7 +75,7 @@ public static X509Certificate2 GetChainDeviceCertificateWithPrivateKey()
public static X509Certificate2 GetRootCACertificate()
{
const string hubCert = "HUB_CHAIN_ROOT_CA_CERTIFICATE";
- var cert = GetBase64EncodedCertificate(hubCert);
+ X509Certificate2 cert = GetBase64EncodedCertificate(hubCert);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubCert} has expired.");
return cert;
}
@@ -83,7 +83,7 @@ public static X509Certificate2 GetRootCACertificate()
public static X509Certificate2 GetIntermediate1Certificate()
{
const string hubCert = "HUB_CHAIN_INTERMEDIATE1_CERTIFICATE";
- var cert = GetBase64EncodedCertificate(hubCert);
+ X509Certificate2 cert = GetBase64EncodedCertificate(hubCert);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubCert} has expired.");
return cert;
}
@@ -91,7 +91,7 @@ public static X509Certificate2 GetIntermediate1Certificate()
public static X509Certificate2 GetIntermediate2Certificate()
{
const string hubCert = "HUB_CHAIN_INTERMEDIATE2_CERTIFICATE";
- var cert = GetBase64EncodedCertificate(hubCert);
+ X509Certificate2 cert = GetBase64EncodedCertificate(hubCert);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubCert} has expired.");
return cert;
}
@@ -111,7 +111,7 @@ public static X509Certificate2 GetIntermediate2Certificate()
private static string GenerateSasToken(string resourceUri, string sharedAccessKey, TimeSpan timeToLive, string policyName = default)
{
- DateTime epochTime = new DateTime(1970, 1, 1);
+ var epochTime = new DateTime(1970, 1, 1);
DateTime expiresOn = DateTime.UtcNow.Add(timeToLive);
TimeSpan secondsFromEpochTime = expiresOn.Subtract(epochTime);
long seconds = Convert.ToInt64(secondsFromEpochTime.TotalSeconds, CultureInfo.InvariantCulture);
diff --git a/e2e/test/helpers/StorageContainer.cs b/e2e/test/helpers/StorageContainer.cs
index d763128d2f..28b7b24330 100644
--- a/e2e/test/helpers/StorageContainer.cs
+++ b/e2e/test/helpers/StorageContainer.cs
@@ -136,7 +136,7 @@ protected virtual void Dispose(bool disposing)
private async Task InitializeAsync()
{
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(TestConfiguration.Storage.ConnectionString);
+ var storageAccount = CloudStorageAccount.Parse(TestConfiguration.Storage.ConnectionString);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer = cloudBlobClient.GetContainerReference(ContainerName);
await CloudBlobContainer.CreateIfNotExistsAsync().ConfigureAwait(false);
diff --git a/e2e/test/helpers/TestDevice.cs b/e2e/test/helpers/TestDevice.cs
index 659e5fd770..ef3be3a394 100644
--- a/e2e/test/helpers/TestDevice.cs
+++ b/e2e/test/helpers/TestDevice.cs
@@ -75,7 +75,7 @@ private static async Task CreateDeviceAsync(TestDeviceType type, str
string deviceName = "E2E_" + prefix + Guid.NewGuid();
// Delete existing devices named this way and create a new one.
- using RegistryManager rm = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var rm = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
s_logger.Trace($"{nameof(GetTestDeviceAsync)}: Creating device {deviceName} with type {type}.");
Client.IAuthenticationMethod auth = null;
diff --git a/e2e/test/iothub/AuthenticationWithTokenRefreshDisposalTests.cs b/e2e/test/iothub/AuthenticationWithTokenRefreshDisposalTests.cs
index a594c29e9d..b133b8c474 100644
--- a/e2e/test/iothub/AuthenticationWithTokenRefreshDisposalTests.cs
+++ b/e2e/test/iothub/AuthenticationWithTokenRefreshDisposalTests.cs
@@ -105,7 +105,7 @@ private async Task AuthenticationMethodDisposesTokenRefresher(Client.TransportTy
var authenticationMethod = new DeviceAuthenticationSasToken(testDevice.ConnectionString, disposeWithClient: true);
// Create an instance of the device client, send a test message and then close and dispose it.
- DeviceClient deviceClient = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
+ var deviceClient = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
using var message1 = new Client.Message();
await deviceClient.SendEventAsync(message1).ConfigureAwait(false);
await deviceClient.CloseAsync();
@@ -115,7 +115,7 @@ private async Task AuthenticationMethodDisposesTokenRefresher(Client.TransportTy
// Perform the same steps again, reusing the previously created authentication method instance.
// Since the default behavior is to dispose AuthenticationWithTokenRefresh authentication method on DeviceClient disposal,
// this should now throw an ObjectDisposedException.
- DeviceClient deviceClient2 = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
+ var deviceClient2 = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
using var message2 = new Client.Message();
Func act = async () => await deviceClient2.SendEventAsync(message2).ConfigureAwait(false);
@@ -131,7 +131,7 @@ private async Task ReuseAuthenticationMethod_SingleDevice(Client.TransportType t
var authenticationMethod = new DeviceAuthenticationSasToken(testDevice.ConnectionString, disposeWithClient: false);
// Create an instance of the device client, send a test message and then close and dispose it.
- DeviceClient deviceClient = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
+ var deviceClient = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
using var message1 = new Client.Message();
await deviceClient.SendEventAsync(message1).ConfigureAwait(false);
await deviceClient.CloseAsync();
@@ -139,8 +139,8 @@ private async Task ReuseAuthenticationMethod_SingleDevice(Client.TransportType t
Logger.Trace("Test with instance 1 completed");
// Perform the same steps again, reusing the previously created authentication method instance to ensure
- // that the sdk did not dispose the user supplied authentication method instance.
- DeviceClient deviceClient2 = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
+ // that the SDK did not dispose the user supplied authentication method instance.
+ var deviceClient2 = DeviceClient.Create(testDevice.IoTHubHostName, authenticationMethod, transport);
using var message2 = new Client.Message();
await deviceClient2.SendEventAsync(message2).ConfigureAwait(false);
await deviceClient2.CloseAsync();
@@ -182,7 +182,7 @@ private async Task ReuseAuthenticationMethod_MuxedDevices(Client.TransportType t
for (int i = 0; i < devicesCount; i++)
{
#pragma warning disable CA2000 // Dispose objects before losing scope - the client instance is disposed during the course of the test.
- DeviceClient deviceClient = DeviceClient.Create(testDevices[i].IoTHubHostName, authenticationMethods[i], new ITransportSettings[] { amqpTransportSettings });
+ var deviceClient = DeviceClient.Create(testDevices[i].IoTHubHostName, authenticationMethods[i], new ITransportSettings[] { amqpTransportSettings });
#pragma warning restore CA2000 // Dispose objects before losing scope
var amqpConnectionStatusChange = new AmqpConnectionStatusChange(testDevices[i].Id, Logger);
@@ -246,7 +246,13 @@ private async Task ReuseAuthenticationMethod_MuxedDevices(Client.TransportType t
for (int i = 0; i < devicesCount; i++)
{
#pragma warning disable CA2000 // Dispose objects before losing scope - the client instance is disposed at the end of the test.
- DeviceClient deviceClient = DeviceClient.Create(testDevices[i].IoTHubHostName, authenticationMethods[i], new ITransportSettings[] { amqpTransportSettings });
+ var deviceClient = DeviceClient.Create(
+ testDevices[i].IoTHubHostName,
+ authenticationMethods[i],
+ new ITransportSettings[]
+ {
+ amqpTransportSettings
+ });
#pragma warning restore CA2000 // Dispose objects before losing scope
var amqpConnectionStatusChange = new AmqpConnectionStatusChange(testDevices[i].Id, Logger);
diff --git a/e2e/test/iothub/ConnectionStatusChangeHandlerTests.cs b/e2e/test/iothub/ConnectionStatusChangeHandlerTests.cs
index 92e1cca9ae..b044d2356f 100644
--- a/e2e/test/iothub/ConnectionStatusChangeHandlerTests.cs
+++ b/e2e/test/iothub/ConnectionStatusChangeHandlerTests.cs
@@ -116,7 +116,7 @@ private async Task DeviceClient_Gives_ConnectionStatus_DeviceDisabled_Base(
ConnectionStatusChangeReason? statusChangeReason = null;
int deviceDisabledReceivedCount = 0;
- using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, protocol))
+ using (var deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, protocol))
{
ConnectionStatusChangesHandler statusChangeHandler = (s, r) =>
{
@@ -135,11 +135,11 @@ private async Task DeviceClient_Gives_ConnectionStatus_DeviceDisabled_Base(
// Receiving the module twin should succeed right now.
Logger.Trace($"{nameof(DeviceClient_Gives_ConnectionStatus_DeviceDisabled_Base)}: DeviceClient GetTwinAsync.");
- var twin = await deviceClient.GetTwinAsync().ConfigureAwait(false);
+ Shared.Twin twin = await deviceClient.GetTwinAsync().ConfigureAwait(false);
Assert.IsNotNull(twin);
// Delete/disable the device in IoT Hub. This should trigger the ConnectionStatusChangesHandler.
- using (RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString))
+ using (var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString))
{
await registryManagerOperation(registryManager, deviceId).ConfigureAwait(false);
}
@@ -168,8 +168,8 @@ private async Task DeviceClient_Gives_ConnectionStatus_DeviceDisabled_Base(
private async Task ModuleClient_Gives_ConnectionStatus_DeviceDisabled_Base(
Client.TransportType protocol, Func registryManagerOperation)
{
- AmqpTransportSettings amqpTransportSettings = new AmqpTransportSettings(protocol);
- ITransportSettings[] transportSettings = new ITransportSettings[] { amqpTransportSettings };
+ var amqpTransportSettings = new AmqpTransportSettings(protocol);
+ var transportSettings = new ITransportSettings[] { amqpTransportSettings };
TestModule testModule = await TestModule.GetTestModuleAsync(DevicePrefix + $"_{Guid.NewGuid()}", ModulePrefix, Logger).ConfigureAwait(false);
ConnectionStatus? status = null;
@@ -185,7 +185,7 @@ private async Task ModuleClient_Gives_ConnectionStatus_DeviceDisabled_Base(
}
};
- using (ModuleClient moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, transportSettings))
+ using (var moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, transportSettings))
{
moduleClient.SetConnectionStatusChangesHandler(statusChangeHandler);
Logger.Trace($"{nameof(ModuleClient_Gives_ConnectionStatus_DeviceDisabled_Base)}: Created {nameof(ModuleClient)} with moduleId={testModule.Id}");
@@ -194,11 +194,11 @@ private async Task ModuleClient_Gives_ConnectionStatus_DeviceDisabled_Base(
// Receiving the module twin should succeed right now.
Logger.Trace($"{nameof(ModuleClient_Gives_ConnectionStatus_DeviceDisabled_Base)}: ModuleClient GetTwinAsync.");
- var twin = await moduleClient.GetTwinAsync().ConfigureAwait(false);
+ Shared.Twin twin = await moduleClient.GetTwinAsync().ConfigureAwait(false);
Assert.IsNotNull(twin);
// Delete/disable the device in IoT Hub.
- using (RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString))
+ using (var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString))
{
await registryManagerOperation(registryManager, testModule.DeviceId).ConfigureAwait(false);
}
diff --git a/e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs b/e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs
index 9f367eded3..fc7d5de7fe 100644
--- a/e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs
+++ b/e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs
@@ -159,7 +159,7 @@ public async Task X509_Cert_Chain_Install_Test_MQTT_TCP()
TestConfiguration.IoTHub.X509ChainDeviceName,
s_chainCertificateWithPrivateKey,
chainCerts);
- using DeviceClient deviceClient = DeviceClient.Create(
+ using var deviceClient = DeviceClient.Create(
_hostName,
auth,
DeviceTransportType.Mqtt_Tcp_Only);
@@ -186,7 +186,7 @@ public async Task X509_Cert_Chain_Install_Test_AMQP_TCP()
TestConfiguration.IoTHub.X509ChainDeviceName,
s_chainCertificateWithPrivateKey,
chainCerts);
- using DeviceClient deviceClient = DeviceClient.Create(
+ using var deviceClient = DeviceClient.Create(
_hostName,
auth,
DeviceTransportType.Amqp_Tcp_Only);
@@ -253,7 +253,7 @@ private async Task X509InvalidDeviceIdOpenAsyncTest(Client.TransportType transpo
{
string deviceName = $"DEVICE_NOT_EXIST_{Guid.NewGuid()}";
using var auth = new DeviceAuthenticationWithX509Certificate(deviceName, s_selfSignedCertificateWithPrivateKey);
- using DeviceClient deviceClient = DeviceClient.Create(_hostName, auth, transportType);
+ using var deviceClient = DeviceClient.Create(_hostName, auth, transportType);
try
{
@@ -274,7 +274,7 @@ private async Task X509InvalidDeviceIdOpenAsyncTwiceTest(Client.TransportType tr
{
string deviceName = $"DEVICE_NOT_EXIST_{Guid.NewGuid()}";
using var auth = new DeviceAuthenticationWithX509Certificate(deviceName, s_selfSignedCertificateWithPrivateKey);
- using DeviceClient deviceClient = DeviceClient.Create(_hostName, auth, transportType);
+ using var deviceClient = DeviceClient.Create(_hostName, auth, transportType);
for (int i = 0; i < 2; i++)
{
diff --git a/e2e/test/iothub/DeviceTokenRefreshE2ETests.cs b/e2e/test/iothub/DeviceTokenRefreshE2ETests.cs
index 96f308eacc..601228c2d3 100644
--- a/e2e/test/iothub/DeviceTokenRefreshE2ETests.cs
+++ b/e2e/test/iothub/DeviceTokenRefreshE2ETests.cs
@@ -31,7 +31,7 @@ public async Task DeviceClient_Not_Exist_AMQP()
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
var config = new TestConfiguration.IoTHub.ConnectionStringParser(testDevice.ConnectionString);
- using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString($"HostName={config.IotHubHostName};DeviceId=device_id_not_exist;SharedAccessKey={config.SharedAccessKey}", Client.TransportType.Amqp_Tcp_Only))
+ using (var deviceClient = DeviceClient.CreateFromConnectionString($"HostName={config.IotHubHostName};DeviceId=device_id_not_exist;SharedAccessKey={config.SharedAccessKey}", Client.TransportType.Amqp_Tcp_Only))
{
await deviceClient.OpenAsync().ConfigureAwait(false);
}
@@ -45,7 +45,7 @@ public async Task DeviceClient_Bad_Credentials_AMQP()
var config = new TestConfiguration.IoTHub.ConnectionStringParser(testDevice.ConnectionString);
string invalidKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("invalid_key"));
- using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString($"HostName={config.IotHubHostName};DeviceId={config.DeviceID};SharedAccessKey={invalidKey}", Client.TransportType.Amqp_Tcp_Only))
+ using (var deviceClient = DeviceClient.CreateFromConnectionString($"HostName={config.IotHubHostName};DeviceId={config.DeviceID};SharedAccessKey={invalidKey}", Client.TransportType.Amqp_Tcp_Only))
{
await deviceClient.OpenAsync().ConfigureAwait(false);
}
@@ -96,7 +96,7 @@ public async Task DeviceClient_TokenConnectionDoubleRelease_Ok()
var auth = new DeviceAuthenticationWithToken(deviceId, builder.ToSignature());
- using DeviceClient deviceClient = DeviceClient.Create(iotHub, auth, Client.TransportType.Amqp_Tcp_Only);
+ using var deviceClient = DeviceClient.Create(iotHub, auth, Client.TransportType.Amqp_Tcp_Only);
Logger.Trace($"{deviceId}: Created {nameof(DeviceClient)} ID={TestLogger.IdOf(deviceClient)}");
Logger.Trace($"{deviceId}: DeviceClient OpenAsync.");
@@ -183,7 +183,7 @@ private async Task DeviceClient_TokenIsRefreshed_Internal(Client.TransportType t
transport,
Logger);
- using DeviceClient deviceClient = DeviceClient.Create(testDevice.IoTHubHostName, refresher, transport);
+ using var deviceClient = DeviceClient.Create(testDevice.IoTHubHostName, refresher, transport);
Logger.Trace($"Created {nameof(DeviceClient)} ID={TestLogger.IdOf(deviceClient)}");
if (transport == Client.TransportType.Mqtt)
diff --git a/e2e/test/iothub/FileUploadFaultInjectionTests.cs b/e2e/test/iothub/FileUploadFaultInjectionTests.cs
index 8e261f4312..35a20bfaf0 100644
--- a/e2e/test/iothub/FileUploadFaultInjectionTests.cs
+++ b/e2e/test/iothub/FileUploadFaultInjectionTests.cs
@@ -87,7 +87,7 @@ private async Task UploadFileDisconnectTransport(
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
TimeSpan operationTimeout = retryDurationInMilliSec == TimeSpan.Zero ? FaultInjection.RecoveryTime : retryDurationInMilliSec;
deviceClient.OperationTimeoutInMilliseconds = (uint)operationTimeout.TotalMilliseconds;
diff --git a/e2e/test/iothub/SasCredentialAuthenticationTests.cs b/e2e/test/iothub/SasCredentialAuthenticationTests.cs
index 827f05ec2b..decc7947ef 100644
--- a/e2e/test/iothub/SasCredentialAuthenticationTests.cs
+++ b/e2e/test/iothub/SasCredentialAuthenticationTests.cs
@@ -101,7 +101,7 @@ public async Task JobClient_Http_SasCredentialAuth_Success()
string jobId = "JOBSAMPLE" + Guid.NewGuid().ToString();
string jobDeviceId = "JobsSample_Device";
string query = $"DeviceId IN ['{jobDeviceId}']";
- Twin twin = new Twin(jobDeviceId);
+ var twin = new Twin(jobDeviceId);
try
{
diff --git a/e2e/test/iothub/TokenCredentialAuthenticationTests.cs b/e2e/test/iothub/TokenCredentialAuthenticationTests.cs
index cbbcc0633c..c7270ef85b 100644
--- a/e2e/test/iothub/TokenCredentialAuthenticationTests.cs
+++ b/e2e/test/iothub/TokenCredentialAuthenticationTests.cs
@@ -66,7 +66,7 @@ public async Task JobClient_Http_TokenCredentialAuth_Success()
string jobId = "JOBSAMPLE" + Guid.NewGuid().ToString();
string jobDeviceId = "JobsSample_Device";
string query = $"DeviceId IN ['{jobDeviceId}']";
- Twin twin = new Twin(jobDeviceId);
+ var twin = new Twin(jobDeviceId);
try
{
diff --git a/e2e/test/iothub/messaging/AzureSecurityCenterForIoTSecurityMessageE2ETests.cs b/e2e/test/iothub/messaging/AzureSecurityCenterForIoTSecurityMessageE2ETests.cs
index a1927d5160..608ff56129 100644
--- a/e2e/test/iothub/messaging/AzureSecurityCenterForIoTSecurityMessageE2ETests.cs
+++ b/e2e/test/iothub/messaging/AzureSecurityCenterForIoTSecurityMessageE2ETests.cs
@@ -92,7 +92,7 @@ private Client.Message ComposeD2CSecurityTestMessage()
private JObject ComposeAzureSecurityCenterForIoTSecurityMessagePayload(string eventId)
{
- var now = DateTime.UtcNow;
+ DateTime now = DateTime.UtcNow;
return new JObject
{
{ "AgentVersion", "0.0.1" },
diff --git a/e2e/test/iothub/messaging/FaultInjectionPoolAmqpTests.MessageReceiveFaultInjectionPoolAmqpTests.cs b/e2e/test/iothub/messaging/FaultInjectionPoolAmqpTests.MessageReceiveFaultInjectionPoolAmqpTests.cs
index e23297a804..9247448d96 100644
--- a/e2e/test/iothub/messaging/FaultInjectionPoolAmqpTests.MessageReceiveFaultInjectionPoolAmqpTests.cs
+++ b/e2e/test/iothub/messaging/FaultInjectionPoolAmqpTests.MessageReceiveFaultInjectionPoolAmqpTests.cs
@@ -953,7 +953,7 @@ private async Task ReceiveMessageUsingCallbackRecoveryPoolOverAmqpAsync(
string proxyAddress = null)
{
// Initialize the service client
- ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
async Task InitOperationAsync(DeviceClient deviceClient, TestDevice testDevice, TestDeviceCallbackHandler testDeviceCallbackHandler)
{
diff --git a/e2e/test/iothub/messaging/MessageFeedbackE2ETests.cs b/e2e/test/iothub/messaging/MessageFeedbackE2ETests.cs
index 8f0ab42de0..239f3aad9c 100644
--- a/e2e/test/iothub/messaging/MessageFeedbackE2ETests.cs
+++ b/e2e/test/iothub/messaging/MessageFeedbackE2ETests.cs
@@ -33,7 +33,7 @@ private static async Task CompleteMessageMixOrder(TestDeviceType type, Client.Tr
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(logger, s_devicePrefix, type).ConfigureAwait(false);
using (DeviceClient deviceClient = testDevice.CreateDeviceClient(transport))
- using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString))
+ using (var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString))
{
await deviceClient.OpenAsync().ConfigureAwait(false);
@@ -61,7 +61,7 @@ private static async Task CompleteMessageMixOrder(TestDeviceType type, Client.Tr
for (int i = 0; i < MESSAGE_COUNT; i++)
{
- Stopwatch stopwatch = new Stopwatch();
+ var stopwatch = new Stopwatch();
stopwatch.Start();
await deviceClient.CompleteAsync(messages[MESSAGE_COUNT - 1 - i]).ConfigureAwait(false);
stopwatch.Stop();
diff --git a/e2e/test/iothub/messaging/MessageReceiveE2ETests.cs b/e2e/test/iothub/messaging/MessageReceiveE2ETests.cs
index e3e58f40f1..98762ff820 100644
--- a/e2e/test/iothub/messaging/MessageReceiveE2ETests.cs
+++ b/e2e/test/iothub/messaging/MessageReceiveE2ETests.cs
@@ -623,7 +623,7 @@ private async Task ReceiveSingleMessageAsync(TestDeviceType type, Client.Transpo
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, s_devicePrefix, type).ConfigureAwait(false);
using DeviceClient deviceClient = testDevice.CreateDeviceClient(transport);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
await deviceClient.OpenAsync().ConfigureAwait(false);
await serviceClient.OpenAsync().ConfigureAwait(false);
@@ -667,7 +667,7 @@ private async Task ReceiveSingleMessageWithCancellationTokenAsync(TestDeviceType
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, s_devicePrefix, type).ConfigureAwait(false);
using DeviceClient deviceClient = testDevice.CreateDeviceClient(transport);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
await deviceClient.OpenAsync().ConfigureAwait(false);
await serviceClient.OpenAsync().ConfigureAwait(false);
@@ -733,7 +733,7 @@ private async Task ReceiveSingleMessageUsingCallbackAsync(TestDeviceType type, C
using DeviceClient deviceClient = testDevice.CreateDeviceClient(transport);
using var testDeviceCallbackHandler = new TestDeviceCallbackHandler(deviceClient, testDevice, Logger);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
(Message msg, string payload, string p1Value) = ComposeC2dTestMessage(Logger);
using (msg)
@@ -760,7 +760,7 @@ private async Task ReceiveMessageUsingCallbackAndUnsubscribeAsync(TestDeviceType
using DeviceClient deviceClient = testDevice.CreateDeviceClient(transport);
using var testDeviceCallbackHandler = new TestDeviceCallbackHandler(deviceClient, testDevice, Logger);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
// For Mqtt - we will need to subscribe to the Mqtt receive telemetry topic
// before the device can begin receiving c2d messages.
@@ -837,7 +837,7 @@ private async Task ReceiveMessageUsingCallbackUpdateHandlerAsync(TestDeviceType
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, s_devicePrefix, type).ConfigureAwait(false);
using DeviceClient deviceClient = testDevice.CreateDeviceClient(transport);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
// Set the first C2D message handler.
await deviceClient.SetReceiveMessageHandlerAsync(
@@ -896,7 +896,7 @@ private async Task ReceiveMessagesSentBeforeSubscriptionAsync(TestDeviceType typ
DeviceClient deviceClient = testDevice.CreateDeviceClient(transport);
var testDeviceCallbackHandler = new TestDeviceCallbackHandler(deviceClient, testDevice, Logger);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
(Message msg, string payload, string p1Value) = ComposeC2dTestMessage(Logger);
@@ -939,7 +939,7 @@ private async Task DoNotReceiveMessagesSentBeforeSubscriptionAsync(TestDeviceTyp
DeviceClient deviceClient = testDevice.CreateDeviceClient(settings);
var testDeviceCallbackHandler = new TestDeviceCallbackHandler(deviceClient, testDevice, Logger);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
(Message msg, string payload, string p1Value) = ComposeC2dTestMessage(Logger);
diff --git a/e2e/test/iothub/messaging/MessageSendE2ETests.cs b/e2e/test/iothub/messaging/MessageSendE2ETests.cs
index 5872b277e7..4ff3f6024c 100644
--- a/e2e/test/iothub/messaging/MessageSendE2ETests.cs
+++ b/e2e/test/iothub/messaging/MessageSendE2ETests.cs
@@ -68,18 +68,18 @@ public async Task Message_DeviceSendSingleMessage_Http()
[LoggedTestMethod]
public async Task Message_DeviceSendSingleMessage_Amqp_WithHeartbeats()
{
- Client.AmqpTransportSettings amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_Tcp_Only);
+ var amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_Tcp_Only);
amqpTransportSettings.IdleTimeout = TimeSpan.FromMinutes(2);
- ITransportSettings[] transportSettings = new ITransportSettings[] { amqpTransportSettings };
+ var transportSettings = new ITransportSettings[] { amqpTransportSettings };
await SendSingleMessage(TestDeviceType.Sasl, transportSettings).ConfigureAwait(false);
}
[LoggedTestMethod]
public async Task Message_DeviceSendSingleMessage_AmqpWs_WithHeartbeats()
{
- Client.AmqpTransportSettings amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_WebSocket_Only);
+ var amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_WebSocket_Only);
amqpTransportSettings.IdleTimeout = TimeSpan.FromMinutes(2);
- ITransportSettings[] transportSettings = new ITransportSettings[] { amqpTransportSettings };
+ var transportSettings = new ITransportSettings[] { amqpTransportSettings };
await SendSingleMessage(TestDeviceType.Sasl, transportSettings).ConfigureAwait(false);
}
@@ -89,9 +89,9 @@ public async Task Message_DeviceSendSingleMessage_AmqpWs_WithHeartbeats()
[TestCategory("LongRunning")]
public async Task Message_DeviceSendSingleMessage_Http_WithProxy()
{
- Client.Http1TransportSettings httpTransportSettings = new Client.Http1TransportSettings();
+ var httpTransportSettings = new Client.Http1TransportSettings();
httpTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
- ITransportSettings[] transportSettings = new ITransportSettings[] { httpTransportSettings };
+ var transportSettings = new ITransportSettings[] { httpTransportSettings };
await SendSingleMessage(TestDeviceType.Sasl, transportSettings).ConfigureAwait(false);
}
@@ -100,10 +100,10 @@ public async Task Message_DeviceSendSingleMessage_Http_WithProxy()
[TestCategory("Proxy")]
public async Task Message_DeviceSendSingleMessage_Http_WithCustomProxy()
{
- Http1TransportSettings httpTransportSettings = new Http1TransportSettings();
- CustomWebProxy proxy = new CustomWebProxy(Logger);
+ var httpTransportSettings = new Http1TransportSettings();
+ var proxy = new CustomWebProxy(Logger);
httpTransportSettings.Proxy = proxy;
- ITransportSettings[] transportSettings = new ITransportSettings[] { httpTransportSettings };
+ var transportSettings = new ITransportSettings[] { httpTransportSettings };
await SendSingleMessage(TestDeviceType.Sasl, transportSettings).ConfigureAwait(false);
Assert.AreNotEqual(proxy.Counter, 0);
@@ -114,9 +114,9 @@ public async Task Message_DeviceSendSingleMessage_Http_WithCustomProxy()
[TestCategory("LongRunning")]
public async Task Message_DeviceSendSingleMessage_AmqpWs_WithProxy()
{
- Client.AmqpTransportSettings amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_WebSocket_Only);
+ var amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_WebSocket_Only);
amqpTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
- ITransportSettings[] transportSettings = new ITransportSettings[] { amqpTransportSettings };
+ var transportSettings = new ITransportSettings[] { amqpTransportSettings };
await SendSingleMessage(TestDeviceType.Sasl, transportSettings).ConfigureAwait(false);
}
@@ -125,10 +125,10 @@ public async Task Message_DeviceSendSingleMessage_AmqpWs_WithProxy()
[TestCategory("Proxy")]
public async Task Message_DeviceSendSingleMessage_MqttWs_WithProxy()
{
- Client.Transport.Mqtt.MqttTransportSettings mqttTransportSettings =
+ var mqttTransportSettings =
new Client.Transport.Mqtt.MqttTransportSettings(Client.TransportType.Mqtt_WebSocket_Only);
mqttTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
- ITransportSettings[] transportSettings = new ITransportSettings[] { mqttTransportSettings };
+ var transportSettings = new ITransportSettings[] { mqttTransportSettings };
await SendSingleMessage(TestDeviceType.Sasl, transportSettings).ConfigureAwait(false);
}
@@ -137,9 +137,9 @@ public async Task Message_DeviceSendSingleMessage_MqttWs_WithProxy()
[TestCategory("Proxy")]
public async Task Message_ModuleSendSingleMessage_AmqpWs_WithProxy()
{
- Client.AmqpTransportSettings amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_WebSocket_Only);
+ var amqpTransportSettings = new Client.AmqpTransportSettings(Client.TransportType.Amqp_WebSocket_Only);
amqpTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
- ITransportSettings[] transportSettings = new ITransportSettings[] { amqpTransportSettings };
+ var transportSettings = new ITransportSettings[] { amqpTransportSettings };
await SendSingleMessageModule(transportSettings).ConfigureAwait(false);
}
@@ -148,10 +148,10 @@ public async Task Message_ModuleSendSingleMessage_AmqpWs_WithProxy()
[TestCategory("Proxy")]
public async Task Message_ModuleSendSingleMessage_MqttWs_WithProxy()
{
- Client.Transport.Mqtt.MqttTransportSettings mqttTransportSettings =
+ var mqttTransportSettings =
new Client.Transport.Mqtt.MqttTransportSettings(Client.TransportType.Mqtt_WebSocket_Only);
mqttTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
- ITransportSettings[] transportSettings = new ITransportSettings[] { mqttTransportSettings };
+ var transportSettings = new ITransportSettings[] { mqttTransportSettings };
await SendSingleMessageModule(transportSettings).ConfigureAwait(false);
}
diff --git a/e2e/test/iothub/method/MethodE2ETests.cs b/e2e/test/iothub/method/MethodE2ETests.cs
index 973b2dcfbb..5717254ff6 100644
--- a/e2e/test/iothub/method/MethodE2ETests.cs
+++ b/e2e/test/iothub/method/MethodE2ETests.cs
@@ -159,7 +159,7 @@ await SendMethodAndRespondAsync(
public async Task Method_ServiceInvokeDeviceMethodWithUnknownDeviceThrows()
{
// setup
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
var methodInvocation = new CloudToDeviceMethod("SetTelemetryInterval");
methodInvocation.SetPayloadJson("10");
@@ -233,7 +233,7 @@ public async Task Method_ServiceInvokeDeviceMethodWithUnknownModuleThrows()
{
// setup
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, "ModuleNotFoundTest").ConfigureAwait(false);
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
var methodInvocation = new CloudToDeviceMethod("SetTelemetryInterval");
methodInvocation.SetPayloadJson("10");
@@ -283,7 +283,7 @@ await deviceClient
.ConfigureAwait(false);
using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- var c2dMethod = new CloudToDeviceMethod(commandName, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1)).SetPayloadJson(null);
+ CloudToDeviceMethod c2dMethod = new CloudToDeviceMethod(commandName, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1)).SetPayloadJson(null);
// act
@@ -572,7 +572,7 @@ private async Task SendMethodAndUnsubscribeAsync(
ServiceClientTransportSettings serviceClientTransportSettings = default)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
await subscribeAndUnsubscribeMethod(deviceClient, MethodName, Logger).ConfigureAwait(false);
@@ -588,7 +588,7 @@ private async Task SendMethodAndRespondAsync(
ServiceClientTransportSettings serviceClientTransportSettings = default)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
Task methodReceivedTask = await setDeviceReceiveMethod(deviceClient, MethodName, Logger).ConfigureAwait(false);
Task serviceSendTask = ServiceSendMethodAndVerifyResponseAsync(
@@ -608,7 +608,7 @@ private async Task SendMethodAndRespondAsync(
private async Task SendMethodAndRespondAsync(Client.TransportType transport, Func> setDeviceReceiveMethod, TimeSpan responseTimeout = default, ServiceClientTransportSettings serviceClientTransportSettings = default)
{
TestModule testModule = await TestModule.GetTestModuleAsync(_devicePrefix, _modulePrefix, Logger).ConfigureAwait(false);
- using ModuleClient moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, transport);
+ using var moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, transport);
Task methodReceivedTask = await setDeviceReceiveMethod(moduleClient, MethodName, Logger).ConfigureAwait(false);
diff --git a/e2e/test/iothub/method/MethodFaultInjectionTests.cs b/e2e/test/iothub/method/MethodFaultInjectionTests.cs
index 4b33787d59..1f08a07cfd 100644
--- a/e2e/test/iothub/method/MethodFaultInjectionTests.cs
+++ b/e2e/test/iothub/method/MethodFaultInjectionTests.cs
@@ -214,7 +214,7 @@ private async Task ServiceSendMethodAndVerifyResponseAsync(string deviceName, st
attempt++;
try
{
- using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var serviceClient = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Logger.Trace($"{nameof(ServiceSendMethodAndVerifyResponseAsync)}: Invoke method {methodName}.");
CloudToDeviceMethodResult response =
diff --git a/e2e/test/iothub/service/BulkOperationsE2ETests.cs b/e2e/test/iothub/service/BulkOperationsE2ETests.cs
index 53ebc5c813..bf686384f0 100644
--- a/e2e/test/iothub/service/BulkOperationsE2ETests.cs
+++ b/e2e/test/iothub/service/BulkOperationsE2ETests.cs
@@ -21,18 +21,18 @@ public class BulkOperationsE2ETests : E2EMsTestBase
[LoggedTestMethod]
public async Task BulkOperations_UpdateTwins2Device_Ok()
{
- var tagName = Guid.NewGuid().ToString();
- var tagValue = Guid.NewGuid().ToString();
+ string tagName = Guid.NewGuid().ToString();
+ string tagValue = Guid.NewGuid().ToString();
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Twin twin = await registryManager.GetTwinAsync(testDevice.Id).ConfigureAwait(false);
twin.Tags = new TwinCollection();
twin.Tags[tagName] = tagValue;
- var result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
+ BulkRegistryOperationResult result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");
Twin twinUpd = await registryManager.GetTwinAsync(testDevice.Id).ConfigureAwait(false);
@@ -48,18 +48,18 @@ public async Task BulkOperations_UpdateTwins2Device_Ok()
[LoggedTestMethod]
public async Task BulkOperations_UpdateTwins2DevicePatch_Ok()
{
- var tagName = Guid.NewGuid().ToString();
- var tagValue = Guid.NewGuid().ToString();
+ string tagName = Guid.NewGuid().ToString();
+ string tagValue = Guid.NewGuid().ToString();
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- Twin twin = new Twin();
+ var twin = new Twin();
twin.DeviceId = testDevice.Id;
twin.Tags = new TwinCollection();
twin.Tags[tagName] = tagValue;
- var result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
+ BulkRegistryOperationResult result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");
Twin twinUpd = await registryManager.GetTwinAsync(testDevice.Id).ConfigureAwait(false);
@@ -75,18 +75,18 @@ public async Task BulkOperations_UpdateTwins2DevicePatch_Ok()
[LoggedTestMethod]
public async Task BulkOperations_UpdateTwins2Module_Ok()
{
- var tagName = Guid.NewGuid().ToString();
- var tagValue = Guid.NewGuid().ToString();
+ string tagName = Guid.NewGuid().ToString();
+ string tagValue = Guid.NewGuid().ToString();
TestModule testModule = await TestModule.GetTestModuleAsync(DevicePrefix, ModulePrefix, Logger).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Twin twin = await registryManager.GetTwinAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
twin.Tags = new TwinCollection();
twin.Tags[tagName] = tagValue;
- var result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
+ BulkRegistryOperationResult result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");
Twin twinUpd = await registryManager.GetTwinAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
@@ -103,19 +103,19 @@ public async Task BulkOperations_UpdateTwins2Module_Ok()
[LoggedTestMethod]
public async Task BulkOperations_UpdateTwins2ModulePatch_Ok()
{
- var tagName = Guid.NewGuid().ToString();
- var tagValue = Guid.NewGuid().ToString();
+ string tagName = Guid.NewGuid().ToString();
+ string tagValue = Guid.NewGuid().ToString();
TestModule testModule = await TestModule.GetTestModuleAsync(DevicePrefix, ModulePrefix, Logger).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
var twin = new Twin();
twin.DeviceId = testModule.DeviceId;
twin.ModuleId = testModule.Id;
twin.Tags = new TwinCollection();
twin.Tags[tagName] = tagValue;
- var result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
+ BulkRegistryOperationResult result = await registryManager.UpdateTwins2Async(new List { twin }, true).ConfigureAwait(false);
Assert.IsTrue(result.IsSuccessful, $"UpdateTwins2Async error:\n{ResultErrorsToString(result)}");
Twin twinUpd = await registryManager.GetTwinAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
@@ -131,9 +131,9 @@ public async Task BulkOperations_UpdateTwins2ModulePatch_Ok()
private string ResultErrorsToString(BulkRegistryOperationResult result)
{
- var errorString = "";
+ string errorString = "";
- foreach (var error in result.Errors)
+ foreach (DeviceRegistryOperationError error in result.Errors)
{
errorString += $"\t{error.ErrorCode} : {error.ErrorStatus}\n";
}
diff --git a/e2e/test/iothub/service/IoTHubCertificateValidationE2ETest.cs b/e2e/test/iothub/service/IoTHubCertificateValidationE2ETest.cs
index 0047b1bc78..932020154a 100644
--- a/e2e/test/iothub/service/IoTHubCertificateValidationE2ETest.cs
+++ b/e2e/test/iothub/service/IoTHubCertificateValidationE2ETest.cs
@@ -19,7 +19,7 @@ public class IoTHubCertificateValidationE2ETest : E2EMsTestBase
[LoggedTestMethod]
public async Task RegistryManager_QueryDevicesInvalidServiceCertificateHttp_Fails()
{
- using RegistryManager rm = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionStringInvalidServiceCertificate);
+ using var rm = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionStringInvalidServiceCertificate);
IQuery query = rm.CreateQuery("select * from devices");
IotHubCommunicationException exception = await Assert.ThrowsExceptionAsync(
() => query.GetNextAsTwinAsync()).ConfigureAwait(false);
@@ -34,7 +34,7 @@ public async Task RegistryManager_QueryDevicesInvalidServiceCertificateHttp_Fail
[LoggedTestMethod]
public async Task ServiceClient_SendMessageToDeviceInvalidServiceCertificateAmqpTcp_Fails()
{
- var transport = TransportType.Amqp;
+ TransportType transport = TransportType.Amqp;
await Assert.ThrowsExceptionAsync(
() => TestServiceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
}
@@ -42,8 +42,8 @@ await Assert.ThrowsExceptionAsync(
[LoggedTestMethod]
public async Task ServiceClient_SendMessageToDeviceInvalidServiceCertificateAmqpWs_Fails()
{
- var transport = TransportType.Amqp_WebSocket_Only;
- var exception = await Assert.ThrowsExceptionAsync(
+ TransportType transport = TransportType.Amqp_WebSocket_Only;
+ WebSocketException exception = await Assert.ThrowsExceptionAsync(
() => TestServiceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
Assert.IsInstanceOfType(exception.InnerException.InnerException, typeof(AuthenticationException));
@@ -51,7 +51,7 @@ public async Task ServiceClient_SendMessageToDeviceInvalidServiceCertificateAmqp
private static async Task TestServiceClientInvalidServiceCertificate(TransportType transport)
{
- using ServiceClient service = ServiceClient.CreateFromConnectionString(
+ using var service = ServiceClient.CreateFromConnectionString(
TestConfiguration.IoTHub.ConnectionStringInvalidServiceCertificate,
transport);
using var testMessage = new Message();
@@ -61,8 +61,8 @@ private static async Task TestServiceClientInvalidServiceCertificate(TransportTy
[LoggedTestMethod]
public async Task JobClient_ScheduleTwinUpdateInvalidServiceCertificateHttp_Fails()
{
- using JobClient jobClient = JobClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionStringInvalidServiceCertificate);
- var exception = await Assert.ThrowsExceptionAsync(
+ using var jobClient = JobClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionStringInvalidServiceCertificate);
+ IotHubCommunicationException exception = await Assert.ThrowsExceptionAsync(
() => jobClient.ScheduleTwinUpdateAsync(
"testDevice",
"DeviceId IN ['testDevice']",
@@ -80,7 +80,7 @@ public async Task JobClient_ScheduleTwinUpdateInvalidServiceCertificateHttp_Fail
[LoggedTestMethod]
public async Task DeviceClient_SendAsyncInvalidServiceCertificateAmqpTcp_Fails()
{
- var transport = Client.TransportType.Amqp_Tcp_Only;
+ Client.TransportType transport = Client.TransportType.Amqp_Tcp_Only;
await Assert.ThrowsExceptionAsync(
() => TestDeviceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
}
@@ -88,7 +88,7 @@ await Assert.ThrowsExceptionAsync(
[LoggedTestMethod]
public async Task DeviceClient_SendAsyncInvalidServiceCertificateMqttTcp_Fails()
{
- var transport = Client.TransportType.Mqtt_Tcp_Only;
+ Client.TransportType transport = Client.TransportType.Mqtt_Tcp_Only;
await Assert.ThrowsExceptionAsync(
() => TestDeviceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
}
@@ -96,8 +96,8 @@ await Assert.ThrowsExceptionAsync(
[LoggedTestMethod]
public async Task DeviceClient_SendAsyncInvalidServiceCertificateHttp_Fails()
{
- var transport = Client.TransportType.Http1;
- var exception = await Assert.ThrowsExceptionAsync(
+ Client.TransportType transport = Client.TransportType.Http1;
+ AuthenticationException exception = await Assert.ThrowsExceptionAsync(
() => TestDeviceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
#if NET451 || NET472
@@ -110,8 +110,8 @@ public async Task DeviceClient_SendAsyncInvalidServiceCertificateHttp_Fails()
[LoggedTestMethod]
public async Task DeviceClient_SendAsyncInvalidServiceCertificateAmqpWs_Fails()
{
- var transport = Client.TransportType.Amqp_WebSocket_Only;
- var exception = await Assert.ThrowsExceptionAsync(
+ Client.TransportType transport = Client.TransportType.Amqp_WebSocket_Only;
+ AuthenticationException exception = await Assert.ThrowsExceptionAsync(
() => TestDeviceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
Assert.IsInstanceOfType(exception.InnerException.InnerException.InnerException, typeof(AuthenticationException));
@@ -120,8 +120,8 @@ public async Task DeviceClient_SendAsyncInvalidServiceCertificateAmqpWs_Fails()
[LoggedTestMethod]
public async Task DeviceClient_SendAsyncInvalidServiceCertificateMqttWs_Fails()
{
- var transport = Client.TransportType.Mqtt_WebSocket_Only;
- var exception = await Assert.ThrowsExceptionAsync(
+ Client.TransportType transport = Client.TransportType.Mqtt_WebSocket_Only;
+ AuthenticationException exception = await Assert.ThrowsExceptionAsync(
() => TestDeviceClientInvalidServiceCertificate(transport)).ConfigureAwait(false);
Assert.IsInstanceOfType(exception.InnerException.InnerException.InnerException, typeof(AuthenticationException));
@@ -129,15 +129,13 @@ public async Task DeviceClient_SendAsyncInvalidServiceCertificateMqttWs_Fails()
private static async Task TestDeviceClientInvalidServiceCertificate(Client.TransportType transport)
{
- using (DeviceClient deviceClient =
+ using var deviceClient =
DeviceClient.CreateFromConnectionString(
TestConfiguration.IoTHub.DeviceConnectionStringInvalidServiceCertificate,
- transport))
- {
- using var testMessage = new Client.Message();
- await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
- await deviceClient.CloseAsync().ConfigureAwait(false);
- }
+ transport);
+ using var testMessage = new Client.Message();
+ await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
+ await deviceClient.CloseAsync().ConfigureAwait(false);
}
}
}
diff --git a/e2e/test/iothub/service/IoTHubServiceProxyE2ETests.cs b/e2e/test/iothub/service/IoTHubServiceProxyE2ETests.cs
index 0cf3a69c07..24a2d778e6 100644
--- a/e2e/test/iothub/service/IoTHubServiceProxyE2ETests.cs
+++ b/e2e/test/iothub/service/IoTHubServiceProxyE2ETests.cs
@@ -30,7 +30,7 @@ public class IoTHubServiceProxyE2ETests : E2EMsTestBase
[LoggedTestMethod]
public async Task ServiceClient_Message_SendSingleMessage_WithProxy()
{
- ServiceClientTransportSettings transportSettings = new ServiceClientTransportSettings();
+ var transportSettings = new ServiceClientTransportSettings();
transportSettings.AmqpProxy = new WebProxy(s_proxyServerAddress);
transportSettings.HttpProxy = new WebProxy(s_proxyServerAddress);
@@ -40,7 +40,7 @@ public async Task ServiceClient_Message_SendSingleMessage_WithProxy()
[LoggedTestMethod]
public async Task RegistryManager_AddAndRemoveDevice_WithProxy()
{
- HttpTransportSettings httpTransportSettings = new HttpTransportSettings();
+ var httpTransportSettings = new HttpTransportSettings();
httpTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
await RegistryManager_AddDevice(httpTransportSettings).ConfigureAwait(false);
@@ -49,7 +49,7 @@ public async Task RegistryManager_AddAndRemoveDevice_WithProxy()
[LoggedTestMethod]
public async Task JobClient_ScheduleAndRunTwinJob_WithProxy()
{
- HttpTransportSettings httpTransportSettings = new HttpTransportSettings();
+ var httpTransportSettings = new HttpTransportSettings();
httpTransportSettings.Proxy = new WebProxy(s_proxyServerAddress);
await JobClient_ScheduleAndRunTwinJob(httpTransportSettings).ConfigureAwait(false);
@@ -58,8 +58,8 @@ public async Task JobClient_ScheduleAndRunTwinJob_WithProxy()
private async Task SendSingleMessageService(ServiceClientTransportSettings transportSettings)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
- using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString))
- using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, TransportType.Amqp, transportSettings))
+ using (var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString))
+ using (var serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, TransportType.Amqp, transportSettings))
{
(Message testMessage, string messageId, string payload, string p1Value) = ComposeD2CTestMessage();
await serviceClient.SendAsync(testDevice.Id, testMessage).ConfigureAwait(false);
@@ -73,7 +73,7 @@ private async Task RegistryManager_AddDevice(HttpTransportSettings httpTransport
{
string deviceName = DevicePrefix + Guid.NewGuid();
- using (RegistryManager registryManager = RegistryManager.CreateFromConnectionString(s_connectionString, httpTransportSettings))
+ using (var registryManager = RegistryManager.CreateFromConnectionString(s_connectionString, httpTransportSettings))
{
await registryManager.AddDeviceAsync(new Device(deviceName)).ConfigureAwait(false);
await registryManager.RemoveDeviceAsync(deviceName).ConfigureAwait(false);
@@ -82,11 +82,11 @@ private async Task RegistryManager_AddDevice(HttpTransportSettings httpTransport
private async Task JobClient_ScheduleAndRunTwinJob(HttpTransportSettings httpTransportSettings)
{
- Twin twin = new Twin(JobDeviceId);
+ var twin = new Twin(JobDeviceId);
twin.Tags = new TwinCollection();
twin.Tags[JobTestTagName] = JobDeviceId;
- using (JobClient jobClient = JobClient.CreateFromConnectionString(s_connectionString, httpTransportSettings))
+ using (var jobClient = JobClient.CreateFromConnectionString(s_connectionString, httpTransportSettings))
{
int tryCount = 0;
while (true)
@@ -111,9 +111,9 @@ private async Task JobClient_ScheduleAndRunTwinJob(HttpTransportSettings httpTra
private (Message message, string messageId, string payload, string p1Value) ComposeD2CTestMessage()
{
- var messageId = Guid.NewGuid().ToString();
- var payload = Guid.NewGuid().ToString();
- var p1Value = Guid.NewGuid().ToString();
+ string messageId = Guid.NewGuid().ToString();
+ string payload = Guid.NewGuid().ToString();
+ string p1Value = Guid.NewGuid().ToString();
Logger.Trace($"{nameof(ComposeD2CTestMessage)}: messageId='{messageId}' payload='{payload}' p1Value='{p1Value}'");
var message = new Message(Encoding.UTF8.GetBytes(payload))
diff --git a/e2e/test/iothub/service/PnpServiceTests.cs b/e2e/test/iothub/service/PnpServiceTests.cs
index 631309c795..bd8f9c918f 100644
--- a/e2e/test/iothub/service/PnpServiceTests.cs
+++ b/e2e/test/iothub/service/PnpServiceTests.cs
@@ -38,13 +38,13 @@ public async Task DeviceTwin_Contains_ModelId()
{
ModelId = TestModelId,
};
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, Client.TransportType.Mqtt_Tcp_Only, options);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, Client.TransportType.Mqtt_Tcp_Only, options);
await deviceClient.OpenAsync().ConfigureAwait(false);
// Act
// Get device twin.
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Twin twin = await registryManager.GetTwinAsync(testDevice.Device.Id).ConfigureAwait(false);
// Assert
@@ -69,13 +69,13 @@ public async Task DeviceTwin_Contains_ModelId_X509()
string hostName = HostNameHelper.GetHostName(TestConfiguration.IoTHub.ConnectionString);
X509Certificate2 authCertificate = TestConfiguration.IoTHub.GetCertificateWithPrivateKey();
using var auth = new DeviceAuthenticationWithX509Certificate(testDevice.Id, authCertificate);
- using DeviceClient deviceClient = DeviceClient.Create(hostName, auth, Client.TransportType.Mqtt_Tcp_Only, options);
+ using var deviceClient = DeviceClient.Create(hostName, auth, Client.TransportType.Mqtt_Tcp_Only, options);
await deviceClient.OpenAsync().ConfigureAwait(false);
// Act
// Get device twin.
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Twin twin = await registryManager.GetTwinAsync(testDevice.Device.Id).ConfigureAwait(false);
// Assert
@@ -104,13 +104,13 @@ public async Task ModuleTwin_Contains_ModelId()
{
ModelId = TestModelId,
};
- using ModuleClient moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, Client.TransportType.Mqtt_Tcp_Only, options);
+ using var moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, Client.TransportType.Mqtt_Tcp_Only, options);
await moduleClient.OpenAsync().ConfigureAwait(false);
// Act
// Get module twin.
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Twin twin = await registryManager.GetTwinAsync(testModule.DeviceId, testModule.Id).ConfigureAwait(false);
// Assert
diff --git a/e2e/test/iothub/service/RegistryManagerE2ETests.cs b/e2e/test/iothub/service/RegistryManagerE2ETests.cs
index 5729f9b7b4..84941b8fc9 100644
--- a/e2e/test/iothub/service/RegistryManagerE2ETests.cs
+++ b/e2e/test/iothub/service/RegistryManagerE2ETests.cs
@@ -26,7 +26,7 @@ public class RegistryManagerE2ETests : E2EMsTestBase
public async Task RegistryManager_BadProxy_ThrowsException()
{
// arrange
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(
+ using var registryManager = RegistryManager.CreateFromConnectionString(
TestConfiguration.IoTHub.ConnectionString,
new HttpTransportSettings
{
@@ -94,7 +94,7 @@ public async Task RegistryManager_AddDeviceWithTwinWithDeviceCapabilities()
{
string deviceId = _idPrefix + Guid.NewGuid();
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
var twin = new Twin
{
Tags = new TwinCollection(@"{ companyId: 1234 }"),
@@ -120,13 +120,16 @@ public async Task RegistryManager_BulkLifecycle()
var devices = new List();
for (int i = 0; i < bulkCount; i++)
{
- var device = new Device(_idPrefix + Guid.NewGuid());
- device.Scope = "someScope" + Guid.NewGuid();
+ var device = new Device(_idPrefix + Guid.NewGuid())
+ {
+ Scope = "someScope" + Guid.NewGuid()
+ };
+
device.ParentScopes.Add("someParentScope" + Guid.NewGuid());
devices.Add(device);
}
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
// Test that you can create devices in bulk
BulkRegistryOperationResult bulkAddResult = await registryManager.AddDevices2Async(devices).ConfigureAwait(false);
@@ -183,7 +186,7 @@ public async Task RegistryManager_AddDeviceWithProxy()
Proxy = new WebProxy(TestConfiguration.IoTHub.ProxyServerAddress)
};
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, transportSettings);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, transportSettings);
var device = new Device(deviceId);
await registryManager.AddDeviceAsync(device).ConfigureAwait(false);
}
@@ -195,7 +198,7 @@ public async Task RegistryManager_ConfigurationOperations_Work()
bool configCreated = false;
string configurationId = (_idPrefix + Guid.NewGuid()).ToLower(); // Configuration Id characters must be all lower-case.
- using RegistryManager client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
try
{
@@ -260,7 +263,7 @@ public async Task RegistryManager_ConfigurationOperations_Work()
public async Task RegistryManager_Query_Works()
{
// arrange
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
string deviceId = $"{_idPrefix}{Guid.NewGuid()}";
try
@@ -312,7 +315,7 @@ public async Task ModulesClient_GetModulesOnDevice()
}
Device device = null;
- using RegistryManager client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
try
{
@@ -355,7 +358,7 @@ public async Task ModulesClient_IdentityLifecycle()
string testDeviceId = $"IdentityLifecycleDevice{Guid.NewGuid()}";
string testModuleId = $"IdentityLifecycleModule{Guid.NewGuid()}";
- using RegistryManager client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
try
{
@@ -398,7 +401,7 @@ public async Task ModulesClient_IdentityLifecycle()
[LoggedTestMethod]
public async Task ModulesClient_DeviceTwinLifecycle()
{
- using RegistryManager client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var client = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
TestModule module = await TestModule.GetTestModuleAsync(_idPrefix, _idPrefix, Logger).ConfigureAwait(false);
try
@@ -427,7 +430,7 @@ public async Task ModulesClient_DeviceTwinLifecycle()
}
}
- private async Task CleanupAsync(RegistryManager client, string deviceId)
+ private static async Task CleanupAsync(RegistryManager client, string deviceId)
{
// cleanup
try
diff --git a/e2e/test/iothub/service/RegistryManagerExportDevicesTests.cs b/e2e/test/iothub/service/RegistryManagerExportDevicesTests.cs
index c779d0099a..d5f0b17a12 100644
--- a/e2e/test/iothub/service/RegistryManagerExportDevicesTests.cs
+++ b/e2e/test/iothub/service/RegistryManagerExportDevicesTests.cs
@@ -57,7 +57,7 @@ public async Task RegistryManager_ExportDevices(StorageAuthenticationType storag
string edgeId2 = $"{nameof(RegistryManager_ExportDevices)}-Edge-{StorageContainer.GetRandomSuffix(4)}";
string deviceId = $"{nameof(RegistryManager_ExportDevices)}-{StorageContainer.GetRandomSuffix(4)}";
string devicesFileName = $"{nameof(RegistryManager_ExportDevices)}-devicesexport-{StorageContainer.GetRandomSuffix(4)}.txt";
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Logger.Trace($"Using deviceId {deviceId}");
@@ -73,7 +73,7 @@ public async Task RegistryManager_ExportDevices(StorageAuthenticationType storag
? storageContainer.SasUri
: storageContainer.Uri;
- var edge1 = await registryManager
+ Device edge1 = await registryManager
.AddDeviceAsync(
new Device(edgeId1)
{
@@ -82,7 +82,7 @@ public async Task RegistryManager_ExportDevices(StorageAuthenticationType storag
})
.ConfigureAwait(false);
- var edge2 = await registryManager
+ Device edge2 = await registryManager
.AddDeviceAsync(
new Device(edgeId2)
{
@@ -119,7 +119,7 @@ await registryManager
};
}
- JobProperties jobProperties = JobProperties.CreateForExportJob(
+ var jobProperties = JobProperties.CreateForExportJob(
containerUri.ToString(),
true,
devicesFileName,
diff --git a/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs b/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs
index 8134adc813..3522d7e9e3 100644
--- a/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs
+++ b/e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs
@@ -48,7 +48,7 @@ public async Task RegistryManager_ImportDevices(StorageAuthenticationType storag
string deviceId = $"{nameof(RegistryManager_ImportDevices)}-device-{StorageContainer.GetRandomSuffix(4)}";
string devicesFileName = $"{nameof(RegistryManager_ImportDevices)}-{StorageContainer.GetRandomSuffix(4)}.txt";
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Logger.Trace($"Using deviceId {deviceId}.");
diff --git a/e2e/test/iothub/service/ServiceClientE2ETests.cs b/e2e/test/iothub/service/ServiceClientE2ETests.cs
index ebad2565b7..d18fdda791 100644
--- a/e2e/test/iothub/service/ServiceClientE2ETests.cs
+++ b/e2e/test/iothub/service/ServiceClientE2ETests.cs
@@ -50,7 +50,7 @@ private async Task TestTimeout(TimeSpan? timeout)
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
using var sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- Stopwatch sw = new Stopwatch();
+ var sw = new Stopwatch();
sw.Start();
Logger.Trace($"Testing ServiceClient SendAsync() timeout in ticks={timeout?.Ticks}");
@@ -73,7 +73,7 @@ public async Task ServiceClient_SendsMessage(TransportType transportType)
{
// arrange
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
- using ServiceClient sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, transportType);
+ using var sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, transportType);
string messageId = Guid.NewGuid().ToString();
// act and expect no exception
@@ -92,7 +92,7 @@ public async Task MessageIdDefaultNotSet_SendEventDoesNotSetMessageId()
{
// arrange
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, DevicePrefix).ConfigureAwait(false);
- using ServiceClient sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
string messageId = Guid.NewGuid().ToString();
// act
@@ -121,7 +121,7 @@ public async Task MessageIdDefaultSetToNull_SendEventDoesNotSetMessageId()
{
SdkAssignsMessageId = Shared.SdkAssignsMessageId.Never,
};
- using ServiceClient sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, options);
+ using var sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, options);
string messageId = Guid.NewGuid().ToString();
// act
@@ -150,7 +150,7 @@ public async Task MessageIdDefaultSetToGuid_SendEventSetMessageIdIfNotSet()
{
SdkAssignsMessageId = Shared.SdkAssignsMessageId.WhenUnset,
};
- using ServiceClient sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, options);
+ using var sender = ServiceClient.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString, options);
string messageId = Guid.NewGuid().ToString();
// act
diff --git a/e2e/test/iothub/twin/FaultInjectionPoolAmqpTests.TwinFaultInjectionPoolAmqpTests.cs b/e2e/test/iothub/twin/FaultInjectionPoolAmqpTests.TwinFaultInjectionPoolAmqpTests.cs
index 53736ec57c..419708e302 100644
--- a/e2e/test/iothub/twin/FaultInjectionPoolAmqpTests.TwinFaultInjectionPoolAmqpTests.cs
+++ b/e2e/test/iothub/twin/FaultInjectionPoolAmqpTests.TwinFaultInjectionPoolAmqpTests.cs
@@ -1481,8 +1481,8 @@ private async Task Twin_DeviceDesiredPropertyUpdateRecoveryPoolOverAmqp(
async Task InitOperationAsync(DeviceClient deviceClient, TestDevice testDevice, TestDeviceCallbackHandler testDeviceCallbackHandler)
{
- var propName = Guid.NewGuid().ToString();
- var propValue = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
+ string propValue = Guid.NewGuid().ToString();
twinPropertyMap.Add(testDevice.Id, new List { propName, propValue });
Logger.Trace($"{nameof(FaultInjectionPoolAmqpTests)}: Setting desired propery callback for device {testDevice.Id}");
@@ -1495,8 +1495,8 @@ async Task TestOperationAsync(DeviceClient deviceClient, TestDevice testDevice,
using var cts = new CancellationTokenSource(FaultInjection.RecoveryTime);
List twinProperties = twinPropertyMap[testDevice.Id];
- var propName = twinProperties[0];
- var propValue = twinProperties[1];
+ string propName = twinProperties[0];
+ string propValue = twinProperties[1];
testDeviceCallbackHandler.ExpectedTwinPropertyValue = propValue;
Logger.Trace($"{nameof(FaultInjectionPoolAmqpTests)}: Updating the desired properties for device {testDevice.Id}");
diff --git a/e2e/test/iothub/twin/TwinE2ETests.cs b/e2e/test/iothub/twin/TwinE2ETests.cs
index be9d0aecca..27e4915ee3 100644
--- a/e2e/test/iothub/twin/TwinE2ETests.cs
+++ b/e2e/test/iothub/twin/TwinE2ETests.cs
@@ -392,7 +392,7 @@ public async Task Twin_ClientSetsReportedPropertyWithoutDesiredPropertyCallback(
// arrange
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transportType);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transportType);
await Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(deviceClient, testDevice.Id, Guid.NewGuid().ToString(), Logger).ConfigureAwait(false);
@@ -418,7 +418,7 @@ public async Task Twin_ClientSetsReportedPropertyWithoutDesiredPropertyCallback(
private async Task Twin_DeviceSetsReportedPropertyAndGetsItBackSingleDeviceAsync(Client.TransportType transport)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
await Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(deviceClient, testDevice.Id, Guid.NewGuid().ToString(), Logger).ConfigureAwait(false);
}
@@ -426,14 +426,14 @@ private async Task Twin_DeviceSetsReportedPropertyAndGetsItBackSingleDeviceAsync
private async Task Twin_DeviceSetsReportedPropertyArrayAndGetsItBackSingleDeviceAsync(Client.TransportType transport)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
await Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(deviceClient, testDevice.Id, s_listOfPropertyValues, Logger).ConfigureAwait(false);
}
public static async Task Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(DeviceClient deviceClient, string deviceId, object propValue, MsTestLogger logger)
{
- var propName = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
logger.Trace($"{nameof(Twin_DeviceSetsReportedPropertyAndGetsItBackAsync)}: name={propName}, value={propValue}");
@@ -443,12 +443,12 @@ public static async Task Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(Devic
// Validate the updated twin from the device-client
Twin deviceTwin = await deviceClient.GetTwinAsync().ConfigureAwait(false);
- var actual = deviceTwin.Properties.Reported[propName];
+ dynamic actual = deviceTwin.Properties.Reported[propName];
Assert.AreEqual(JsonConvert.SerializeObject(actual), JsonConvert.SerializeObject(propValue));
// Validate the updated twin from the service-client
Twin completeTwin = await _registryManager.GetTwinAsync(deviceId).ConfigureAwait(false);
- var actualProp = completeTwin.Properties.Reported[propName];
+ dynamic actualProp = completeTwin.Properties.Reported[propName];
Assert.AreEqual(JsonConvert.SerializeObject(actualProp), JsonConvert.SerializeObject(propValue));
}
@@ -523,7 +523,7 @@ await deviceClient
public static async Task RegistryManagerUpdateDesiredPropertyAsync(string deviceId, string propName, object propValue)
{
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
var twinPatch = new Twin();
twinPatch.Properties.Desired[propName] = propValue;
@@ -534,12 +534,12 @@ public static async Task RegistryManagerUpdateDesiredPropertyAsync(string device
private async Task Twin_ServiceSetsDesiredPropertyAndDeviceUnsubscribes(Client.TransportType transport, object propValue)
{
- var propName = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
Logger.Trace($"{nameof(Twin_ServiceSetsDesiredPropertyAndDeviceReceivesEventAsync)}: name={propName}, value={propValue}");
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
// Set a callback
await deviceClient.
@@ -569,12 +569,12 @@ await RegistryManagerUpdateDesiredPropertyAsync(testDevice.Id, propName, propVal
private async Task Twin_ServiceSetsDesiredPropertyAndDeviceReceivesEventAsync(Client.TransportType transport, Func> setTwinPropertyUpdateCallbackAsync, object propValue)
{
- var propName = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
Logger.Trace($"{nameof(Twin_ServiceSetsDesiredPropertyAndDeviceReceivesEventAsync)}: name={propName}, value={propValue}");
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
Task updateReceivedTask = await setTwinPropertyUpdateCallbackAsync(deviceClient, propName, propValue, Logger).ConfigureAwait(false);
@@ -584,12 +584,12 @@ await Task.WhenAll(
// Validate the updated twin from the device-client
Twin deviceTwin = await deviceClient.GetTwinAsync().ConfigureAwait(false);
- var actual = deviceTwin.Properties.Desired[propName];
+ dynamic actual = deviceTwin.Properties.Desired[propName];
Assert.AreEqual(JsonConvert.SerializeObject(actual), JsonConvert.SerializeObject(propValue));
// Validate the updated twin from the service-client
Twin completeTwin = await _registryManager.GetTwinAsync(testDevice.Id).ConfigureAwait(false);
- var actualProp = completeTwin.Properties.Desired[propName];
+ dynamic actualProp = completeTwin.Properties.Desired[propName];
Assert.AreEqual(JsonConvert.SerializeObject(actualProp), JsonConvert.SerializeObject(propValue));
await deviceClient.SetDesiredPropertyUpdateCallbackAsync(null, null).ConfigureAwait(false);
@@ -598,12 +598,12 @@ await Task.WhenAll(
private async Task Twin_ServiceSetsDesiredPropertyAndDeviceReceivesItOnNextGetAsync(Client.TransportType transport)
{
- var propName = Guid.NewGuid().ToString();
- var propValue = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
+ string propValue = Guid.NewGuid().ToString();
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
var twinPatch = new Twin();
twinPatch.Properties.Desired[propName] = propValue;
@@ -618,12 +618,12 @@ private async Task Twin_ServiceSetsDesiredPropertyAndDeviceReceivesItOnNextGetAs
private async Task Twin_DeviceSetsReportedPropertyAndServiceReceivesItAsync(Client.TransportType transport)
{
- var propName = Guid.NewGuid().ToString();
- var propValue = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
+ string propValue = Guid.NewGuid().ToString();
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
var patch = new TwinCollection();
patch[propName] = propValue;
@@ -638,13 +638,13 @@ private async Task Twin_DeviceSetsReportedPropertyAndServiceReceivesItAsync(Clie
private async Task Twin_ServiceDoesNotCreateNullPropertyInCollectionAsync(Client.TransportType transport)
{
- var propName1 = Guid.NewGuid().ToString();
- var propName2 = Guid.NewGuid().ToString();
- var propEmptyValue = "{}";
+ string propName1 = Guid.NewGuid().ToString();
+ string propName2 = Guid.NewGuid().ToString();
+ string propEmptyValue = "{}";
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
await deviceClient
.UpdateReportedPropertiesAsync(
@@ -690,14 +690,14 @@ await deviceClient
private async Task Twin_ClientHandlesRejectionInvalidPropertyNameAsync(Client.TransportType transport)
{
- var propName1 = "$" + Guid.NewGuid().ToString();
- var propName2 = Guid.NewGuid().ToString();
+ string propName1 = "$" + Guid.NewGuid().ToString();
+ string propName2 = Guid.NewGuid().ToString();
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(Logger, _devicePrefix).ConfigureAwait(false);
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
- using DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var deviceClient = DeviceClient.CreateFromConnectionString(testDevice.ConnectionString, transport);
- var exceptionThrown = false;
+ bool exceptionThrown = false;
try
{
await deviceClient
diff --git a/e2e/test/iothub/twin/TwinFaultInjectionTests.cs b/e2e/test/iothub/twin/TwinFaultInjectionTests.cs
index 0d76a46aec..eb94dd3fbc 100644
--- a/e2e/test/iothub/twin/TwinFaultInjectionTests.cs
+++ b/e2e/test/iothub/twin/TwinFaultInjectionTests.cs
@@ -219,12 +219,12 @@ private async Task Twin_DeviceReportedPropertiesRecovery(
TimeSpan delayInSec,
string proxyAddress = null)
{
- var propName = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
var props = new TwinCollection();
Func testOperation = async (deviceClient, testDevice) =>
{
- var propValue = Guid.NewGuid().ToString();
+ string propValue = Guid.NewGuid().ToString();
props[propName] = propValue;
await deviceClient.UpdateReportedPropertiesAsync(props).ConfigureAwait(false);
@@ -256,7 +256,7 @@ await FaultInjection
private async Task RegistryManagerUpdateDesiredPropertyAsync(string deviceId, string propName, string propValue)
{
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
var twinPatch = new Twin();
twinPatch.Properties.Desired[propName] = propValue;
@@ -273,10 +273,10 @@ private async Task Twin_DeviceDesiredPropertyUpdateRecoveryAsync(
string proxyAddress = null)
{
TestDeviceCallbackHandler testDeviceCallbackHandler = null;
- using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
+ using var registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
using var cts = new CancellationTokenSource(FaultInjection.RecoveryTime);
- var propName = Guid.NewGuid().ToString();
+ string propName = Guid.NewGuid().ToString();
var props = new TwinCollection();
// Configure the callback and start accepting twin changes.
@@ -289,7 +289,7 @@ async Task InitOperationAsync(DeviceClient deviceClient, TestDevice testDevice)
// Change the twin from the service side and verify the device received it.
async Task TestOperationAsync(DeviceClient deviceClient, TestDevice testDevice)
{
- var propValue = Guid.NewGuid().ToString();
+ string propValue = Guid.NewGuid().ToString();
testDeviceCallbackHandler.ExpectedTwinPropertyValue = propValue;
Logger.Trace($"{nameof(Twin_DeviceDesiredPropertyUpdateRecoveryAsync)}: name={propName}, value={propValue}");
diff --git a/e2e/test/provisioning/ProvisioningCertificateValidationE2ETest.cs b/e2e/test/provisioning/ProvisioningCertificateValidationE2ETest.cs
index 31d790610c..ca3afe1125 100644
--- a/e2e/test/provisioning/ProvisioningCertificateValidationE2ETest.cs
+++ b/e2e/test/provisioning/ProvisioningCertificateValidationE2ETest.cs
@@ -20,12 +20,12 @@ public class ProvisioningCertificateValidationE2ETest : E2EMsTestBase
[LoggedTestMethod]
public async Task ProvisioningServiceClient_QueryInvalidServiceCertificateHttp_Fails()
{
- using ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(
+ using var provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(
TestConfiguration.Provisioning.ConnectionStringInvalidServiceCertificate);
Query q = provisioningServiceClient.CreateEnrollmentGroupQuery(
new QuerySpecification("SELECT * FROM enrollmentGroups"));
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningServiceClientTransportException exception = await Assert.ThrowsExceptionAsync(
() => q.NextAsync()).ConfigureAwait(false);
#if NET472 || NET451
@@ -39,7 +39,7 @@ public async Task ProvisioningServiceClient_QueryInvalidServiceCertificateHttp_F
public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificateAmqpTcp_Fails()
{
using var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.TcpOnly);
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningTransportException exception = await Assert.ThrowsExceptionAsync(
() => TestInvalidServiceCertificate(transport)).ConfigureAwait(false);
Assert.IsInstanceOfType(exception.InnerException, typeof(AuthenticationException));
@@ -49,7 +49,7 @@ public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificat
public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificateMqttTcp_Fails()
{
using var transport = new ProvisioningTransportHandlerMqtt(TransportFallbackType.TcpOnly);
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningTransportException exception = await Assert.ThrowsExceptionAsync(
() => TestInvalidServiceCertificate(transport)).ConfigureAwait(false);
if (exception.InnerException == null)
@@ -66,7 +66,7 @@ public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificat
public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificateHttp_Fails()
{
using var transport = new ProvisioningTransportHandlerHttp();
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningTransportException exception = await Assert.ThrowsExceptionAsync(
() => TestInvalidServiceCertificate(transport)).ConfigureAwait(false);
#if NET472 || NET451
@@ -80,7 +80,7 @@ public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificat
public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificateAmqpWs_Fails()
{
using var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.WebSocketOnly);
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningTransportException exception = await Assert.ThrowsExceptionAsync(
() => TestInvalidServiceCertificate(transport)).ConfigureAwait(false);
Assert.IsInstanceOfType(exception.InnerException.InnerException.InnerException, typeof(AuthenticationException));
@@ -90,7 +90,7 @@ public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificat
public async Task ProvisioningDeviceClient_RegisterAsyncInvalidServiceCertificateMqttWs_Fails()
{
using var transport = new ProvisioningTransportHandlerMqtt(TransportFallbackType.WebSocketOnly);
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningTransportException exception = await Assert.ThrowsExceptionAsync(
() => TestInvalidServiceCertificate(transport)).ConfigureAwait(false);
Assert.IsInstanceOfType(exception.InnerException.InnerException.InnerException, typeof(AuthenticationException));
@@ -100,7 +100,7 @@ private static async Task TestInvalidServiceCertificate(ProvisioningTransportHan
{
using X509Certificate2 cert = TestConfiguration.Provisioning.GetIndividualEnrollmentCertificate();
using var security = new SecurityProviderX509Certificate(cert);
- ProvisioningDeviceClient provisioningDeviceClient = ProvisioningDeviceClient.Create(
+ var provisioningDeviceClient = ProvisioningDeviceClient.Create(
TestConfiguration.Provisioning.GlobalDeviceEndpointInvalidServiceCertificate,
"0ne00000001",
security,
diff --git a/e2e/test/provisioning/ProvisioningE2ETests.cs b/e2e/test/provisioning/ProvisioningE2ETests.cs
index 5f56f48c22..61c73f1698 100644
--- a/e2e/test/provisioning/ProvisioningE2ETests.cs
+++ b/e2e/test/provisioning/ProvisioningE2ETests.cs
@@ -4,14 +4,12 @@
using System;
using System.Collections.Generic;
using System.Net;
-using System.Net.Sockets;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
-using Microsoft.Azure.Devices.E2ETests.Helpers;
using Microsoft.Azure.Devices.Provisioning.Client;
using Microsoft.Azure.Devices.Provisioning.Client.Transport;
using Microsoft.Azure.Devices.Provisioning.Security.Samples;
@@ -559,7 +557,7 @@ private async Task ProvisioningDeviceClientValidRegistrationIdRegisterOkAsync(
transport.Proxy = (proxyServerAddress != null) ? new WebProxy(s_proxyServerAddress) : null;
}
- ProvisioningDeviceClient provClient = ProvisioningDeviceClient.Create(
+ var provClient = ProvisioningDeviceClient.Create(
s_globalDeviceEndpoint,
TestConfiguration.Provisioning.IdScope,
security,
@@ -577,14 +575,9 @@ private async Task ProvisioningDeviceClientValidRegistrationIdRegisterOkAsync(
{
try
{
- if (timeout != TimeSpan.MaxValue)
- {
- result = await provClient.RegisterAsync(timeout).ConfigureAwait(false);
- }
- else
- {
- result = await provClient.RegisterAsync(cts.Token).ConfigureAwait(false);
- }
+ result = timeout != TimeSpan.MaxValue
+ ? await provClient.RegisterAsync(timeout).ConfigureAwait(false)
+ : await provClient.RegisterAsync(cts.Token).ConfigureAwait(false);
break;
}
// Catching all ProvisioningTransportException as the status code is not the same for Mqtt, Amqp and Http.
@@ -653,7 +646,7 @@ private async Task ProvisioningDeviceClientProvisioningFlowCustomAllocationAlloc
transport.Proxy = (proxyServerAddress != null) ? new WebProxy(s_proxyServerAddress) : null;
}
- ProvisioningDeviceClient provClient = ProvisioningDeviceClient.Create(
+ var provClient = ProvisioningDeviceClient.Create(
s_globalDeviceEndpoint,
TestConfiguration.Provisioning.IdScope,
security,
@@ -720,7 +713,7 @@ public async Task ProvisioningDeviceClient_InvalidRegistrationId_TpmRegister_Fai
{
using ProvisioningTransportHandler transport = CreateTransportHandlerFromName(transportProtocol);
using SecurityProvider security = new SecurityProviderTpmSimulator("invalidregistrationid");
- ProvisioningDeviceClient provClient = ProvisioningDeviceClient.Create(
+ var provClient = ProvisioningDeviceClient.Create(
s_globalDeviceEndpoint,
TestConfiguration.Provisioning.IdScope,
security,
@@ -829,7 +822,7 @@ private async Task ProvisioningDeviceClientInvalidIdScopeRegisterFailAsync(
{
using ProvisioningTransportHandler transport = CreateTransportHandlerFromName(transportProtocol);
using SecurityProvider security = await CreateSecurityProviderFromNameAsync(attestationType, enrollmentType, groupId, null, AllocationPolicy.Hashed, null, null).ConfigureAwait(false);
- ProvisioningDeviceClient provClient = ProvisioningDeviceClient.Create(
+ var provClient = ProvisioningDeviceClient.Create(
s_globalDeviceEndpoint,
InvalidIdScope,
security,
@@ -837,7 +830,7 @@ private async Task ProvisioningDeviceClientInvalidIdScopeRegisterFailAsync(
using var cts = new CancellationTokenSource(FailingTimeoutMiliseconds);
- var exception = await Assert.ThrowsExceptionAsync(
+ ProvisioningTransportException exception = await Assert.ThrowsExceptionAsync(
() => provClient.RegisterAsync(cts.Token)).ConfigureAwait(false);
Logger.Trace($"Exception: {exception}");
@@ -887,7 +880,7 @@ private async Task ProvisioningDeviceClientInvalidGlobalAddressRegisterFailAsync
using ProvisioningTransportHandler transport = CreateTransportHandlerFromName(transportProtocol);
using SecurityProvider security = await CreateSecurityProviderFromNameAsync(attestationType, enrollmentType, groupId, null, AllocationPolicy.Hashed, null, null).ConfigureAwait(false);
- ProvisioningDeviceClient provClient = ProvisioningDeviceClient.Create(
+ var provClient = ProvisioningDeviceClient.Create(
InvalidGlobalAddress,
TestConfiguration.Provisioning.IdScope,
security,
@@ -936,7 +929,7 @@ public static ProvisioningTransportHandler CreateTransportHandlerFromName(Client
/// CreateSecurityProviderFromNameAsync(Attesta
{
_verboseLog.WriteLine($"{nameof(CreateSecurityProviderFromNameAsync)}({attestationType})");
- using ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
+ using var provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
switch (attestationType)
{
@@ -1016,7 +1009,7 @@ private async Task CreateSecurityProviderFromNameAsync(Attesta
case EnrollmentType.Group:
EnrollmentGroup symmetricKeyEnrollmentGroup = await CreateEnrollmentGroup(provisioningServiceClient, AttestationMechanismType.SymmetricKey, groupId, reprovisionPolicy, allocationPolicy, customAllocationDefinition, iothubs, capabilities).ConfigureAwait(false);
Assert.IsTrue(symmetricKeyEnrollmentGroup.Attestation is SymmetricKeyAttestation);
- SymmetricKeyAttestation symmetricKeyAttestation = (SymmetricKeyAttestation)symmetricKeyEnrollmentGroup.Attestation;
+ var symmetricKeyAttestation = (SymmetricKeyAttestation)symmetricKeyEnrollmentGroup.Attestation;
string registrationIdSymmetricKey = _idPrefix + Guid.NewGuid();
string primaryKeyEnrollmentGroup = symmetricKeyAttestation.PrimaryKey;
string secondaryKeyEnrollmentGroup = symmetricKeyAttestation.SecondaryKey;
diff --git a/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs b/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
index 3757ae6825..1ada9be022 100644
--- a/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
+++ b/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
@@ -76,7 +76,7 @@ public async Task ProvisioningServiceClient_SymmetricKey_GroupEnrollments_Create
//This webhook won't actually work for reprovisioning, but this test is only testing that the field is accepted by the service
var customAllocationDefinition = new CustomAllocationDefinition { ApiVersion = "2019-03-31", WebhookUrl = "https://www.microsoft.com" };
var reprovisionPolicy = new ReprovisionPolicy { MigrateDeviceData = false, UpdateHubAssignment = true };
- var allocationPolicy = AllocationPolicy.GeoLatency;
+ AllocationPolicy allocationPolicy = AllocationPolicy.GeoLatency;
await ProvisioningServiceClient_GroupEnrollments_Create_Ok("", AttestationMechanismType.SymmetricKey, reprovisionPolicy, allocationPolicy, customAllocationDefinition, null).ConfigureAwait(false);
}
@@ -112,7 +112,7 @@ public async Task ProvisioningServiceClient_GetEnrollmentGroupAttestation_Symmet
public async Task ProvisioningServiceClient_GetIndividualEnrollmentAttestation(AttestationMechanismType attestationType)
{
- using ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
+ using var provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
IndividualEnrollment individualEnrollment = await CreateIndividualEnrollment(provisioningServiceClient, attestationType, null, AllocationPolicy.Static, null, null, null);
AttestationMechanism attestationMechanism = await provisioningServiceClient.GetIndividualEnrollmentAttestationAsync(individualEnrollment.RegistrationId);
@@ -120,21 +120,21 @@ public async Task ProvisioningServiceClient_GetIndividualEnrollmentAttestation(A
if (attestationType == AttestationMechanismType.SymmetricKey)
{
Assert.AreEqual(AttestationMechanismType.SymmetricKey, attestationMechanism.Type);
- SymmetricKeyAttestation symmetricKeyAttestation = (SymmetricKeyAttestation)attestationMechanism.GetAttestation();
+ var symmetricKeyAttestation = (SymmetricKeyAttestation)attestationMechanism.GetAttestation();
Assert.AreEqual(((SymmetricKeyAttestation)individualEnrollment.Attestation).PrimaryKey, symmetricKeyAttestation.PrimaryKey);
Assert.AreEqual(((SymmetricKeyAttestation)individualEnrollment.Attestation).SecondaryKey, symmetricKeyAttestation.SecondaryKey);
}
else if (attestationType == AttestationMechanismType.X509)
{
Assert.AreEqual(AttestationMechanismType.X509, attestationMechanism.Type);
- X509Attestation x509Attestation = (X509Attestation)attestationMechanism.GetAttestation();
+ var x509Attestation = (X509Attestation)attestationMechanism.GetAttestation();
Assert.AreEqual(((X509Attestation)individualEnrollment.Attestation).GetPrimaryX509CertificateInfo().SHA1Thumbprint, x509Attestation.GetPrimaryX509CertificateInfo().SHA1Thumbprint);
Assert.AreEqual(((X509Attestation)individualEnrollment.Attestation).GetSecondaryX509CertificateInfo().SHA1Thumbprint, x509Attestation.GetSecondaryX509CertificateInfo().SHA1Thumbprint);
}
else
{
Assert.AreEqual(AttestationMechanismType.Tpm, attestationMechanism.Type);
- TpmAttestation tpmAttestation = (TpmAttestation)attestationMechanism.GetAttestation();
+ var tpmAttestation = (TpmAttestation)attestationMechanism.GetAttestation();
Assert.AreEqual(((TpmAttestation)individualEnrollment.Attestation).EndorsementKey, tpmAttestation.EndorsementKey);
Assert.AreEqual(((TpmAttestation)individualEnrollment.Attestation).StorageRootKey, tpmAttestation.StorageRootKey);
}
@@ -142,7 +142,7 @@ public async Task ProvisioningServiceClient_GetIndividualEnrollmentAttestation(A
public async Task ProvisioningServiceClient_GetEnrollmentGroupAttestation(AttestationMechanismType attestationType)
{
- using ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
+ using var provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
string groupId = AttestationTypeToString(attestationType) + "-" + Guid.NewGuid();
EnrollmentGroup enrollmentGroup = await CreateEnrollmentGroup(provisioningServiceClient, attestationType, groupId, null, AllocationPolicy.Static, null, null, null);
@@ -152,14 +152,14 @@ public async Task ProvisioningServiceClient_GetEnrollmentGroupAttestation(Attest
if (attestationType == AttestationMechanismType.SymmetricKey)
{
Assert.AreEqual(AttestationMechanismType.SymmetricKey, attestationMechanism.Type);
- SymmetricKeyAttestation symmetricKeyAttestation = (SymmetricKeyAttestation)attestationMechanism.GetAttestation();
+ var symmetricKeyAttestation = (SymmetricKeyAttestation)attestationMechanism.GetAttestation();
Assert.AreEqual(((SymmetricKeyAttestation)enrollmentGroup.Attestation).PrimaryKey, symmetricKeyAttestation.PrimaryKey);
Assert.AreEqual(((SymmetricKeyAttestation)enrollmentGroup.Attestation).SecondaryKey, symmetricKeyAttestation.SecondaryKey);
}
else if (attestationType == AttestationMechanismType.X509)
{
Assert.AreEqual(AttestationMechanismType.X509, attestationMechanism.Type);
- X509Attestation x509Attestation = (X509Attestation)attestationMechanism.GetAttestation();
+ var x509Attestation = (X509Attestation)attestationMechanism.GetAttestation();
Assert.AreEqual(((X509Attestation)enrollmentGroup.Attestation).GetPrimaryX509CertificateInfo().SHA1Thumbprint, x509Attestation.GetPrimaryX509CertificateInfo().SHA1Thumbprint);
Assert.AreEqual(((X509Attestation)enrollmentGroup.Attestation).GetSecondaryX509CertificateInfo().SHA1Thumbprint, x509Attestation.GetSecondaryX509CertificateInfo().SHA1Thumbprint);
}
@@ -266,7 +266,7 @@ public static async Task CreateIndividualEnrollment(Provis
using (var tpmSim = new SecurityProviderTpmSimulator(registrationId))
{
string base64Ek = Convert.ToBase64String(tpmSim.GetEndorsementKey());
- using ProvisioningServiceClient provisioningService = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
+ using var provisioningService = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString);
individualEnrollment = new IndividualEnrollment(registrationId, new TpmAttestation(base64Ek))
{
Capabilities = capabilities,
diff --git a/e2e/test/provisioning/ReprovisioningE2ETests.cs b/e2e/test/provisioning/ReprovisioningE2ETests.cs
index f647a52d02..d80d2170ef 100644
--- a/e2e/test/provisioning/ReprovisioningE2ETests.cs
+++ b/e2e/test/provisioning/ReprovisioningE2ETests.cs
@@ -211,7 +211,7 @@ public async Task ProvisioningDeviceClient_ReprovisioningBlockingWorks_MqttWs_Sy
///
private async Task ProvisioningDeviceClient_ReprovisioningFlow_ResetTwin(Client.TransportType transportProtocol, AttestationMechanismType attestationType, EnrollmentType enrollmentType, bool setCustomProxy, string customServerProxy = null)
{
- IotHubConnectionStringBuilder connectionString = IotHubConnectionStringBuilder.Create(TestConfiguration.IoTHub.ConnectionString);
+ var connectionString = IotHubConnectionStringBuilder.Create(TestConfiguration.IoTHub.ConnectionString);
ICollection iotHubsToStartAt = new List() { TestConfiguration.Provisioning.FarAwayIotHubHostName };
ICollection iotHubsToReprovisionTo = new List() { connectionString.HostName };
await ProvisioningDeviceClient_ReprovisioningFlow(transportProtocol, attestationType, enrollmentType, setCustomProxy, new ReprovisionPolicy { MigrateDeviceData = false, UpdateHubAssignment = true }, AllocationPolicy.Hashed, null, iotHubsToStartAt, iotHubsToReprovisionTo, customServerProxy).ConfigureAwait(false);
@@ -223,7 +223,7 @@ private async Task ProvisioningDeviceClient_ReprovisioningFlow_ResetTwin(Client.
///
private async Task ProvisioningDeviceClient_ReprovisioningFlow_KeepTwin(Client.TransportType transportProtocol, AttestationMechanismType attestationType, EnrollmentType enrollmentType, bool setCustomProxy, string customServerProxy = null)
{
- IotHubConnectionStringBuilder connectionString = IotHubConnectionStringBuilder.Create(TestConfiguration.IoTHub.ConnectionString);
+ var connectionString = IotHubConnectionStringBuilder.Create(TestConfiguration.IoTHub.ConnectionString);
ICollection iotHubsToStartAt = new List() { TestConfiguration.Provisioning.FarAwayIotHubHostName };
ICollection iotHubsToReprovisionTo = new List() { connectionString.HostName };
await ProvisioningDeviceClient_ReprovisioningFlow(transportProtocol, attestationType, enrollmentType, setCustomProxy, new ReprovisionPolicy { MigrateDeviceData = true, UpdateHubAssignment = true }, AllocationPolicy.Hashed, null, iotHubsToStartAt, iotHubsToReprovisionTo, customServerProxy).ConfigureAwait(false);
@@ -234,7 +234,7 @@ private async Task ProvisioningDeviceClient_ReprovisioningFlow_KeepTwin(Client.T
///
private async Task ProvisioningDeviceClient_ReprovisioningFlow_DoNotReprovision(Client.TransportType transportProtocol, AttestationMechanismType attestationType, EnrollmentType enrollmentType, bool setCustomProxy, string customServerProxy = null)
{
- IotHubConnectionStringBuilder connectionString = IotHubConnectionStringBuilder.Create(TestConfiguration.IoTHub.ConnectionString);
+ var connectionString = IotHubConnectionStringBuilder.Create(TestConfiguration.IoTHub.ConnectionString);
ICollection iotHubsToStartAt = new List() { TestConfiguration.Provisioning.FarAwayIotHubHostName };
ICollection iotHubsToReprovisionTo = new List() { connectionString.HostName };
await ProvisioningDeviceClient_ReprovisioningFlow(transportProtocol, attestationType, enrollmentType, setCustomProxy, new ReprovisionPolicy { MigrateDeviceData = false, UpdateHubAssignment = false }, AllocationPolicy.Hashed, null, iotHubsToStartAt, iotHubsToReprovisionTo, customServerProxy).ConfigureAwait(false);
@@ -281,7 +281,7 @@ public async Task ProvisioningDeviceClient_ReprovisioningFlow(
transport.Proxy = (proxyServerAddress != null) ? new WebProxy(s_proxyServerAddress) : null;
}
- ProvisioningDeviceClient provClient = ProvisioningDeviceClient.Create(
+ var provClient = ProvisioningDeviceClient.Create(
s_globalDeviceEndpoint,
TestConfiguration.Provisioning.IdScope,
security,
@@ -320,7 +320,7 @@ public async Task ProvisioningDeviceClient_ReprovisioningFlow(
///
private async Task ConfirmRegisteredDeviceWorks(DeviceRegistrationResult result, Client.IAuthenticationMethod auth, Client.TransportType transportProtocol, bool sendReportedPropertiesUpdate)
{
- using (DeviceClient iotClient = DeviceClient.Create(result.AssignedHub, auth, transportProtocol))
+ using (var iotClient = DeviceClient.Create(result.AssignedHub, auth, transportProtocol))
{
Logger.Trace("DeviceClient OpenAsync.");
await iotClient.OpenAsync().ConfigureAwait(false);
@@ -346,7 +346,7 @@ private async Task ConfirmExpectedDeviceCapabilities(DeviceRegistrationResult re
if (capabilities != null)
{
//hardcoding amqp since http does not support twin, but tests that call into this may use http
- using (DeviceClient iotClient = DeviceClient.Create(result.AssignedHub, auth, Client.TransportType.Amqp))
+ using (var iotClient = DeviceClient.Create(result.AssignedHub, auth, Client.TransportType.Amqp))
{
//Confirm that the device twin reflects what the enrollment dictated
Twin twin = await iotClient.GetTwinAsync().ConfigureAwait(false);
@@ -369,7 +369,7 @@ private async Task CreateSecurityProviderFromName(AttestationM
string base64Ek = Convert.ToBase64String(tpmSim.GetEndorsementKey());
- using (ProvisioningServiceClient provisioningService = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString))
+ using (var provisioningService = ProvisioningServiceClient.CreateFromConnectionString(TestConfiguration.Provisioning.ConnectionString))
{
Logger.Trace($"Getting enrollment: RegistrationID = {registrationId}");
var individualEnrollment = new IndividualEnrollment(registrationId, new TpmAttestation(base64Ek)) { AllocationPolicy = allocationPolicy, ReprovisionPolicy = reprovisionPolicy, IotHubs = iothubs, CustomAllocationDefinition = customAllocationDefinition, Capabilities = capabilities };
@@ -409,7 +409,7 @@ private async Task CreateSecurityProviderFromName(AttestationM
case EnrollmentType.Group:
EnrollmentGroup symmetricKeyEnrollmentGroup = await CreateEnrollmentGroup(provisioningServiceClient, AttestationMechanismType.SymmetricKey, groupId, reprovisionPolicy, allocationPolicy, customAllocationDefinition, iothubs, capabilities).ConfigureAwait(false);
Assert.IsTrue(symmetricKeyEnrollmentGroup.Attestation is SymmetricKeyAttestation);
- SymmetricKeyAttestation symmetricKeyAttestation = (SymmetricKeyAttestation)symmetricKeyEnrollmentGroup.Attestation;
+ var symmetricKeyAttestation = (SymmetricKeyAttestation)symmetricKeyEnrollmentGroup.Attestation;
string registrationIdSymmetricKey = _devicePrefix + Guid.NewGuid();
string primaryKeyEnrollmentGroup = symmetricKeyAttestation.PrimaryKey;
string secondaryKeyEnrollmentGroup = symmetricKeyAttestation.SecondaryKey;
@@ -525,7 +525,7 @@ private void ConfirmDeviceInExpectedHub(DeviceRegistrationResult result, Reprovi
private async Task ConfirmDeviceWorksAfterReprovisioning(DeviceRegistrationResult result, Client.IAuthenticationMethod auth, Client.TransportType transportProtocol, ReprovisionPolicy reprovisionPolicy, bool twinOperationsAllowed)
{
- using (DeviceClient iotClient = DeviceClient.Create(result.AssignedHub, auth, transportProtocol))
+ using (var iotClient = DeviceClient.Create(result.AssignedHub, auth, transportProtocol))
{
Logger.Trace("DeviceClient OpenAsync.");
await iotClient.OpenAsync().ConfigureAwait(false);
diff --git a/iothub/device/src/AuthenticationMethodFactory.cs b/iothub/device/src/AuthenticationMethodFactory.cs
index 85f68a908d..c371040a20 100644
--- a/iothub/device/src/AuthenticationMethodFactory.cs
+++ b/iothub/device/src/AuthenticationMethodFactory.cs
@@ -33,16 +33,14 @@ internal static IAuthenticationMethod GetAuthenticationMethod(IotHubConnectionSt
}
else if (iotHubConnectionStringBuilder.SharedAccessSignature != null)
{
- if (iotHubConnectionStringBuilder.ModuleId != null)
- {
- return new ModuleAuthenticationWithToken(
- iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.ModuleId, iotHubConnectionStringBuilder.SharedAccessSignature);
- }
- else
- {
- return new DeviceAuthenticationWithToken(
- iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.SharedAccessSignature);
- }
+ return iotHubConnectionStringBuilder.ModuleId != null
+ ? new ModuleAuthenticationWithToken(
+ iotHubConnectionStringBuilder.DeviceId,
+ iotHubConnectionStringBuilder.ModuleId,
+ iotHubConnectionStringBuilder.SharedAccessSignature)
+ : (IAuthenticationMethod)new DeviceAuthenticationWithToken(
+ iotHubConnectionStringBuilder.DeviceId,
+ iotHubConnectionStringBuilder.SharedAccessSignature);
}
else if (iotHubConnectionStringBuilder.UsingX509Cert)
{
diff --git a/iothub/device/src/ClientFactory.cs b/iothub/device/src/ClientFactory.cs
index 3532c5516c..3ab6d9b710 100644
--- a/iothub/device/src/ClientFactory.cs
+++ b/iothub/device/src/ClientFactory.cs
@@ -122,12 +122,11 @@ internal static InternalClient Create(
throw new ArgumentException("No certificate was found. To use certificate authentication certificate must be present.");
}
-#pragma warning disable CA2000 // This is returned to client so cannot be disposed here.
InternalClient dc = CreateFromConnectionString(
connectionStringBuilder.ToString(),
PopulateCertificateInTransportSettings(connectionStringBuilder, transportType),
options);
-#pragma warning restore CA2000
+
dc.Certificate = connectionStringBuilder.Certificate;
// Install all the intermediate certificates in the chain if specified.
@@ -438,7 +437,7 @@ internal static InternalClient CreateFromConnectionString(
builder.SasTokenRenewalBuffer = options?.SasTokenRenewalBuffer ?? default;
}
- IotHubConnectionString iotHubConnectionString = builder.ToIotHubConnectionString();
+ var iotHubConnectionString = builder.ToIotHubConnectionString();
foreach (ITransportSettings transportSetting in transportSettings)
{
@@ -612,7 +611,7 @@ private static ITransportSettings[] PopulateCertificateInTransportSettings(
private static ITransportSettings[] PopulateCertificateInTransportSettings(IotHubConnectionStringBuilder connectionStringBuilder, ITransportSettings[] transportSettings)
{
- foreach (var transportSetting in transportSettings)
+ foreach (ITransportSettings transportSetting in transportSettings)
{
switch (transportSetting.GetTransportType())
{
diff --git a/iothub/device/src/Common/Amqp/ClientWebSocketTransport.cs b/iothub/device/src/Common/Amqp/ClientWebSocketTransport.cs
index e17018693b..da7e9f7eb3 100644
--- a/iothub/device/src/Common/Amqp/ClientWebSocketTransport.cs
+++ b/iothub/device/src/Common/Amqp/ClientWebSocketTransport.cs
@@ -249,7 +249,7 @@ private static void OnReadComplete(IAsyncResult result)
private static void HandleReadComplete(IAsyncResult result)
{
- Task taskResult = (Task)result;
+ var taskResult = (Task)result;
var args = (TransportAsyncCallbackArgs)taskResult.AsyncState;
ReadTaskDone(taskResult, args);
@@ -291,7 +291,7 @@ private static void OnWriteComplete(IAsyncResult result)
private static void HandleWriteComplete(IAsyncResult result)
{
- Task taskResult = (Task)result;
+ var taskResult = (Task)result;
var args = (TransportAsyncCallbackArgs)taskResult.AsyncState;
WriteTaskDone(taskResult, args);
args.CompletedCallback(args);
diff --git a/iothub/device/src/Common/Extensions/CommonExtensions.cs b/iothub/device/src/Common/Extensions/CommonExtensions.cs
index 95f2c6ddb1..944e21eda8 100644
--- a/iothub/device/src/Common/Extensions/CommonExtensions.cs
+++ b/iothub/device/src/Common/Extensions/CommonExtensions.cs
@@ -121,7 +121,7 @@ public static string GetMaskedClientIpAddress(this HttpRequestMessage requestMes
// note that this only works if we are hosted as an OWIN app
if (requestMessage.Properties.ContainsKey("MS_OwinContext"))
{
- OwinContext owinContext = requestMessage.Properties["MS_OwinContext"] as OwinContext;
+ var owinContext = requestMessage.Properties["MS_OwinContext"] as OwinContext;
if (owinContext != null)
{
string remoteIpAddress = owinContext.Request.RemoteIpAddress;
diff --git a/iothub/device/src/Common/Fx.cs b/iothub/device/src/Common/Fx.cs
index 14dc31e8ec..12d03b05b6 100644
--- a/iothub/device/src/Common/Fx.cs
+++ b/iothub/device/src/Common/Fx.cs
@@ -212,7 +212,7 @@ internal static Type[] BreakOnExceptionTypes
string[] typeNames = value as string[];
if (typeNames != null && typeNames.Length > 0)
{
- List types = new List(typeNames.Length);
+ var types = new List(typeNames.Length);
for (int i = 0; i < typeNames.Length; i++)
{
types.Add(Type.GetType(typeNames[i], false));
diff --git a/iothub/device/src/Common/PartialTrustHelpers.cs b/iothub/device/src/Common/PartialTrustHelpers.cs
index fbd857815e..0d7976e9bd 100644
--- a/iothub/device/src/Common/PartialTrustHelpers.cs
+++ b/iothub/device/src/Common/PartialTrustHelpers.cs
@@ -173,7 +173,7 @@ internal static bool HasEtwPermissions()
throw new NotImplementedException();
#else
//Currently unrestricted permissions are required to create Etw provider.
- PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
+ var permissions = new PermissionSet(PermissionState.Unrestricted);
return CheckAppDomainPermissions(permissions);
#endif
}
diff --git a/iothub/device/src/Common/ReadOnlyDictionary45.cs b/iothub/device/src/Common/ReadOnlyDictionary45.cs
index 7faf42c1a6..f63baf8af2 100644
--- a/iothub/device/src/Common/ReadOnlyDictionary45.cs
+++ b/iothub/device/src/Common/ReadOnlyDictionary45.cs
@@ -283,7 +283,7 @@ bool IDictionary.Contains(object key)
IDictionaryEnumerator IDictionary.GetEnumerator()
{
- IDictionary d = Dictionary as IDictionary;
+ var d = Dictionary as IDictionary;
if (d != null)
{
return d.GetEnumerator();
@@ -352,17 +352,17 @@ void ICollection.CopyTo(Array array, int index)
throw Fx.Exception.Argument(nameof(array), Resources.InvalidBufferSize);
}
- KeyValuePair[] pairs = array as KeyValuePair[];
+ var pairs = array as KeyValuePair[];
if (pairs != null)
{
Dictionary.CopyTo(pairs, index);
}
else
{
- DictionaryEntry[] dictEntryArray = array as DictionaryEntry[];
+ var dictEntryArray = array as DictionaryEntry[];
if (dictEntryArray != null)
{
- foreach (var item in Dictionary)
+ foreach (KeyValuePair item in Dictionary)
{
dictEntryArray[index++] = new DictionaryEntry(item.Key, item.Value);
}
@@ -377,7 +377,7 @@ void ICollection.CopyTo(Array array, int index)
try
{
- foreach (var item in Dictionary)
+ foreach (KeyValuePair item in Dictionary)
{
objects[index++] = new KeyValuePair(item.Key, item.Value);
}
@@ -401,7 +401,7 @@ object ICollection.SyncRoot
{
if (_syncRoot == null)
{
- ICollection c = Dictionary as ICollection;
+ var c = Dictionary as ICollection;
if (c != null)
{
_syncRoot = c.SyncRoot;
@@ -568,7 +568,7 @@ object ICollection.SyncRoot
{
if (_syncRoot == null)
{
- ICollection c = _collection as ICollection;
+ var c = _collection as ICollection;
if (c != null)
{
_syncRoot = c.SyncRoot;
@@ -715,7 +715,7 @@ object ICollection.SyncRoot
{
if (m_syncRoot == null)
{
- ICollection c = m_collection as ICollection;
+ var c = m_collection as ICollection;
if (c != null)
{
m_syncRoot = c.SyncRoot;
diff --git a/iothub/device/src/Common/SynchronizedPool.cs b/iothub/device/src/Common/SynchronizedPool.cs
index 5fce4fc1b4..25ca74a7bd 100644
--- a/iothub/device/src/Common/SynchronizedPool.cs
+++ b/iothub/device/src/Common/SynchronizedPool.cs
@@ -201,7 +201,7 @@ private void RecordTakeFromGlobalPool(int thisThreadID)
}
else
{
- PendingEntry[] newPending = new PendingEntry[localPending.Length * 2];
+ var newPending = new PendingEntry[localPending.Length * 2];
Array.Copy(localPending, newPending, localPending.Length);
this.pending = newPending;
}
diff --git a/iothub/device/src/Common/TaskHelpers.cs b/iothub/device/src/Common/TaskHelpers.cs
index a258da2980..6fffea7e20 100644
--- a/iothub/device/src/Common/TaskHelpers.cs
+++ b/iothub/device/src/Common/TaskHelpers.cs
@@ -122,7 +122,7 @@ internal static void MarshalTaskResults(Task source, TaskCompletionSour
break;
case TaskStatus.RanToCompletion:
- Task castedSource = source as Task;
+ var castedSource = source as Task;
proxy.TrySetResult(
castedSource == null ? default(TResult) : // source is a Task
castedSource.Result); // source is a Task
diff --git a/iothub/device/src/Common/Utils.cs b/iothub/device/src/Common/Utils.cs
index a858b3ed2a..11baccaa08 100644
--- a/iothub/device/src/Common/Utils.cs
+++ b/iothub/device/src/Common/Utils.cs
@@ -115,7 +115,7 @@ public static IReadOnlyDictionary MergeDictionaries(
throw new ArgumentNullException(nameof(dictionaries), "Provided dictionaries should not be null");
}
- Dictionary result = dictionaries.SelectMany(dict => dict)
+ var result = dictionaries.SelectMany(dict => dict)
.ToLookup(pair => pair.Key, pair => pair.Value)
.ToDictionary(group => group.Key, group => group.First());
diff --git a/iothub/device/src/GlobalSuppressions.cs b/iothub/device/src/GlobalSuppressions.cs
index 30c80222e1..0dc33d307d 100644
--- a/iothub/device/src/GlobalSuppressions.cs
+++ b/iothub/device/src/GlobalSuppressions.cs
@@ -7,7 +7,35 @@
using System.Diagnostics.CodeAnalysis;
-[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Not localizing", Scope = "module")]
-[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "SDK hides non-actionable errors from user", Scope = "module")]
-[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Public API cannot be changed.", Scope = "type", Target = "~T:Microsoft.Azure.Devices.Client.ConnectionStatusChangeReason")]
-[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Public API cannot be changed.", Scope = "type", Target = "~T:Microsoft.Azure.Devices.Client.ConnectionStatus")]
+[assembly: SuppressMessage(
+ "Globalization",
+ "CA1303:Do not pass literals as localized parameters",
+ Justification = "Not localizing",
+ Scope = "module")]
+[assembly: SuppressMessage(
+ "Design",
+ "CA1031:Do not catch general exception types",
+ Justification = "SDK hides non-actionable errors from user",
+ Scope = "module")]
+[assembly: SuppressMessage(
+ "Naming",
+ "CA1707:Identifiers should not contain underscores",
+ Justification = "Public API cannot be changed.",
+ Scope = "type",
+ Target = "~T:Microsoft.Azure.Devices.Client.ConnectionStatusChangeReason")]
+[assembly: SuppressMessage(
+ "Naming",
+ "CA1707:Identifiers should not contain underscores",
+ Justification = "Public API cannot be changed.",
+ Scope = "type",
+ Target = "~T:Microsoft.Azure.Devices.Client.ConnectionStatus")]
+[assembly: SuppressMessage(
+ "Style",
+ "IDE0011:Add braces",
+ Justification = "Agreement in the team to keep this style as is for logging methods only.",
+ Scope = "module")]
+[assembly: SuppressMessage(
+ "CodeQuality",
+ "IDE0079:Remove unnecessary suppression",
+ Justification = "Each frameworks consider certain suppressions required by other frameworks unnecessary.",
+ Scope = "module")]
diff --git a/iothub/device/src/IotHubClientDiagnostic.cs b/iothub/device/src/IotHubClientDiagnostic.cs
index 4ed50de462..603576b4a4 100644
--- a/iothub/device/src/IotHubClientDiagnostic.cs
+++ b/iothub/device/src/IotHubClientDiagnostic.cs
@@ -34,7 +34,7 @@ internal static bool HasDiagnosticProperties(Message message)
private static string GenerateEightRandomCharacters()
{
- var stringChars = new char[8];
+ char[] stringChars = new char[8];
var random = new Random();
for (int i = 0; i < stringChars.Length; i++)
{
diff --git a/iothub/device/src/ModernDotNet/HsmAuthentication/Transport/HttpUdsMessageHandler.cs b/iothub/device/src/ModernDotNet/HsmAuthentication/Transport/HttpUdsMessageHandler.cs
index 66a0ea0372..62889cf2d3 100644
--- a/iothub/device/src/ModernDotNet/HsmAuthentication/Transport/HttpUdsMessageHandler.cs
+++ b/iothub/device/src/ModernDotNet/HsmAuthentication/Transport/HttpUdsMessageHandler.cs
@@ -40,7 +40,7 @@ protected override async Task SendAsync(HttpRequestMessage
private async Task GetConnectedSocketAsync()
{
- Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
+ var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
// The Edge Agent uses unix sockets for communication with the modules deployed in docker for HSM.
// For netstandard 2.0 there was no implementation for a Unix Domain Socket (UDS) so we used a version
diff --git a/iothub/device/src/TransientFaultHandling/AsyncExecution[T].cs b/iothub/device/src/TransientFaultHandling/AsyncExecution[T].cs
index 7645591a68..278ca97689 100644
--- a/iothub/device/src/TransientFaultHandling/AsyncExecution[T].cs
+++ b/iothub/device/src/TransientFaultHandling/AsyncExecution[T].cs
@@ -79,7 +79,7 @@ private Task ExecuteAsyncImpl(Task ignore)
{
return this.previousTask;
}
- TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
+ var taskCompletionSource = new TaskCompletionSource();
taskCompletionSource.TrySetCanceled();
return taskCompletionSource.Task;
}
@@ -96,7 +96,7 @@ private Task ExecuteAsyncImpl(Task ignore)
{
throw;
}
- TaskCompletionSource taskCompletionSource2 = new TaskCompletionSource();
+ var taskCompletionSource2 = new TaskCompletionSource();
taskCompletionSource2.TrySetException(ex);
task = taskCompletionSource2.Task;
}
diff --git a/iothub/device/src/Transport/Amqp/AmqpTransportHandler.cs b/iothub/device/src/Transport/Amqp/AmqpTransportHandler.cs
index f38a52ef62..df4ab761d6 100644
--- a/iothub/device/src/Transport/Amqp/AmqpTransportHandler.cs
+++ b/iothub/device/src/Transport/Amqp/AmqpTransportHandler.cs
@@ -21,7 +21,7 @@ internal class AmqpTransportHandler : TransportHandler
protected AmqpUnit _amqpUnit;
private readonly Action _onDesiredStatePatchListener;
private readonly object _lock = new object();
- private ConcurrentDictionary> _twinResponseCompletions = new ConcurrentDictionary>();
+ private readonly ConcurrentDictionary> _twinResponseCompletions = new ConcurrentDictionary>();
private bool _closed;
static AmqpTransportHandler()
@@ -478,7 +478,7 @@ public override async Task EnableEventReceiveAsync(bool isAnEdgeModule, Cancella
{
Logging.Exit(this, cancellationToken, nameof(EnableEventReceiveAsync));
}
- }
+ }
else
{
await EnableReceiveMessageAsync(cancellationToken).ConfigureAwait(false);
diff --git a/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs b/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs
index cfbd235133..5c8f290897 100644
--- a/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs
+++ b/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs
@@ -117,7 +117,7 @@ internal async Task SendMessagesAsync(IEnumerable messa
}
Outcome outcome;
- using (AmqpMessage amqpMessage = AmqpMessage.Create(messageList))
+ using (var amqpMessage = AmqpMessage.Create(messageList))
{
amqpMessage.MessageFormat = AmqpConstants.AmqpBatchedMessageFormat;
outcome = await SendAmqpMessageAsync(amqpMessage, cancellationToken).ConfigureAwait(false);
diff --git a/iothub/device/src/Transport/AmqpIot/AmqpIotTransport.cs b/iothub/device/src/Transport/AmqpIot/AmqpIotTransport.cs
index 4af039ddb6..3406e2a13d 100644
--- a/iothub/device/src/Transport/AmqpIot/AmqpIotTransport.cs
+++ b/iothub/device/src/Transport/AmqpIot/AmqpIotTransport.cs
@@ -117,7 +117,7 @@ private async Task CreateClientWebSocketTransportAsync(Cancellati
|| (Environment.OSVersion.Version.Major == 6
&& Environment.OSVersion.Version.Minor <= 1))
{
- var websocket = await CreateLegacyClientWebSocketAsync(
+ IotHubClientWebSocket websocket = await CreateLegacyClientWebSocketAsync(
websocketUri,
this._amqpTransportSettings.ClientCertificate,
cancellationToken)
diff --git a/iothub/device/src/Transport/DefaultDelegatingHandler.cs b/iothub/device/src/Transport/DefaultDelegatingHandler.cs
index 355cb32507..8c2959b339 100644
--- a/iothub/device/src/Transport/DefaultDelegatingHandler.cs
+++ b/iothub/device/src/Transport/DefaultDelegatingHandler.cs
@@ -30,10 +30,7 @@ protected DefaultDelegatingHandler(IPipelineContext context, IDelegatingHandler
public IDelegatingHandler InnerHandler
{
- get
- {
- return _innerHandler;
- }
+ get => _innerHandler;
protected set
{
_innerHandler = value;
diff --git a/iothub/device/src/Transport/ErrorDelegatingHandler.cs b/iothub/device/src/Transport/ErrorDelegatingHandler.cs
index 9c17a5e97d..a75e34570b 100644
--- a/iothub/device/src/Transport/ErrorDelegatingHandler.cs
+++ b/iothub/device/src/Transport/ErrorDelegatingHandler.cs
@@ -158,9 +158,12 @@ private static bool IsSecurityExceptionChain(Exception exceptionChain)
private static bool IsTlsSecurity(Exception singleException)
{
if (// WinHttpException (0x80072F8F): A security error occurred.
- (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (singleException.HResult == unchecked((int)0x80072F8F))) ||
+ (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+ && singleException.HResult == unchecked((int)0x80072F8F))
+ ||
// CURLE_SSL_CACERT (60): Peer certificate cannot be authenticated with known CA certificates.
- (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (singleException.HResult == 60)) ||
+ (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && singleException.HResult == 60)
+ ||
singleException is AuthenticationException)
{
return true;
diff --git a/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs b/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs
index 3ef42f0769..f26b7a7ce1 100644
--- a/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs
+++ b/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs
@@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
@@ -235,7 +236,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message)
// If a message is received when the state is Connected or a CONNACK is received when the state is Connecting, then the message should be processed.
if (IsInState(StateFlags.Connected) || IsInState(StateFlags.Connecting) && packet.PacketType == PacketType.CONNACK)
{
- ProcessMessage(context, packet);
+ ProcessMessageAsync(context, packet);
}
else
{
@@ -697,10 +698,10 @@ private void ProcessUnsubAck(IChannelHandlerContext context, UnsubAckPacket pack
#region Receiving
- private async void ProcessMessage(IChannelHandlerContext context, Packet packet)
+ private async void ProcessMessageAsync(IChannelHandlerContext context, Packet packet)
{
if (Logging.IsEnabled)
- Logging.Enter(this, context.Name, packet.PacketType, nameof(ProcessMessage));
+ Logging.Enter(this, context.Name, packet.PacketType, nameof(ProcessMessageAsync));
try
{
@@ -732,7 +733,7 @@ private async void ProcessMessage(IChannelHandlerContext context, Packet packet)
default:
if (Logging.IsEnabled)
- Logging.Error(context, $"Received an unexpected packet type {packet.PacketType}, will shut down.", nameof(ProcessMessage));
+ Logging.Error(context, $"Received an unexpected packet type {packet.PacketType}, will shut down.", nameof(ProcessMessageAsync));
ShutdownOnErrorAsync(context, new InvalidOperationException($"Unexpected packet type {packet.PacketType}"));
break;
@@ -741,18 +742,18 @@ private async void ProcessMessage(IChannelHandlerContext context, Packet packet)
catch (Exception ex) when (!ex.IsFatal())
{
if (Logging.IsEnabled)
- Logging.Error(context, $"Received a non-fatal exception while processing a received packet of type {packet.PacketType}, will shut down: {ex}", nameof(ProcessMessage));
+ Logging.Error(context, $"Received a non-fatal exception while processing a received packet of type {packet.PacketType}, will shut down: {ex}", nameof(ProcessMessageAsync));
ShutdownOnErrorAsync(context, ex);
}
finally
{
if (Logging.IsEnabled)
- Logging.Exit(this, context.Name, packet.PacketType, nameof(ProcessMessage));
+ Logging.Exit(this, context.Name, packet.PacketType, nameof(ProcessMessageAsync));
}
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ [SuppressMessage(
"Reliability",
"CA2000:Dispose objects before losing scope",
Justification = "The created message is handed to the user and the user application is in charge of disposing the message.")]
diff --git a/iothub/device/src/Transport/Mqtt/MqttIotHubAdapterFactory.cs b/iothub/device/src/Transport/Mqtt/MqttIotHubAdapterFactory.cs
index 536a0bfcbe..d15395125a 100644
--- a/iothub/device/src/Transport/Mqtt/MqttIotHubAdapterFactory.cs
+++ b/iothub/device/src/Transport/Mqtt/MqttIotHubAdapterFactory.cs
@@ -1,17 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using System;
-
namespace Microsoft.Azure.Devices.Client.Transport.Mqtt
{
internal class MqttIotHubAdapterFactory
{
- private readonly MqttTransportSettings settings;
+ private readonly MqttTransportSettings _settings;
public MqttIotHubAdapterFactory(MqttTransportSettings settings)
{
- this.settings = settings;
+ _settings = settings;
}
public MqttIotHubAdapter Create(
@@ -21,7 +19,7 @@ public MqttIotHubAdapter Create(
ProductInfo productInfo,
ClientOptions options)
{
- IWillMessage willMessage = mqttTransportSettings.HasWill ? this.settings.WillMessage : null;
+ IWillMessage willMessage = mqttTransportSettings.HasWill ? _settings.WillMessage : null;
return new MqttIotHubAdapter(
iotHubConnectionString.DeviceId,
diff --git a/iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs b/iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs
index 9f52f42a88..84dbc6cd66 100644
--- a/iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs
+++ b/iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs
@@ -1389,7 +1389,7 @@ private static IEventLoopGroup GetEventLoopGroup()
if (!string.IsNullOrWhiteSpace(envValue))
{
string processorEventCountValue = Environment.ExpandEnvironmentVariables(envValue);
- if (int.TryParse(processorEventCountValue, out var processorThreadCount))
+ if (int.TryParse(processorEventCountValue, out int processorThreadCount))
{
if (Logging.IsEnabled)
Logging.Info(null, $"EventLoopGroup threads count {processorThreadCount}.");
diff --git a/iothub/device/src/Transport/RetryDelegatingHandler.cs b/iothub/device/src/Transport/RetryDelegatingHandler.cs
index 16a59ae9ef..1445db352e 100644
--- a/iothub/device/src/Transport/RetryDelegatingHandler.cs
+++ b/iothub/device/src/Transport/RetryDelegatingHandler.cs
@@ -53,9 +53,7 @@ private class TransientErrorStrategy : ITransientErrorDetectionStrategy
{
public bool IsTransient(Exception ex)
{
- return ex is IotHubException
- ? ((IotHubException)ex).IsTransient
- : false;
+ return ex is IotHubException exception && exception.IsTransient;
}
}
@@ -837,8 +835,8 @@ await _internalRetryPolicy
{
Logging.Enter(this, timeoutHelper, nameof(OpenAsync));
- // Will throw on error.
- await base.OpenAsync(timeoutHelper).ConfigureAwait(false);
+ // Will throw on error.
+ await base.OpenAsync(timeoutHelper).ConfigureAwait(false);
_onConnectionStatusChanged(ConnectionStatus.Connected, ConnectionStatusChangeReason.Connection_Ok);
}
catch (Exception ex) when (!ex.IsFatal())
@@ -852,7 +850,7 @@ await _internalRetryPolicy
}
}
-
+
}
// Triggered from connection loss event
diff --git a/iothub/service/src/Common/Amqp/LegacyClientWebSocketTransport.cs b/iothub/service/src/Common/Amqp/LegacyClientWebSocketTransport.cs
index 0ed936706e..91987b998e 100644
--- a/iothub/service/src/Common/Amqp/LegacyClientWebSocketTransport.cs
+++ b/iothub/service/src/Common/Amqp/LegacyClientWebSocketTransport.cs
@@ -197,7 +197,7 @@ protected override bool OpenInternal()
protected override bool CloseInternal()
{
- var webSocketState = this.webSocket.State;
+ IotHubClientWebSocket.WebSocketState webSocketState = this.webSocket.State;
if (webSocketState != IotHubClientWebSocket.WebSocketState.Closed && webSocketState != IotHubClientWebSocket.WebSocketState.Aborted)
{
this.CloseInternalAsync().Fork();
@@ -237,7 +237,7 @@ void OnReadComplete(IAsyncResult result)
return;
}
- Task taskResult = (Task)result;
+ var taskResult = (Task)result;
var args = (TransportAsyncCallbackArgs)taskResult.AsyncState;
this.ReadTaskDone(taskResult, args);
@@ -294,7 +294,7 @@ static void OnWriteComplete(IAsyncResult result)
return;
}
- Task taskResult = (Task)result;
+ var taskResult = (Task)result;
var args = (TransportAsyncCallbackArgs)taskResult.AsyncState;
WriteTaskDone(taskResult, args);
args.CompletedCallback(args);
@@ -325,7 +325,7 @@ static bool WriteTaskDone(Task taskResult, TransportAsyncCallbackArgs args)
void ThrowIfNotOpen()
{
- var webSocketState = this.webSocket.State;
+ IotHubClientWebSocket.WebSocketState webSocketState = this.webSocket.State;
if (webSocketState == IotHubClientWebSocket.WebSocketState.Open)
{
return;
diff --git a/iothub/service/src/Common/IOThreadScheduler.cs b/iothub/service/src/Common/IOThreadScheduler.cs
index b08a2ccfef..69fc4951f4 100644
--- a/iothub/service/src/Common/IOThreadScheduler.cs
+++ b/iothub/service/src/Common/IOThreadScheduler.cs
@@ -176,7 +176,7 @@ private bool ScheduleCallbackHelper(Action