< Summary

Information
Class: ArturRios.Data.Export.Exporters.TxtExporter<T>
Assembly: ArturRios.Data.Export
File(s): D:\Repositories\dotnet-data\src\ArturRios.Data.Export\Exporters\TxtExporter.cs
Line coverage
92%
Covered lines: 13
Uncovered lines: 1
Coverable lines: 14
Total lines: 39
Line coverage: 92.8%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage
80%
Covered methods: 4
Fully covered methods: 3
Total methods: 5
Method coverage: 80%
Full method coverage: 60%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
WriteCoreAsync(...)75%44100%
WriteAsync(...)100%11100%
WriteToFileAsync(...)100%210%
WriteLinesAsync()100%22100%

File(s)

D:\Repositories\dotnet-data\src\ArturRios.Data.Export\Exporters\TxtExporter.cs

#LineLine coverage
 1using ArturRios.Data.Export.Configuration;
 2using ArturRios.Output;
 3
 4namespace ArturRios.Data.Export.Exporters;
 5
 6/// <summary>Writes one line per record: default <see cref="object.ToString" />, or a custom selector.</summary>
 7/// <typeparam name="T">The record type.</typeparam>
 8/// <param name="options">TXT options.</param>
 69public class TxtExporter<T>(TxtOptions options) : ExporterBase<T> where T : class
 10{
 11    /// <inheritdoc />
 12    protected override Task WriteCoreAsync(IEnumerable<T> data, Stream destination, CancellationToken ct) =>
 313        WriteLinesAsync(data, destination, item => item?.ToString() ?? string.Empty, ct);
 14
 15    /// <summary>Writes each record on its own line using <paramref name="lineSelector" />.</summary>
 16    public Task<ProcessOutput> WriteAsync(IEnumerable<T> data, Stream destination, Func<T, string> lineSelector,
 17        CancellationToken ct = default) =>
 318        GuardedWriteAsync(data, destination, stream => WriteLinesAsync(data, stream, lineSelector, ct));
 19
 20    /// <summary>Writes each record on its own line to a file using <paramref name="lineSelector" />.</summary>
 21    public Task<ProcessOutput> WriteToFileAsync(IEnumerable<T> data, string path, Func<T, string> lineSelector,
 22        CancellationToken ct = default) =>
 023        GuardedFileAsync(data, path, stream => WriteLinesAsync(data, stream, lineSelector, ct));
 24
 25    private async Task WriteLinesAsync(IEnumerable<T> data, Stream destination, Func<T, string> lineSelector,
 26        CancellationToken ct)
 327    {
 328        await using var writer = new StreamWriter(destination, options.Encoding, leaveOpen: true);
 29
 1530        foreach (var item in data)
 331        {
 332            ct.ThrowIfCancellationRequested();
 333            await writer.WriteAsync(lineSelector(item));
 334            await writer.WriteAsync(options.NewLine);
 335        }
 36
 337        await writer.FlushAsync(ct);
 338    }
 39}