Skip to content

share-argument-exception-extension #8098

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

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

Zombach
Copy link
Contributor

@Zombach Zombach commented Mar 16, 2025

Description

message

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 16, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 16, 2025
@Zombach
Copy link
Contributor Author

Zombach commented Mar 16, 2025

@danmoseley Hello. Please look. Made a check share code

@@ -16,6 +16,8 @@ public class RedisResource(string name) : ContainerResource(name), IResourceWith
/// <param name="password">A parameter that contains the Redis server password.</param>
public RedisResource(string name, ParameterResource password) : this(name)
{
ArgumentNullException.ThrowIfNull(password);
Copy link
Member

Choose a reason for hiding this comment

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

where you've added new checks, do they need tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add today. I will also add tests to "Builder.addgarnet ..." => "Addganet (Builder ..."
I just wanted to understand, this option is suitable for the implementation of the Share check

@Zombach
Copy link
Contributor Author

Zombach commented Mar 21, 2025

@danmoseley If anything is ready, you can fill.

@Zombach Zombach requested a review from danmoseley March 21, 2025 17:18
@mitchdenny
Copy link
Member

This looks good to me. Just need the covering tests for all the other resource types.

@danmoseley
Copy link
Member

Tests should pass in all locales

@RussKie
Copy link
Contributor

RussKie commented Apr 29, 2025

I think there are (at least) two ways of solving this.

  1. Tactical - set the culture for each test and unset at it at the end. E.g. something like this pseudocode:
        try
        {
             _originalCulture = Thread.CurrentThread.CurrentCulture;
             _originalUICulture = Thread.CurrentThread.CurrentUICulture;
    
             CultureInfo.DefaultThreadCurrentCulture = Culture;
             Thread.CurrentThread.CurrentCulture = "en-US";
             Thread.CurrentThread.CurrentUICulture = "en-US"
    
            // ... body of the test
        }
        finally
        {
             Thread.CurrentThread.CurrentCulture = _originalCulture;
             Thread.CurrentThread.CurrentUICulture = _originalUICulture;
        }
  2. Pass the culture as a theory argument. This would allow asserting the messages/formatting are correct across different locales.
  3. Strategic - add an attribute which can be applies to a test/fixture. Something like dotnet/winforms@9a26e66 (though it'd be simpler since there are no unmanaged resources here).

@RussKie RussKie added the needs-author-action An issue or pull request that requires more info or actions from the author. label Apr 29, 2025
@Zombach
Copy link
Contributor Author

Zombach commented Apr 29, 2025

I think there are (at least) two ways of solving this.

  1. Tactical - set the culture for each test and unset at it at the end. E.g. something like this pseudocode:
        try
        {
             _originalCulture = Thread.CurrentThread.CurrentCulture;
             _originalUICulture = Thread.CurrentThread.CurrentUICulture;
    
             CultureInfo.DefaultThreadCurrentCulture = Culture;
             Thread.CurrentThread.CurrentCulture = "en-US";
             Thread.CurrentThread.CurrentUICulture = "en-US"
    
            // ... body of the test
        }
        finally
        {
             Thread.CurrentThread.CurrentCulture = _originalCulture;
             Thread.CurrentThread.CurrentUICulture = _originalUICulture;
        }
  2. Pass the culture as a theory argument. This would allow asserting the messages/formatting are correct across different locales.
  3. Strategic - add an attribute which can be applies to a test/fixture. Something like dotnet/winforms@9a26e66 (though it'd be simpler since there are no unmanaged resources here).

I chose the 3rd point.
But this did not help this test, here is the problem with ''. ' => ',' which depends on OSPlatform
image>

You need to understand what to do with it.
Also due to static resources when using
[UsedEfaultxunitculture]
This test breaks even more.
image

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Apr 29, 2025
@danmoseley
Copy link
Member

@Zombach not about this PR directly, but chatting offline, I think we want to hold off on any future large "argument validation" PR's without agreement first. Yes, code changes should validate arguments. A PR fixing a particular instance is probably fine. But any more large scale ones don't make sense right now as we're biasing for speed, and it brings the risk of regressions.

@Zombach
Copy link
Contributor Author

Zombach commented Apr 29, 2025

@Zombach not about this PR directly, but chatting offline, I think we want to hold off on any future large "argument validation" PR's without agreement first. Yes, code changes should validate arguments. A PR fixing a particular instance is probably fine. But any more large scale ones don't make sense right now as we're biasing for speed, and it brings the risk of regressions.

Yes, I will make Culture fix in a separate PR.
And i will roll back this one to the previous state (before Culture fix)

@Zombach Zombach requested a review from danmoseley April 29, 2025 18:41
@Zombach Zombach mentioned this pull request Apr 29, 2025
16 tasks
@@ -10,6 +10,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)src\Shared\AzureRoleAssignmentUtils.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this in each project file, I suggest considering a different approach.

@@ -10,6 +10,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)src\Shared\AzureRoleAssignmentUtils.cs" />
<Compile Include="$(ComponentsDir)\Common\ArgumentExceptionExtensions.cs" Link="ArgumentExceptionExtensions.cs" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put the shared file in the Shared folder (like the line above)?


namespace Aspire;

internal static class ArgumentExceptionExtensions
Copy link
Contributor

Choose a reason for hiding this comment

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

These extensions aren't very discoverable. I very much suggest taking an inspiration from https://github.com/dotnet/extensions/tree/1e4f6c51798be661b8d8743dd464ca9f54b0c9a3/src/Shared/Throw, and do the same way (both in terms of API naming and the location of the file).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooo. This option is really good. I will do the other day

@RussKie RussKie added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 2, 2025
@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label May 7, 2025
@danmoseley
Copy link
Member

Let's merge this after the 9.3 snap

…-exception-extension-for-check-null-or-empty
@danmoseley danmoseley added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 12, 2025
Copy link

This submission has been automatically marked as stale because it has been marked as requiring author action but has not had any activity for 14 days.
It will be closed if no further activity occurs within 7 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants