• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 16301005024

15 Jul 2025 06:03PM UTC coverage: 54.951%. First build
16301005024

push

github

pwelter34
import data tweaks, xml doc updates

1716 of 3630 branches covered (47.27%)

Branch coverage included in aggregate %.

78 of 143 new or added lines in 11 files covered. (54.55%)

4361 of 7429 relevant lines covered (58.7%)

231.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.89
/src/FluentCommand.SqlServer/Import/ImportProcessContext.cs
1
namespace FluentCommand.Import;
2

3
/// <summary>
4
/// Provides shared data and context for the current import process, including import definitions, data, user information, errors, and mapped fields.
5
/// </summary>
6
public class ImportProcessContext
7
{
8
    private readonly Lazy<IReadOnlyList<ImportFieldMapping>> _mappedFields;
9

10
    /// <summary>
11
    /// Initializes a new instance of the <see cref="ImportProcessContext"/> class.
12
    /// </summary>
13
    /// <param name="serviceProvider">The <see cref="IServiceProvider"/> used for dependency resolution during import.</param>
14
    /// <param name="definition">The <see cref="ImportDefinition"/> describing the import configuration and rules.</param>
15
    /// <param name="importData">The <see cref="ImportData"/> containing the data and field mappings to be imported.</param>
16
    /// <param name="userName">The name of the user performing the import operation.</param>
17
    public ImportProcessContext(IServiceProvider serviceProvider, ImportDefinition definition, ImportData importData, string userName)
2✔
18
    {
19
        Services = serviceProvider;
2✔
20
        Definition = definition;
2✔
21
        ImportData = importData;
2✔
22
        UserName = userName;
2✔
23
        Errors = new List<Exception>();
2✔
24

25
        _mappedFields = new Lazy<IReadOnlyList<ImportFieldMapping>>(GetMappedFields);
2✔
26
    }
2✔
27

28
    /// <summary>
29
    /// Gets the name of the user performing the import operation.
30
    /// </summary>
31
    /// <value>
32
    /// The user name.
33
    /// </value>
34
    public string UserName { get; }
×
35

36
    /// <summary>
37
    /// Gets the <see cref="ImportDefinition"/> describing the import configuration and rules.
38
    /// </summary>
39
    /// <value>
40
    /// The import definition.
41
    /// </value>
42
    public ImportDefinition Definition { get; }
4✔
43

44
    /// <summary>
45
    /// Gets the <see cref="ImportData"/> containing the data and field mappings to be imported.
46
    /// </summary>
47
    /// <value>
48
    /// The import data.
49
    /// </value>
50
    public ImportData ImportData { get; }
16✔
51

52
    /// <summary>
53
    /// Gets the list of mapped fields for the import operation.
54
    /// Each <see cref="ImportFieldMapping"/> associates a field definition with its mapping information.
55
    /// </summary>
56
    /// <value>
57
    /// The mapped fields for the import process.
58
    /// </value>
59
    public IReadOnlyList<ImportFieldMapping> MappedFields => _mappedFields.Value;
5✔
60

61
    /// <summary>
62
    /// Gets or sets the list of errors that occurred during the import process.
63
    /// </summary>
64
    /// <value>
65
    /// A list of <see cref="Exception"/> instances representing errors encountered.
66
    /// </value>
67
    public List<Exception> Errors { get; set; }
2✔
68

69
    /// <summary>
70
    /// Gets the <see cref="IServiceProvider"/> used for resolving services during the import process.
71
    /// </summary>
72
    /// <value>
73
    /// The service provider.
74
    /// </value>
NEW
75
    public IServiceProvider Services { get; }
×
76

77
    private List<ImportFieldMapping> GetMappedFields()
78
    {
79
        var list = new List<ImportFieldMapping>();
2✔
80

81
        var firstRow = ImportData.Data.FirstOrDefault();
2✔
82
        var columns = firstRow?.Length ?? 0;
2!
83

84
        foreach (var field in Definition.Fields)
24✔
85
        {
86
            // if default value, include
87
            if (field.Default.HasValue)
10!
88
            {
89
                list.Add(new ImportFieldMapping(field));
×
90
                continue;
×
91
            }
92

93
            var name = field.Name;
10✔
94

95
            // if mapped to an index, include
96
            var mapping = ImportData.Mappings.FirstOrDefault(f => f.Name == name);
40✔
97
            if (mapping?.Index == null)
10!
98
            {
99
                if (field.IsRequired)
×
100
                    throw new InvalidOperationException($"Missing required field mapping for '{name}'");
×
101

102
                continue;
103
            }
104

105
            if (mapping.Index.Value >= columns)
10!
106
                throw new IndexOutOfRangeException(
×
107
                    $"The mapped index {mapping.Index.Value} for field '{name}' is out of range of {columns}");
×
108

109
            list.Add(new ImportFieldMapping(field, mapping));
10✔
110
        }
111

112
        return list;
2✔
113
    }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc