1
1
using System . Collections . Immutable ;
2
2
using System . Composition ;
3
+ using System . Runtime . InteropServices . ComTypes ;
3
4
using Microsoft . CodeAnalysis ;
4
5
using Microsoft . CodeAnalysis . CodeFixes ;
5
6
using Microsoft . CodeAnalysis . Operations ;
@@ -26,6 +27,20 @@ protected override CreateChangedDocument TryComputeFix(IInvocationOperation invo
26
27
return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeSameAs" , subjectIndex : 1 , argumentsToRemove : [ ] ) ;
27
28
case "NotSame" when ArgumentsAreTypeOf ( invocation , t . Object , t . Object ) : // Assert.NotSame(object expected, object actual)
28
29
return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "NotBeSameAs" , subjectIndex : 1 , argumentsToRemove : [ ] ) ;
30
+ case "Equivalent" when ArgumentsCount ( invocation , 2 ) : // Assert.Equivalent(object? expected, object? actual)
31
+ return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeEquivalentTo" , subjectIndex : 1 , argumentsToRemove : [ ] ) ;
32
+ case "Equivalent" when ArgumentsCount ( invocation , 3 ) : // Assert.Equivalent(object? expected, object? actual, bool strict = false)
33
+ {
34
+ if ( invocation . Arguments [ 2 ] . Value is ILiteralOperation literal )
35
+ {
36
+ return literal . ConstantValue . Value switch {
37
+ false => DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeEquivalentTo" , subjectIndex : 1 , argumentsToRemove : literal . IsImplicit ? [ ] : [ 2 ] ) ,
38
+ _ => null
39
+ } ;
40
+ }
41
+
42
+ return null ; // passing a reference for the "strict" argument
43
+ }
29
44
case "Equal" when ArgumentsAreTypeOf ( invocation , t . Float , t . Float , t . Float ) : // Assert.Equal(float expected, float actual, float tolerance)
30
45
case "Equal" when ArgumentsAreTypeOf ( invocation , t . Double , t . Double , t . Double ) : // Assert.Equal(double expected, double actual, double tolerance)
31
46
return DocumentEditorUtils . RenameMethodToSubjectShouldAssertion ( invocation , context , "BeApproximately" , subjectIndex : 1 , argumentsToRemove : [ ] ) ;
0 commit comments