Skip to content

Rewrite Method Member Syntax Elements Tests and Refactor Method Member Syntax Elements#465

Open
alexanderlinne wants to merge 2 commits into
mainfrom
method-member-syntax-elements-tests
Open

Rewrite Method Member Syntax Elements Tests and Refactor Method Member Syntax Elements#465
alexanderlinne wants to merge 2 commits into
mainfrom
method-member-syntax-elements-tests

Conversation

@alexanderlinne

Copy link
Copy Markdown
Collaborator

Note: there are still two implementations of HaveReturnType/NotHaveReturnType to keep the current differences in how System.Type and IType are handled.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.53925% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.89%. Comparing base (312f823) to head (972b456).

Files with missing lines Patch % Lines
.../Members/MethodMembers/AddMethodMemberCondition.cs 78.57% 6 Missing ⚠️
.../Members/MethodMembers/AddMethodMemberPredicate.cs 78.57% 6 Missing ⚠️
.../MethodMembers/MethodMemberConditionsDefinition.cs 98.67% 0 Missing and 2 partials ⚠️
.../MethodMembers/MethodMemberPredicatesDefinition.cs 97.67% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #465      +/-   ##
==========================================
+ Coverage   79.97%   82.89%   +2.91%     
==========================================
  Files         259      259              
  Lines       13326    12548     -778     
  Branches     1240     1194      -46     
==========================================
- Hits        10658    10402     -256     
+ Misses       2291     1785     -506     
+ Partials      377      361      -16     

☔ View full report in Codecov by Harness.
📢 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.

public TNextElement HaveReturnType(IObjectProvider<IType> types) => CreateNextElement(MethodMemberConditionsDefinition.HaveReturnType(types));
public TNextElement HaveReturnType(Type type, params Type[] moreTypes) => CreateNextElement(MethodMemberConditionsDefinition.HaveReturnType(type, moreTypes));
public TNextElement HaveReturnType(IEnumerable<IType> types) => HaveReturnType(new ObjectProvider<IType>(types));
public TNextElement HaveReturnType(IEnumerable<Type> types) => CreateNextElement(MethodMemberConditionsDefinition.HaveReturnType(types));

@mak638 mak638 Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Was this an oversight or left out on purpose? Same for NotHaveReturnType(IEnumerable<Type> types) further below in this same file and for the corresponding method calls in AddMethodMemberPredicate.cs.

Suggested change
public TNextElement HaveReturnType(IEnumerable<Type> types) => CreateNextElement(MethodMemberConditionsDefinition.HaveReturnType(types));
public TNextElement HaveReturnType(IEnumerable<Type> types) => HaveReturnType(new SystemTypeObjectProvider<IType>(types));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I just realized that there are still two versions of HaveReturnType depending on the input arguments in MethodMemberConditionDefinition.cs but I'm still not exactly sure if this was on purpose and if so why. Let's have a chat about this the next time.

should.NotHaveReturnType(helper.OtherRegularClassSystemType, helper.RegularClassSystemType).AssertOnlyViolations(helper);
should.NotHaveReturnType(new List<System.Type> { helper.OtherRegularClassSystemType, helper.RegularClassSystemType }).AssertOnlyViolations(helper);

// DoNotHaveReturnType predicate now uses consistent set-based semantics —

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Praise: good catch of the error in the prior implementation. :)


Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" should be called by one of no types (impossible)
Result: False
Description: System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() is not called by

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nitpick: The description is not ending correctly in this case. If it is easy to fix we should do so. If it isn't I guess it would still be okay since it is only an edge case.


----- Conditions -----

Query: Method members that are "TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass()" should not have return type "TypeNamespace.GenericClass`1[[TypeNamespace.RegularClass, TypeAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=015f...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nitpick: The description of the generic type is pretty verbose (including assembly name, version, culture, ...) and should be shortened if possible.


Query: Method members that are "TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass()" should not have return type "TypeNamespace.GenericClass`1[[TypeNamespace.RegularClass, TypeAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=015f...
Result: False
Description: TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass() has return type "TypeNamespace.GenericClass`1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In contrast: Here the description is actually to short since it is missing the actual generic type - this leads to a rather confusing error message in the end...

Description: TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass() has return type "TypeNamespace.GenericClass`1"
Message:
"Method members that are "TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass()" should have return type "TypeNamespace.GenericClass`1[[TypeNamespace.OtherRegularClass, TypeAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=015..." failed:
TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass() has return type "TypeNamespace.GenericClass`1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See comment in MethodMemberSyntaxElementsTests.DoNotHaveReturnTypeTest.verified.txt - here the error message is actually wrong now because of this.

Description: TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass() has return type "TypeNamespace.GenericClass`1"
Message:
"Method members that are "TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass()" should have return type "TypeNamespace.GenericClass`1[[TypeNamespace.OtherRegularClass, TypeAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=015..." failed:
TypeNamespace.GenericClass`1<TypeNamespace.RegularClass> TypeNamespace.ClassWithGenericReturnType::MethodReturningGenericClass() has return type "TypeNamespace.GenericClass`1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See comment in MethodMemberSyntaxElementsTests.DoNotHaveReturnTypeTest.verified.txt - here the error message is actually wrong now because of this.

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.

3 participants