Fix #810
This commit is contained in:
parent
7c16c92317
commit
49c2317c14
|
|
@ -15,6 +15,11 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|||
[DebuggerDisplay("{DebuggerDisplayString,nq}")]
|
||||
public class LinkGenerationDecisionTree
|
||||
{
|
||||
// Fallback value for cases where the ambient values weren't provided.
|
||||
//
|
||||
// This is safe because we don't mutate the route values in here.
|
||||
private static readonly RouteValueDictionary EmptyAmbientValues = new RouteValueDictionary();
|
||||
|
||||
private readonly DecisionTreeNode<OutboundMatch> _root;
|
||||
|
||||
public LinkGenerationDecisionTree(IReadOnlyList<OutboundMatch> entries)
|
||||
|
|
@ -30,7 +35,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|||
if (_root.Matches.Count > 0 || _root.Criteria.Count > 0)
|
||||
{
|
||||
var results = new List<OutboundMatchResult>();
|
||||
Walk(results, values, ambientValues, _root, isFallbackPath: false);
|
||||
Walk(results, values, ambientValues ?? EmptyAmbientValues, _root, isFallbackPath: false);
|
||||
results.Sort(OutboundMatchResultComparer.Instance);
|
||||
return results;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,26 @@ namespace Microsoft.AspNetCore.Routing.Internal.Routing
|
|||
{
|
||||
public class LinkGenerationDecisionTreeTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetMatches_AllowsNullAmbientValues()
|
||||
{
|
||||
// Arrange
|
||||
var entries = new List<OutboundMatch>();
|
||||
|
||||
var entry = CreateMatch(new { });
|
||||
entries.Add(entry);
|
||||
|
||||
var tree = new LinkGenerationDecisionTree(entries);
|
||||
|
||||
var context = CreateContext(new { });
|
||||
|
||||
// Act
|
||||
var matches = tree.GetMatches(context.Values, ambientValues: null);
|
||||
|
||||
// Assert
|
||||
Assert.Same(entry, Assert.Single(matches).Match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SelectSingleEntry_NoCriteria()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue