public void WritesScopeMessagesUsingFormatter(string?sensitiveValue, string state, string expected)
        {
            var logLevel     = LogLevel.Error;
            var eventId      = Model.Create <EventId>();
            var message      = Guid.NewGuid().ToString();
            var categoryName = Guid.NewGuid().ToString();

            string Formatter(string logState, Exception?error) => message;

            var config = new LoggingConfig();

            if (sensitiveValue != null)
            {
                config.SensitiveValues.Add(sensitiveValue);
            }

            var output = Substitute.For <ITestOutputHelper>();

            var sut = new TestOutputLogger(categoryName, output, config);

            using (sut.BeginScope(state))
            {
                sut.Log(logLevel, eventId, state, null, Formatter);
            }

            output.Received().WriteLine($"<Scope: {expected}>");
            output.Received().WriteLine($"   {logLevel} [{eventId.Id}]: {message}");
            output.Received().WriteLine($"</Scope: {expected}>");
        }
        public void BeginScopeShouldNotThrowWhenStateDataHasCircularReference()
        {
            var categoryName = Guid.NewGuid().ToString();
            var state        = new CircularReference();

            var sut = new TestOutputLogger(categoryName, _output);

            using (sut.BeginScope(state))
            {
                sut.LogDebug("...");
            }
        }
        public void BeginScopeReturnsInstance()
        {
            var categoryName = Guid.NewGuid().ToString();
            var state        = Guid.NewGuid().ToString();

            var sut = new TestOutputLogger(categoryName, _output);

            var actual = sut.BeginScope(state);

            actual.Should().NotBeNull();

            Action action = () => actual.Dispose();

            action.Should().NotThrow();
        }
        public void WritesScopeMessagesWithStructuredDataUsingFormatter()
        {
            var logLevel       = LogLevel.Error;
            var eventId        = Model.Create <EventId>();
            var message        = Guid.NewGuid().ToString();
            var sensitiveValue = Guid.NewGuid().ToString();
            var categoryName   = Guid.NewGuid().ToString();
            var config         = new LoggingConfig().Set(x => x.SensitiveValues.Add(sensitiveValue));

            var state = Model.Create <StructuredData>().Set(x => x.FirstName += " " + sensitiveValue);

            var output = Substitute.For <ITestOutputHelper>();

            var sut = new TestOutputLogger(categoryName, output, config);

            using (sut.BeginScope(state))
            {
                sut.Log(logLevel, eventId, message);
            }

            output.DidNotReceive().WriteLine(Arg.Is <string>(x => x.Contains(sensitiveValue)));
        }