Skip to content

refactor(tests): consolidate duplicate Facts into Theories#334

Merged
piotrzajac merged 3 commits intomasterfrom
refactor/consolidate-facts-into-theories
Apr 22, 2026
Merged

refactor(tests): consolidate duplicate Facts into Theories#334
piotrzajac merged 3 commits intomasterfrom
refactor/consolidate-facts-into-theories

Conversation

@piotrzajac
Copy link
Copy Markdown
Collaborator

@piotrzajac piotrzajac commented Apr 22, 2026

Summary

Replace pairs of [Fact] methods that tested the same behaviour with different inputs with a single [Theory] using [InlineData] or [MemberData]/[TheoryData].

Summary by CodeRabbit

  • Chores

    • Updated dotnet-stryker tool to version 4.14.1
  • Tests

    • Consolidated duplicate test cases into parameterized tests for improved maintainability
    • Added new backlog task documenting test consolidation objectives

Checklist

  • Commit messages follow Conventional Commits (type(scope): description)
  • dotnet build src/Objectivity.AutoFixture.XUnit2.AutoMock.sln passes with no warnings
  • dotnet test src/Objectivity.AutoFixture.XUnit2.AutoMock.sln passes on all framework slices
  • Code coverage remains at least at the level prior the change (verified by Codecov)
  • Mutation score remains at least at the level prior the change (verified by Stryker)
  • New tests follow the GIVEN/WHEN/THEN naming convention and AAA structure (see AGENTS.md)
  • No new [SuppressMessage] without a justification comment
  • No // TODO: comments added — open a GitHub issue instead
  • No new dependencies introduced that are incompatible with the MIT license (verified by FOSSA)

Replace pairs of [Fact] methods that tested the same behaviour with
different inputs with a single [Theory] using [InlineData] or
[MemberData]/TheoryData. Affected files: RandomFixedValuesGeneratorTests,
RandomExceptValuesGeneratorTests, ValuesRequestTests,
RequestFactoryRelayTests, and EnumerableExtensionsTests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@piotrzajac has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c025e1b-c807-4579-894f-cf9b4db746ea

📥 Commits

Reviewing files that changed from the base of the PR and between 64b15f8 and 0048fbc.

📒 Files selected for processing (2)
  • .backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.md
  • src/Objectivity.AutoFixture.XUnit2.Core.Tests/Requests/ValuesRequestTests.cs
📝 Walkthrough

Walkthrough

The PR consolidates duplicate test cases across five test files by converting separate [Fact] tests into parameterized [Theory] tests using [MemberData] and TheoryData<T>, eliminating test duplication while maintaining coverage. Additionally, dotnet-stryker version is updated to 4.14.1, and a backlog task for this consolidation effort is documented.

Changes

Cohort / File(s) Summary
Configuration & Documentation
.backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.md, dotnet-tools.json
Added new backlog task metadata defining acceptance criteria for consolidating duplicate facts into theories. Updated dotnet-stryker version from 4.14.0 to 4.14.1.
Test Consolidation: EnumerableExtensionsTests
src/Objectivity.AutoFixture.XUnit2.Core.Tests/Common/EnumerableExtensionsTests.cs
Consolidated separate [Fact] test for generic-definition collection validation into a single parameterized [Theory] using InvalidCollectionTestData [MemberData] source, covering tuple, non-generic IEnumerable, and generic type definition cases.
Test Consolidation: ValuesRequestTests
src/Objectivity.AutoFixture.XUnit2.Core.Tests/Requests/ValuesRequestTests.cs
Merged two separate null-argument [Fact] tests into a single [Theory] with NullArgumentConstructorTestData [MemberData], consolidating operandType and values null validations.
Test Consolidation: RandomExceptValuesGeneratorTests
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomExceptValuesGeneratorTests.cs
Combined two separate null-argument [Fact] validations into a single [Theory] using NullArgumentCreateTestData [MemberData], covering null context and null request scenarios.
Test Consolidation: RandomFixedValuesGeneratorTests
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomFixedValuesGeneratorTests.cs
Unified two separate null-argument [Fact] tests into a single parameterized [Theory] with NullArgumentCreateTestData [MemberData], consolidating uninitialized context and request validation.
Test Consolidation: RequestFactoryRelayTests
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs
Consolidated two separate null-argument [Fact] tests for Create() into a single [Theory] driven by NullArgumentCreateTestData [MemberData], replacing hardcoded null cases with parameterized invocations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Initial commit with first changes #248: Modifies the same test files (EnumerableExtensionsTests, RequestFactoryRelayTests, ValuesRequestTests, RandomExcept/Fixed generator tests) with overlapping test consolidation changes.

