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

loresoft / FluentCommand / 6497765030

12 Oct 2023 03:22PM UTC coverage: 51.463% (+0.5%) from 50.964%
6497765030

push

github

web-flow
Merge pull request #306 from loresoft/feature/services

Feature/services

979 of 2448 branches covered (0.0%)

Branch coverage included in aggregate %.

213 of 213 new or added lines in 8 files covered. (100.0%)

2890 of 5070 relevant lines covered (57.0%)

156.2 hits per line

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

96.15
/src/FluentCommand/DataQueryFormatter.cs
1
using System.Data;
2

3
using FluentCommand.Internal;
4

5
namespace FluentCommand;
6

7
/// <summary>
8
/// A class to format an <see cref="IDbCommand"/> for logging
9
/// </summary>
10
public class DataQueryFormatter
11
    : IDataQueryFormatter
12
{
13
    /// <summary>
14
    /// Formats the command for logging.
15
    /// </summary>
16
    /// <param name="command">The command to log.</param>
17
    /// <param name="duration">The execution duration.</param>
18
    /// <param name="exception">The exception thrown when executing the command.</param>
19
    /// <returns>The command formatted as a string</returns>
20
    /// <exception cref="System.ArgumentNullException">command</exception>
21
    public string FormatCommand(IDbCommand command, TimeSpan duration, Exception exception)
22
    {
23
        if (command == null)
140!
24
            throw new ArgumentNullException(nameof(command));
×
25

26
        var elapsed = duration.TotalMilliseconds;
140✔
27
        var commandType = command.CommandType;
140✔
28
        var commandTimeout = command.CommandTimeout;
140✔
29
        var resultText = exception == null ? "Executed" : "Error Executing";
140✔
30

31
        var buffer = StringBuilderCache.Acquire();
140✔
32

33
        buffer
140✔
34
            .Append(resultText)
140✔
35
            .Append(" DbCommand (")
140✔
36
            .Append(elapsed)
140✔
37
            .Append("ms) [CommandType='")
140✔
38
            .Append(commandType)
140✔
39
            .Append("', CommandTimeout='")
140✔
40
            .Append(commandTimeout)
140✔
41
            .Append("']")
140✔
42
            .AppendLine()
140✔
43
            .AppendLine(command.CommandText);
140✔
44

45
        foreach (IDataParameter parameter in command.Parameters)
888✔
46
        {
47
            int precision = 0;
304✔
48
            int scale = 0;
304✔
49
            int size = 0;
304✔
50

51
            if (parameter is IDbDataParameter dataParameter)
304✔
52
            {
53
                precision = dataParameter.Precision;
304✔
54
                scale = dataParameter.Scale;
304✔
55
                size = dataParameter.Size;
304✔
56
            }
57

58
            buffer
304✔
59
                .Append("-- ")
304✔
60
                .Append(parameter.ParameterName)
304✔
61
                .Append(": ")
304✔
62
                .Append(parameter.Direction)
304✔
63
                .Append(" ")
304✔
64
                .Append(parameter.DbType)
304✔
65
                .Append("(Size=")
304✔
66
                .Append(size)
304✔
67
                .Append("; Precision=")
304✔
68
                .Append(precision)
304✔
69
                .Append("; Scale=")
304✔
70
                .Append(scale)
304✔
71
                .Append(") [")
304✔
72
                .Append(parameter.Value)
304✔
73
                .Append("]")
304✔
74
                .AppendLine();
304✔
75
        }
76

77
        return StringBuilderCache.ToString(buffer);
140✔
78
    }
79

80
}
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