-
Notifications
You must be signed in to change notification settings - Fork 1
V9.1.0/fixture enhancements #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… (latter allows for Assert.Throws*)
|
Caution Review failedThe pull request is closed. WalkthroughThis PR introduces multiple improvements across documentation, host initialization, logging, and testing. A documentation link has been added to the README. The host fixture startup is simplified with a new method ( Changes
Sequence Diagram(s)sequenceDiagram
participant T as Test
participant HF as HostFixture
participant CH as StartConfiguredHost
participant Cfg as Configuration
T->>HF: Check HasValidState()
alt Fixture not valid
HF->>HF: Set ConfigureHost, Configure, Services, & Application callbacks
HF->>CH: Call StartConfiguredHost()
CH-->>HF: Host started (blocking/async)
HF->>T: Provide Host, ServiceProvider, Application
T->>Cfg: Call Configure(configuration, environment)
else Fixture valid
HF-->>T: Existing Host state provided
end
sequenceDiagram
participant Test as WebHostTestFactoryTest
participant WHF as WebHostTestFactory
participant HostF as HostFixture
Test->>WHF: Invoke Create(..., hostFixture)
alt Using Blocking Fixture
WHF->>HostF: Initialize blocking host
HostF-->>WHF: Throws SecurityException
WHF-->>Test: Exception propagated
else Using Non-blocking Fixture
WHF->>HostF: Initialize non-blocking host
HostF-->>WHF: Captures and logs SecurityException
WHF-->>Test: Returns response with logged exception
end
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
Note 🎁 Summarized by CodeRabbit FreeYour organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request improves the functionality and maintainability of the Codebelt.Extensions.Xunit.Hosting.AspNetCore library by updating documentation, refactoring host fixture initialization, and introducing a blocking fixture for synchronous host start.
- Updated documentation with a DocFx-generated link in README.md
- Refactored host fixture initialization in multiple files to separate configuration, building, and starting the host
- Introduced BlockingAspNetCoreHostFixture for synchronous host starting and updated method overloads to support a fixture parameter
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/AspNetCoreHostTestTest.cs | Adjusted fixture initialization, but potential duplicate invocation of configuration logic. |
| src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs | Updated logger provider to extend InMemoryTestStore and pass itself to logger instances. |
| src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs | Modified logger to delegate log entry storage to its provider. |
| src/Codebelt.Extensions.Xunit.Hosting/LoggerExtensions.cs | Changed generic GetTestStore to non-generic version with XML documentation updates. |
| src/Codebelt.Extensions.Xunit.Hosting/IHostFixture.cs | Shifted ConfigureCallback member from a partial interface to the primary interface definition. |
| src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs | Removed host fixture initialization helper and changed Configure from virtual to non-virtual. |
| src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs | Refactored ConfigureHost to build the host and start it via a new StartConfiguredHost method. |
| src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs | Added overloaded Create methods to optionally accept a host fixture parameter. |
| src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs | Added overloads for Create, CreateWithHostBuilderContext, and RunAsync accepting an IAspNetCoreHostFixture. |
| src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs | Changed usage from concrete AspNetCoreHostFixture to the IAspNetCoreHostFixture interface and refactored initialization. |
| src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixture.cs | Updated ConfigureHost to build the host and invoke StartConfiguredHost. |
| README.md | Added a DocFx documentation link. |
Comments suppressed due to low confidence (1)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/AspNetCoreHostTestTest.cs:24
- [nitpick] The fixture initialization block invokes hostFixture.ConfigureHost(this) and then later calls Configure explicitly, which could result in duplicate configuration. Consider refactoring the initialization to avoid redundant calls to Configure.
if (!hostFixture.HasValidState()) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
README.md (1)
9-9: Documentation link should use proper markdown formattingThe added documentation link is valuable but uses a bare URL, which violates markdown best practices.
-Full documentation (generated by [DocFx](https://github.com/dotnet/docfx)) located here: https://xunit.codebelt.net/ +Full documentation (generated by [DocFx](https://github.com/dotnet/docfx)) located here: [https://xunit.codebelt.net/](https://xunit.codebelt.net/)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
9-9: Bare URL used
null(MD034, no-bare-urls)
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs (1)
4-4: Remove unused import.The import for
System.Net.Mime.MediaTypeNamesappears to be unused in this class.- using static System.Net.Mime.MediaTypeNames;src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs (1)
29-34: New overload supports custom fixtures.Allowing an optional
IHostFixtureparameter increases flexibility. Consider throwing anArgumentNullExceptionif the developer explicitly provides anullfixture, ensuring that any required fixture initialization logic remains consistent.public static IGenericHostTest Create(Action<IServiceCollection> serviceSetup = null, Action<IHostBuilder> hostSetup = null, IHostFixture hostFixture = null) { + if (hostFixture == null) + { + // e.g. throw new ArgumentNullException(nameof(hostFixture)); + } return new GenericHostTest(serviceSetup, hostSetup, hostFixture ?? new HostFixture()); }src/Codebelt.Extensions.Xunit.Hosting/GenericHostTest.cs (1)
28-40: Centralized fixture initialization enhances maintainability.Encapsulating fixture checks and configuration callbacks in
InitializeHostFixtureclarifies the constructor flow. Consider an additional safety check forhostFixturenull references if potentially passed incorrectly.src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs (1)
12-24: Proactive null checks recommended in constructors.You store
_providerand either_outputor_accessorwithout validating they are non-null. For better fail-fast behavior, consider addingArgumentNullExceptionchecks to avoid subtle runtime errors if anything is unexpectedly null.public XunitTestLogger(XunitTestLoggerProvider provider, ITestOutputHelper output) { + if (provider == null) throw new ArgumentNullException(nameof(provider)); + if (output == null) throw new ArgumentNullException(nameof(output)); _provider = provider; _output = output; } public XunitTestLogger(XunitTestLoggerProvider provider, ITestOutputHelperAccessor accessor) { + if (provider == null) throw new ArgumentNullException(nameof(provider)); _provider = provider; _accessor = accessor; }test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (1)
143-175: Consider replacing the synchronous delay with an asynchronous wait approach.Using
Thread.Sleep(400)can slow down tests unnecessarily. An asynchronous alternative (e.g.,await Task.Delay(400).ConfigureAwait(false)) may be more aligned with async best practices.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (25)
README.md(1 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixture.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostTest.cs(0 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/GlobalSuppressions.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs(2 hunks)src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs(4 hunks)src/Codebelt.Extensions.Xunit.Hosting/GenericHostTest.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting/GlobalSuppressions.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs(2 hunks)src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs(1 hunks)src/Codebelt.Extensions.Xunit.Hosting/IHostFixture.cs(2 hunks)src/Codebelt.Extensions.Xunit.Hosting/LoggerExtensions.cs(2 hunks)src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs(3 hunks)src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs(2 hunks)test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/AspNetCoreHostTestTest.cs(1 hunks)test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/ValidHostTest.cs(1 hunks)test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MvcAspNetCoreHostTestTest.cs(1 hunks)test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs(1 hunks)test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs(1 hunks)test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs(1 hunks)
💤 Files with no reviewable changes (1)
- src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostTest.cs
🧰 Additional context used
🧬 Code Definitions (4)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixture.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (1)
StartConfiguredHost(80-86)
src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs (1)
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs (1)
HasValidState(18-22)
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs (1)
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs (3)
XunitTestLogger(8-61)XunitTestLogger(14-18)XunitTestLogger(20-24)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (1)
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/AspNetCoreHostTestTest.cs (5)
Fact(42-64)Fact(67-75)Fact(78-101)Fact(103-126)Fact(128-139)
🪛 markdownlint-cli2 (0.17.2)
README.md
9-9: Bare URL used
null
(MD034, no-bare-urls)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: 🧪 Test (windows-2022, Debug)
- GitHub Check: 🧪 Test (windows-2022, Release)
🔇 Additional comments (55)
src/Codebelt.Extensions.Xunit.Hosting/GlobalSuppressions.cs (1)
10-11: Suppression correctly addresses code analysis warning to maintain semantic versioningThe added suppressions for rule S3427 properly address the method overload warnings for
GenericHostTestFactory.CreateandCreateWithHostBuilderContextmethods. This is a reasonable approach to avoid a major version bump while providing enhanced API flexibility with optional parameters.src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/BlockingAspNetCoreHostFixture.cs (1)
1-20: Well-structured synchronous host fixture implementationThe new
BlockingAspNetCoreHostFixtureclass provides a good synchronous alternative to the default asynchronous implementation, with proper XML documentation and inheritance structure. This enhancement supports better exception capturing in synchronous testing scenarios.src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/HttpClientExtensions.cs (1)
21-21: Documentation properly updated with full method signaturesThe XML documentation remarks have been correctly updated to reference the complete method signatures including the new
IAspNetCoreHostFixtureparameter, maintaining accurate API reference documentation.test/Codebelt.Extensions.Xunit.Hosting.Tests/HostTestTest.cs (1)
23-33: Well-structured host initialization pattern added.The new conditional initialization pattern ensures proper host configuration when the fixture doesn't have a valid state. This promotes more reliable test execution by centralizing the initialization logic in the constructor rather than requiring separate initialization methods.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixture.cs (1)
93-95: Good refactoring of host initialization logic.The host building and starting logic has been cleanly separated by using the new
StartConfiguredHost()method. This refactoring improves code maintainability by centralizing the host starting logic in a dedicated method that handles the asynchronous operations and deadlock prevention.test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/AspNetCoreHostTestTest.cs (1)
24-36: Consistent initialization pattern applied.The conditional initialization logic follows the same pattern as implemented in other test classes, ensuring consistent behavior across the test suite. This approach properly configures the host fixture when it's not in a valid state, establishing the necessary callbacks and properties before test execution.
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/Assets/ValidHostTest.cs (1)
10-22: Consistent initialization pattern applied.The same host initialization pattern has been properly implemented here, maintaining consistency with other test classes. This systematic approach ensures that all test classes handle fixture initialization in the same way, improving code maintainability and test reliability.
test/Codebelt.Extensions.Xunit.Hosting.Tests/Assets/ValidHostTest.cs (1)
12-22: LGTM - Improved host initialization with conditional state checking.The new conditional host initialization logic is a good improvement, ensuring that the host is properly configured only if its state is invalid. This helps prevent redundant configuration and aligns with the fixture initialization changes mentioned in the PR objectives.
test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/MvcAspNetCoreHostTestTest.cs (1)
20-32: LGTM - Consistent host fixture initialization pattern.The conditional initialization pattern matches the approach used in other test classes. This ensures the host fixture is only configured when needed and consistently sets up the test environment properties.
src/Codebelt.Extensions.Xunit.Hosting/XunitTestLoggerProvider.cs (3)
7-7: LGTM - Enhanced logger provider with in-memory storage.The
XunitTestLoggerProvidernow inherits fromInMemoryTestStore<XunitTestLoggerEntry>, which is a good architectural improvement separating provider management from storage functionality.
25-28: LGTM - Updated logger creation to use the provider instance.Passing
thisto the logger constructor properly connects the logger instances with their provider for centralized log management.
30-33: LGTM - Added method for centralized log entry management.The new
WriteLoggerEntrymethod centralizes the creation and storage of log entries, which improves the separation of concerns between the logger and its provider.src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs (4)
71-74: LGTM - Improved host configuration with clearer separation of concerns.The refactored
ConfigureHostmethod now properly separates host building from host starting, delegating the starting process to the newStartConfiguredHostmethod. This improves maintainability and makes the code easier to extend or override in derived classes.
76-86: LGTM - New method for centralizing host startup logic.The new
StartConfiguredHostmethod appropriately encapsulates the host starting logic, including important documentation about potential deadlocks. This makes the code more maintainable and helps prevent issues when working with ASP.NET Core integration tests.
62-66: LGTM - Improved formatting of conditional compilation block.The formatting improvements to the conditional compilation block maintain the same functionality while improving readability.
191-195: LGTM - Consistent formatting of fallback implementation.The formatting improvements to the fallback implementation of
OnDisposeManagedResourcesAsyncmaintain the same functionality while improving readability.src/Codebelt.Extensions.Xunit.Hosting/IHostFixture.cs (2)
17-17: Interface consolidation looks good.The removal of the
partialkeyword simplifies the interface structure by consolidating all members into a single declaration, improving code maintainability.
38-42: Property relocation enhances code organization.Moving the
ConfigureCallbackproperty from a separate partial declaration to the main interface improves discoverability of all interface members in one place, making the code easier to understand and maintain.src/Codebelt.Extensions.Xunit.Hosting/HostFixtureExtensions.cs (3)
3-6: Enhanced accessibility and documentation.Changing the class from
internaltopublicappropriately exposes this utility to external consumers, which aligns with the PR objectives of enhancing the library's functionality. The added XML documentation improves the usability of the API.
8-17: Comprehensive method documentation.The added XML documentation clearly explains the purpose, parameters, return value, and conditions for a valid state, which greatly enhances the usability of the method for consumers.
18-23: Improved code formatting.The reformatted return statement enhances readability while maintaining the same logical conditions for determining a valid state.
src/Codebelt.Extensions.Xunit.Hosting/HostTest.cs (1)
67-67: Removal of virtual modifier restricts extensibility.Removing the
virtualkeyword from theConfiguremethod prevents derived classes from overriding this behavior, which appears to be an intentional design change to enforce consistent configuration handling across all host tests.Ensure this change was intentional as it reduces extensibility. Consider documenting this design decision if extensibility was previously allowed but is now being restricted.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/AspNetCoreHostFixtureExtensions.cs (3)
3-6: Enhanced accessibility and documentation.Making this class
publicexposes these extension methods to consumers outside the assembly, which aligns with the PR's goal of improving library functionality. The added XML documentation improves API usability.
8-17: Comprehensive method documentation.The detailed XML documentation clearly explains the purpose, parameters, return value, and conditions for a valid state, making the API more user-friendly.
18-22: Improved implementation with code reuse.The refactored implementation reduces duplication by delegating part of the validation to the
IHostFixture.HasValidState()method, which follows the DRY principle. This change also makes the method more maintainable - if the base interface's validation logic changes, this method will automatically incorporate those changes.src/Codebelt.Extensions.Xunit.Hosting/LoggerExtensions.cs (2)
25-50: Consider potential fragility with reflection-based retrieval.This newly introduced
GetTestStore(this ILogger logger)method uses reflection to find_loggerand itsLoggerscollection, then searches for anXunitTestLoggerProvider. While effective, reflection can be brittle if internal structures change. Verify whether this is the only feasible approach and consider caching or a more direct mechanism to avoid repeated reflection calls and improve performance.
63-67: Good backward compatibility approach.Marking the generic
GetTestStore<T>as obsolete while delegating to the new non-generic method gracefully preserves existing usage without breaking changes. This helps guide users to the preferred method signature.src/Codebelt.Extensions.Xunit.Hosting/GenericHostTestFactory.cs (3)
18-22: Obsolete method gracefully redirects to new overload.Adding the
[Obsolete]attribute and calling the new method with anullfixture is a neat way to archive old usage while steering developers toward the updated overloads.
36-46: Consistent deprecation of CreateWithHostBuilderContext.Similar to the first overload, marking this method as obsolete while internally deferring to the updated API helps maintain backward compatibility.
48-57: Enhanced flexibility in CreateWithHostBuilderContext.The new overload accepting
IHostFixtureoffers extensibility for users needing specialized fixture logic. This is consistent with the approach used in the standardCreatemethod overload.src/Codebelt.Extensions.Xunit.Hosting/GenericHostTest.cs (3)
7-7: Switch to interface type improves abstraction.Changing the inheritance to
HostTest<IHostFixture>decouples the class from a concreteHostFixture, allowing alternate fixture implementations.
14-19: Check for null fixture when calling InitializeHostFixture.While you rely on
hostFixture.HasValidState(), consider explicitly handling a nullhostFixtureto prevent potential null references in future refactors.internal GenericHostTest(Action<IServiceCollection> serviceConfigurator, Action<IHostBuilder> hostConfigurator, IHostFixture hostFixture) : base(hostFixture, callerType: serviceConfigurator?.Target?.GetType() ?? hostConfigurator?.Target?.GetType()) { + if (hostFixture == null) throw new ArgumentNullException(nameof(hostFixture)); _serviceConfigurator = serviceConfigurator; _hostConfigurator = hostConfigurator; InitializeHostFixture(hostFixture); }
21-26: Parallel constructor handles context-based service configuration.The second constructor is consistent with the first, ensuring the optional
HostBuilderContextlogic gets integrated similarly. No immediate issues spotted.src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs (3)
8-8: Sealed class with ILogger & IDisposable is acceptable.Marking the logger as
internal sealedprevents inheritance. This is often appropriate for specialized logging classes, unless there is a need for mocking or customization.
33-33: Confirm thread-safe behavior of _provider.WriteLoggerEntry.Ensure
_provider.WriteLoggerEntryis safe under concurrent calls toLog. If it manipulates shared state, additional synchronization might be necessary.
46-46: Exposed provider supports external test store retrieval.Providing property-based access to the underlying
XunitTestLoggerProvideris consistent with howLoggerExtensions.GetTestStorelocates it. No further concerns here.test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/WebHostTestFactoryTest.cs (6)
1-25: No issues found in the newly introduced namespace and using directives.Everything appears consistent with the rest of the codebase.
26-51: Test method verifies the blocking fixture behavior successfully.This test correctly checks that a
SecurityExceptionis thrown with theBlockingAspNetCoreHostFixture.
53-81: Test method correctly captures theSecurityExceptionlogs.The log-based assertion is appropriate, ensuring the exception is properly recorded without halting the host startup.
83-98: No issues found with the caller type assertion logic.This test accurately verifies the declaring type for the middleware.
100-110: Application name assertion is straightforward and correct.No issues found with this test’s logic for verifying the assembly name.
113-141: Host builder context test logic is verified properly.The checks for non-null context properties are valid, and the assembly name assertion is correct.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTest.cs (4)
8-8: Good interface-based refactor.Switching to
IAspNetCoreHostFixtureenhances flexibility and abstraction.
17-23: Constructor logic looks appropriate.Calling the base constructor and then initializing the fixture is cohesive and readable.
25-31: Second constructor is consistent with the updated interface approach.No issues found.
32-47: Centralized fixture initialization is a good practice.The
InitializeHostFixturemethod encapsulates repeated logic, improving maintainability.src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/WebHostTestFactory.cs (8)
24-29: Obsolete method retains backward compatibility.Marking it as obsolete while delegating to the new overload is an appropriate migration strategy.
38-41: New overload adds flexibility for custom host fixtures.Allowing an optional
IAspNetCoreHostFixtureparameter is a welcome enhancement.
43-54: Obsolete method with host builder context also properly delegates to the new overload.Retains existing functionality while guiding consumers to the newer method.
64-67: New overload with host builder context looks good.The logic to instantiate
WebHostTestwith the optional host fixture is clear.
77-81: ObsoleteRunAsyncmethod references the improved overload.This maintains existing usage patterns without breaking compatibility.
92-96: The updatedRunAsyncoverload supports custom fixtures gracefully.No issues found with this approach.
106-110: Second obsolete method again defers to the new method.Keeps older callers functional while prompting a transition.
120-124: Final new overload aligns with the host builder context approach.All optional parameters and usage patterns appear consistent.
src/Codebelt.Extensions.Xunit.Hosting.AspNetCore/GlobalSuppressions.cs (1)
1-11: Good approach to maintain backward compatibility.The suppressions are correctly implemented to address the "Method overloads with default parameter values should not overlap" warning for the WebHostTestFactory methods. This approach allows the introduction of the new IAspNetCoreHostFixture parameter while avoiding a major version bump, which aligns well with the PR objectives.
Consider documenting a plan to clean up these suppressions in a future major version update when backward compatibility can be broken.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26 +/- ##
==========================================
- Coverage 85.86% 84.58% -1.29%
==========================================
Files 31 32 +1
Lines 672 668 -4
Branches 84 85 +1
==========================================
- Hits 577 565 -12
- Misses 92 100 +8
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…beltnet/xunit into v9.1.0/fixture-enhancements
|



This pull request includes several changes to improve the functionality and maintainability of the
Codebelt.Extensions.Xunit.Hosting.AspNetCorelibrary. The most important changes include adding documentation, refactoring theAspNetCoreHostFixtureclass, introducing a newBlockingAspNetCoreHostFixtureclass, and updating method signatures to use interfaces for better flexibility.Documentation updates:
README.md: Added a link to the full documentation generated by DocFx.Refactoring and enhancements:
AspNetCoreHostFixture.cs: Refactored theConfigureHostmethod to separate the host building and starting logic.AspNetCoreHostFixtureExtensions.cs: ChangedAspNetCoreHostFixtureExtensionsfrominternaltopublicand added XML documentation.AspNetCoreHostTest.cs: Removed theInitializeHostFixturemethod and moved its logic to the constructor.WebHostTest.cs: Updated the class to use theIAspNetCoreHostFixtureinterface instead of the concreteAspNetCoreHostFixtureclass. [1] [2] [3]WebHostTestFactory.cs: Added overloads forCreateandRunAsyncmethods to accept an optionalIAspNetCoreHostFixtureparameter. [1] [2] [3]New class introduction:
BlockingAspNetCoreHostFixture.cs: Introduced a new classBlockingAspNetCoreHostFixturethat extendsAspNetCoreHostFixtureto provide synchronous host starting.Suppressions for code analysis:
GlobalSuppressions.cs: Added suppressions for method overloads with default parameter values to avoid bumping the major version.Summary by CodeRabbit
Documentation
New Features
Refactor
Chores