Suggested labels

enhancement

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main refactoring objective: consolidating duplicate [Fact] tests into [Theory] tests, which matches the primary change across all modified test files.
Description check ✅ Passed The description provides context for the changes (consolidating duplicate Facts into Theories), includes the required checklist with all items marked as completed, and aligns with the repository's template structure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/consolidate-facts-into-theories

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@piotrzajac piotrzajac self-assigned this Apr 22, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 22, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8611052) to head (0048fbc).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #334   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           39        39           
  Lines          419       419           
  Branches        53        53           
=========================================
  Hits           419       419           
Flag Coverage Δ
unittests 99.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs (1)

24-28: Use the global:: prefix for the new Moq usage.

Line 27 adds another external package type reference without the repository’s ambiguity guard.

Suggested guideline alignment
 public static TheoryData<object, ISpecimenContext, string> NullArgumentCreateTestData { get; } = new()
 {
     { new object(), null, "context" },
-    { null, new Mock<ISpecimenContext>().Object, "request" },
+    { null, new global::Moq.Mock<ISpecimenContext>().Object, "request" },
 };

As per coding guidelines, Use global:: prefix on external packages (AutoFixture, Moq, etc.) to avoid ambiguity

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs`
around lines 24 - 28, The test data property NullArgumentCreateTestData uses Moq
without the repository ambiguity guard; update the Moq type usage to use the
global:: prefix (e.g., replace Mock<ISpecimenContext>() references with
global::Moq.Mock<ISpecimenContext>() so the { null, new
Mock<ISpecimenContext>().Object, "request" } entry becomes unambiguous). Ensure
any other external package types in this property use the global:: prefix as
well to follow the coding guideline.
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomFixedValuesGeneratorTests.cs (1)

20-24: Use the global:: prefix for the new Moq usage.

Line 23 adds another external package type reference without the repository’s ambiguity guard.

Suggested guideline alignment
 public static TheoryData<object, ISpecimenContext, string> NullArgumentCreateTestData { get; } = new()
 {
     { new object(), null, "context" },
-    { null, new Mock<ISpecimenContext>().Object, "request" },
+    { null, new global::Moq.Mock<ISpecimenContext>().Object, "request" },
 };

As per coding guidelines, Use global:: prefix on external packages (AutoFixture, Moq, etc.) to avoid ambiguity

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomFixedValuesGeneratorTests.cs`
around lines 20 - 24, The test data initializer NullArgumentCreateTestData
introduces an unqualified reference to Moq's Mock<ISpecimenContext>, which
violates the repository guideline; update the specimen data to use the global::
namespace prefix for external package types (i.e., replace
Mock<ISpecimenContext>() with
global::Moq.Mock<global::AutoFixture.Kernel.ISpecimenContext>() or at minimum
global::Moq.Mock<ISpecimenContext>()) so the new Moq usage is fully qualified
and avoids ambiguity when locating the Mock type.
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomExceptValuesGeneratorTests.cs (1)

19-23: Use the global:: prefix for the new Moq usage.

Line 22 adds another external package type reference without the repository’s ambiguity guard.

Suggested guideline alignment
 public static TheoryData<object, ISpecimenContext, string> NullArgumentCreateTestData { get; } = new()
 {
     { new object(), null, "context" },
-    { null, new Mock<ISpecimenContext>().Object, "request" },
+    { null, new global::Moq.Mock<ISpecimenContext>().Object, "request" },
 };

