refactor(tests): consolidate duplicate Facts into Theories#334
refactor(tests): consolidate duplicate Facts into Theories#334piotrzajac merged 3 commits intomasterfrom
Conversation
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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR consolidates duplicate test cases across five test files by converting separate Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs (1)
24-28: Use theglobal::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 theglobal::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 theglobal::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
📒 Files selected for processing (7)
.backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.mddotnet-tools.jsonsrc/Objectivity.AutoFixture.XUnit2.Core.Tests/Common/EnumerableExtensionsTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/Requests/ValuesRequestTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomExceptValuesGeneratorTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RandomFixedValuesGeneratorTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/SpecimenBuilders/RequestFactoryRelayTests.cs
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
Tests
Checklist
type(scope): description)dotnet build src/Objectivity.AutoFixture.XUnit2.AutoMock.slnpasses with no warningsdotnet test src/Objectivity.AutoFixture.XUnit2.AutoMock.slnpasses on all framework slices[SuppressMessage]without a justification comment// TODO:comments added — open a GitHub issue instead