@@ -240,27 +240,38 @@ private CreateChangedDocument TryComputeFixForNunitThat(IInvocationOperation inv
240240 }
241241
242242 if ( invocation . Arguments [ 1 ] . Value . UnwrapConversion ( ) is not IPropertyReferenceOperation constraint ) return null ;
243+ var subject = invocation . Arguments [ 0 ] . Value ;
243244
244- switch ( constraint . Property . Name )
245+ if ( IsPropertyOfSymbol ( constraint , "True" , t . Is ) // Assert.That(subject, Is.True)
246+ || IsPropertyOfSymbol ( constraint , "Not" , "False" , t . Is ) ) // Assert.That(subject, Is.False)
247+ return RenameAssertThatAssertionToSubjectShouldAssertion ( "BeTrue" ) ;
248+ else if ( IsPropertyOfSymbol ( constraint , "False" , t . Is ) // Assert.That(subject, Is.False)
249+ || IsPropertyOfSymbol ( constraint , "Not" , "True" , t . Is ) ) // Assert.That(subject, Is.Not.True)
250+ return RenameAssertThatAssertionToSubjectShouldAssertion ( "BeFalse" ) ;
251+ else if ( IsPropertyOfSymbol ( constraint , "Null" , t . Is ) ) // Assert.That(subject, Is.Null)
252+ return RenameAssertThatAssertionToSubjectShouldAssertion ( "BeNull" ) ;
253+ else if ( IsPropertyOfSymbol ( constraint , "Not" , "Null" , t . Is ) ) // Assert.That(subject, Is.Not.Null)
254+ return RenameAssertThatAssertionToSubjectShouldAssertion ( "NotBeNull" ) ;
255+ else if ( subject . Type . SpecialType is not SpecialType . System_Collections_IEnumerable )
245256 {
246- case "True" when constraint . Property . ContainingType . EqualsSymbol ( t . Is ) : // Assert.That(subject, Is.True)
247- case "False" when constraint . Instance is IPropertyReferenceOperation { Property . Name : "Not" } chainedReference && PropertyReferencedFromType ( chainedReference , t . Is ) : // Assert.That(subject, Is.Not.False)
248- return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeTrue" , subjectIndex : 0 , argumentsToRemove : [ 1 ] ) ;
249- case "True" when constraint . Instance is IPropertyReferenceOperation { Property . Name : "Not" } chainedReference && PropertyReferencedFromType ( chainedReference , t . Is ) : // Assert.That(subject, Is.Not.True)
250- case "False" when PropertyReferencedFromType ( constraint , t . Is ) : // Assert.That(subject, Is.False)
251- return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeFalse" , subjectIndex : 0 , argumentsToRemove : [ 1 ] ) ;
252- case "Null" when PropertyReferencedFromType ( constraint , t . Is ) : // Assert.That(subject, Is.Null)
253- return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeNull" , subjectIndex : 0 , argumentsToRemove : [ 1 ] ) ;
254- case "Null" when constraint . Instance is IPropertyReferenceOperation { Property . Name : "Not" } chainedReference && PropertyReferencedFromType ( chainedReference , t . Is ) : // Assert.That(subject, Is.Not.Null)
255- return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "NotBeNull" , subjectIndex : 0 , argumentsToRemove : [ 1 ] ) ;
256-
257- default :
258- return null ;
257+ if ( IsPropertyOfSymbol ( constraint , "Empty" , t . Is ) ) // Assert.That(subject, Is.Empty)
258+ return RenameAssertThatAssertionToSubjectShouldAssertion ( "BeEmpty" ) ;
259+ else if ( IsPropertyOfSymbol ( constraint , "Not" , "Empty" , t . Is ) ) // Assert.That(subject, Is.Not.Empty)
260+ return RenameAssertThatAssertionToSubjectShouldAssertion ( "NotBeEmpty" ) ;
259261 }
260262
263+ return null ;
264+
265+ CreateChangedDocument RenameAssertThatAssertionToSubjectShouldAssertion ( string assertionName )
266+ => DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , assertionName , subjectIndex : 0 , argumentsToRemove : [ 1 ] ) ;
261267 }
262268
263- private static bool PropertyReferencedFromType ( IPropertyReferenceOperation propertyReference , INamedTypeSymbol type ) => propertyReference . Property . ContainingType . EqualsSymbol ( type ) ;
269+ private static bool IsPropertyReferencedFromType ( IPropertyReferenceOperation propertyReference , INamedTypeSymbol type )
270+ => propertyReference . Property . ContainingType . EqualsSymbol ( type ) ;
271+ private static bool IsPropertyOfSymbol ( IPropertyReferenceOperation propertyReference , string firstProperty , string secondProperty , INamedTypeSymbol type )
272+ => propertyReference . Property . Name == secondProperty && IsPropertyOfSymbol ( propertyReference . Instance , firstProperty , type ) ;
273+ private static bool IsPropertyOfSymbol ( IOperation operation , string property , INamedTypeSymbol type )
274+ => operation is IPropertyReferenceOperation propertyReference && propertyReference . Property . Name == property && IsPropertyReferencedFromType ( propertyReference , type ) ;
264275
265276 public class NunitCodeFixContext ( Compilation compilation ) : TestingFrameworkCodeFixProvider . TestingFrameworkCodeFixContext ( compilation )
266277 {
0 commit comments