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

loresoft / NLog.Mongo / 11217039547

07 Oct 2024 01:52PM UTC coverage: 61.67%. Remained the same
11217039547

push

github

web-flow
Create FUNDING.yml

125 of 230 branches covered (54.35%)

Branch coverage included in aggregate %.

200 of 297 relevant lines covered (67.34%)

21.21 hits per line

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

73.58
/src/NLog.Mongo/MongoField.cs
1
using System;
2
using System.ComponentModel;
3
using NLog.Config;
4
using NLog.Layouts;
5

6
namespace NLog.Mongo
7
{
8
    /// <summary>
9
    /// A configuration item for MongoDB target.
10
    /// </summary>
11
    [NLogConfigurationItem]
12
    [ThreadAgnostic]
13
    public sealed class MongoField
14
    {
15
        /// <summary>
16
        /// Initializes a new instance of the <see cref="MongoField"/> class.
17
        /// </summary>
18
        public MongoField()
19
            : this(null, null, "String")
21✔
20
        {
21
        }
21✔
22

23
        /// <summary>
24
        /// Initializes a new instance of the <see cref="MongoField"/> class.
25
        /// </summary>
26
        /// <param name="name">The name of the field.</param>
27
        /// <param name="layout">The layout used to generate the value for the field.</param>
28
        public MongoField(string name, Layout layout)
29
            : this(name, layout, "String")
×
30
        {
31
        }
×
32

33
        /// <summary>
34
        /// Initializes a new instance of the <see cref="MongoField" /> class.
35
        /// </summary>
36
        /// <param name="name">The name.</param>
37
        /// <param name="layout">The layout.</param>
38
        /// <param name="bsonType">The bson type.</param>
39
        public MongoField(string name, Layout layout, string bsonType)
21✔
40
        {
41
            Name = name;
21✔
42
            Layout = layout;
21✔
43
            BsonType = bsonType ?? "String";
21!
44
        }
21✔
45

46
        /// <summary>
47
        /// Gets or sets the name of the MongoDB field.
48
        /// </summary>
49
        /// <value>
50
        /// The name of the MongoDB field.
51
        /// </value>
52
        [RequiredParameter]
53
        public string Name { get; set; }
235✔
54

55
        /// <summary>
56
        /// Gets or sets the layout used to generate the value for the field.
57
        /// </summary>
58
        /// <value>
59
        /// The layout used to generate the value for the field.
60
        /// </value>
61
        [RequiredParameter]
62
        public Layout Layout { get; set; }
493✔
63

64
        /// <summary>
65
        /// Gets or sets the bson type of the field. Possible values are Boolean, DateTime, Double, Int32, Int64 and String
66
        /// </summary>
67
        /// <value>
68
        /// The bson type of the field..
69
        /// </value>
70
        [DefaultValue("String")]
71
        public string BsonType
72
        {
73
            get => _bsonType;
×
74
            set
75
            { 
76
                _bsonType = value;
29✔
77
                BsonTypeCode = ConvertToTypeCode(value?.Trim() ?? string.Empty);
29!
78
            }
29✔
79
        }
80
        private string _bsonType;
81

82
        internal TypeCode BsonTypeCode { get; private set; } = TypeCode.String;
204✔
83

84
        private TypeCode ConvertToTypeCode(string bsonType)
85
        {
86
            if (string.IsNullOrEmpty(bsonType) || string.Equals(bsonType, "String", StringComparison.OrdinalIgnoreCase))
29✔
87
                return TypeCode.String;
21✔
88

89
            if (string.Equals(bsonType, "Boolean", StringComparison.OrdinalIgnoreCase))
8!
90
                return TypeCode.Boolean;
×
91

92
            if (string.Equals(bsonType, "DateTime", StringComparison.OrdinalIgnoreCase))
8✔
93
                return TypeCode.DateTime;
1✔
94

95
            if (string.Equals(bsonType, "Double", StringComparison.OrdinalIgnoreCase))
7!
96
                return TypeCode.Double;
×
97

98
            if (string.Equals(bsonType, "Int32", StringComparison.OrdinalIgnoreCase))
7✔
99
                return TypeCode.Int32;
6✔
100

101
            if (string.Equals(bsonType, "Int64", StringComparison.OrdinalIgnoreCase))
1!
102
                return TypeCode.Int64;
×
103

104
            if (string.Equals(bsonType, "Object", StringComparison.OrdinalIgnoreCase))
1!
105
                return TypeCode.Object;
1✔
106

107
            return TypeCode.String;
×
108
        }
109
    }
110
}
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

© 2025 Coveralls, Inc