Skip to content

Commit

Permalink
Handling null and empty setting name parameter in DefaultNameResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocav committed Sep 18, 2018
1 parent 4f0fa18 commit aeabc5f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Microsoft.Azure.WebJobs.Host/DefaultNameResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DefaultNameResolver : INameResolver

public DefaultNameResolver(IConfiguration configuration)
{
_configuration = configuration;
_configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration));
}

/// <summary>
Expand All @@ -26,6 +26,11 @@ public DefaultNameResolver(IConfiguration configuration)
/// <returns>The token value from App Settings or environment variables. If the token is not found, null is returned.</returns>
public virtual string Resolve(string name)
{
if (string.IsNullOrEmpty(name))
{
return null;
}

return _configuration[name];
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace Microsoft.Azure.WebJobs.Host.UnitTests
{
public class DefaultNameResolverTests
{
[Fact]
public void Resolve_WithNullOrEmptyNameParameter_ReturnsNull()
{
var configuration = new ConfigurationBuilder().Build();
var resolver = new DefaultNameResolver(configuration);

// Assert we null returns null
string result = resolver.Resolve(null);
Assert.Null(result);

// Assert empty returns null
result = resolver.Resolve(string.Empty);
Assert.Null(result);
}
}
}

0 comments on commit aeabc5f

Please sign in to comment.