public void AmqpTransportHandler_RejectAmqpSettingsChange() { // Added [Obsolete] attribute to this method to suppress CS0618 message for ConnectionIdleTimeout var amqpTransportHandler1 = new AmqpTransportHandler(new PipelineContext(), new IotHubConnectionString(IotHubConnectionStringBuilder.Create(TestConnectionString)), new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 60, new AmqpConnectionPoolSettings() { Pooling = true, MaxPoolSize = 10, ConnectionIdleTimeout = TimeSpan.FromMinutes(1) })); try { // Try to create a set AmqpTransportHandler with different connection pool settings. var amqpTransportHandler2 = new AmqpTransportHandler(new PipelineContext(), new IotHubConnectionString(IotHubConnectionStringBuilder.Create(TestConnectionString)), new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 60, new AmqpConnectionPoolSettings() { Pooling = true, MaxPoolSize = 7, // different pool size ConnectionIdleTimeout = TimeSpan.FromMinutes(1) })); } catch (ArgumentException ae) { Assert.IsTrue(ae.Message.Contains("AmqpTransportSettings cannot be modified from the initial settings."), "Did not return the correct error message"); } }
public void DeviceClient_ConnectionString_DeviceScope_ExplicitSharedAccessSignatureCredentialType_Test() { string connectionString = "HostName=acme.azure-devices.net;CredentialScope=Device;CredentialType=SharedAccessSignature;DeviceId=device1;SharedAccessSignature=SharedAccessSignature sr=dh%3a%2f%2facme.azure-devices.net&sig=poifbMLdBGtCJknubF2FW6FLn5vND5k1IKoeQ%2bONgkE%3d&se=87824124985&skn=AllAccessKey"; var deviceClient = AmqpTransportHandler.CreateFromConnectionString(connectionString); Assert.IsNotNull(deviceClient.Connection); Assert.IsNotNull(deviceClient.Connection.ConnectionString); }
public void DeviceClient_ConnectionString_DeviceScope_ImplicitSharedAccessSignatureCredentialType_Test() { string connectionString = "HostName=acme.azure-devices.net;CredentialScope=Device;CredentialType=SharedAccessSignature;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var deviceClient = AmqpTransportHandler.CreateFromConnectionString(connectionString); Assert.IsNotNull(deviceClient.Connection); Assert.IsNotNull(deviceClient.Connection.ConnectionString); }
public void DeviceClient_ConnectionString_IotHubScope_SharedAccessKeyCredentialType_Test() { string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKeyName=AllAccessKey;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var deviceClient = AmqpTransportHandler.CreateFromConnectionString(connectionString); Assert.IsNotNull(deviceClient.IotHubConnection); Assert.IsNotNull(((IotHubSingleTokenConnection)deviceClient.IotHubConnection).ConnectionString); }
public void DeviceClient_ConnectionString_DefaultScope_DefaultCredentialType_Test() { string connectionString = "HostName=acme.azure-devices.net;SharedAccessKeyName=AllAccessKey;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var deviceClient = AmqpTransportHandler.CreateFromConnectionString(connectionString); Assert.IsNotNull(deviceClient.Connection); Assert.IsNotNull(deviceClient.Connection.ConnectionString); var iotHubConnectionStringBuilder = IotHubConnectionStringBuilder.Create(connectionString); }
async AsyncTask TryOpenPrioritizedTransportsAsync() { Exception lastException = null; // Concrete Device Client creation was deferred. Use prioritized list of transports. foreach (var transportSetting in this.transportSettings) { TransportHandlerBase helper; try { switch (transportSetting.GetTransportType()) { case TransportType.Amqp_WebSocket_Only: case TransportType.Amqp_Tcp_Only: helper = new AmqpTransportHandler(this.iotHubConnectionString, transportSetting as AmqpTransportSettings); break; case TransportType.Http1: helper = new HttpTransportHandler(this.iotHubConnectionString, transportSetting as Http1TransportSettings); break; case TransportType.Mqtt: helper = new MqttTransportHandler(this.iotHubConnectionString, transportSetting as MqttTransportSettings); break; default: throw new InvalidOperationException("Unsupported Transport Setting {0}".FormatInvariant(transportSetting)); } // Try to open a connection with this transport await helper.OpenAsync(); } catch (Exception exception) { if (exception.IsFatal() || exception is UnauthorizedException || exception is InvalidOperationException) { throw; } lastException = exception; // open connection failed. Move to next transport type continue; } // Success - return this transport type this.impl = helper; this.TransportTypeInUse = transportSetting.GetTransportType(); return; } throw lastException; }
public void DeviceClient_Create_DeviceScope_SharedAccessSignature_Test() { string hostName = "acme.azure-devices.net"; string password = "******"; var sasRule = new SharedAccessSignatureBuilder() { Key = password, Target = hostName + "/devices/" + "device1" }; var authMethod = new DeviceAuthenticationWithToken("device1", sasRule.ToSignature()); var deviceClient = AmqpTransportHandler.Create(hostName, authMethod); Assert.IsNotNull(deviceClient.Connection); Assert.IsNotNull(deviceClient.Connection.ConnectionString); }
async AsyncTask TryOpenPrioritizedTransportsAsync() { Exception lastException = null; // Concrete Device Client creation was deferred. Use prioritized list of transports. foreach (var transportSetting in this.transportSettings) { TransportHandlerBase helper = null; try { switch (transportSetting.GetTransportType()) { case TransportType.Amqp_WebSocket_Only: case TransportType.Amqp_Tcp_Only: helper = new AmqpTransportHandler(this.iotHubConnectionString, transportSetting as AmqpTransportSettings); break; case TransportType.Http1: helper = new HttpTransportHandler(this.iotHubConnectionString, transportSetting as Http1TransportSettings); break; case TransportType.Mqtt: helper = new MqttTransportHandler(this.iotHubConnectionString, transportSetting as MqttTransportSettings); break; default: throw new InvalidOperationException("Unsupported Transport Setting {0}".FormatInvariant(transportSetting)); } // Try to open a connection with this transport await helper.OpenAsync(); } catch (Exception exception) { await helper.CloseAsync(); if (!(exception is IotHubCommunicationException || exception is TimeoutException || exception is SocketException || exception is AggregateException)) { throw; } if (exception is AggregateException) { var aggregateException = (AggregateException)exception; var innerExceptions = aggregateException.Flatten().InnerExceptions; if (!innerExceptions.Any(x => x is IotHubCommunicationException || x is SocketException || x is TimeoutException)) { throw; } } lastException = exception; // open connection failed. Move to next transport type continue; } // Success - return this transport type this.impl = helper; this.TransportTypeInUse = transportSetting.GetTransportType(); return; } throw lastException; }
public async Task AmqpTransportHandler_RejectAsync_TokenCancellationRequested() { await TestOperationCanceledByToken(token => AmqpTransportHandler.CreateFromConnectionString(DumpyConnectionString).RejectAsync(Guid.NewGuid().ToString(), token)); }
public async Task AmqpTransportHandler_ReceiveAsync_TokenCancellationRequested() { await TestOperationCanceledByToken(token => AmqpTransportHandler.CreateFromConnectionString(DumpyConnectionString).ReceiveAsync(new TimeSpan(0, 10, 0), token)); }
public async Task AmqpTransportHandler_SendEventAsync_MultipleMessages_TokenCancellationRequested() { await TestOperationCanceledByToken(token => AmqpTransportHandler.CreateFromConnectionString(DumpyConnectionString).SendEventAsync(new List <Message>(), token)); }
public async Task AmqpTransportHandler_OpenAsync_TokenCancellationRequested() { await TestOperationCanceledByToken(token => AmqpTransportHandler.CreateFromConnectionString(DumpyConnectionString).OpenAsync(true, token)); }