< Summary

Information
Class: ArturRios.Data.Export.Abstractions.ExporterFactory
Assembly: ArturRios.Data.Export
File(s): /home/runner/work/dotnet-data/dotnet-data/src/ArturRios.Data.Export/Abstractions/ExporterFactory.cs
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 35
Line coverage: 93.3%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage
100%
Covered methods: 3
Fully covered methods: 2
Total methods: 3
Method coverage: 100%
Full method coverage: 66.6%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Resolve(...)83.33%6690%
ResolveExcelType()100%22100%

File(s)

/home/runner/work/dotnet-data/dotnet-data/src/ArturRios.Data.Export/Abstractions/ExporterFactory.cs

#LineLine coverage
 1using ArturRios.Data.Export.Exporters;
 2using ArturRios.Data.Export.Interfaces;
 3using Microsoft.Extensions.DependencyInjection;
 4
 5namespace ArturRios.Data.Export.Abstractions;
 6
 7/// <summary>Resolves exporters from the DI container by <see cref="ExportFormat" />.</summary>
 8/// <param name="serviceProvider">The service provider holding the registered exporters.</param>
 149public class ExporterFactory(IServiceProvider serviceProvider) : IExporterFactory
 10{
 11    /// <inheritdoc />
 12    public IExporter<T> Resolve<T>(ExportFormat format) where T : class
 13    {
 1214        var openType = format switch
 1215        {
 216            ExportFormat.Csv => typeof(CsvExporter<>),
 217            ExportFormat.Json => typeof(JsonExporter<>),
 218            ExportFormat.Txt => typeof(TxtExporter<>),
 219            ExportFormat.MessagePack => typeof(MessagePackExporter<>),
 420            ExportFormat.Excel => ResolveExcelType(),
 021            _ => throw new ArgumentOutOfRangeException(nameof(format))
 1222        };
 23
 1024        return (IExporter<T>)serviceProvider.GetRequiredService(openType.MakeGenericType(typeof(T)));
 25    }
 26
 27    private Type ResolveExcelType()
 28    {
 429        var registration = serviceProvider.GetService<ExcelExporterRegistration>()
 430            ?? throw new NotSupportedException(
 431                "Excel export requires the ArturRios.Data.Export.Excel package — call AddExcelExport().");
 32
 233        return registration.ExporterType;
 34    }
 35}