Skip to content

Add an analyzer + fixer scenario to support converting type comparisons to use TypeOf<> constraint #884

@stevenaw

Description

@stevenaw

Tests checking that an expected and actual are the same type may written in a way that compares the types directly using EqualTo() like the below:

// generic 'expected'
Assert.That(0.GetType(), Is.EqualTo(typeof(int)));

// non-generic 'expected'
Assert.That(0.GetType(), Is.EqualTo(1.GetType()));

It might be desirable to allow for these to be converted to use the TypeOf constraints instead as it would be a shorter yet clearer assertion with a potentially more descriptive failure messages.

// generic 'expected'
-Assert.That(0.GetType(), Is.EqualTo(typeof(int)));
+Assert.That(0, Is.TypeOf<int>());

// non-generic 'expected'
-Assert.That(0.GetType(), Is.EqualTo(1.GetType()));
+Assert.That(0, Is.TypeOf(1.GetType()));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions