Skip to content

Commit

Permalink
Fix build errors in previews/v2 (#3024)
Browse files Browse the repository at this point in the history
* Fix param name matching in base class method and derived class overridden method (#3023)

* Fix reserved keyword error (#3025)

* Change param name to not be a reserved keyword

* Cleanup

* Update to match ModulesClient

* Add missing constructors to exception classes (#3026)

* Fix for Specify IFormatProvider errors (#3027)

* Specify IFormatProvider

* Change to InvariantCulture to stay consistent with track 2 SDKs

* Throw InvalidOperationException instead of System.Exception (#3029)

* Assign the instance to a variable (#3030)

* Collections should implement generic interface (#3028)

* Fix StringComparison Errors (#3031)

* Mark members as static (#3032)

* Fix param name matching in base class method and derived class overridden method (#3033)

* More build fixes (#3034)

* Change Parameter names to match base declaration

* Fix error CA1854, Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup

* Change Parameter names to match base declaration

* Fix error CA1854, Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup

* More string IFormatProvider fixes

* Cleanup

* IDisposable fixes (#3035)

* Fix IDisposable errors

* Fix Dispose implementation

* Use Array.Empty instead of zero lenth arrays, static methods for tests (#3037)

* Simplify access

* Update iothub/device/tests/Transport/Amqp/AmqpConnectionPoolTests.cs

Co-authored-by: ngastelum-ms <[email protected]>

Co-authored-by: ngastelum-ms <[email protected]>
  • Loading branch information
abhipsaMisra and ngastelum-ms authored Dec 16, 2022
1 parent 20b9901 commit f06a70e
Show file tree
Hide file tree
Showing 57 changed files with 255 additions and 232 deletions.
2 changes: 1 addition & 1 deletion e2e/test/helpers/TestDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum ConnectionStringAuthScope
Device,
}

public class TestDevice : IDisposable
public sealed class TestDevice : IDisposable
{
private static readonly SemaphoreSlim s_semaphore = new(1, 1);

Expand Down
2 changes: 1 addition & 1 deletion e2e/test/helpers/TestDeviceCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Microsoft.Azure.Devices.E2ETests.Helpers
{
public class TestDeviceCallbackHandler : IDisposable
public sealed class TestDeviceCallbackHandler : IDisposable
{
private readonly IotHubDeviceClient _deviceClient;
private readonly TestDevice _testDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Task SecurityMessage_ModuleSendSingleMessage_MqttWs()
return TestSecurityMessageModuleAsync(new IotHubClientMqttSettings(IotHubClientTransportProtocol.WebSocket));
}

private TelemetryMessage ComposeD2CSecurityTestMessage()
private static TelemetryMessage ComposeD2CSecurityTestMessage()
{
string eventId = Guid.NewGuid().ToString();
string p1Value = eventId;
Expand Down Expand Up @@ -137,7 +137,7 @@ private async Task TestSecurityMessageModuleAsync(IotHubClientTransportSettings
await SendSingleSecurityMessageModuleAsync(moduleClient).ConfigureAwait(false);
}

private async Task SendSingleSecurityMessageAsync(
private static async Task SendSingleSecurityMessageAsync(
IotHubDeviceClient deviceClient)
{
await deviceClient.OpenAsync().ConfigureAwait(false);
Expand All @@ -146,7 +146,7 @@ private async Task SendSingleSecurityMessageAsync(
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

private async Task SendSingleSecurityMessageModuleAsync(
private static async Task SendSingleSecurityMessageModuleAsync(
IotHubModuleClient moduleClient)
{
await moduleClient.OpenAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task X509_Cert_Chain_Install_Test_MqttTcp()
await deviceClient.CloseAsync().ConfigureAwait(false);

// assert
DeviceClientX509AuthenticationE2ETests.ValidateCertsAreInstalled(chainCerts);
ValidateCertsAreInstalled(chainCerts);
}

[TestMethod]
Expand Down Expand Up @@ -171,13 +171,13 @@ private static void ValidateCertsAreInstalled(X509Certificate2Collection certifi
store?.Dispose();
}

private async Task SendMessageTestAsync(IotHubClientTransportSettings transportSetting)
private static async Task SendMessageTestAsync(IotHubClientTransportSettings transportSetting)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(s_devicePrefix, TestDeviceType.X509).ConfigureAwait(false);

await using IotHubDeviceClient deviceClient = testDevice.CreateDeviceClient(new IotHubClientOptions(transportSetting));
await deviceClient.OpenAsync().ConfigureAwait(false);
var message = TelemetryE2ETests.ComposeD2cTestMessage(out string _, out string _);
TelemetryMessage message = TelemetryE2ETests.ComposeD2cTestMessage(out string _, out string _);
await deviceClient.SendTelemetryAsync(message).ConfigureAwait(false);
await deviceClient.CloseAsync().ConfigureAwait(false);
}
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/iothub/device/MessageReceiveE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static async Task VerifyReceivedC2dMessageAsync(IotHubDeviceClient dc, st
received.Should().BeTrue($"No message received for device {deviceId} with payload={payload} in {FaultInjection.RecoveryTime}.");
}

private async Task ReceiveMessageUsingCallbackAndUnsubscribeAsync(TestDeviceType type, IotHubClientTransportSettings transportSettings)
private static async Task ReceiveMessageUsingCallbackAndUnsubscribeAsync(TestDeviceType type, IotHubClientTransportSettings transportSettings)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(s_devicePrefix, type).ConfigureAwait(false);
await using IotHubDeviceClient deviceClient = testDevice.CreateDeviceClient(new IotHubClientOptions(transportSettings));
Expand Down Expand Up @@ -203,7 +203,7 @@ private async Task ReceiveMessageUsingCallbackAndUnsubscribeAsync(TestDeviceType
}
}

private async Task DoNotReceiveMessagesSentBeforeSubscriptionAsync(TestDeviceType type, IotHubClientTransportSettings transportSettings)
private static async Task DoNotReceiveMessagesSentBeforeSubscriptionAsync(TestDeviceType type, IotHubClientTransportSettings transportSettings)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(s_devicePrefix, type).ConfigureAwait(false);
var options = new IotHubClientOptions(transportSettings);
Expand Down Expand Up @@ -253,7 +253,7 @@ private async Task DoNotReceiveMessagesSentBeforeSubscriptionAsync(TestDeviceTyp
testDeviceCallbackHandler.Dispose();
}

private async Task ReceiveMessageAfterOpenCloseOpenAsync(TestDeviceType type, IotHubClientTransportSettings transportSettings)
private static async Task ReceiveMessageAfterOpenCloseOpenAsync(TestDeviceType type, IotHubClientTransportSettings transportSettings)
{
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(s_devicePrefix, type).ConfigureAwait(false);
await using IotHubDeviceClient deviceClient = testDevice.CreateDeviceClient(new IotHubClientOptions(transportSettings));
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/device/TelemetryE2eTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static async Task SendBatchMessagesAsync(IotHubDeviceClient deviceClient)
await deviceClient.SendTelemetryBatchAsync(messagesToBeSent.Keys.ToList()).ConfigureAwait(false);
}

private async Task SendSingleMessageModuleAsync(IotHubModuleClient moduleClient)
private static async Task SendSingleMessageModuleAsync(IotHubModuleClient moduleClient)
{
TelemetryMessage testMessage = ComposeD2cTestMessage(out string _, out string _);

Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/BulkOperationsE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task BulkOperations_UpdateTwins2ModulePatch_Ok()
Assert.AreEqual((string)twin.Tags[tagName], (string)twinUpd.Tags[tagName], "Tag value changed");
}

private string ResultErrorsToString(BulkRegistryOperationResult result)
private static string ResultErrorsToString(BulkRegistryOperationResult result)
{
string errorString = "";

Expand Down
8 changes: 4 additions & 4 deletions e2e/test/iothub/service/ExportDevicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ await ValidateConfigurationsAsync(
}
}

private async Task<IotHubJobResponse> CreateAndWaitForJobAsync(
private static async Task<IotHubJobResponse> CreateAndWaitForJobAsync(
StorageAuthenticationType storageAuthenticationType,
bool isUserAssignedMsi,
string devicesFileName,
Expand Down Expand Up @@ -211,7 +211,7 @@ private async Task<IotHubJobResponse> CreateAndWaitForJobAsync(
return jobResponse;
}

private async Task ValidateDevicesAsync(
private static async Task ValidateDevicesAsync(
string devicesFileName,
StorageContainer storageContainer,
Device edge1,
Expand Down Expand Up @@ -272,7 +272,7 @@ private async Task ValidateDevicesAsync(
foundDeviceInExport.Should().BeTrue("Expected device did not appear in the export");
}

private async Task ValidateConfigurationsAsync(
private static async Task ValidateConfigurationsAsync(
string configsFileName,
StorageContainer storageContainer,
Configuration configuration)
Expand Down Expand Up @@ -300,7 +300,7 @@ private static async Task<string> DownloadFileAsync(StorageContainer storageCont
return await exportFile.DownloadTextAsync().ConfigureAwait(false);
}

private async Task CleanUpDevicesAsync(
private static async Task CleanUpDevicesAsync(
string edgeId1,
string edgeId2,
string deviceId,
Expand Down
12 changes: 6 additions & 6 deletions e2e/test/iothub/service/FileUploadNotificationE2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task FileUploadNotification_Operation(IotHubTransportProtocol proto

using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString, options);

FileUploadNotificationCounter counter = new FileUploadNotificationCounter();
var counter = new FileUploadNotificationCounter();
Func<FileUploadNotification, AcknowledgementType> OnFileUploadNotificationReceived = (fileUploadNotification) =>
{
counter.FileUploadNotificationsReceived++;
Expand All @@ -64,14 +64,14 @@ public async Task FileUploadNotification_Operation(IotHubTransportProtocol proto
[DataRow(IotHubTransportProtocol.WebSocket)]
public async Task FileUploadNotification_Operation_OpenCloseOpen(IotHubTransportProtocol protocol)
{
IotHubServiceClientOptions options = new IotHubServiceClientOptions()
var options = new IotHubServiceClientOptions()
{
Protocol = protocol
};

using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString, options);

FileUploadNotificationCounter counter = new FileUploadNotificationCounter();
var counter = new FileUploadNotificationCounter();
Func<FileUploadNotification, AcknowledgementType> OnFileUploadNotificationReceived = (fileUploadNotification) =>
{
counter.FileUploadNotificationsReceived++;
Expand All @@ -97,14 +97,14 @@ public async Task FileUploadNotification_Operation_OpenCloseOpen(IotHubTransport
[DataRow(IotHubTransportProtocol.WebSocket)]
public async Task FileUploadNotification_ReceiveMultipleNotificationsInOneConnection(IotHubTransportProtocol protocol)
{
IotHubServiceClientOptions options = new IotHubServiceClientOptions()
var options = new IotHubServiceClientOptions()
{
Protocol = protocol
};

using var serviceClient = new IotHubServiceClient(TestConfiguration.IotHub.ConnectionString, options);

FileUploadNotificationCounter counter = new FileUploadNotificationCounter();
var counter = new FileUploadNotificationCounter();
Func<FileUploadNotification, AcknowledgementType> OnFileUploadNotificationReceived = (fileUploadNotification) =>
{
counter.FileUploadNotificationsReceived++;
Expand All @@ -130,7 +130,7 @@ public async Task FileUploadNotification_ReceiveMultipleNotificationsInOneConnec
/// </summary>
/// <param name="fileUploadNotificationReceivedCount">The current number of file upload notifications received.</param>
/// <param name="expectedFileUploadNotificationReceivedCount">The expected number of file upload notifications to receive in this test.</param>
private async Task WaitForFileUploadNotification(FileUploadNotificationCounter counter, int expectedFileUploadNotificationReceivedCount)
private static async Task WaitForFileUploadNotification(FileUploadNotificationCounter counter, int expectedFileUploadNotificationReceivedCount)
{
var timer = Stopwatch.StartNew();
try
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/ImportDevicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private static async Task UploadFileAndConfirmAsync(StorageContainer storageCont
foundBlob.Should().BeTrue($"Failed to find {fileName} in storage container - required for test.");
}

private async Task<IotHubJobResponse> CreateAndWaitForJobAsync(
private static async Task<IotHubJobResponse> CreateAndWaitForJobAsync(
StorageAuthenticationType storageAuthenticationType,
string devicesFileName,
string configsFileName,
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/PurgeMessageQueueE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task PurgeMessageQueueOperation()
result.TotalMessagesPurged.Should().Be(numberOfSends);
}

private Message ComposeD2CTestMessage()
private static Message ComposeD2CTestMessage()
{
return new Message(Encoding.UTF8.GetBytes("some payload"));
}
Expand Down
2 changes: 1 addition & 1 deletion iothub/device/src/Exceptions/IotHubClientException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected internal IotHubClientException(string message, IotHubClientErrorCode e
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected internal IotHubClientException(SerializationInfo info, StreamingContext context)
protected IotHubClientException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
if (info != null)
Expand Down
4 changes: 1 addition & 3 deletions iothub/device/src/Messaging/IncomingMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ public bool TryGetPayload<T>(out T payload)

private T GetSystemProperty<T>(string key)
{
return SystemProperties.ContainsKey(key)
? (T)SystemProperties[key]
: default;
return SystemProperties.TryGetValue(key, out object value) ? (T)value : default;
}
}
}
4 changes: 1 addition & 3 deletions iothub/device/src/Messaging/TelemetryMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ internal byte[] GetPayloadObjectBytes()

private T GetSystemProperty<T>(string key)
{
return SystemProperties.ContainsKey(key)
? (T)SystemProperties[key]
: default;
return SystemProperties.TryGetValue(key, out object value) ? (T)value : default;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public IotHubClientExponentialBackoffRetryPolicy(uint maxRetries, TimeSpan maxWa
}

/// <inheritdoc/>
public override bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryInterval)
public override bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryDelay)
{
if (!base.ShouldRetry(currentRetryCount, lastException, out retryInterval))
if (!base.ShouldRetry(currentRetryCount, lastException, out retryDelay))
{
return false;
}
Expand All @@ -56,7 +56,7 @@ public override bool ShouldRetry(uint currentRetryCount, Exception lastException

double clampedWaitMs = Math.Min(exponentialIntervalMs, _maxDelay.TotalMilliseconds);

retryInterval = _useJitter
retryDelay = _useJitter
? UpdateWithJitter(clampedWaitMs)
: TimeSpan.FromMilliseconds(clampedWaitMs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public IotHubClientFixedDelayRetryPolicy(uint maxRetries, TimeSpan fixedDelay, b
}

/// <inheritdoc/>
public override bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryInterval)
public override bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryDelay)
{
if (!base.ShouldRetry(currentRetryCount, lastException, out retryInterval))
if (!base.ShouldRetry(currentRetryCount, lastException, out retryDelay))
{
return false;
}

retryInterval = _useJitter
retryDelay = _useJitter
? UpdateWithJitter(_fixedDelay.TotalMilliseconds)
: _fixedDelay;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public IotHubClientIncrementalDelayRetryPolicy(uint maxRetries, TimeSpan delayIn
internal protected bool UseJitter { get; }

/// <inheritdoc/>
public override bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryInterval)
public override bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryDelay)
{
if (!base.ShouldRetry(currentRetryCount, lastException, out retryInterval))
if (!base.ShouldRetry(currentRetryCount, lastException, out retryDelay))
{
return false;
}
Expand All @@ -58,7 +58,7 @@ public override bool ShouldRetry(uint currentRetryCount, Exception lastException
currentRetryCount * DelayIncrement.TotalMilliseconds,
MaxDelay.TotalMilliseconds);

retryInterval = UseJitter
retryDelay = UseJitter
? UpdateWithJitter(waitDurationMs)
: TimeSpan.FromMilliseconds(waitDurationMs);

Expand Down
4 changes: 2 additions & 2 deletions iothub/device/src/RetryPolicies/IotHubClientNoRetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public IotHubClientNoRetry()
}

/// <inheritdoc/>
public bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryInterval)
public bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryDelay)
{
retryInterval = TimeSpan.Zero;
retryDelay = TimeSpan.Zero;
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public override T DeserializeToType<T>(string stringToDeserialize)
}

/// <inheritdoc/>
public override T ConvertFromJsonObject<T>(object objectToConvert)
public override T ConvertFromJsonObject<T>(object jsonObjectToConvert)
{
var token = JToken.FromObject(objectToConvert);
var token = JToken.FromObject(jsonObjectToConvert);

return objectToConvert == null
return jsonObjectToConvert == null
? default
: token.ToObject<T>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public override T DeserializeToType<T>(string stringToDeserialize)
}

/// <inheritdoc/>
public override T ConvertFromJsonObject<T>(object objectToConvert)
public override T ConvertFromJsonObject<T>(object jsonObjectToConvert)
{
return DeserializeToType<T>(SerializeToString(objectToConvert));
return DeserializeToType<T>(SerializeToString(jsonObjectToConvert));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Microsoft.Azure.Devices.Client.Transport.Amqp
{
internal class AmqpAuthenticationRefresher : IAmqpAuthenticationRefresher
internal class AmqpAuthenticationRefresher : IAmqpAuthenticationRefresher, IDisposable
{
private static readonly string[] s_accessRightsStringArray = new[] { "DeviceConnect" };
private readonly Uri _amqpEndpoint;
Expand Down Expand Up @@ -170,5 +170,10 @@ private static string CreateAmqpCbsAudience(IConnectionCredentials connectionCre
// SAS tokens granted to a group SAS authenticated client will scoped to the IoT hub-level; for example, myHub.azure-devices.net
return connectionCredentials.HostName;
}

public void Dispose()
{
_loopCancellationTokenSource?.Dispose();
}
}
}
6 changes: 3 additions & 3 deletions iothub/device/src/Transport/AmqpIot/AmqpIotReceivingLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Amqp;
using Microsoft.Azure.Amqp.Framing;
using Microsoft.Azure.Devices.Client.Transport.Mqtt;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.Client.Transport.AmqpIot
Expand Down Expand Up @@ -237,8 +237,8 @@ private void OnTwinChangesReceived(AmqpMessage amqpMessage)
// Check if we have an int to string error code translation for the service returned error code.
// The error code could be a part of the service returned error message, or it can be a part of the amqp message annotations map.
// We will check with the error code in the error message first (if present) since that is the more specific error code returned.
if ((Enum.TryParse(errorResponse.ErrorCode.ToString(), out IotHubClientErrorCode errorCode)
|| Enum.TryParse(status.ToString(), out errorCode))
if ((Enum.TryParse(errorResponse.ErrorCode.ToString(CultureInfo.InvariantCulture), out IotHubClientErrorCode errorCode)
|| Enum.TryParse(status.ToString(CultureInfo.InvariantCulture), out errorCode))
&& Enum.IsDefined(typeof(IotHubClientErrorCode), errorCode))
{
twinException = new IotHubClientException(errorResponse.Message, errorCode)
Expand Down
Loading

0 comments on commit f06a70e

Please sign in to comment.