• 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

41.67
/Mirage/Generators/Default/TimeSpanGeneratorAttribute.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
23
{
24
    /// <summary>
25
    /// TimeSpan generator
26
    /// </summary>
27
    /// <seealso cref="IGenerator{TimeSpan}"/>
28
    public class TimeSpanGenerator : IGenerator<TimeSpan>
29
    {
30
        /// <summary>
31
        /// Gets a value indicating whether this <see cref="IGenerator"/> is a default one.
32
        /// </summary>
33
        /// <value><c>true</c> if default; otherwise, <c>false</c>.</value>
34
        public bool Default => true;
2✔
35

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

42
        /// <summary>
43
        /// Generates a random value of the specified type
44
        /// </summary>
45
        /// <param name="rand">Random number generator that it can use</param>
46
        /// <returns>A randomly generated object of the specified type</returns>
47
        public TimeSpan Next(Random rand) => Next(rand, TimeSpan.MinValue, TimeSpan.MaxValue);
2✔
48

49
        /// <summary>
50
        /// Generates a random value of the specified type
51
        /// </summary>
52
        /// <param name="rand">Random number generator that it can use</param>
53
        /// <param name="min">Minimum value (inclusive)</param>
54
        /// <param name="max">Maximum value (inclusive)</param>
55
        /// <returns>A randomly generated object of the specified type</returns>
56
        public TimeSpan Next(Random rand, TimeSpan min, TimeSpan max)
57
        {
58
            if (min > max)
7,981!
59
            {
60
                (max, min) = (min, max);
×
61
            }
62
            return min + new TimeSpan((long)(new TimeSpan(max.Ticks - min.Ticks).Ticks * (rand?.NextDouble() ?? 0)));
7,981✔
63
        }
64

65
        /// <summary>
66
        /// Generates next object
67
        /// </summary>
68
        /// <param name="rand">Random number generator</param>
69
        /// <param name="previouslySeen">The previously seen.</param>
70
        /// <returns>The next object</returns>
71
        public object NextObj(Random rand, List<object> previouslySeen) => TimeSpan.MinValue != default || TimeSpan.MaxValue != default ? Next(rand, TimeSpan.MinValue, TimeSpan.MaxValue) : (object)Next(rand);
4,789!
72
    }
73

74
    /// <summary>
75
    /// TimeSpan generator
76
    /// </summary>
77
    /// <seealso cref="GeneratorAttributeBase"/>
78
    public sealed class TimeSpanGeneratorAttribute : GeneratorAttributeBase
79
    {
80
        /// <summary>
81
        /// Constructor
82
        /// </summary>
83
        public TimeSpanGeneratorAttribute()
84
            : base(TimeSpan.MinValue.ToString(), TimeSpan.MaxValue.ToString())
×
85
        {
86
        }
×
87

88
        /// <summary>
89
        /// Initializes a new instance of the <see cref="TimeSpanGeneratorAttribute"/> class.
90
        /// </summary>
91
        /// <param name="min">The minimum.</param>
92
        /// <param name="max">The maximum.</param>
93
        public TimeSpanGeneratorAttribute(string min, string max)
94
            : base(min, max)
1✔
95
        {
96
        }
1✔
97

98
        /// <summary>
99
        /// Gets a value indicating whether this <see cref="IGenerator"/> is a default one.
100
        /// </summary>
101
        /// <value><c>true</c> if default; otherwise, <c>false</c>.</value>
102
        public override bool Default => true;
1✔
103

104
        /// <summary>
105
        /// Gets the type generated.
106
        /// </summary>
107
        /// <value>The type generated.</value>
108
        public override Type TypeGenerated => typeof(TimeSpan);
1✔
109

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