• 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

32.0
/src/FluentCommand.Import/ImportDefinitionBuilder.cs
1
namespace FluentCommand.Import;
2

3
/// <summary>
4
/// Provides a fluent API for configuring and building an <see cref="Import.ImportDefinition"/> instance.
5
/// Enables chaining of configuration methods for setting import metadata, target table, field definitions, and validation options.
6
/// </summary>
7
public class ImportDefinitionBuilder
8
{
9
    /// <summary>
10
    /// Initializes a new instance of the <see cref="ImportDefinitionBuilder"/> class.
11
    /// </summary>
12
    /// <param name="importDefinition">The <see cref="Import.ImportDefinition"/> to configure.</param>
13
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="importDefinition"/> is <c>null</c>.</exception>
14
    public ImportDefinitionBuilder(ImportDefinition importDefinition)
5✔
15
    {
16
        ImportDefinition = importDefinition ?? throw new ArgumentNullException(nameof(importDefinition));
5!
17
    }
5✔
18

19
    protected ImportDefinition ImportDefinition { get; }
62✔
20

21
    /// <summary>
22
    /// Sets the name of the import operation for the <see cref="Import.ImportDefinition"/>.
23
    /// </summary>
24
    /// <param name="name">The name of the import operation.</param>
25
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
26
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is <c>null</c>.</exception>
27
    public ImportDefinitionBuilder Name(string name)
28
    {
29
        if (name == null)
5!
30
            throw new ArgumentNullException(nameof(name));
×
31

32
        ImportDefinition.Name = name;
5✔
33
        return this;
5✔
34
    }
35

36
    /// <summary>
37
    /// Sets the target table name for the <see cref="Import.ImportDefinition"/>.
38
    /// </summary>
39
    /// <param name="name">The name of the target table into which data will be imported.</param>
40
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
41
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is <c>null</c>.</exception>
42
    public ImportDefinitionBuilder TargetTable(string name)
43
    {
44
        if (name == null)
2!
45
            throw new ArgumentNullException(nameof(name));
×
46

47
        ImportDefinition.TargetTable = name;
2✔
48
        return this;
2✔
49
    }
50

51
    /// <summary>
52
    /// Sets whether new data can be inserted into the target table during import.
53
    /// </summary>
54
    /// <param name="value"><c>true</c> to allow inserts; otherwise, <c>false</c>. Default is <c>true</c>.</param>
55
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
56
    public ImportDefinitionBuilder CanInsert(bool value = true)
57
    {
NEW
58
        ImportDefinition.CanInsert = value;
×
59
        return this;
×
60
    }
61

62
    /// <summary>
63
    /// Sets whether existing data in the target table can be updated during import.
64
    /// </summary>
65
    /// <param name="value"><c>true</c> to allow updates; otherwise, <c>false</c>. Default is <c>true</c>.</param>
66
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
67
    public ImportDefinitionBuilder CanUpdate(bool value = true)
68
    {
NEW
69
        ImportDefinition.CanUpdate = value;
×
70
        return this;
×
71
    }
72

73
    /// <summary>
74
    /// Adds a new field definition to the import configuration using the specified builder action.
75
    /// </summary>
76
    /// <param name="builder">An action to configure the <see cref="FieldDefinitionBuilder"/> for the new field.</param>
77
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
78
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is <c>null</c>.</exception>
79
    public ImportDefinitionBuilder Field(Action<FieldDefinitionBuilder> builder)
80
    {
81
        if (builder == null)
15!
82
            throw new ArgumentNullException(nameof(builder));
×
83

84
        var fieldMapping = new FieldDefinition();
15✔
85
        var fieldBuilder = new FieldDefinitionBuilder(fieldMapping);
15✔
86
        builder(fieldBuilder);
15✔
87

88
        if (fieldMapping.DataType == null)
15!
89
            fieldMapping.DataType = typeof(string); // default type
×
90

91
        ImportDefinition.Fields.Add(fieldMapping);
15✔
92

93
        return this;
15✔
94
    }
95

96
    /// <summary>
97
    /// Adds or updates a field definition for the specified field name using the provided builder action.
98
    /// If the field already exists, it is updated; otherwise, a new field is added.
99
    /// </summary>
100
    /// <param name="fieldName">The name of the field to configure.</param>
101
    /// <param name="builder">An action to configure the <see cref="FieldDefinitionBuilder"/> for the field.</param>
102
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
103
    /// <exception cref="ArgumentException">Thrown when <paramref name="fieldName"/> is <c>null</c> or empty.</exception>
104
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is <c>null</c>.</exception>
105
    public ImportDefinitionBuilder Field(string fieldName, Action<FieldDefinitionBuilder> builder)
106
    {
107
        if (string.IsNullOrEmpty(fieldName))
×
108
            throw new ArgumentException($"'{nameof(fieldName)}' cannot be null or empty.", nameof(fieldName));
×
109

110
        if (builder == null)
×
111
            throw new ArgumentNullException(nameof(builder));
×
112

NEW
113
        var fieldMapping = ImportDefinition.Fields.FirstOrDefault(m => m.Name == fieldName);
×
114
        if (fieldMapping == null)
×
115
        {
116
            fieldMapping = new FieldDefinition { Name = fieldName };
×
NEW
117
            ImportDefinition.Fields.Add(fieldMapping);
×
118
        }
119

120
        var fieldBuilder = new FieldDefinitionBuilder(fieldMapping);
×
121
        builder(fieldBuilder);
×
122

123
        // default type
124
        if (fieldMapping.DataType == null)
×
125
            fieldMapping.DataType = typeof(string);
×
126

127
        return this;
×
128
    }
129

130
    /// <summary>
131
    /// Gets or creates a <see cref="FieldDefinitionBuilder"/> for the specified field name.
132
    /// If the field does not exist, it is created and added to the import definition.
133
    /// </summary>
134
    /// <param name="fieldName">The name of the field to configure.</param>
135
    /// <returns>A <see cref="FieldDefinitionBuilder"/> for the specified field.</returns>
136
    /// <exception cref="ArgumentException">Thrown when <paramref name="fieldName"/> is <c>null</c> or empty.</exception>
137
    public FieldDefinitionBuilder Field(string fieldName)
138
    {
139
        if (string.IsNullOrEmpty(fieldName))
×
140
            throw new ArgumentException($"'{nameof(fieldName)}' cannot be null or empty.", nameof(fieldName));
×
141

NEW
142
        var fieldMapping = ImportDefinition.Fields.FirstOrDefault(m => m.Name == fieldName);
×
143
        if (fieldMapping == null)
×
144
        {
145
            fieldMapping = new FieldDefinition { Name = fieldName };
×
NEW
146
            ImportDefinition.Fields.Add(fieldMapping);
×
147
        }
148

149
        return new FieldDefinitionBuilder(fieldMapping);
×
150
    }
151

152
    /// <summary>
153
    /// Sets the maximum number of errors allowed before the import operation is aborted.
154
    /// </summary>
155
    /// <param name="value">The maximum number of errors permitted during import.</param>
156
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
157
    public ImportDefinitionBuilder MaxErrors(int value)
158
    {
NEW
159
        ImportDefinition.MaxErrors = value;
×
160
        return this;
×
161
    }
162

163
    /// <summary>
164
    /// Sets the import validator type for the <see cref="Import.ImportDefinition"/> using a generic type parameter.
165
    /// The validator type must implement <see cref="IImportValidator"/>.
166
    /// </summary>
167
    /// <typeparam name="T">The type of validator implementing <see cref="IImportValidator"/>.</typeparam>
168
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
169
    [Obsolete("Use ValidatorKey(string) instead.")]
170
    public ImportDefinitionBuilder Validator<T>()
171
        where T : IImportValidator
172
    {
NEW
173
        ImportDefinition.Validator = typeof(T);
×
174
        return this;
×
175
    }
176

177
    /// <summary>
178
    /// Sets the import validator type for the <see cref="Import.ImportDefinition"/> using a <see cref="Type"/> instance.
179
    /// The validator type must implement <see cref="IImportValidator"/>.
180
    /// </summary>
181
    /// <param name="type">The <see cref="Type"/> of the validator.</param>
182
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
183
    [Obsolete("Use ValidatorKey(string) instead.")]
184
    public ImportDefinitionBuilder Validator(Type type)
185
    {
NEW
186
        ImportDefinition.Validator = type;
×
187
        return this;
×
188
    }
189

190
    /// <summary>
191
    /// Sets the service key used to resolve the <see cref="IImportValidator"/> service from the dependency injection container.
192
    /// The service must be registered in the DI container with this key and implement <see cref="IImportValidator"/>.
193
    /// </summary>
194
    /// <param name="key">The service key for the validator.</param>
195
    /// <returns>The current <see cref="ImportDefinitionBuilder"/> instance for method chaining.</returns>
196
    public ImportDefinitionBuilder ValidatorKey(string key)
197
    {
198
        ImportDefinition.ValidatorKey = key;
2✔
199
        return this;
2✔
200
    }
201
}
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