Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Nov 9, 2025

Link issues

fixes #7087

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Update the GetJsonStringByTypeName_UseKeyWhenValueIsNull unit test to handle different null value behaviors in .NET 9 and .NET 10+, refine related assertions and assembly call, and clarify the UseKeyWhenValueIsNull option description.

Enhancements:

  • Clarify the XML summary for UseKeyWhenValueIsNull in JsonLocalizationOptions by removing the exception note.

Tests:

  • Add conditional assertions in GetJsonStringByTypeName_UseKeyWhenValueIsNull test to expect empty strings under .NET9_0 and correct values under .NET10_0_OR_GREATER, update test2 expectation to empty string, and simplify assembly retrieval call.

Copilot AI review requested due to automatic review settings November 9, 2025 02:30
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 9, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances the GetJsonStringByTypeName_UseKeyWhenValueIsNull unit test to handle behavior differences across .NET versions, updates expected assertion values, simplifies method calls, and refines the XML documentation for UseKeyWhenValueIsNull.

Class diagram for updated JsonLocalizationOptions documentation

classDiagram
class JsonLocalizationOptions {
  bool IgnoreLocalizerMissing
  bool UseKeyWhenValueIsNull
}
JsonLocalizationOptions --|> LocalizationOptions
Loading

File-Level Changes

Change Details Files
Adapt unit test to .NET version differences and update assertions
  • Wrap first assertion in #if NET9_0/#elif NET10_0_OR_GREATER to expect "" on .NET 9 and "Test-Null" on newer runtimes
  • Change test2.Value assertion to expect an empty string when UseKeyWhenValueIsNull is true
  • Remove unnecessary 'this.' qualifier in Utility.GetJsonStringByTypeName invocation
  • Standardize license header comment spacing
test/UnitTest/Utils/UtilityTest.cs
Refine XML doc comment for UseKeyWhenValueIsNull option
  • Remove the phrase about triggering exceptions from the property summary
src/BootstrapBlazor/Localization/Json/JsonLocalizationOptions.cs

Possibly linked issues

  • #test(Localizer): update GetJsonStringByTypeName_UseKeyWhenValueIsNull test: PR updates GetJsonStringByTypeName_UseKeyWhenValueIsNull test, changing assertions for different .NET versions, directly addressing the issue.
  • #N/A: The PR updates localization tests to correctly handle null values, directly addressing the ArgumentNullException bug from malformed JSON in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 91d0151 into main Nov 9, 2025
6 of 7 checks passed
@ArgoZhang ArgoZhang deleted the refactor-cache branch November 9, 2025 02:31
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `test/UnitTest/Utils/UtilityTest.cs:394-401` </location>
<code_context>
         var test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
         Assert.NotNull(test1);
+
+#if NET9_0
+        Assert.Equal("", test1.Value);
+#elif NET10_0_OR_GREATER
         Assert.Equal("Test-Null", test1.Value);
+#endif

         var test2 = items.FirstOrDefault(i => i.Name == "Test-Key");
</code_context>

<issue_to_address>
**suggestion (testing):** Conditional assertions for different .NET versions may lead to inconsistent test coverage.

Ensure your CI pipeline runs tests for all supported .NET versions so these assertions are validated. Also, add a comment clarifying the version-specific behavior for maintainability.

```suggestion
        var test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
        Assert.NotNull(test1);

        // NOTE: The expected value for test1.Value differs by .NET version:
        // - On .NET 9.0, Value is expected to be an empty string ("").
        // - On .NET 10.0 or greater, Value is expected to be "Test-Null".
        // Please ensure CI runs tests for all supported .NET versions so these assertions are validated.
#if NET9_0
        Assert.Equal("", test1.Value);
#elif NET10_0_OR_GREATER
        Assert.Equal("Test-Null", test1.Value);
#endif
```
</issue_to_address>

### Comment 2
<location> `test/UnitTest/Utils/UtilityTest.cs:405` </location>
<code_context>
         var test2 = items.FirstOrDefault(i => i.Name == "Test-Key");
         Assert.NotNull(test2);
-        Assert.Equal("Test-Key", test2.Value);
+        Assert.Equal("", test2.Value);

         option.UseKeyWhenValueIsNull = false;
</code_context>

<issue_to_address>
**suggestion (testing):** Test does not cover the scenario when both UseKeyWhenValueIsNull is false and the value is null.

Add assertions for when `UseKeyWhenValueIsNull` is false and the value is null to verify correct fallback or error handling.
</issue_to_address>

### Comment 3
<location> `test/UnitTest/Utils/UtilityTest.cs:408` </location>
<code_context>

         option.UseKeyWhenValueIsNull = false;
