Skip to content

V10.5.3/code coverage bump#162

Merged
gimlichael merged 13 commits into
mainfrom
v10.5.3/code-coverage-bump
Jun 3, 2026
Merged

V10.5.3/code coverage bump#162
gimlichael merged 13 commits into
mainfrom
v10.5.3/code-coverage-bump

Conversation

@gimlichael
Copy link
Copy Markdown
Member

This pull request significantly expands unit test coverage across the library, introduces new focused test classes for various components, and improves documentation and code quality. It also includes several targeted code improvements and bug fixes, particularly in core utilities, extension methods, and data infrastructure. Additionally, it enhances internal documentation and coding guidelines to discourage the exclusion of code from coverage metrics.

Test Coverage Expansion and Improvements:

  • Added 36 new, focused unit test classes covering core utilities, extension methods, serialization, resilience, threading, mail, and data infrastructure, replacing the previous generic CoverageTest approach. New tests include ActionFactoryTest, FuncFactoryTest, WrapperTest, RegionInfoExtensionsTest, HierarchyTest, MvcBuilderExtensionsTest, LatencyExceptionTest, MailDistributorTest, and more. [1] [2] [3] [4] [5]
  • Enhanced test guidelines in .github/copilot-instructions.md with clarifications on namespace conventions, base class usage, public facade testing, and best practices for test organization. [1] [2]

Documentation and Coding Guidelines:

  • Added a new section to .github/copilot-instructions.md prohibiting the use of the ExcludeFromCodeCoverage attribute on any code, with rationale and alternative approaches for handling untestable code paths.

Bug Fixes and Behavioral Improvements:

  • Fixed AssemblyContext.GetCurrentDomainAssemblies to clarify and document the effect of loading referenced assemblies, and improved the corresponding test to assert that including referenced assemblies does not omit any assemblies present when not including them. [1] [2]
  • Improved null argument validation in constructors and methods for Wrapper<T>, HttpWatcher, and DatabaseWatcher, ensuring more robust error handling. [1] [2] [3]

API and Usability Enhancements:

  • Changed MvcCoreBuilderExtensions.AddJsonFormatters to make the setup parameter optional, improving usability.
  • Improved HttpMethodConverter to use a case-insensitive dictionary for string-to-enum mapping, ensuring correct HTTP method resolution regardless of input case.

References: [1] [2] [3] [4] [5]

gimlichael and others added 8 commits June 3, 2026 16:44
- Add 36 new test files covering core utilities, extension methods,
  serialization, resilience, and threading components
- Fix Wrapper<T> to throw ArgumentNullException for null instance
- Fix HttpMethodConverter lookup table to be case-insensitive
- Fix HttpWatcher to null-guard the location parameter
- Make IMvcCoreBuilder.AddJsonFormatters setup parameter optional

Assemblies now at or above 95% line coverage:
  Cuemon.Data                                      97.58%
  Cuemon.Data.Integrity                            99.29%
  Cuemon.Extensions.AspNetCore.Mvc.Formatters.Text.Json  100%
  Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml  100%
  Cuemon.Extensions.Core                           97.27%
  Cuemon.Extensions.Data.Integrity                100%
  Cuemon.Extensions.Hosting                       100%
  Cuemon.Extensions.Net                            99.50%
  Cuemon.Extensions.Xml                            95.72%
  Cuemon.Net                                       95.97%
  Cuemon.Resilience                               100%
  Cuemon.Threading                                 96.78%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update 10.5.3 release notes to clarify the scope of new unit test additions: 36 focused SUT-specific test classes replacing generic CoverageTest approach. Emphasizes focused test organization and public facade testing patterns per updated guidelines.
