< Summary

Information
Class: Nabs.Tests.LoadFromCsvDataAttribute<T>
Assembly: Nabs.Tests
File(s): /home/runner/work/Nabs/Nabs/src/Nabs.Tests/LoadFromCsvDataAttribute.cs
Tag: 90_14636759620
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetData()100%44100%

File(s)

/home/runner/work/Nabs/Nabs/src/Nabs.Tests/LoadFromCsvDataAttribute.cs

#LineLine coverage
 1namespace Nabs.Tests;
 2
 3[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
 4public class LoadFromCsvDataAttribute<T> : DataAttribute
 5    where T : class, new()
 6{
 7    private readonly Type _relativeAssemblyType;
 8    private readonly string _resourceFilePathEndsWith;
 9    private readonly CsvConfiguration _csvConfiguration;
 10    private readonly EmbeddedResourceLoader _resourceLoader;
 11
 112    public LoadFromCsvDataAttribute(Type relativeAssemblyType, string resourceFilePathEndsWith)
 13    {
 114        _relativeAssemblyType = relativeAssemblyType;
 115        _resourceFilePathEndsWith = resourceFilePathEndsWith;
 116        _resourceLoader = new EmbeddedResourceLoader(_relativeAssemblyType);
 117        _csvConfiguration = GlobalSettings.CsvConfiguration;
 118    }
 19
 20    public override IEnumerable<object[]> GetData(MethodInfo testMethod)
 21    {
 222        var items = _resourceLoader.GetResourceStreamContent(x => x.Path.EndsWith(_resourceFilePathEndsWith))
 123            .Match(
 124                content =>
 125                {
 126                    var csvReader = new CsvReader(new StreamReader(content), _csvConfiguration);
 127                    var records = csvReader.GetRecords<T>();
 228                    var data = records.Select(x => new object[] { x });
 129                    return data;
 130                },
 131                exception =>
 132                {
 133                    throw exception;
 134                });
 35
 336        foreach (var item in items)
 37        {
 138            yield return item;
 39        }
 140    }
 41}