-        items = Utility.GetJsonStringByTypeName(option, this.GetType().Assembly, "UnitTest.Utils.UtilityTest", "en-US", true);
+        items = Utility.GetJsonStringByTypeName(option, GetType().Assembly, "UnitTest.Utils.UtilityTest", "en-US", true);

         test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding negative test cases for invalid or missing keys.

Please include tests for scenarios where the key is missing, or its value is null or empty, to verify correct handling of these cases.

Suggested implementation:

```csharp
        test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
        Assert.NotNull(test1);

        // Negative test: missing key
        var missingKey = items.FirstOrDefault(i => i.Name == "Test-Missing");
        Assert.Null(missingKey);

        // Negative test: key with null value
        var nullValueKey = items.FirstOrDefault(i => i.Name == "Test-ExplicitNull");
        if (nullValueKey != null)
        {
            Assert.Null(nullValueKey.Value);
        }

        // Negative test: key with empty value
        var emptyValueKey = items.FirstOrDefault(i => i.Name == "Test-Empty");
        if (emptyValueKey != null)
        {
            Assert.Equal("", emptyValueKey.Value);
        }

```

You may need to ensure that your test data (the JSON or source for `Utility.GetJsonStringByTypeName`) includes entries for "Test-ExplicitNull" and "Test-Empty" with appropriate values (null and empty string, respectively). If these do not exist, add them to your test data.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@bb-auto bb-auto bot added the test This is unit test label Nov 9, 2025
@bb-auto bb-auto bot added this to the 10.0.0 milestone Nov 9, 2025
@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (746d0c9) to head (20a239a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7088   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          745       745           
  Lines        32556     32556           
  Branches      4512      4512           
=========================================
  Hits         32556     32556           
Flag Coverage Δ
BB 100.00% <ø> (?)

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
Contributor

Copilot AI left a 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 PR makes several improvements to the JSON localization handling, including fixing a typo in the test locale file, updating documentation, and adding framework-specific test assertions.

  • Fixed typo in locale file key name (Test-Key:Test-Key)
  • Updated documentation to remove misleading exception reference
  • Added conditional compilation for framework-specific test behavior
  • Removed redundant this. qualifier for code consistency

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/UnitTest/Utils/UtilityTest.cs Added framework-specific conditional compilation for test assertions and removed redundant this. qualifier
test/UnitTest/Locales/en-US.json Fixed typo in JSON key name by removing erroneous trailing colon from "Test-Key:"
src/BootstrapBlazor/Localization/Json/JsonLocalizationOptions.cs Improved documentation accuracy by removing misleading exception reference
Comments suppressed due to low confidence (2)

test/UnitTest/Utils/UtilityTest.cs:523

  • Class 'MockClone' implements 'ICloneable'.
    private class MockClone : ICloneable

test/UnitTest/Utils/UtilityTest.cs:511

  • Field 'Field' can be 'readonly'.
        public string Field = "";

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

var test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
Assert.NotNull(test1);

#if NET9_0
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

The conditional compilation directive uses NET9_0 (exact version match) which is inconsistent with the pattern used elsewhere in the codebase. Other files use NET9_0_OR_GREATER (e.g., in CacheManager.cs, DefaultDispatchService.cs, ICacheManager.cs).

Consider using NET9_0_OR_GREATER instead for consistency and to ensure the code works correctly for future .NET 9.x patch versions.

Suggested change
#if NET9_0
#if NET9_0_OR_GREATER

Copilot uses AI. Check for mistakes.
Comment on lines +397 to +401
#if NET9_0
Assert.Equal("", test1.Value);
#elif NET10_0_OR_GREATER
Assert.Equal("Test-Null", test1.Value);
#endif
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

The NET10_0_OR_GREATER preprocessor symbol references .NET 10, which does not exist yet. As of January 2025 (my knowledge cutoff), .NET 9 is the latest stable release. While .NET 10 may be in preview or released by November 2025, this conditional compilation logic appears speculative.

Additionally, the test logic suggests different behavior between .NET 9 and .NET 10 for the same localization scenario (empty string vs. "Test-Null"), which seems unexpected. This conditional should be reviewed to ensure it reflects actual behavioral differences in the framework, or simplified if the behavior is actually the same across versions.

Suggested change
#if NET9_0
Assert.Equal("", test1.Value);
#elif NET10_0_OR_GREATER
Assert.Equal("Test-Null", test1.Value);
#endif
Assert.Equal("", test1.Value);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test This is unit test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(Localizer): update GetJsonStringByTypeName_UseKeyWhenValueIsNull test

2 participants