diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs
index eb7fa6abe4008..a01945ca1861e 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs
@@ -115,6 +115,10 @@ protected ServiceBusClient()
/// If the connection string specifies a specific entity name, any subsequent calls to
/// , ,
/// etc. must still specify the same entity name.
+ ///
+ /// The connection string will recognize and apply properties populated by the
+ /// Azure portal such as Endpoint, SharedAccessKeyName, SharedAccessKey, and EntityPath.
+ /// Other values will be ignored; to configure the processor, please use the .
///
public ServiceBusClient(string connectionString) :
this(connectionString, new ServiceBusClientOptions())
@@ -134,6 +138,10 @@ public ServiceBusClient(string connectionString) :
/// If the connection string specifies a specific entity name, any subsequent calls to
/// , ,
/// etc. must still specify the same entity name.
+ ///
+ /// The connection string will recognize and apply properties populated by the
+ /// Azure portal such as Endpoint, SharedAccessKeyName, SharedAccessKey, and EntityPath.
+ /// Other values will be ignored; to configure the processor, please use the .
///
public ServiceBusClient(string connectionString, ServiceBusClientOptions options)
{
@@ -142,6 +150,7 @@ public ServiceBusClient(string connectionString, ServiceBusClientOptions options
Logger.ClientCreateStart(typeof(ServiceBusClient), FullyQualifiedNamespace);
Identifier = DiagnosticUtilities.GenerateIdentifier(FullyQualifiedNamespace);
Plugins = _options.Plugins;
+ TransportType = _options.TransportType;
Logger.ClientCreateComplete(typeof(ServiceBusClient), Identifier);
}
@@ -218,14 +227,15 @@ private ServiceBusClient(
object credential,
ServiceBusClientOptions options)
{
- _options = options?.Clone() ?? new ServiceBusClientOptions();
Logger.ClientCreateStart(typeof(ServiceBusClient), fullyQualifiedNamespace);
+ _options = options?.Clone() ?? new ServiceBusClientOptions();
Identifier = DiagnosticUtilities.GenerateIdentifier(fullyQualifiedNamespace);
Connection = ServiceBusConnection.CreateWithCredential(
fullyQualifiedNamespace,
credential,
_options);
Plugins = _options.Plugins;
+ TransportType = _options.TransportType;
Logger.ClientCreateComplete(typeof(ServiceBusClient), Identifier);
}
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Client/ServiceBusClientTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Client/ServiceBusClientTests.cs
index 951a684ce3eb9..05058c4cd2665 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Client/ServiceBusClientTests.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Client/ServiceBusClientTests.cs
@@ -12,6 +12,7 @@
namespace Azure.Messaging.ServiceBus.Tests.Client
{
+ [TestFixture]
public class ServiceBusClientTests
{
///
@@ -266,10 +267,11 @@ public void ConstructorWithConnectionStringValidatesOptions()
///
///
[Test]
- public void ConstructorWithTokenCredentialArgumentsValidatesOptions()
+ public void ConstructorWithTokenCredentialValidatesOptions()
{
var token = new Mock(Mock.Of());
var invalidOptions = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpTcp, WebProxy = Mock.Of() };
+
Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", Mock.Of(), invalidOptions), Throws.InstanceOf(), "The expanded argument constructor should validate client options");
}
@@ -279,11 +281,12 @@ public void ConstructorWithTokenCredentialArgumentsValidatesOptions()
///
///
[Test]
- public void ConstructorWithSharedKeyCredentialArgumentsValidatesOptions()
+ public void ConstructorWithSharedKeyCredentialValidatesOptions()
{
var token = new AzureNamedKeyCredential("key", "value");
var invalidOptions = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpTcp, WebProxy = Mock.Of() };
- Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", Mock.Of(), invalidOptions), Throws.InstanceOf(), "The expanded argument constructor should validate client options");
+
+ Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", token, invalidOptions), Throws.InstanceOf(), "The expanded argument constructor should validate client options");
}
///
@@ -292,12 +295,74 @@ public void ConstructorWithSharedKeyCredentialArgumentsValidatesOptions()
///
///
[Test]
- public void ConstructorWithSasCredentialArgumentsValidatesOptions()
+ public void ConstructorWithSasCredentialValidatesOptions()
{
var signature = new SharedAccessSignature("sb://fake.thing.com", "fakeKey", "fakeValue");
var token = new AzureSasCredential(signature.Value);
var invalidOptions = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpTcp, WebProxy = Mock.Of() };
- Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", Mock.Of(), invalidOptions), Throws.InstanceOf(), "The expanded argument constructor should validate client options");
+
+ Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", token, invalidOptions), Throws.InstanceOf(), "The expanded argument constructor should validate client options");
+ }
+
+ ///
+ /// Verifies functionality of the
+ /// constructor.
+ ///
+ ///
+ [Test]
+ public void ConstructorWithConnectionStringSetsTransportTypeFromOptions()
+ {
+ var fakeConnection = "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake";
+ var options = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpWebSockets };
+ var client = new ServiceBusClient(fakeConnection, options);
+
+ Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
+ }
+
+ ///
+ /// Verifies functionality of the
+ /// constructor.
+ ///
+ ///
+ [Test]
+ public void ConstructorWithTokenCredentialSetsTransportTypeFromOptions()
+ {
+ var token = new Mock(Mock.Of());
+ var options = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpWebSockets };
+ var client = new ServiceBusClient("fullyQualifiedNamespace", Mock.Of(), options);
+
+ Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
+ }
+
+ ///
+ /// Verifies functionality of the
+ /// constructor.
+ ///
+ ///
+ [Test]
+ public void ConstructorWithSharedKeyCredentialSetsTransportTypeFromOptions()
+ {
+ var token = new AzureNamedKeyCredential("key", "value");
+ var options = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpWebSockets };
+ var client = new ServiceBusClient("fullyQualifiedNamespace", token, options);
+
+ Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
+ }
+
+ ///
+ /// Verifies functionality of the
+ /// constructor.
+ ///
+ ///
+ [Test]
+ public void ConstructorWithSasCredentialSetsTransportTypeFromOptions()
+ {
+ var signature = new SharedAccessSignature("sb://fake.thing.com", "fakeKey", "fakeValue");
+ var token = new AzureSasCredential(signature.Value);
+ var options = new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpWebSockets };
+ var client = new ServiceBusClient("fullyQualifiedNamespace", token, options);
+
+ Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
}
///