Skip to content

Conversation

@h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented Oct 4, 2024

Description

Adds test coverage for TextDecorationCollectionConverter. Both the original and my PR #9778 have been tested against this.

  • Again, this class is rather inconsistent with others.
    • Static ConvertFromString will return null on null but instance method will throw with NotSupportedException
    • While ConvertTo claims it only supports InstanceDescriptor as destinationType, it calls into base which will gladly accept string and based on the value type it will either return string.Empty (if value was null), or it returns the type name using ToString.
  • I did not even include those edge cases because they should be rather fixed imho for more consistent behavior.

Customer Impact

Improved test coverage on public surface.

Regression

No.

Testing

Local build.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

@dipeshmsft
Copy link
Member

@h3xds1nz here are a few things that I think we can do in this PR :

  1. Add a test where ConvertTo runs successfully and for verification we can use the InstanceDescriptor to create an instance of the TextDecorationCollection class .
  2. Add a test for ConvertFrom with input of type other than string to hit the other code paths of ConvertFrom method.

@dipeshmsft
Copy link
Member

  • Again, this class is rather inconsistent with others.
    - Static ConvertFromString will return null on null but instance method will throw with NotSupportedException
    - While ConvertTo claims it only supports InstanceDescriptor as destinationType, it calls into base which will gladly accept string and based on the value type it will either return string.Empty (if value was null), or it returns the type name using ToString.
  • I did not even include those edge cases because they should be rather fixed imho for more consistent behavior.

Probably you can open one issue for these issues you found in this and the MouseActionConverter class.

@h3xds1nz h3xds1nz force-pushed the add-textdecorations-tests branch from 9f8e6e2 to d81434a Compare January 22, 2025 11:38
@h3xds1nz
Copy link
Member Author

@dipeshmsft I've added multitude of other tests, what I do not like is that its dependent now on InstanceDescriptor as a whole so its beyond the "unit" standard and verifies the ctor of TextDecorationCollection directly in the test.

It doesn't hurt but it is no longer fully "unit" in this case. Not that it really matters, some test is better than no-test, right.

#9778 guess it is time for this sad PR? 😀

@dipeshmsft
Copy link
Member

Thanks @h3xds1nz for the quick resolution.

I understand that invoking InstanceDescriptor makes it less of a unit test and if there is a way to test the ConvertTo function without it, I am more than happy to have that.

@h3xds1nz
Copy link
Member Author

h3xds1nz commented Jan 22, 2025

@dipeshmsft We could technically just check the arguments match in the descriptor, but that's still not isolated.

I'd just do it (keep it) this way now. Can be always pulled away into an integration test later and only check for not null here and typeof(InstanceDescriptor).

@dipeshmsft dipeshmsft merged commit 662423d into dotnet:main Jan 22, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants