Skip to content

Add IsAssignableFrom and IsNotAssignableFrom type assertions#4833

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-isassignableto-support
Draft

Add IsAssignableFrom and IsNotAssignableFrom type assertions#4833
Copilot wants to merge 2 commits intomainfrom
copilot/add-isassignableto-support

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Adds IsAssignableFrom<T>() / IsNotAssignableFrom<T>() as counterparts to the existing IsAssignableTo<T>() / IsNotAssignableTo<T>().

  • New assertion classes: IsAssignableFromAssertion<TTarget, TValue> and IsNotAssignableFromAssertion<TTarget, TValue> in TypeOfAssertion.cs, using actualType.IsAssignableFrom(typeof(TTarget))
  • Interface: Added both methods to IAssertionSource<TValue>
  • Implementations: All 16 assertion source classes (ValueAssertion, DelegateAssertion, AsyncDelegateAssertion, TaskAssertion, CollectionAssertionBase, MemoryAssertionBase, etc.) plus explicit interface implementations and NotSupportedException stubs in CountWrapper/LengthWrapper
  • Public API snapshots: Updated all 4 verified snapshot files
// IsAssignableTo: value's type can be assigned to T (value is subtype of T)
await Assert.That(derived).IsAssignableTo<BaseClass>();

// IsAssignableFrom: value's type can accept T (value is supertype of T)
await Assert.That(baseInstance).IsAssignableFrom<DerivedClass>();
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: IsAssignableFrom needs to be completed with it's counterpart IsAssignableTo</issue_title>
<issue_description>### Problem Statement

This is a simple one:

TUnit supports IsAssignableFom()

It would be nice to also support its counterpart IsAssignableTo()

Proposed Solution

simply call IsAssignableFrom reversing the parameters

Alternatives Considered

No response

Feature Category

Test Discovery / Attributes

How important is this feature to you?

None

Additional Context

No response

Contribution

  • I'm willing to submit a pull request for this feature</issue_description>

<agent_instructions>Make sure to update public API snapshots</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add IsAssignableFromAssertion and IsNotAssignableFromAssertion classes
- Add IsAssignableFrom/IsNotAssignableFrom to IAssertionSource interface
- Implement in all assertion source classes
- Update public API snapshots

Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot AI changed the title [WIP] Add IsAssignableTo support for TUnit Add IsAssignableFrom and IsNotAssignableFrom type assertions Feb 17, 2026
Copilot AI requested a review from thomhurst February 17, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: IsAssignableFrom needs to be completed with it's counterpart IsAssignableTo

2 participants