diff --git a/src/Analyzers/MSTest.Analyzers/AvoidAssertAreSameWithValueTypesAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/AvoidAssertAreSameWithValueTypesAnalyzer.cs
index fc6a8b0fec..4da001105c 100644
--- a/src/Analyzers/MSTest.Analyzers/AvoidAssertAreSameWithValueTypesAnalyzer.cs
+++ b/src/Analyzers/MSTest.Analyzers/AvoidAssertAreSameWithValueTypesAnalyzer.cs
@@ -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;
@@ -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));
}
}
}
diff --git a/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs b/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
index 8b7c3bc0da..0b67805132 100644
--- a/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
+++ b/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
@@ -181,7 +181,7 @@ internal static string AssertionArgsShouldBePassedInCorrectOrderTitle {
}
///
- /// Looks up a localized string similar to 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..
+ /// Looks up a localized string similar to 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..
///
internal static string AvoidAssertAreSameWithValueTypesDescription {
get {
@@ -190,7 +190,7 @@ internal static string AvoidAssertAreSameWithValueTypesDescription {
}
///
- /// Looks up a localized string similar to Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types.
+ /// Looks up a localized string similar to Use '{0}' instead of '{1}' when comparing value types.
///
internal static string AvoidAssertAreSameWithValueTypesMessageFormat {
get {
@@ -199,7 +199,7 @@ internal static string AvoidAssertAreSameWithValueTypesMessageFormat {
}
///
- /// Looks up a localized string similar to Don't use 'Assert.AreSame' with value types.
+ /// Looks up a localized string similar to Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types.
///
internal static string AvoidAssertAreSameWithValueTypesTitle {
get {
diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx
index 93e6d7f3da..a0c20d4122 100644
--- a/src/Analyzers/MSTest.Analyzers/Resources.resx
+++ b/src/Analyzers/MSTest.Analyzers/Resources.resx
@@ -544,12 +544,12 @@ The type declaring these methods should also respect the following rules:
'[DynamicData]' member '{0}.{1}' is not a property nor a method. Only properties and methods are supported.
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- 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.
+ 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.
-
\ No newline at end of file
+
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
index 6e330b099f..fea7e43a4b 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
@@ -118,18 +118,18 @@ Typ deklarující tyto metody by měl také respektovat následující pravidla:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
index e8158f968a..d97754638a 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
@@ -118,18 +118,18 @@ Der Typ, der diese Methoden deklariert, sollte auch die folgenden Regeln beachte
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
index d906f03e01..5314ae2834 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
@@ -118,18 +118,18 @@ El tipo que declara estos métodos también debe respetar las reglas siguientes:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
index 5007193e4a..8c619eb032 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
@@ -118,18 +118,18 @@ Le type doit être une classe
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
index 04e4eab6eb..5f77bc4ccc 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
@@ -118,18 +118,18 @@ Anche il tipo che dichiara questi metodi deve rispettare le regole seguenti:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf
index ef8201b9f2..c6bd722af3 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf
@@ -118,18 +118,18 @@ The type declaring these methods should also respect the following rules:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf
index 01418be2c5..aa32398e06 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf
@@ -118,18 +118,18 @@ The type declaring these methods should also respect the following rules:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf
index 71f8dc79e2..519ae66ab8 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf
@@ -118,18 +118,18 @@ Typ deklarujący te metody powinien również przestrzegać następujących regu
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf
index 07cc18781f..31cea31278 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf
@@ -118,18 +118,18 @@ O tipo que declara esses métodos também deve respeitar as seguintes regras:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf
index ec3a3f092e..d7be24e727 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf
@@ -121,18 +121,18 @@ The type declaring these methods should also respect the following rules:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf
index efebdd5ad3..67a0463e19 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf
@@ -118,18 +118,18 @@ Bu yöntemleri bildiren tipin ayrıca aşağıdaki kurallara uyması gerekir:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf
index 2c8a1b9bc0..b6bc1e5a0d 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf
@@ -118,18 +118,18 @@ The type declaring these methods should also respect the following rules:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf
index c8c3516c3c..508370179d 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf
@@ -118,18 +118,18 @@ The type declaring these methods should also respect the following rules:
- 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.
- 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.
+ 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.
+ 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.
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
- Use 'Assert.AreEqual' instead of 'Assert.AreSame' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
+ Use '{0}' instead of '{1}' when comparing value types
- Don't use 'Assert.AreSame' with value types
- Don't use 'Assert.AreSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
+ Don't use 'Assert.AreSame' or 'Assert.AreNotSame' with value types
diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidAssertAreSameWithValueTypesAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidAssertAreSameWithValueTypesAnalyzerTests.cs
index 42c8306e5e..11f7b53938 100644
--- a/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidAssertAreSameWithValueTypesAnalyzerTests.cs
+++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidAssertAreSameWithValueTypesAnalyzerTests.cs
@@ -57,4 +57,52 @@ public void TestMethod()
await VerifyCS.VerifyCodeFixAsync(code, code);
}
+
+ [TestMethod]
+ public async Task UseAssertAreNotSameWithValueTypes_Diagnostic()
+ {
+ string code = """
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using System.Collections.Generic;
+
+ [TestClass]
+ public class MyTestClass
+ {
+ [TestMethod]
+ public void TestMethod()
+ {
+ // Both are value types
+ [|Assert.AreNotSame(0, 1)|];
+ [|Assert.AreNotSame(0, 1, "Message")|];
+ [|Assert.AreNotSame(0, 1, "Message {0}", "Arg")|];
+ [|Assert.AreNotSame(message: "Message", notExpected: 0, actual: 1)|];
+
+ [|Assert.AreNotSame