Add XML documentation remarks to GetCurrentDomainAssemblies() explaining that setting IncludeReferencedAssemblies to true may load referenced assemblies and change results from AppDomain.GetAssemblies(). Clarifies the behavioral impact for users of this API.
Delete generic CoverageTest.cs files from Cuemon.Data.Tests and Cuemon.Net.Tests.Http. These have been replaced by focused, SUT-specific unit test classes that follow the per-class testing pattern, improving test maintainability and clarity.
Refactor While/WhileAsync loop conditions in parallel factory tests to use Count > 0 instead of TryPeek(out _). This makes test intent clearer and eliminates unnecessary out-parameter usage, improving readability and maintainability of test code.
Update GetCurrentDomainAssemblies test to verify that referenced assemblies are included when requested. Change assertion from >= comparison to Except() validation, ensuring no assembly is lost when IncludeReferencedAssemblies option is enabled. Improves test precision and behavior verification.
Introduce 8 focused, SUT-specific unit test classes covering core data infrastructure: DataManager, DataReader, DataStatement, DataTransfer, InOperator, QueryBuilder, and TokenBuilder. Tests follow the public facade testing pattern, verifying behavior through public APIs rather than internal implementation details.
Introduce 4 focused, SUT-specific unit test classes for HTTP client dependencies: HttpDependency, HttpManager, HttpMethodConverter, and HttpWatcher. Tests follow the public facade testing pattern and replace the generic CoverageTest approach, improving maintainability and clarity of HTTP infrastructure test coverage.
@gimlichael gimlichael self-assigned this Jun 3, 2026
Comment on lines +182 to +185
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(Array.Empty<byte>())
});
Comment on lines +114 to +117
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(Array.Empty<byte>())
});
[Fact]
public async Task WithFuncAsync_ShouldReturnExpectedValues_WhenUsingZeroOneFourAndFiveArgumentOverloads()
{
var token = new CancellationTokenSource().Token;
[Fact]
public async Task WithActionAsync_ShouldCaptureExpectedValues_WhenUsingZeroOneFourAndFiveArgumentOverloads()
{
var token = new CancellationTokenSource().Token;
public async Task SafeInvokeAsync_ShouldSupportAllOverloads_WhenTesterSucceeds()
{
var actual = new List<string>();
var cts = new CancellationTokenSource();
[Fact]
public void For_ShouldRunConcurrently_WhenConfiguredWithMultiplePartitions()
{
var ready = new CountdownEvent(3);
[Fact]
public async Task ForAsync_ShouldRunConcurrently_WhenConfiguredWithMultiplePartitions()
{
var ready = new CountdownEvent(3);

var handler = factory.CreateHandler("expiring");
handler = null;
GC.Collect();
handler = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

var replacement = factory.CreateHandler("expiring");
replacement = null;
GC.Collect();
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 3, 2026

Greptile Summary

This PR significantly expands unit test coverage across the library (36 new focused test classes), fixes a test ordering bug in AssemblyContextTest, and delivers several targeted source improvements. The production-side changes are small and surgical.

  • Null guards added to Wrapper<T>, HttpWatcher, CollectionExtensions.ToPartitioner, and CollectionExtensions.AddRange — consistent with the existing Validator.ThrowIfNull pattern; two of the four new guards are missing <exception> XML doc entries (continuing a pattern flagged for Wrapper.cs and MvcCoreBuilderExtensions.cs in the previous review).
  • HttpMethodConverter now uses a case-insensitive dictionary, and MvcCoreBuilderExtensions.AddJsonFormatters makes setup optional — both are clean, backward-compatible improvements.
  • AssemblyContextTest ordering fix (fetch withoutRefs before withRefs) correctly eliminates a flaky assertion caused by side-effect assembly loading.

Confidence Score: 5/5

All production changes are small, additive null guards and a case-insensitive dictionary fix — no behavioural regressions expected.

The source changes are minimal and well-tested by the accompanying new test classes. The null guards follow the established Validator.ThrowIfNull pattern, HttpMethodConverter gains robustness without breaking existing callers, and AssemblyContextTest correctly fixes a test ordering dependency. No logic regressions or data-loss paths were identified.

src/Cuemon.Extensions.Collections.Generic/CollectionExtensions.cs and src/Cuemon.Net/Http/HttpWatcher.cs are missing XML exception documentation for the newly added null guards.

Important Files Changed

Filename Overview
src/Cuemon.Net/Http/HttpWatcher.cs Adds null guard for location parameter; constructor XML doc is missing the <exception> element for ArgumentNullException
src/Cuemon.Extensions.Collections.Generic/CollectionExtensions.cs Adds null guards to ToPartitioner and AddRange(IEnumerable<T>); XML docs for both methods are missing <exception cref="ArgumentNullException"> entries
src/Cuemon.Extensions.Core/Wrapper.cs Adds null guard and XML doc exception to Wrapper<T> constructor; guard is correct because the old code would NullRef on instance.GetType() anyway
src/Cuemon.Net/Http/HttpMethodConverter.cs Switches string-to-enum lookup dictionary to StringComparer.OrdinalIgnoreCase, ensuring case-insensitive HTTP method resolution
src/Cuemon.Extensions.AspNetCore.Mvc.Formatters.Text.Json/MvcCoreBuilderExtensions.cs Makes setup parameter optional (default null); removes stale null exception doc for setup (flagged in previous review)
src/Cuemon.Core/Reflection/AssemblyContext.cs Adds <remarks> documenting side-effect of loading referenced assemblies into the AppDomain
test/Cuemon.Core.Tests/Reflection/AssemblyContextTest.cs Fixes test ordering bug: now fetches withoutRefs before withRefs so the baseline isn't contaminated by assembly loading side-effects
test/Cuemon.Net.Tests/Http/HttpWatcherTest.cs New test covering ETag, Last-Modified, body-checksum, invalid-response, and null-location paths for HttpWatcher
test/Cuemon.Extensions.Core.Tests/WrapperTest.cs New test covering null-guard, instance parsing, metadata, and string-formatting paths for Wrapper<T>
test/Cuemon.Extensions.AspNetCore.Mvc.Formatters.Text.Json.Tests/MvcCoreBuilderExtensionsTest.cs New integration test verifying JSON formatters are registered and functional via AddJsonFormatters() with no argument

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[HttpWatcher constructor] --> B{location == null?}
    B -- yes --> C[ArgumentNullException thrown]
    B -- no --> D[Configure options & assign fields]
    D --> E[HandleSignalingAsync called]
    E --> F{ReadResponseBody?}
    F -- yes --> G[FetchUsingHttpGetAsync\ncompute body checksum]
    F -- no --> H[FetchUsingHttpHeadAsync\ncheck ETag / Last-Modified]
    G --> I{Checksum changed?}
    I -- yes --> J[OnChangedRaised]
    I -- no --> K[No event]
    H --> L{Last-Modified present?}
    L -- yes --> J
    L -- no --> M{ETag present?}
    M -- yes --> N{ETag changed?}
    N -- yes --> J
    N -- no --> K
    M -- no --> O[InvalidOperationException]
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
src/Cuemon.Extensions.Collections.Generic/CollectionExtensions.cs:11-51
**Missing `ArgumentNullException` XML documentation on null-guarded methods**

Both `ToPartitioner` and `AddRange(IEnumerable<T>)` received `Validator.ThrowIfNull` guards in this PR, but neither method's XML doc block documents the thrown `ArgumentNullException`. Callers reading IntelliSense or generated API docs won't be informed of the preconditions. This is the same pattern flagged on `Wrapper.cs` and `MvcCoreBuilderExtensions.cs` in the previous review.

`ToPartitioner` needs `<exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>`, and `AddRange(IEnumerable<T>)` needs the same for both `collection` and `source`.

### Issue 2 of 2
src/Cuemon.Net/Http/HttpWatcher.cs:19-27
**Missing `ArgumentNullException` XML documentation on constructor**

`Validator.ThrowIfNull(location)` was added to the constructor body, but the constructor's XML doc block has no `<exception cref="ArgumentNullException">` entry documenting when it is thrown. This is the same pattern flagged for `Wrapper.cs` and `MvcCoreBuilderExtensions.cs`. An `<exception cref="ArgumentNullException"><paramref name="location"/> is null.</exception>` element should be added to the constructor doc.

Reviews (4): Last reviewed commit: "✅ add unit tests for slimhttpclientfacto..." | Re-trigger Greptile

gimlichael and others added 5 commits June 3, 2026 19:55
- Cuemon.Core: EradicateTest, ExceptionInsightsTest, MutableTupleFactoryTest,
  StringFactoryTest, WatcherTest, GenerateTest updates, StringReplacePairTest updates
- Cuemon.IO: StreamFactoryTest, StreamOptionsTest, TextReaderDecoratorExtensionsTest
- Cuemon.Xml: XmlDocumentFactoryTest, XPathDocumentFactoryTest, and extensions tests for
  Stream, String, XmlReader, XmlWriter, Linq.String decorators
- Cuemon.Diagnostics: FaultResolverTest, TimeMeasureTest updates
- Cuemon.Runtime.Caching: CacheEntryTest, CacheEntryEventArgsTest, CacheInvalidationTest,
  SlimMemoryCacheCoverageTest
- Cuemon.Extensions.Collections.Generic: QueueExtensionsTest, collection extension updates
- Cuemon.Extensions.Runtime.Caching: CacheEnumerableExtensionsCoverageTest
- Cuemon.Extensions.Text.Json: JsonConverterCollectionExtensionsCoverageTest,
  StringEnumConverterTest, StringFlagsEnumConverterTest, DynamicJsonConverterTest,
  JsonNamingPolicyExtensionsTest, JsonSerializerOptionsExtensionsTest, net48 TFM added
- Cuemon.AspNetCore: MiddlewareTest, HttpStatusCodeExceptionTest, InternalServerErrorExceptionTest,
  HttpRequestDecoratorExtensionsTest, HttpResponseDecoratorExtensionsTest,
  HeaderDictionaryDecoratorExtensionsTest, Int32DecoratorExtensionsTest,
  HttpRequestEvidenceTest, HttpExceptionDescriptorDecoratorExtensionsTest,
  HttpExceptionDescriptorResponseFormatterTest, DynamicCacheBustingTest
- Cuemon.AspNetCore.Mvc: BreadcrumbTest, ResultClassesTest, ConfigurableFilterBaseTest,
  MvcFaultDescriptorOptionsTest, HttpCacheHeaderOptionsTest, HttpEntityTagHeaderFilterTest,
  DisableModelBindingAttributeTest, FormatterBaseTest
- Cuemon.AspNetCore.Authentication: AuthenticatorTest, AuthenticationHandlerFeatureTest,
  MemoryNonceTrackerTest, NonceTrackerEntryTest, DigestHashFactoryTest, MiddlewareConstructorTest
- Cuemon.Extensions.AspNetCore: ApplicationBuilderExtensionsTest, ServiceCollectionExtensionsCoverageTest,
  Headers/ServiceCollectionExtensionsTest, Headers/ApplicationBuilderExtensionsTest,
  Headers/EntityTagCacheableValidatorTest, Throttling/ServiceCollectionExtensionsTest,
  Throttling/ApplicationBuilderExtensionsTest, HttpExceptionDescriptorResponseFormatterExtensionsTest,
  XmlConverterExtensionsTest
- Cuemon.Extensions.AspNetCore.Mvc: FilterCollectionExtensionsTest, MvcBuilderExtensionsTest
- Cuemon.Extensions.AspNetCore.Authentication: AuthorizationResponseHandlerOptionsTest
- src fix: CollectionExtensions null guards (Cuemon.Extensions.Collections.Generic)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔥 Remove obsolete placeholder test files:
  - ServiceCollectionExtensionsCoverageTest
  - Cuemon.Extensions.Net coverage tests
  - Cuemon.Extensions.Runtime.Caching coverage test
  - Cuemon.Extensions.Text.Json converter coverage test
  - Cuemon.Extensions.Xml coverage tests (4 files)
  - Cuemon.Net coverage test
  - SlimMemoryCache coverage test

✅ Add comprehensive unit tests for extension methods:
  - HttpMethodExtensionsTest
  - SlimHttpClientFactoryTest
  - HttpStatusCodeExtensionsTest
  - StringExtensionsTest
  - HierarchyExtensionsTest
  - XElementExtensionsTest
  - XmlConverterExtensionsTest
  - XmlSerializerOptionsExtensionsTest
  - XmlExtensionsTest
  - ByteArrayDecoratorExtensionsTest

♻️ Refactor and enhance existing tests:
  - ServiceCollectionExtensionsTest
  - UriExtensionsTest
  - CacheEnumerableExtensionsTest
  - JsonConverterCollectionExtensionsTest
  - SlimMemoryCacheTest
  - Cuemon.Extensions.Text.Json.Tests.csproj updates

📝 Update documentation:
  - AGENTS.md workflow guidance
  - CHANGELOG.md release notes
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.19%. Comparing base (36e50ca) to head (5a5a2ab).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #162       +/-   ##
===========================================
+ Coverage   82.80%   94.19%   +11.39%     
===========================================
  Files         602      602               
  Lines       19157    19186       +29     
  Branches     2001     2009        +8     
===========================================
+ Hits        15863    18073     +2210     
+ Misses       3216     1049     -2167     
+ Partials       78       64       -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gimlichael gimlichael merged commit 271aa02 into main Jun 3, 2026
315 checks passed
@gimlichael gimlichael deleted the v10.5.3/code-coverage-bump branch June 3, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants