Skip to content

Feature request: Add option to disable SQL reformatting #993

@0xced

Description

@0xced

I'd like to have the option to disable the SQL reformatting through a new Verify setting.

I found a workaround to disable SQL reformatting, but I'd rather use a proper setting instead of this hack.

[ModuleInitializer]
public static void Initialize()
{
    VerifyEntityFramework.Initialize();
    var converter = DefaultContractResolver.Converters.Find(e => e.GetType().Name == "LogEntryConverter") ?? throw new InvalidOperationException("LogEntryConverter not found");
    DefaultContractResolver.Converters.Remove(converter);
    DefaultContractResolver.Converters.Add(new NoFormattingLogEntryConverter());
}

// Based https://github.com/VerifyTests/Verify.EntityFramework/blob/15.1.0/src/Verify.EntityFramework/Converters/LogEntryConverter.cs
// But without the SQL reformatting
private class NoFormattingLogEntryConverter : WriteOnlyJsonConverter<LogEntry>
{
    public override void Write(VerifyJsonWriter writer, LogEntry logEntry)
    {
        writer.WriteStartObject();

        writer.WriteMember(logEntry, logEntry.Type, "Type");
        writer.WriteMember(logEntry, logEntry.HasTransaction, "HasTransaction");
        writer.WriteMember(logEntry, logEntry.Exception, "Exception");
        writer.WriteMember(logEntry, logEntry.Parameters, "Parameters");
        writer.WriteMember(logEntry, logEntry.Text, "Text");

        writer.WriteEndObject();
    }
}

If you think it's a good idea, I can try working on a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions