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

loresoft / FluentCommand / 16300818838

15 Jul 2025 06:03PM UTC coverage: 54.951% (+0.3%) from 54.61%
16300818838

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%)

7 existing lines in 5 files now uncovered.

4361 of 7429 relevant lines covered (58.7%)

231.0 hits per line

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

0.0
/src/FluentCommand.SqlServer/Import/ImportValidator.cs
1
using System.ComponentModel.DataAnnotations;
2
using System.Data;
3

4
using FluentCommand.Extensions;
5

6
using HashCode = FluentCommand.Internal.HashCode;
7

8
namespace FluentCommand.Import;
9

10
/// <summary>
11
/// An import data validator
12
/// </summary>
13
public class ImportValidator : IImportValidator
14
{
NEW
15
    private readonly HashSet<int> _duplicateHash = [];
×
16

17
    /// <summary>
18
    /// Validates the specified <paramref name="targetRow" />.
19
    /// </summary>
20
    /// <param name="importDefinition">The import definition.</param>
21
    /// <param name="targetRow">The target row.</param>
22
    /// <returns></returns>
23
    public virtual Task ValidateRow(ImportDefinition importDefinition, DataRow targetRow)
24
    {
25
        // check for DBNull or null
26
        CheckForNull(importDefinition, targetRow);
×
27

28
        // look for duplicate key values
29
        CheckForDuplicate(importDefinition, targetRow);
×
30

31
        return Task.CompletedTask;
×
32
    }
33

34

35
    /// <summary>
36
    /// Checks specified <paramref name="targetRow" /> for null values.
37
    /// </summary>
38
    /// <param name="importDefinition">The import definition.</param>
39
    /// <param name="targetRow">The target row.</param>
40
    /// <exception cref="ValidationException">When a required field is null</exception>
41
    protected virtual void CheckForNull(ImportDefinition importDefinition, DataRow targetRow)
42
    {
43
        var requiredFields = importDefinition
×
44
            .Fields
×
45
            .Where(b => b.IsRequired || b.IsKey)
×
46
            .Select(b => b.Name)
×
47
            .ToList();
×
48

49
        // first null
50
        var invalidField = requiredFields
×
51
            .FirstOrDefault(targetRow.IsNull);
×
52

53
        if (!invalidField.HasValue())
×
54
            return;
×
55

56
        string message = "Field '{0}' can not be null. {1}"
×
57
            .FormatWith(invalidField, targetRow.ItemArray.ToDelimitedString());
×
58

59
        throw new ValidationException(message);
×
60
    }
61

62
    /// <summary>
63
    /// Checks specified <paramref name="targetRow" /> for key duplicates.
64
    /// </summary>
65
    /// <param name="importDefinition">The import definition.</param>
66
    /// <param name="targetRow">The target row.</param>
67
    /// <exception cref="ValidationException">When key is duplicate</exception>
68
    protected virtual void CheckForDuplicate(ImportDefinition importDefinition, DataRow targetRow)
69
    {
70
        var keyFields = importDefinition
×
71
            .Fields
×
72
            .Where(b => b.IsKey)
×
73
            .Select(b => b.Name)
×
74
            .ToList();
×
75

76
        var keyValues = keyFields
×
77
            .Select(k => targetRow[k])
×
78
            .ToList();
×
79

80
        // use a hash code of all the key values to check duplicate
81
        var hashCode = keyValues
×
82
            .Aggregate(HashCode.Seed, (hash, value) => hash.Combine(value));
×
83

84
        bool added = _duplicateHash.Add(hashCode);
×
85
        if (added)
×
86
            return;
×
87

88
        string message = "Duplicate key found.  Field: {0}, Value: {1}"
×
89
            .FormatWith(keyFields.ToDelimitedString(), keyValues.ToDelimitedString());
×
90

91
        throw new ValidationException(message);
×
92
    }
93
}
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