public void BeginScope_CreatesScope_WithFormatStringValues() { // Arrange var testSink = new TestSink( writeEnabled: (writeContext) => true, beginEnabled: (beginScopeContext) => true); var logger = new TestLogger("TestLogger", testSink, enabled: true); var actionName = "App.Controllers.Home.Index"; var expectedStringMessage = "Executing action " + actionName; // Act var scope = logger.BeginScope("Executing action {ActionName}", actionName); // Assert Assert.Equal(1, testSink.Scopes.Count); Assert.IsType<FormattedLogValues>(testSink.Scopes[0].Scope); var scopeState = (FormattedLogValues)testSink.Scopes[0].Scope; Assert.Equal(expectedStringMessage, scopeState.ToString()); var scopeProperties = scopeState.GetValues(); Assert.NotNull(scopeProperties); Assert.Contains(scopeProperties, (kvp) => { return (string.Equals(kvp.Key, "ActionName") && string.Equals(kvp.Value?.ToString(), actionName)); }); }
private TestLogger SetUp(TestSink sink) { // Arrange var logger = new TestLogger(_name, sink, enabled: true); return logger; }