As per coding guidelines, Use global:: prefix on external packages (AutoFixture, Moq, etc.) to avoid ambiguity

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomExceptValuesGeneratorTests.cs`
around lines 19 - 23, The test data initializer NullArgumentCreateTestData adds
a Moq type reference without the repository ambiguity guard; update the Mock
usage to use the global:: prefix (e.g., global::Moq.Mock<ISpecimenContext>) so
external package types are fully-qualified, ensuring the entry "{ null, new
Mock<ISpecimenContext>().Object, "request" }" becomes "{ null, new
global::Moq.Mock<ISpecimenContext>().Object, "request" }" and similarly qualify
any other external types like AutoFixture with global:: as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.md:
- Line 17: Update the acceptance-criteria wording by removing the extra "the":
change the checklist line that reads "Identify all [Fact] methods across the all
test projects that test the same behavior with different inputs" to "Identify
all [Fact] methods across all test projects that test the same behavior with
different inputs" so the phrase "across all test projects" is used; edit the
checklist item text accordingly.

In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/Requests/ValuesRequestTests.cs`:
- Around line 17-21: The first row in the TheoryData
NullArgumentConstructorTestData (in ValuesRequestTests) passes both operandType
and values as null which couples validation order; change that row so only
operandType is null and values is a valid non-null array (e.g. new object[] { 1
}) so the test isolates the operandType guard; keep the second row (typeof(int),
null, "values") as-is to test the values guard.

---

Nitpick comments:
In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomExceptValuesGeneratorTests.cs`:
- Around line 19-23: The test data initializer NullArgumentCreateTestData adds a
Moq type reference without the repository ambiguity guard; update the Mock usage
to use the global:: prefix (e.g., global::Moq.Mock<ISpecimenContext>) so
external package types are fully-qualified, ensuring the entry "{ null, new
Mock<ISpecimenContext>().Object, "request" }" becomes "{ null, new
global::Moq.Mock<ISpecimenContext>().Object, "request" }" and similarly qualify
any other external types like AutoFixture with global:: as needed.

In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomFixedValuesGeneratorTests.cs`:
- Around line 20-24: The test data initializer NullArgumentCreateTestData
introduces an unqualified reference to Moq's Mock<ISpecimenContext>, which
violates the repository guideline; update the specimen data to use the global::
namespace prefix for external package types (i.e., replace
Mock<ISpecimenContext>() with
global::Moq.Mock<global::AutoFixture.Kernel.ISpecimenContext>() or at minimum
global::Moq.Mock<ISpecimenContext>()) so the new Moq usage is fully qualified
and avoids ambiguity when locating the Mock type.

In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs`:
- Around line 24-28: The test data property NullArgumentCreateTestData uses Moq
without the repository ambiguity guard; update the Moq type usage to use the
global:: prefix (e.g., replace Mock<ISpecimenContext>() references with
global::Moq.Mock<ISpecimenContext>() so the { null, new
Mock<ISpecimenContext>().Object, "request" } entry becomes unambiguous). Ensure
any other external package types in this property use the global:: prefix as
well to follow the coding guideline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f2dfcac8-837a-4c7e-b5d1-d8d2aea3926f

📥 Commits

Reviewing files that changed from the base of the PR and between 8611052 and 64b15f8.

📒 Files selected for processing (7)
  • .backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.md
  • dotnet-tools.json
  • src/Objectivity.AutoFixture.XUnit2.Core.Tests/Common/EnumerableExtensionsTests.cs
  • src/Objectivity.AutoFixture.XUnit2.Core.Tests/Requests/ValuesRequestTests.cs
  • src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomExceptValuesGeneratorTests.cs
  • src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomFixedValuesGeneratorTests.cs
  • src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs

Comment thread .backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.md Outdated
@piotrzajac piotrzajac merged commit fc951ee into master Apr 22, 2026
19 of 20 checks passed
@piotrzajac piotrzajac deleted the refactor/consolidate-facts-into-theories branch April 22, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants