Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit 7073d81

Browse files
committed
Changed log message and added test for log values
1 parent 3af4789 commit 7073d81

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/Microsoft.AspNet.Routing/RouteConstraintMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static bool Match(IReadOnlyDictionary<string, IRouteConstraint> constrain
3333
routeValues.TryGetValue(kvp.Key, out routeValue);
3434

3535
logger.LogVerbose(
36-
"Route value '{RouteValue}' of key '{RouteKey}' did not match " +
36+
"Route value '{RouteValue}' with key '{RouteKey}' did not match " +
3737
"the constraint '{RouteConstraint}'.",
3838
routeValue,
3939
kvp.Key,

test/Microsoft.AspNet.Routing.Tests/ConstraintMatcherTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void MatchFail_LogsCorrectData()
5858
{"b", new FailConstraint()}
5959
};
6060
var sink = SetUpMatch(constraints, loggerEnabled: true);
61-
var expectedMessage = "Route value 'value' of key 'b' did not match the constraint " +
61+
var expectedMessage = "Route value 'value' with key 'b' did not match the constraint " +
6262
$"'{typeof(FailConstraint).FullName}'.";
6363

6464
// Assert

test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTest.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Framework.Logging;
1616
using Moq;
1717
using Xunit;
18+
using Microsoft.Framework.Logging.Internal;
1819

1920
namespace Microsoft.AspNet.Routing.Template
2021
{
@@ -131,13 +132,33 @@ public async Task RouteAsync_MatchFailOnConstraints_LogsCorrectValues()
131132
requestPath: "/Home/Index/Failure",
132133
loggerEnabled: true,
133134
testSink: sink);
134-
var expectedMessage = "Route value 'Failure' of key 'id' did not match the " +
135+
var expectedMessage = "Route value 'Failure' with key 'id' did not match the " +
135136
$"constraint '{typeof(IntRouteConstraint).FullName}'.";
137+
var expectedLogValues = new[]
138+
{
139+
new KeyValuePair<string, object>("RouteValue", "Failure"),
140+
new KeyValuePair<string, object>("RouteKey", "id"),
141+
new KeyValuePair<string, object>("RouteConstraint", typeof(IntRouteConstraint).FullName)
142+
};
136143

137144
// Assert
138145
Assert.Empty(sink.Scopes);
139146
Assert.Single(sink.Writes);
140-
Assert.Equal(expectedMessage, sink.Writes[0].State?.ToString());
147+
var sinkWrite = sink.Writes[0];
148+
Assert.IsType<FormattedLogValues>(sinkWrite.State);
149+
var formattedLogValues = (FormattedLogValues)sinkWrite.State;
150+
Assert.Equal(expectedMessage, formattedLogValues.ToString());
151+
var actualLogValues = formattedLogValues.GetValues();
152+
foreach(var expectedPair in expectedLogValues)
153+
{
154+
Assert.Contains(
155+
actualLogValues,
156+
(kvp) =>
157+
{
158+
return string.Equals(expectedPair.Key, kvp.Key)
159+
&& string.Equals(expectedPair.Value?.ToString(), kvp.Value?.ToString());
160+
});
161+
}
141162
}
142163

143164
[Fact]

0 commit comments

Comments
 (0)