• 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

40.0
/src/FluentCommand.Import/FieldDefinitionBuilder.cs
1
namespace FluentCommand.Import;
2

3
/// <summary>
4
/// Provides a fluent API for configuring and building a <see cref="Import.FieldDefinition"/> instance for import operations.
5
/// Enables chaining of configuration methods for setting field metadata, data type, mapping, validation, and transformation options.
6
/// </summary>
7
public class FieldDefinitionBuilder
8
{
9
    /// <summary>
10
    /// Initializes a new instance of the <see cref="FieldDefinitionBuilder"/> class.
11
    /// </summary>
12
    /// <param name="fieldDefinition">The <see cref="Import.FieldDefinition"/> to configure.</param>
13
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="fieldDefinition"/> is <c>null</c>.</exception>
14
    public FieldDefinitionBuilder(FieldDefinition fieldDefinition)
16✔
15
    {
16
        if (fieldDefinition == null)
16!
17
            throw new ArgumentNullException(nameof(fieldDefinition));
×
18

19
        FieldDefinition = fieldDefinition;
16✔
20
    }
16✔
21

22
    protected FieldDefinition FieldDefinition { get; }
56✔
23

24
    /// <summary>
25
    /// Sets the unique field name for the <see cref="Import.FieldDefinition"/>.
26
    /// </summary>
27
    /// <param name="value">The unique name of the field.</param>
28
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
29
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is <c>null</c>.</exception>
30
    public FieldDefinitionBuilder FieldName(string value)
31
    {
32
        if (value == null)
15!
33
            throw new ArgumentNullException(nameof(value));
×
34

35
        FieldDefinition.Name = value;
15✔
36

37
        return this;
15✔
38
    }
39

40
    /// <summary>
41
    /// Sets the display name for the <see cref="Import.FieldDefinition"/>, typically used for user interfaces or reporting.
42
    /// </summary>
43
    /// <param name="value">The display name of the field.</param>
44
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
45
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is <c>null</c>.</exception>
46
    public FieldDefinitionBuilder DisplayName(string value)
47
    {
48
        if (value == null)
17!
49
            throw new ArgumentNullException(nameof(value));
×
50

51
        FieldDefinition.DisplayName = value;
17✔
52

53
        return this;
17✔
54
    }
55

56
    /// <summary>
57
    /// Sets the data type for the <see cref="Import.FieldDefinition"/>.
58
    /// </summary>
59
    /// <param name="value">The <see cref="Type"/> representing the field's data type.</param>
60
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
61
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is <c>null</c>.</exception>
62
    public FieldDefinitionBuilder DataType(Type value)
63
    {
64
        if (value == null)
1!
65
            throw new ArgumentNullException(nameof(value));
×
66

67
        FieldDefinition.DataType = value;
1✔
68

69
        return this;
1✔
70
    }
71

72
    /// <summary>
73
    /// Sets the data type for the <see cref="Import.FieldDefinition"/> using a generic type parameter.
74
    /// </summary>
75
    /// <typeparam name="T">The type to use as the field's data type.</typeparam>
76
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
77
    public FieldDefinitionBuilder DataType<T>()
78
    {
79
        FieldDefinition.DataType = typeof(T);
15✔
80
        return this;
15✔
81
    }
82

83
    /// <summary>
84
    /// Marks the field as a key field, which uniquely identifies records.
85
    /// When set to <c>true</c>, the field is also marked as required and cannot be updated.
86
    /// </summary>
87
    /// <param name="value"><c>true</c> to mark the field as a key; otherwise, <c>false</c>. Default is <c>true</c>.</param>
88
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
89
    public FieldDefinitionBuilder IsKey(bool value = true)
90
    {
91
        FieldDefinition.IsKey = value;
1✔
92

93
        if (!value)
1!
94
            return this;
1✔
95

96
        // defaults for a key field
NEW
97
        FieldDefinition.IsRequired = true;
×
NEW
98
        FieldDefinition.CanUpdate = false;
×
99

100
        return this;
×
101
    }
102

103
    /// <summary>
104
    /// Sets whether the field can be inserted during import operations.
105
    /// </summary>
106
    /// <param name="value"><c>true</c> if the field can be inserted; otherwise, <c>false</c>. Default is <c>true</c>.</param>
107
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
108
    public FieldDefinitionBuilder CanInsert(bool value = true)
109
    {
110
        FieldDefinition.CanInsert = value;
1✔
111
        return this;
1✔
112
    }
113

114
    /// <summary>
115
    /// Sets whether the field can be updated during import operations.
116
    /// </summary>
117
    /// <param name="value"><c>true</c> if the field can be updated; otherwise, <c>false</c>. Default is <c>true</c>.</param>
118
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
119
    public FieldDefinitionBuilder CanUpdate(bool value = true)
120
    {
121
        FieldDefinition.CanUpdate = value;
1✔
122
        return this;
1✔
123
    }
124

125
    /// <summary>
126
    /// Sets whether the field can be mapped by users during import configuration.
127
    /// </summary>
128
    /// <param name="value"><c>true</c> if the field can be mapped; otherwise, <c>false</c>. Default is <c>true</c>.</param>
129
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
130
    public FieldDefinitionBuilder CanMap(bool value = true)
131
    {
NEW
132
        FieldDefinition.CanMap = value;
×
133
        return this;
×
134
    }
135

136
    /// <summary>
137
    /// Sets whether the field is required for import. Required fields must be provided in the import data.
138
    /// </summary>
139
    /// <param name="value"><c>true</c> if the field is required; otherwise, <c>false</c>. Default is <c>true</c>.</param>
140
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
141
    public FieldDefinitionBuilder Required(bool value = true)
142
    {
143
        FieldDefinition.IsRequired = value;
5✔
144
        return this;
5✔
145
    }
146

147
    /// <summary>
148
    /// Sets the default value behavior for this field, as specified by <see cref="FieldDefault"/>.
149
    /// </summary>
150
    /// <param name="value">The <see cref="FieldDefault"/> option that determines how the default value is assigned.</param>
151
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
152
    public FieldDefinitionBuilder Default(FieldDefault? value)
153
    {
NEW
154
        FieldDefinition.Default = value;
×
155

156
        if (value.HasValue && value != FieldDefault.Static)
×
NEW
157
            FieldDefinition.CanMap = false;
×
158

159
        return this;
×
160
    }
161

162
    /// <summary>
163
    /// Sets a static default value for this field, used when <see cref="FieldDefault.Static"/> is selected.
164
    /// </summary>
165
    /// <param name="value">The static default value to assign to the field if no value is provided during import.</param>
166
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
167
    public FieldDefinitionBuilder Default(object value)
168
    {
NEW
169
        FieldDefinition.DefaultValue = value;
×
NEW
170
        FieldDefinition.Default = FieldDefault.Static;
×
171

172
        if (!Equals(value, null))
×
NEW
173
            FieldDefinition.CanMap = false;
×
174

175
        return this;
×
176
    }
177

178
    /// <summary>
179
    /// Adds a match or validation regular expression to the <see cref="Import.FieldDefinition"/>.
180
    /// These expressions can be used for mapping or validating field values during import.
181
    /// </summary>
182
    /// <param name="value">The regular expression pattern.</param>
183
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
184
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is <c>null</c>.</exception>
185
    public FieldDefinitionBuilder Expression(string value)
186
    {
187
        if (value == null)
×
188
            throw new ArgumentNullException(nameof(value));
×
189

NEW
190
        FieldDefinition.Expressions.Add(value);
×
191

192
        return this;
×
193
    }
194

195
    /// <summary>
196
    /// Adds multiple match or validation regular expressions to the <see cref="Import.FieldDefinition"/>.
197
    /// These expressions can be used for mapping or validating field values during import.
198
    /// </summary>
199
    /// <param name="values">A collection of regular expression patterns.</param>
200
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
201
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="values"/> is <c>null</c>.</exception>
202
    public FieldDefinitionBuilder Expressions(IEnumerable<string> values)
203
    {
204
        if (values == null)
×
205
            throw new ArgumentNullException(nameof(values));
×
206

NEW
207
        FieldDefinition.Expressions.AddRange(values);
×
208

209
        return this;
×
210
    }
211

212
    /// <summary>
213
    /// Sets the field translator type for the <see cref="Import.FieldDefinition"/>, used to transform or convert field values during import.
214
    /// </summary>
215
    /// <typeparam name="T">The type of translator implementing <see cref="IFieldTranslator"/>.</typeparam>
216
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
217
    [Obsolete("Use TranslatorKey(string) instead. This will be removed in a future version.")]
218
    public FieldDefinitionBuilder Translator<T>()
219
        where T : IFieldTranslator
220
    {
NEW
221
        FieldDefinition.Translator = typeof(T);
×
222
        return this;
×
223
    }
224

225
    /// <summary>
226
    /// Sets the dependency injection service key for accessing the field translator, which is used to transform or convert field values during import.
227
    /// The service must be registered in the DI container with this key and implement <see cref="IFieldTranslator"/>.
228
    /// </summary>
229
    /// <param name="value">The service key for the field translator.</param>
230
    /// <returns>The current <see cref="FieldDefinitionBuilder"/> instance for method chaining.</returns>
231
    public FieldDefinitionBuilder TranslatorKey(string value)
232
    {
NEW
233
        FieldDefinition.TranslatorKey = value;
×
NEW
234
        return this;
×
235
    }
236
}
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