public Task Verify <T>(T input, VerifySettings?settings = null) { Guard.AgainstNull(input, nameof(input)); settings = settings.OrDefault(); if (SharedVerifySettings.TryGetConverter <T>( settings.extension, out var typeConverter)) { var converterSettings = GetConverterSettings <T>(settings, typeConverter); var result = typeConverter.Func(input !, converterSettings); return(VerifyBinary(result.Streams, converterSettings, result.Info)); } if (input is Stream stream) { return(VerifyStream(settings, stream)); } if (typeof(T).ImplementsStreamEnumerable()) { var enumerable = (IEnumerable)input !; return(VerifyBinary(enumerable.Cast <Stream>(), settings, null)); } var formatJson = JsonFormatter.AsJson(input, settings.serialization.currentSettings); return(Verify(formatJson, settings)); }
public async Task Verify <T>(T input, VerifySettings?settings = null) { Guard.AgainstNull(input, nameof(input)); settings = settings.OrDefault(); if (SharedVerifySettings.TryGetConverter <T>(out var typeConverter)) { var converterSettings = new VerifySettings(settings); converterSettings.UseExtension(typeConverter.ToExtension); var converterFunc = typeConverter.Func(input !, converterSettings); await VerifyBinary(converterFunc, converterSettings); return; } if (input is Stream stream) { using (stream) { if (settings.HasExtension()) { if (SharedVerifySettings.TryGetConverter(settings.extension !, out var converter)) { var converterSettings = new VerifySettings(settings); converterSettings.UseExtension(converter.ToExtension); var streams = converter.Func(stream, converterSettings); await VerifyBinary(streams, converterSettings); return; } } await VerifyBinary(new List <Stream> { stream }, settings); return; } } if (typeof(T).IsStreamEnumerable()) { var enumerable = (IEnumerable)input !; await VerifyBinary(enumerable.Cast <Stream>(), settings); return; } var formatJson = JsonFormatter.AsJson(input, settings.serialization.currentSettings); await Verify(formatJson, settings); return; }
bool TryGetTargetBuilder(object?target, [NotNullWhen(true)] out StringBuilder?builder, [NotNullWhen(true)] out string?extension) { var appends = VerifierSettings.GetJsonAppenders(settings); var hasAppends = appends.Any(); if (target == null) { if (!hasAppends) { builder = null; extension = null; return(false); } extension = "txt"; if (VerifierSettings.StrictJson) { extension = "json"; } builder = JsonFormatter.AsJson( null, settings.serialization.currentSettings, appends, settings); return(true); } if (!hasAppends && target is string stringTarget) { builder = new StringBuilder(stringTarget); builder.FixNewlines(); extension = settings.ExtensionOrTxt(); return(true); } extension = "txt"; if (VerifierSettings.StrictJson) { extension = "json"; } builder = JsonFormatter.AsJson( target, settings.serialization.currentSettings, appends, settings); return(true); }
public async Task Verify <T>(T target, VerifySettings?settings = null) { settings = settings.OrDefault(); if (target == null) { await VerifyString("null", settings); return; } if (target != null && VerifierSettings.typeToString.TryGetValue(target.GetType(), out var toString)) { await VerifyString(toString.Invoke(target, settings), settings); return; } if (VerifierSettings.TryGetTypedConverter(target, settings, out var converter)) { var result = await converter.Conversion(target !, settings); await VerifyBinary(result.Streams, settings.ExtensionOrTxt(), settings, result.Info, result.Cleanup); return; } if (target is Stream stream) { await VerifyStream(settings, stream); return; } if (typeof(T).ImplementsStreamEnumerable()) { var enumerable = (IEnumerable)target !; var streams = enumerable.Cast <Stream>().Select(x => new ConversionStream(settings.ExtensionOrBin(), x)); await VerifyBinary(streams, settings.ExtensionOrTxt(), settings, null, null); return; } var formatJson = JsonFormatter.AsJson( target, settings.serialization.currentSettings, settings.IsNewLineEscapingDisabled); await Verify(formatJson, settings); }
async Task VerifyInfo(VerifyEngine engine, VerifySettings settings, object?info) { if (info == null) { return; } var file = GetFileNames("txt", settings.Namer, "info"); var formatJson = JsonFormatter.AsJson(info, settings.serialization.currentSettings); var scrubbedInput = ScrubInput(formatJson, settings); var result = await Comparer.Text(file, scrubbedInput); engine.HandleCompareResult(result, file); }
async Task VerifyInfo(VerifyEngine engine, VerifySettings settings, object?info) { if (info == null) { return; } var file = GetFileNames("txt", settings.Namer, "info"); var builder = JsonFormatter.AsJson( info, settings.serialization.currentSettings, settings.IsNewLineEscapingDisabled); ApplyScrubbers.Apply(builder, settings.instanceScrubbers); var result = await Comparer.Text(file, builder, settings); engine.HandleCompareResult(result, file); }
public async Task Verify <T>(T target, VerifySettings?settings = null) { Guard.AgainstNull(target, nameof(target)); settings = settings.OrDefault(); if (SharedVerifySettings.TryGetConverter( target, settings.extension, out var converter)) { var converterSettings = GetConverterSettings(settings, converter); var result = await converter.Conversion(target !, converterSettings); await VerifyBinary(result.Streams, converterSettings, result.Info); return; } if (target is Stream stream) { await VerifyStream(settings, stream); return; } if (typeof(T).ImplementsStreamEnumerable()) { var enumerable = (IEnumerable)target !; await VerifyBinary(enumerable.Cast <Stream>(), settings, null); return; } var formatJson = JsonFormatter.AsJson( target, settings.serialization.currentSettings, settings.IsNewLineEscapingDisabled); var s = formatJson.ToString(); await Verify(formatJson, settings); }
public async Task Verify <T>(T input, VerifySettings?settings = null) { Guard.AgainstNull(input, nameof(input)); settings = settings.OrDefault(); if (SharedVerifySettings.TryGetConverter <T>( settings.extension, out var converter)) { var converterSettings = GetConverterSettings(settings, converter); var result = await converter.Func(input !, converterSettings); await VerifyBinary(result.Streams, converterSettings, result.Info); return; } if (input is Stream stream) { await VerifyStream(settings, stream); return; } if (typeof(T).ImplementsStreamEnumerable()) { var enumerable = (IEnumerable)input !; await VerifyBinary(enumerable.Cast <Stream>(), settings, null); return; } var formatJson = JsonFormatter.AsJson(input, settings.serialization.currentSettings); if (settings.newLineEscapingDisabled || SharedVerifySettings.newLineEscapingDisabled) { formatJson = formatJson.Replace("\\n", "\n").Replace("\\r", "\r"); } settings.IgnoreTrailingWhitespace(); await Verify(formatJson, settings); }
async Task VerifyInfo(VerifyEngine engine, object?info) { var appends = VerifierSettings.GetJsonAppenders(settings); if (info == null && !appends.Any()) { return; } var file = GetFileNames("txt", settings.Namer, "info"); var builder = JsonFormatter.AsJson( info, settings.serialization.currentSettings, appends, settings); ApplyScrubbers.Apply(builder, settings.instanceScrubbers); var result = await Comparer.Text(file, builder, settings); engine.HandleCompareResult(result, file); }