async Task VerifyInner(object?target, Func <Task>?cleanup, IEnumerable <Target> targets)
        {
            var targetList = targets.ToList();

            if (TryGetTargetBuilder(target, out var builder, out var extension))
            {
                ApplyScrubbers.Apply(extension, builder, settings);

                var received = builder.ToString();
                var stream   = new Target(extension, received);
                targetList.Insert(0, stream);
            }

            targetList.AddRange(VerifierSettings.GetFileAppenders(settings));
            var builders = targetList
                           .Select(
                stream =>
            {
                return(new ResultBuilder(
                           stream.Extension,
                           file => GetResult(settings, file, stream)));
            })
                           .ToList();

            VerifyEngine engine = new(fileNameBuilder, settings.autoVerify);

            await engine.HandleResults(builders);

            if (cleanup != null)
            {
                await cleanup();
            }

            await engine.ThrowIfRequired();
        }
Beispiel #2
0
        async Task VerifyInner(object?target, Func <Task>?cleanup, IEnumerable <ConversionStream> streams)
        {
            VerifyEngine engine = new(settings, fileNameBuilder);

            var streamsList = streams.ToList();

            if (TryGetTargetBuilder(target, out var builder, out var extension))
            {
                ApplyScrubbers.Apply(builder, settings.instanceScrubbers);

                var received = builder.ToString();
                var stream   = new ConversionStream(extension, received);
                streamsList.Insert(0, stream);
            }

            streamsList.AddRange(VerifierSettings.GetFileAppenders(settings));
            var builders = streamsList
                           .Select(
                stream =>
            {
                return(new ResultBuilder(
                           stream.Extension,
                           file => GetResult(settings, file, stream)));
            })
                           .ToList();

            await engine.HandleResults(builders);

            if (cleanup != null)
            {
                await cleanup.Invoke();
            }

            await engine.ThrowIfRequired();
        }
    static async Task <(Equality equality, string?message)> GetResult(VerifySettings settings, FilePair file, Stream stream)
    {
        if (Extensions.IsText(file.Extension))
        {
            var readAsString = await stream.ReadAsString();

            var scrubbedInput = ApplyScrubbers.Apply(readAsString, settings.instanceScrubbers);
            return(await Comparer.Text(file, scrubbedInput, settings));
        }

        return(await Comparer.Streams(settings, stream, file));
    }
    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 = ApplyScrubbers.Apply(formatJson, settings.instanceScrubbers);

        var result = await Comparer.Text(file, scrubbedInput, settings);

        engine.HandleCompareResult(result, file);
    }
Beispiel #5
0
        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);
        }
Beispiel #6
0
    static async Task <EqualityResult> GetResult(VerifySettings settings, FilePair file, Stream stream)
    {
#if NETSTANDARD2_1
        await using (stream)
#else
        using (stream)
#endif
        {
            stream.MoveToStart();
            if (!Extensions.IsText(file.Extension))
            {
                return(await Comparer.Streams(settings, stream, file));
            }

            var builder = await stream.ReadAsString();

            ApplyScrubbers.Apply(builder, settings.instanceScrubbers);
            return(await Comparer.Text(file, builder, settings));
        }
    }
Beispiel #7
0
        async Task Verify(StringBuilder target, VerifySettings?settings)
        {
            Guard.AgainstNull(target, nameof(target));
            settings = settings.OrDefault();

            var extension = settings.ExtensionOrTxt();
            var engine    = new VerifyEngine(
                extension,
                settings,
                directory,
                testName,
                assembly);

            var file = GetFileNames(extension, settings.Namer);

            ApplyScrubbers.Apply(target, settings.instanceScrubbers);
            var result = await Comparer.Text(file, target, settings);

            engine.HandleCompareResult(result, file);
            await engine.ThrowIfRequired();
        }
        static async Task <EqualityResult> GetResult(VerifySettings settings, FilePair filePair, Target target)
        {
            if (target.IsString)
            {
                var builder = new StringBuilder(target.StringData);
                ApplyScrubbers.Apply(target.Extension, builder, settings);
                return(await Comparer.Text(filePair, builder.ToString(), settings));
            }

            var stream = target.StreamData;

#if NETSTANDARD2_0 || NETFRAMEWORK
            using (stream)
#else
            await using (stream)
#endif
            {
                stream.MoveToStart();
                return(await Comparer.Streams(settings, stream, filePair));
            }
        }
Beispiel #9
0
        static async Task <EqualityResult> GetResult(VerifySettings settings, FilePair filePair, ConversionStream conversionStream)
        {
            if (conversionStream.IsData)
            {
                var builder = new StringBuilder(conversionStream.Data);
                ApplyScrubbers.Apply(builder, settings.instanceScrubbers);
                return(await Comparer.Text(filePair, builder.ToString(), settings));
            }

            var stream = conversionStream.Stream;

#if NETSTANDARD2_0 || NETFRAMEWORK
            using (stream)
#else
            await using (stream)
#endif
            {
                stream.MoveToStart();
                return(await Comparer.Streams(settings, stream, filePair));
            }
        }
Beispiel #10
0
        static async Task <EqualityResult> GetResult(VerifySettings settings, FilePair filePair, ConversionStream conversionStream)
        {
            var stream = conversionStream.Stream;

#if NETSTANDARD2_0 || NETFRAMEWORK
            using (stream)
#else
            await using (stream)
#endif
            {
                stream.MoveToStart();
                if (!EmptyFiles.Extensions.IsText(conversionStream.Extension))
                {
                    return(await Comparer.Streams(settings, stream, filePair));
                }

                var builder = await stream.ReadAsString();

                ApplyScrubbers.Apply(builder, settings.instanceScrubbers);
                return(await Comparer.Text(filePair, builder, settings));
            }
        }
    public async Task Verify(string input, VerifySettings?settings = null)
    {
        Guard.AgainstNull(input, nameof(input));
        settings = settings.OrDefault();

        var extension = settings.ExtensionOrTxt();
        var engine    = new VerifyEngine(
            extension,
            settings,
            testType,
            directory,
            testName);

        var file = GetFileNames(extension, settings.Namer);

        var scrubbedInput = ApplyScrubbers.Apply(input, settings.instanceScrubbers);

        var result = await Comparer.Text(file, scrubbedInput, settings);

        engine.HandleCompareResult(result, file);
        await engine.ThrowIfRequired();
    }
Beispiel #12
0
        async Task VerifyStringBuilder(StringBuilder target, string extension)
        {
            ApplyScrubbers.Apply(target, settings.instanceScrubbers);

            VerifyEngine engine = new(extension, settings, directory, testName, assembly);

            List <ResultBuilder> builders = new()
            {
                new(extension, file => Comparer.Text(file, target, settings))
            };

            builders.AddRange(VerifierSettings.GetFileAppenders(settings)
                              .Select(appender =>
            {
                return(new ResultBuilder(
                           appender.Extension,
                           file => GetResult(settings, file, appender)));
            }));

            await HandleResults(builders, engine);

            await engine.ThrowIfRequired();
        }
Beispiel #13
0
        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);
        }
 static string ScrubInput(string input, VerifySettings settings)
 {
     return(ApplyScrubbers.Apply(input, settings.instanceScrubbers)
            .Replace("\r\n", "\n"));
 }