public async Task Verify <T>(IAsyncEnumerable <T> target)
        {
            Guard.AgainstNull(target, nameof(target));
            List <T> list = new();

            await foreach (var item in target)
            {
                list.Add(item);
            }

            try
            {
                await SerializeAndVerify(list, VerifierSettings.GetJsonAppenders(settings));
            }
            finally
            {
                foreach (var item in list)
                {
                    if (item is IAsyncDisposable asyncDisposable)
                    {
                        await asyncDisposable.DisposeAsync();
                    }
                    else if (item is IDisposable disposable)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
        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);
        }
Beispiel #3
0
        Task VerifyString(string target)
        {
            var           appenders = VerifierSettings.GetJsonAppenders(settings);
            StringBuilder builder   = new(target);

            builder.FixNewlines();
            if (appenders.Any())
            {
                return(SerializeAndVerify(builder.ToString(), appenders));
            }

            var extension = settings.ExtensionOrTxt();

            return(VerifyStringBuilder(builder, extension));
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public Task Verify(Expression <Func <ITuple> > target)
        {
            var dictionary = TupleConverter.ExpressionToDictionary(target);

            return(SerializeAndVerify(dictionary, VerifierSettings.GetJsonAppenders(settings)));
        }