Skip to content

Commit

Permalink
Improving error message for missing ServiceBus connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewc committed Oct 20, 2015
1 parent f958e47 commit 9ab2199
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
Binary file not shown.
10 changes: 9 additions & 1 deletion src/Microsoft.Azure.WebJobs.ServiceBus/MessagingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.ServiceBus;
Expand Down Expand Up @@ -86,14 +87,21 @@ public virtual MessageProcessor CreateMessageProcessor(string entityPath)
/// </summary>
/// <param name="connectionStringName">The connection string name.</param>
/// <returns>The ServiceBus connection string.</returns>
protected string GetConnectionString(string connectionStringName = null)
protected internal string GetConnectionString(string connectionStringName = null)
{
string connectionString = _config.ConnectionString;
if (!string.IsNullOrEmpty(connectionStringName))
{
connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(connectionStringName);
}

if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException(
string.Format(CultureInfo.InvariantCulture, "Microsoft Azure WebJobs SDK ServiceBus connection string '{0}{1}' is missing or empty.",
"AzureWebJobs", connectionStringName));
}

return connectionString;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<Compile Include="Config\ServiceBusExtensionConfig.cs" />
<Compile Include="Constants.cs" />
<Compile Include="ContentTypes.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="MessagingProvider.cs" />
<Compile Include="Listeners\NamespaceManagerExtensions.cs" />
<Compile Include="Listeners\ServiceBusListener.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public void CreateNamespaceManager_ReturnsExpectedManager()
Assert.Equal("override.servicebus.windows.net", manager.Address.Host);
}

[Fact]
public void GetConnectionString_ThrowsIfConnectionStringNullOrEmpty()
{
var ex = Assert.Throws<InvalidOperationException>(() =>
{
_provider.GetConnectionString("MissingConnection");
});
Assert.Equal("Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsMissingConnection' is missing or empty.", ex.Message);
}

public void Dispose()
{
Environment.SetEnvironmentVariable("AzureWebJobsServiceBusOverride", null);
Expand Down

0 comments on commit 9ab2199

Please sign in to comment.