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

JaCraig / Mirage / 18607011349

17 Oct 2025 11:14PM UTC coverage: 88.111% (-0.9%) from 88.976%
18607011349

push

github

web-flow
Merge pull request #359 from JaCraig/dependabot/nuget/Mirage.Tests/dependencies-c829456dd6

chore: Bump the dependencies group with 1 update

546 of 860 branches covered (63.49%)

Branch coverage included in aggregate %.

3834 of 4111 relevant lines covered (93.26%)

47539.56 hits per line

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

47.73
/Mirage/Generators/Default/Nullable/NullableTimeSpanGenerator.cs
1
/*
2
Copyright 2017 James Craig
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
using Mirage.Generators.BaseClasses;
18
using Mirage.Interfaces;
19
using System;
20
using System.Collections.Generic;
21

22
namespace Mirage.Generators.Default.Nullable
23
{
24
    /// <summary>
25
    /// TimeSpan generator
26
    /// </summary>
27
    public class NullableTimeSpanGenerator : IGenerator<TimeSpan?>
28
    {
29
        /// <summary>
30
        /// Gets a value indicating whether this <see cref="IGenerator"/> is a default one.
31
        /// </summary>
32
        /// <value><c>true</c> if default; otherwise, <c>false</c>.</value>
33
        public bool Default => true;
2✔
34

35
        /// <summary>
36
        /// Gets the type generated.
37
        /// </summary>
38
        /// <value>The type generated.</value>
39
        public Type TypeGenerated => typeof(TimeSpan?);
3✔
40

41
        /// <summary>
42
        /// Generates a random value of the specified type
43
        /// </summary>
44
        /// <param name="rand">Random number generator that it can use</param>
45
        /// <returns>A randomly generated object of the specified type</returns>
46
        public TimeSpan? Next(Random rand)
47
        {
48
            return !(rand?.Next<bool>() ?? false) ? null : (TimeSpan?)rand.Next(TimeSpan.MinValue, TimeSpan.MaxValue);
104✔
49
        }
50

51
        /// <summary>
52
        /// Generates a random value of the specified type
53
        /// </summary>
54
        /// <param name="rand">Random number generator that it can use</param>
55
        /// <param name="min">Minimum value (inclusive)</param>
56
        /// <param name="max">Maximum value (inclusive)</param>
57
        /// <returns>A randomly generated object of the specified type</returns>
58
        public TimeSpan? Next(Random rand, TimeSpan? min, TimeSpan? max)
59
        {
60
            if (!(rand?.Next<bool>() ?? false))
2!
61
                return null;
2✔
62
            min ??= TimeSpan.MinValue;
×
63
            max ??= TimeSpan.MaxValue;
×
64
            return rand.Next(min.Value, max.Value);
×
65
        }
66

67
        /// <summary>
68
        /// Generates next object
69
        /// </summary>
70
        /// <param name="rand">Random number generator</param>
71
        /// <param name="previouslySeen">The previously seen.</param>
72
        /// <returns>The next object</returns>
73
        public object? NextObj(Random rand, List<object> previouslySeen)
74
        {
75
            return !(rand?.Next<bool>() ?? false) ? null : (object)rand.Next(TimeSpan.MinValue, TimeSpan.MaxValue);
6,223✔
76
        }
77
    }
78

79
    /// <summary>
80
    /// NullableTimeSpan generator
81
    /// </summary>
82
    /// <seealso cref="GeneratorAttributeBase"/>
83
    public sealed class NullableTimeSpanGeneratorAttribute : GeneratorAttributeBase
84
    {
85
        /// <summary>
86
        /// Constructor
87
        /// </summary>
88
        public NullableTimeSpanGeneratorAttribute()
89
            : base(TimeSpan.MinValue.ToString(), TimeSpan.MaxValue.ToString())
×
90
        {
91
        }
×
92

93
        /// <summary>
94
        /// Initializes a new instance of the <see cref="NullableTimeSpanGeneratorAttribute"/> class.
95
        /// </summary>
96
        /// <param name="min">The minimum.</param>
97
        /// <param name="max">The maximum.</param>
98
        public NullableTimeSpanGeneratorAttribute(string min, string max)
99
            : base(min, max)
1✔
100
        {
101
        }
1✔
102

103
        /// <summary>
104
        /// Gets a value indicating whether this <see cref="IGenerator"/> is a default one.
105
        /// </summary>
106
        /// <value><c>true</c> if default; otherwise, <c>false</c>.</value>
107
        public override bool Default => true;
1✔
108

109
        /// <summary>
110
        /// Gets the type generated.
111
        /// </summary>
112
        /// <value>The type generated.</value>
113
        public override Type TypeGenerated => typeof(TimeSpan?);
1✔
114

115
        /// <summary>
116
        /// Generates next object
117
        /// </summary>
118
        /// <param name="rand">Random number generator</param>
119
        /// <param name="previouslySeen">The previously seen.</param>
120
        /// <returns>The next object</returns>
121
        public override object? NextObj(Random rand, List<object> previouslySeen)
122
        {
123
            if (Min is null || Max is null)
×
124
                return null;
×
125
            _ = TimeSpan.TryParse((string)Min, out var TempMin);
×
126
            _ = TimeSpan.TryParse((string)Max, out var TempMax);
×
127
            return !(rand?.Next<bool>() ?? false) ? null : (object)rand.Next(TempMin, TempMax);
×
128
        }
129
    }
130
}
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