From fea30a40964a57208ffe545061f94832ba3a1da5 Mon Sep 17 00:00:00 2001 From: YishaiGalatzer Date: Tue, 7 Oct 2014 23:32:59 -0700 Subject: [PATCH] Making action selection logging not throw on 404 --- .../DefaultActionSelectorSelectAsyncValues.cs | 2 +- ...aultActionSelectorSelectAsyncValuesTest.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/Microsoft.AspNet.Mvc.Core.Test/DefaultActionSelectorSelectAsyncValuesTest.cs diff --git a/src/Microsoft.AspNet.Mvc.Core/Logging/DefaultActionSelectorSelectAsyncValues.cs b/src/Microsoft.AspNet.Mvc.Core/Logging/DefaultActionSelectorSelectAsyncValues.cs index 913cec8991..084e4ac875 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Logging/DefaultActionSelectorSelectAsyncValues.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Logging/DefaultActionSelectorSelectAsyncValues.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.Logging private string Formatter(ActionDescriptor descriptor) { - return descriptor.DisplayName; + return descriptor?.DisplayName ?? "No action selected"; } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/DefaultActionSelectorSelectAsyncValuesTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/DefaultActionSelectorSelectAsyncValuesTest.cs new file mode 100644 index 0000000000..52ffc962c4 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.Core.Test/DefaultActionSelectorSelectAsyncValuesTest.cs @@ -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); + } + } +}