Пример #1
0
        async Task VerifyStream(Stream stream, string?extension)
        {
#if NETSTANDARD2_0 || NETFRAMEWORK
            using (stream)
#else
            await using (stream)
#endif
            {
                if (extension != null)
                {
                    if (VerifierSettings.TryGetExtensionConverter(extension, out var conversion))
                    {
                        var result = await conversion(stream, settings.Context);
                        await VerifyBinary(result.Streams, extension, result.Info, result.Cleanup);

                        return;
                    }
                }

                extension ??= "bin";

                List <ConversionStream> streams = new()
                {
                    new(extension, stream)
                };
                await VerifyBinary(streams, extension, null, null);
            }
        }

        async Task VerifyBinary(IEnumerable <ConversionStream> streams, string infoExtension, object?info, Func <Task>?cleanup)
        {
            VerifyEngine engine = new(infoExtension, settings, directory, testName, assembly);

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

            await VerifyInfo(engine, info);

            await HandleResults(builders, engine);

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

            await engine.ThrowIfRequired();
        }
Пример #2
0
        async Task VerifyStream(Stream stream)
        {
            var extension = settings.extension;

#if NETSTANDARD2_0 || NETFRAMEWORK
            using (stream)
#else
            await using (stream)
#endif
            {
                if (extension != null)
                {
                    if (VerifierSettings.TryGetExtensionConverter(extension, out var conversion))
                    {
                        var result = await conversion(stream, settings.Context);
                        await VerifyInner(result.Info, result.Cleanup, result.Targets);

                        return;
                    }
                }

                extension ??= "bin";

                List <Target> targets;
                if (EmptyFiles.Extensions.IsText(extension))
                {
                    targets = new()
                    {
                        new(extension, await stream.ReadAsString())
                    };
                    await VerifyInner(null, null, targets);
                }
                else
                {
                    targets = new()
                    {
                        new(extension, stream)
                    };
                }

                await VerifyInner(null, null, targets);
            }
        }
    }