Making action selection logging not throw on 404

This commit is contained in:
YishaiGalatzer 2014-10-07 23:32:59 -07:00
parent ba1884aacb
commit fea30a4096
2 changed files with 31 additions and 1 deletions

View File

@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.Logging
private string Formatter(ActionDescriptor descriptor)
{
return descriptor.DisplayName;
return descriptor?.DisplayName ?? "No action selected";
}
}
}

View File

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class DefaultActionSelectorSelectAsyncValuesTest
{
[Fact]
public void EmptyDefaultActionSelectorSelectAsyncValues_ReturnValue()
{
// Arrange
var logObject = new DefaultActionSelectorSelectAsyncValues();
// Act
var result = logObject.ToString();
var expected = "DefaultActionSelector.SelectAsync" + Environment.NewLine +
"\tActions matching route constraints: " + Environment.NewLine +
"\tActions matching action constraints: " + Environment.NewLine +
"\tFinal Matches: " + Environment.NewLine +
"\tSelected action: No action selected";
// Assert
Assert.Equal(expected, result);
}
}
}