V10.5.3/code coverage bump#162
Conversation
- 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.
| return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new ByteArrayContent(Array.Empty<byte>()) | ||
| }); |
| 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 SummaryThis PR significantly expands unit test coverage across the library (36 new focused test classes), fixes a test ordering bug in
Confidence Score: 5/5All 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
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]
Prompt To Fix All With AIFix 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 |
- 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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:
CoverageTestapproach. New tests includeActionFactoryTest,FuncFactoryTest,WrapperTest,RegionInfoExtensionsTest,HierarchyTest,MvcBuilderExtensionsTest,LatencyExceptionTest,MailDistributorTest, and more. [1] [2] [3] [4] [5].github/copilot-instructions.mdwith clarifications on namespace conventions, base class usage, public facade testing, and best practices for test organization. [1] [2]Documentation and Coding Guidelines:
.github/copilot-instructions.mdprohibiting the use of theExcludeFromCodeCoverageattribute on any code, with rationale and alternative approaches for handling untestable code paths.Bug Fixes and Behavioral Improvements:
AssemblyContext.GetCurrentDomainAssembliesto 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]Wrapper<T>,HttpWatcher, andDatabaseWatcher, ensuring more robust error handling. [1] [2] [3]API and Usability Enhancements:
MvcCoreBuilderExtensions.AddJsonFormattersto make thesetupparameter optional, improving usability.HttpMethodConverterto 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]