• 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

92.86
/Mecha.Core/Datasources/Defaults/DefaultSerializer.cs
1
/*
2
Copyright 2021 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 Mecha.Core.Datasources.Interfaces;
18
using Mecha.Core.ExtensionMethods;
19
using System;
20
using System.Text.Json;
21

22
namespace Mecha.Core.Datasources.Defaults
23
{
24
    /// <summary>
25
    /// Default serializer (goes to JSON)
26
    /// </summary>
27
    /// <seealso cref="ISerializer"/>
28
    public class DefaultSerializer : ISerializer
29
    {
30
        /// <summary>
31
        /// Deserializes the specified data.
32
        /// </summary>
33
        /// <param name="objectType">Type of the object.</param>
34
        /// <param name="data">The data.</param>
35
        /// <returns>The deserialized value.</returns>
36
        public object? Deserialize(Type objectType, string? data)
37
        {
38
            if (string.IsNullOrWhiteSpace(data))
8✔
39
                return null;
6✔
40
            try
41
            {
42
                return JsonSerializer.Deserialize(data, objectType);
2✔
43
            }
UNCOV
44
            catch { return null; }
×
45
        }
2✔
46

47
        /// <summary>
48
        /// Serializes the specified data.
49
        /// </summary>
50
        /// <param name="objectType">Type of the object.</param>
51
        /// <param name="data">The data.</param>
52
        /// <returns>The serialized value used for storage.</returns>
53
        public string? Serialize(Type objectType, object? data)
54
        {
55
            if (data.IsInfinite())
12✔
56
                data = 0;
4✔
57
            try
58
            {
59
                return JsonSerializer.Serialize(data, objectType);
12✔
60
            }
61
            catch { return ""; }
12✔
62
        }
12✔
63
    }
64
}
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