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

JaCraig / Mecha / 12871043181

20 Jan 2025 03:17PM UTC coverage: 81.554% (-0.3%) from 81.902%
12871043181

push

github

JaCraig
feat(core): enhance exception handling and refactor code

This commit introduces several enhancements and refactorings across multiple files to improve exception handling, code readability, and consistency.

- Added `ArgumentThrowingClass` to `ExceptionHandlerTests.cs` to test `ArgumentNullException.ThrowIfNull`.
- Added two new test methods `IgnoreException` and `IgnoreExceptionCalledFromDotThrowsX` in `ExceptionHandlerTests.cs`.
- Updated `coverlet.msbuild` and `coverlet.collector` package versions in `Mecha.Core.Tests.csproj` from `6.0.3` to `6.0.4`.
- Replaced array initialization using `Array.Empty<T>()` with `[]` in multiple files for brevity.
- Modified `ExceptionHandler` class to handle nullable exceptions and methods, and added a new method `IsFromThrowsMethodOnException`. This check looks for exceptions that are thrown by calling the .ThrowIfX methods on exception types.
- Updated `Services` class to use nullable `IServiceProvider` and renamed `ServiceProviderLock` to `_ServiceProviderLock`.
- Refactored constructors in `FileStreamGenerator`, `HttpClientGenerator`, `SpecialGenerator`, and `StreamGenerator` to use new C# 9.0 record-like syntax.
- Updated `GeneratorManager` constructor to use new C# 9.0 record-like syntax and replaced array initialization with `[.. generators.OrderBy(x => x.Order)]`.
- Changed `ParameterValues` class to handle nullable `ParameterValue` and refactored the `Same` method for better readability.
- Updated `Mech` class to handle nullable `ServiceProvider`.
- Refactored `AttemptToSubstitute` method in `Mech` class to use new C# 9.0 collection initialization syntax.
- Updated `MutatorManager` constructor to use new C# 9.0 collection initialization syntax.
- Changed `RunnerBaseClass` constructor to public and updated `DefaultRunner` to use it.
- Updated `MethodInvoker<TTarget>` to use a constructor with `MethodInfo` parameter.
- Changed loop variable names for consistency.
- Updated several methods to use shorthand ar... (continued)

745 of 1052 branches covered (70.82%)

Branch coverage included in aggregate %.

94 of 109 new or added lines in 22 files covered. (86.24%)

2 existing lines in 2 files now uncovered.

1333 of 1496 relevant lines covered (89.1%)

6421052.13 hits per line

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

88.24
/Mecha.Core/Generator/ParameterValues.cs
1
using BigBook;
2
using Mecha.Core.ExtensionMethods;
3
using System.Collections.Generic;
4
using System.ComponentModel.DataAnnotations;
5
using System.Linq;
6
using System.Reflection;
7
using System.Text.Json;
8

9
namespace Mecha.Core.Generator
10
{
11
    /// <summary>
12
    /// Parameter values
13
    /// </summary>
14
    public class ParameterValues
15
    {
16
        /// <summary>
17
        /// Initializes a new instance of the <see cref="ParameterValues"/> class.
18
        /// </summary>
19
        /// <param name="parameter">The parameter.</param>
20
        public ParameterValues(ParameterInfo parameter)
492✔
21
        {
22
            Parameter = parameter;
492✔
23
            ValidationAttributes = Parameter?.GetCustomAttributes<ValidationAttribute>() ?? [];
492!
24
        }
492✔
25

26
        /// <summary>
27
        /// Gets the generated values.
28
        /// </summary>
29
        /// <value>The generated values.</value>
30
        public List<ParameterValue> GeneratedValues { get; } = [];
205,689,332✔
31

32
        /// <summary>
33
        /// Gets or sets the parameter.
34
        /// </summary>
35
        /// <value>The parameter.</value>
36
        public ParameterInfo? Parameter { get; set; }
300,880,805✔
37

38
        /// <summary>
39
        /// Gets the validation attributes.
40
        /// </summary>
41
        /// <value>The validation attributes.</value>
42
        private IEnumerable<ValidationAttribute> ValidationAttributes { get; }
421,700✔
43

44
        /// <summary>
45
        /// Adds the value specified if it is valid.
46
        /// </summary>
47
        /// <param name="value">The value.</param>
48
        public void AddValue(ParameterValue? value)
49
        {
50
            if (value is null)
23,601,834!
NEW
51
                return;
×
52
            if (GeneratedValues.Any(x => x.Value == value.Value) || ValidationAttributes.Any(x => !x.IsValid(value.Value)))
48,152,903✔
53
                return;
23,180,262✔
54
            _ = GeneratedValues.AddIfUnique(Same, value);
421,572✔
55
        }
421,572✔
56

57
        /// <summary>
58
        /// Determines if the 2 arrays are the same.
59
        /// </summary>
60
        /// <param name="paramValue1">The parameter value1.</param>
61
        /// <param name="paramValue2">The parameter value2.</param>
62
        /// <returns>True if they are, false otherwise.</returns>
63
        private bool Same(ParameterValue paramValue1, ParameterValue paramValue2)
64
        {
65
            var Value1 = paramValue1.Value;
906,468✔
66
            var Value2 = paramValue2.Value;
906,468✔
67
            if (Value1.IsInfinite() && Value2.IsInfinite())
906,468✔
68
                return true;
23,334✔
69
            if (Value1.IsInfinite() || Value2.IsInfinite())
883,134✔
70
                return false;
93,340✔
71
            try
72
            {
73
                return (Value1 is null && Value2 is null)
789,794!
74
                    || (Value1 is not null
789,794✔
75
                        && Value2 is not null
789,794✔
76
                        && JsonSerializer.Serialize(Value1) == JsonSerializer.Serialize(Value2));
789,794✔
77
            }
78
            catch { return false; }
2,176✔
79
        }
789,794✔
80
    }
81
}
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