Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void AnalyzeOperation(OperationAnalysisContext context, INamedTyp
{
var operation = (IInvocationOperation)context.Operation;
IMethodSymbol targetMethod = operation.TargetMethod;
if (targetMethod.Name != "AreSame" ||
if ((targetMethod.Name != "AreSame" && targetMethod.Name != "AreNotSame") ||
!assertSymbol.Equals(operation.TargetMethod.ContainingType, SymbolEqualityComparer.Default))
{
return;
Expand All @@ -72,7 +72,8 @@ private static void AnalyzeOperation(OperationAnalysisContext context, INamedTyp
if (argExpected.Value.WalkDownConversion().Type?.IsValueType == true ||
argActual.Value.WalkDownConversion().Type?.IsValueType == true)
{
context.ReportDiagnostic(operation.CreateDiagnostic(Rule));
string suggestedReplacement = targetMethod.Name == "AreSame" ? "AreEqual" : "AreNotEqual";
context.ReportDiagnostic(operation.CreateDiagnostic(Rule, targetMethod.Name, suggestedReplacement));
}
}
}
6 changes: 3 additions & 3 deletions src/Analyzers/MSTest.Analyzers/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Analyzers/MSTest.Analyzers/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ The type declaring these methods should also respect the following rules:
<value>'[DynamicData]' member '{0}.{1}' is not a property nor a method. Only properties and methods are supported.</value>
</data>
<data name="AvoidAssertAreSameWithValueTypesTitle" xml:space="preserve">
<value>Don't use 'Assert.AreSame' with value types</value>
<value>Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</value>
</data>
<data name="AvoidAssertAreSameWithValueTypesMessageFormat" xml:space="preserve">
<value>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</value>
<value>Use '{0}' instead of '{1}' when comparing value types</value>
</data>
<data name="AvoidAssertAreSameWithValueTypesDescription" xml:space="preserve">
<value>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</value>
<value>Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</value>
</data>
</root>
</root>
12 changes: 6 additions & 6 deletions src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ Typ deklarující tyto metody by měl také respektovat následující pravidla:
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesDescription">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</target>
<source>Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</source>
<target state="new">Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesMessageFormat">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</target>
<source>Use '{0}' instead of '{1}' when comparing value types</source>
<target state="new">Use '{0}' instead of '{1}' when comparing value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesTitle">
<source>Don't use 'Assert.AreSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' with value types</target>
<source>Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidExpectedExceptionAttributeDescription">
Expand Down
12 changes: 6 additions & 6 deletions src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ Der Typ, der diese Methoden deklariert, sollte auch die folgenden Regeln beachte
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesDescription">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</target>
<source>Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</source>
<target state="new">Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesMessageFormat">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</target>
<source>Use '{0}' instead of '{1}' when comparing value types</source>
<target state="new">Use '{0}' instead of '{1}' when comparing value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesTitle">
<source>Don't use 'Assert.AreSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' with value types</target>
<source>Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidExpectedExceptionAttributeDescription">
Expand Down
12 changes: 6 additions & 6 deletions src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ El tipo que declara estos métodos también debe respetar las reglas siguientes:
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesDescription">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</target>
<source>Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</source>
<target state="new">Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesMessageFormat">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</target>
<source>Use '{0}' instead of '{1}' when comparing value types</source>
<target state="new">Use '{0}' instead of '{1}' when comparing value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesTitle">
<source>Don't use 'Assert.AreSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' with value types</target>
<source>Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidExpectedExceptionAttributeDescription">
Expand Down
12 changes: 6 additions & 6 deletions src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ Le type doit être une classe
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesDescription">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</target>
<source>Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</source>
<target state="new">Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesMessageFormat">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</target>
<source>Use '{0}' instead of '{1}' when comparing value types</source>
<target state="new">Use '{0}' instead of '{1}' when comparing value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesTitle">
<source>Don't use 'Assert.AreSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' with value types</target>
<source>Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidExpectedExceptionAttributeDescription">
Expand Down
12 changes: 6 additions & 6 deletions src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ Anche il tipo che dichiara questi metodi deve rispettare le regole seguenti:
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesDescription">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types. Passing a value type to 'Assert.AreSame' will be boxed (creating a new object). Because 'Assert.AreSame' does the comparison by reference, it will fail when boxing happens.</target>
<source>Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</source>
<target state="new">Use 'Assert.AreEqual'/'Assert.AreNotEqual' instead of 'Assert.AreSame'/'Assert.AreNotSame' when comparing value types. Passing a value type to 'Assert.AreSame'/'Assert.AreNotSame' will be boxed (creating a new object). Because 'Assert.AreSame'/'Assert.AreNotSame' does the comparison by reference, 'Assert.AreSame' will fail when boxing happens, and 'Assert.AreNotSame' will always pass.</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesMessageFormat">
<source>Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</source>
<target state="new">Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types</target>
<source>Use '{0}' instead of '{1}' when comparing value types</source>
<target state="new">Use '{0}' instead of '{1}' when comparing value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidAssertAreSameWithValueTypesTitle">
<source>Don't use 'Assert.AreSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' with value types</target>
<source>Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</source>
<target state="new">Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types</target>
<note />
</trans-unit>
<trans-unit id="AvoidExpectedExceptionAttributeDescription">
Expand Down
Loading