< Summary

Information
Class: ArturRios.Data.Export.Abstractions.ExporterFactory
Assembly: ArturRios.Data.Export
File(s): D:\Repositories\dotnet-data\src\ArturRios.Data.Export\Abstractions\ExporterFactory.cs
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 35
Line coverage: 94.7%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage
100%
Covered methods: 3
Fully covered methods: 1
Total methods: 3
Method coverage: 100%
Full method coverage: 33.3%

Metrics

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

File(s)

D:\Repositories\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>
 79public class ExporterFactory(IServiceProvider serviceProvider) : IExporterFactory
 10{
 11    /// <inheritdoc />
 12    public IExporter<T> Resolve<T>(ExportFormat format) where T : class
 613    {
 614        var openType = format switch
 615        {
 116            ExportFormat.Csv => typeof(CsvExporter<>),
 117            ExportFormat.Json => typeof(JsonExporter<>),
 118            ExportFormat.Txt => typeof(TxtExporter<>),
 119            ExportFormat.MessagePack => typeof(MessagePackExporter<>),
 220            ExportFormat.Excel => ResolveExcelType(),
 021            _ => throw new ArgumentOutOfRangeException(nameof(format))
 622        };
 23
 524        return (IExporter<T>)serviceProvider.GetRequiredService(openType.MakeGenericType(typeof(T)));
 525    }
 26
 27    private Type ResolveExcelType()
 228    {
 229        var registration = serviceProvider.GetService<ExcelExporterRegistration>()
 230            ?? throw new NotSupportedException(
 231                "Excel export requires the ArturRios.Data.Export.Excel package — call AddExcelExport().");
 32
 133        return registration.ExporterType;
 134    }
 35}